/* OneRemote - one stylesheet for portal, sign-in and admin console. Mobile first. */
:root {
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --muted: #5b6577;
  --line: #e3e8f0;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 4px 16px rgb(15 23 42 / 6%);
  --radius: 12px;
  --gutter: 16px;
  font-synthesis: none;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --surface: #111a2c; --surface-2: #0f1727; --ink: #e5eaf3; --muted: #93a0b5; --line: #22304a;
    --ok: #4ade80; --ok-bg: #12351f; --warn: #fbbf24; --warn-bg: #3a2a0b; --bad: #f87171; --bad-bg: #3b1414;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #111a2c; --surface-2: #0f1727; --ink: #e5eaf3; --muted: #93a0b5; --line: #22304a;
  --ok: #4ade80; --ok-bg: #12351f; --warn: #fbbf24; --warn-bg: #3a2a0b; --bad: #f87171; --bad-bg: #3b1414;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .9em; }

/* ---------- layout container: wide-screen rule lives here, in one place ---------- */
.container { width: 100%; margin: 0 auto; padding: 0 var(--gutter); }
@media (min-width: 1280px) {
  .container { max-width: min(100%, 1680px); padding: 0 clamp(1.5rem, 2.5vw, 3rem); }
}
@media (min-width: 1920px) {
  .container { max-width: 1840px; }
}
.narrow { max-width: 440px; margin: 0 auto; }
.reading { max-width: 760px; }

/* ---------- top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .container { display: flex; align-items: center; gap: 12px; min-height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.brand img, .brand .mark { width: 30px; height: 30px; border-radius: 8px; }
.brand .mark { background: var(--brand); display: grid; place-items: center; color: var(--brand-ink); font-size: 15px; }
.spacer { flex: 1; }
.topbar nav { display: flex; gap: 4px; align-items: center; min-width: 0; overflow-x: auto; scrollbar-width: none; }
@media (max-width: 520px) { .topbar .container { gap: 6px; } .topbar nav a { padding: 6px 7px; font-size: .88rem; white-space: nowrap; } .brand > span:last-child { display: none; } }
.topbar nav a { color: var(--muted); text-decoration: none; padding: 7px 10px; border-radius: 8px; font-weight: 500; }
.topbar nav a:hover, .topbar nav a.active { background: var(--surface-2); color: var(--ink); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  min-height: 38px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn.block { width: 100%; white-space: normal; text-align: center; }

/* Option cards: a list of choices with an icon, a title and a short explanation. */
.choices { display: grid; gap: 10px; margin-top: 14px; }
.choice {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  width: 100%; padding: 12px 14px; text-align: left; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.choice:hover { border-color: var(--brand); background: var(--surface-2); }
.choice:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.choice .ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 20px;
  background: color-mix(in srgb, var(--brand) 12%, transparent); }
.choice .t { display: block; font-weight: 600; }
.choice .d { display: block; font-size: .85rem; color: var(--muted); margin-top: 2px; }
.choice .go { color: var(--muted); font-size: 1.2rem; }
.choice:hover .go { color: var(--brand); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { border-color: transparent; background: transparent; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .82rem; margin-top: 3px; }
input:not([type]), input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], input[type=time],
input[type=datetime-local], input[type=url], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; min-height: 40px;
}
textarea { min-height: 90px; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 18px; height: 18px; }
.row { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .row.two { grid-template-columns: 1fr 1fr; } .row.three { grid-template-columns: 1fr 1fr 1fr; } }

/* ---------- cards & surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.reading > .card + .card, .stack > .card + .card { margin-top: 16px; }
.page { padding-top: 22px; padding-bottom: 48px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.notice { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: .92rem; }
.notice.error { background: var(--bad-bg); color: var(--bad); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); text-transform: uppercase; letter-spacing: .03em; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); } .dot.off { background: var(--bad); }

/* ---------- portal tiles ---------- */
.tiles { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px; cursor: pointer; text-align: left; color: var(--ink); font: inherit;
  transition: transform .08s ease, border-color .08s ease;
}
.tile:hover { border-color: var(--brand); transform: translateY(-1px); }
.tile .ico { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); font-size: 22px; }
.tile .name { font-weight: 700; overflow-wrap: anywhere; }
.tile .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.tile .actions { display: flex; gap: 6px; margin-top: auto; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 26px 0 12px; font-size: .95rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* ---------- sign-in ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px var(--gutter); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { justify-content: center; margin-bottom: 18px; font-size: 1.3rem; }
.auth-card .brand img, .auth-card .brand .mark { width: 40px; height: 40px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .82rem; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.code-input { font-size: 1.6rem !important; letter-spacing: .4em; text-align: center; font-family: ui-monospace, Consolas, monospace; }
.qr { display: block; margin: 10px auto; border-radius: 8px; background: #fff; padding: 6px; }

/* ---------- admin ---------- */
.admin-shell { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: calc(100vh - 58px); }
.side { background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; min-width: 0; }
.side nav { display: flex; gap: 2px; padding: 8px var(--gutter); }
.side a { display: flex; align-items: center; gap: 8px; color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 500; white-space: nowrap; }
.side a:hover { background: var(--surface-2); color: var(--ink); }
.side a.active { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); }
@media (min-width: 1024px) {
  .admin-shell { grid-template-columns: 230px minmax(0, 1fr); grid-template-rows: 1fr; }
  .side { border-bottom: 0; border-right: 1px solid var(--line); overflow: visible; }
  .side nav { flex-direction: column; position: sticky; top: 58px; padding: 14px 10px; }
}
.admin-main { min-width: 0; }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); margin-bottom: 16px; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1280px) { .stats { grid-template-columns: repeat(6, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 1.7rem; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.grid-agents { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .grid-agents { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1400px) { .grid-agents { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1800px) { .grid-agents { grid-template-columns: repeat(4, 1fr); } }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 4px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 320px; }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.bar.warn > span { background: var(--warn); } .bar.bad > span { background: var(--bad); }
.metric-row { display: grid; grid-template-columns: 48px 1fr 46px; gap: 8px; align-items: center; font-size: .82rem; margin-top: 6px; }
.chart { width: 100%; height: 160px; display: block; }

/* ---------- dialogs ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgb(0 0 0 / 30%); }
dialog.wide { width: min(980px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(10 15 30 / 55%); }
dialog .dlg-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
dialog .dlg-head h2 { margin: 0; flex: 1; }
dialog .dlg-body { padding: 18px; }
dialog .dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
.pick { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; }
.pick .check { padding: 4px 0; }
details > summary { cursor: pointer; font-weight: 600; margin: 8px 0; }
.secret-box { background: var(--surface-2); border: 1px dashed var(--line); border-radius: 9px; padding: 10px; word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }

/* ---------- remote session viewer ---------- */
body.session { background: #000; overflow: hidden; height: 100vh; }
#display { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
#display > div { box-shadow: 0 0 0 1px #111; }
.session-bar {
  position: fixed; top: 0; left: 50%; transform: translate(-50%, -100%); transition: transform .15s ease; z-index: 30;
  background: rgb(17 26 44 / 96%); color: #e5eaf3; border-radius: 0 0 12px 12px; padding: 6px 8px; display: flex; gap: 4px; align-items: center;
  flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 16px);
}
.session-bar.open { transform: translate(-50%, 0); }
.session-bar .btn { background: transparent; color: #e5eaf3; border-color: #2b3a57; min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.session-bar .btn:hover { background: #1c2942; }
.session-bar .title { padding: 0 8px; font-weight: 600; font-size: .85rem; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-handle { position: fixed; top: 0; left: 50%; transform: translateX(-50%); width: 80px; height: 10px; z-index: 29; background: rgb(37 99 235 / 75%); border-radius: 0 0 8px 8px; cursor: pointer; }
.overlay { position: fixed; inset: 0; display: grid; place-items: center; z-index: 40; background: rgb(11 18 32 / 92%); color: #e5eaf3; padding: 16px; }
.overlay .card { color: var(--ink); max-width: 440px; width: 100%; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #2b3a57; border-top-color: #60a5fa; animation: spin 0.8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.side-panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(380px, 100vw); background: var(--surface); color: var(--ink); z-index: 35; padding: 16px; overflow: auto; box-shadow: -8px 0 30px rgb(0 0 0 / 35%); }
.watermark { position: fixed; right: 12px; bottom: 10px; z-index: 25; font-size: 12px; color: rgb(255 255 255 / 45%); pointer-events: none; font-weight: 600; }
.player-controls { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: rgb(17 26 44 / 96%); color: #e5eaf3; display: flex; gap: 10px; align-items: center; padding: 8px 12px; }
.player-controls input[type=range] { flex: 1; }
.osk-input { position: fixed; left: -1000px; top: 0; opacity: 0; width: 10px; height: 10px; }
.toolbar select, .toolbar input:not([type=checkbox]) { width: auto; flex: 0 1 auto; }
.toolbar input[type=search] { flex: 1 1 200px; }
