/* Lyra Remote: shared styles. No inline styles anywhere (the CSP forbids them). */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2230;
  --muted: #5d6676;
  --line: #e1e4ea;
  --accent: #1f6feb;
  --accent-hover: #1a5fd0;
  --accent-ink: #ffffff;
  --ok: #1a9b4b;
  --off: #a3aab5;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --info-soft: #e8f0fe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13161b;
    --card: #1c2028;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --line: #2c323d;
    --accent: #4c8dff;
    --accent-hover: #6aa0ff;
    --accent-ink: #0b1220;
    --ok: #3cc46f;
    --off: #69717e;
    --danger: #ff6b5e;
    --danger-soft: #3a1d1b;
    --info-soft: #1b2a44;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 1.05rem; margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small-text { font-size: .88rem; }
.error { color: var(--danger); margin: .25rem 0; }
.ok-text { color: var(--ok); font-weight: 600; }
.offscreen { position: fixed; left: -9999px; top: 0; }

/* ---------------------------------------------------------------- layout */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-weight: 650;
  color: var(--text);
  text-decoration: none;
}
.who { display: flex; align-items: center; gap: .75rem; }

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 3rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
}
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 420px; margin: 2.5rem auto; padding: 1.5rem 1.75rem; }
.empty { color: var(--muted); }
.pad { padding: 1rem 1.25rem; margin: 0; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.5rem 0 .75rem;
}
.section-head:first-child { margin-top: .25rem; }

.notice {
  margin: 0 0 1rem;
  padding: .6rem .9rem;
  border-radius: 8px;
  background: var(--info-soft);
}
.notice.error { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------- forms and buttons */

.form { display: flex; flex-direction: column; gap: .85rem; }
.form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 550; }
input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .7rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[readonly] { color: var(--muted); }
textarea { width: 100%; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  font: inherit;
  font-weight: 550;
  padding: .5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.small { padding: .25rem .65rem; font-size: .88rem; }
.btn.wide { width: 100%; padding: .65rem 1rem; }

/* ---------------------------------------------------------------- devices */

.devices { display: flex; flex-direction: column; gap: .75rem; }
.device { padding: .85rem 1.1rem; }
.device-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.device-actions { display: flex; gap: .5rem; margin-left: auto; }
.device.is-offline .name-input { color: var(--muted); }

.name-input {
  font-size: 1.08rem;
  font-weight: 650;
  background: transparent;
  border: 1px solid transparent;
  padding: .2rem .4rem;
  margin-left: -.4rem;
  min-width: 8ch;
  max-width: 100%;
  flex: 0 1 22rem;
}
.name-input:hover { border-color: var(--line); }

.dot { width: .7rem; height: .7rem; border-radius: 50%; flex: none; background: var(--off); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }

.badge {
  font-size: .78rem;
  font-weight: 600;
  padding: .1rem .5rem;
  border-radius: 999px;
  background: var(--info-soft);
  color: var(--accent);
}
.badge.live { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }

.device-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: .35rem 1.25rem;
  margin-top: .6rem;
}
.meta { display: flex; flex-direction: column; min-width: 0; }
.meta-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.meta-value { overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- enrolment */

.enroll { margin-bottom: .75rem; border-color: var(--accent); }
.enroll-head { display: flex; align-items: center; justify-content: space-between; }
.enroll .code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.25rem; letter-spacing: .06em; }
.steps { margin: .5rem 0; padding-left: 1.3rem; }
.steps li { margin: .3rem 0; }
.cmd {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .8rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.cmd code { flex: 1; overflow-wrap: anywhere; user-select: all; }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .55rem .9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .detail { color: var(--muted); overflow-wrap: anywhere; }
.open-cell { display: inline-flex; gap: .5rem; align-items: center; }
.kind { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.kind-login_fail, .kind-device_revoked, .kind-setup_failed { color: var(--danger); }

.audit { margin-top: 1.5rem; padding: 0; }
.audit summary { padding: .8rem 1.25rem; cursor: pointer; font-weight: 600; }
.audit[open] summary { border-bottom: 1px solid var(--line); }

/* Phone width: tables become stacked cards. */
@media (max-width: 640px) {
  .page { padding: 1rem .75rem 2rem; }
  .topbar { padding: .6rem .9rem; }
  .card.narrow { margin: 1rem auto; padding: 1.25rem; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: .5rem .9rem; border-bottom: 1px solid var(--line); }
  .table td { border: 0; padding: .15rem 0; display: flex; gap: .75rem; }
  .table td::before { content: attr(data-label); flex: 0 0 5.5rem; color: var(--muted); font-size: .8rem; text-transform: uppercase; }
  .device-actions { margin-left: 0; width: 100%; }
  .device-actions .btn { flex: 1; }
  .name-input { flex: 1 1 auto; }
}

/* ---------------------------------------------------------------- setup */

.step { margin-top: .75rem; font-size: 1.02rem; }
.qr { display: flex; justify-content: center; padding: .5rem; background: #fff; border-radius: 8px; border: 1px solid var(--line); }
.qr img { display: block; width: 210px; height: 210px; image-rendering: pixelated; }
.secret { font-size: 1rem; letter-spacing: .04em; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- viewer */

body.viewer {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0d0f12;
  color: #e6e8ec;
}

.vbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .35rem .5rem;
  padding: .35rem .6rem;
  background: #1a1d23;
  border-bottom: 1px solid #2c313a;
  font-size: .86rem;
  flex: none;
}
.vname { margin-right: .25rem; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vsep { width: 1px; height: 1.2rem; background: #343a44; }
.vbtn {
  display: inline-flex;
  align-items: center;
  font: inherit;
  color: #e6e8ec;
  background: #262a32;
  border: 1px solid #343a44;
  border-radius: 6px;
  padding: .25rem .6rem;
  cursor: pointer;
  text-decoration: none;
}
.vbtn:hover { background: #30353f; }
.vbtn.danger { color: #ff8a80; }
.vlabel { display: inline-flex; align-items: center; gap: .3rem; color: #9aa3b2; }
.vlabel select { background: #262a32; border-color: #343a44; color: #e6e8ec; padding: .2rem .35rem; border-radius: 6px; font-size: .86rem; }
.vstatus { margin-left: auto; display: inline-flex; gap: .6rem; color: #c7ccd5; white-space: nowrap; }
.vdim { color: #8c95a3; }
body[data-state="connected"] #stState { color: #3cc46f; }
body[data-state="ended"] #stState { color: #ff8a80; }

.stage { flex: 1; min-height: 0; position: relative; }
.stage.fit { display: flex; align-items: center; justify-content: center; overflow: hidden; }
.stage.actual { overflow: auto; }
.stage canvas { display: block; background: #000; cursor: default; touch-action: none; }
.stage.actual canvas { margin: 0; }
.stage canvas:focus { outline: none; }
body[data-state="connected"] .stage canvas:focus { box-shadow: 0 0 0 2px #1f6feb inset; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 15, 18, .78);
  z-index: 10;
}
.overlay-box {
  max-width: 30rem;
  margin: 1rem;
  padding: 1.5rem 1.75rem;
  text-align: center;
  background: #1c2028;
  border: 1px solid #2c323d;
  border-radius: 12px;
}
.ov-text { font-size: 1.15rem; font-weight: 600; margin: .5rem 0; }
.ov-sub { color: #aab2bf; margin: .25rem 0 1rem; }
.ov-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin: 0; }
.overlay .btn { background: #262a32; color: #e6e8ec; border-color: #343a44; }
.overlay .btn.primary { background: #1f6feb; border-color: #1f6feb; color: #fff; }

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto .5rem;
  border-radius: 50%;
  border: 3px solid #343a44;
  border-top-color: #4c8dff;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: #262a32;
  color: #e6e8ec;
  border: 1px solid #343a44;
  border-radius: 8px;
  padding: .5rem 1rem;
  z-index: 20;
  max-width: 90vw;
}

.dialog {
  width: min(36rem, 92vw);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  padding: 1.25rem 1.5rem;
}
.dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; }
