/* MonkViewer web client. Design language: docs/design/V2-PLAN.md section 7. */

:root {
  color-scheme: light dark;
  --bg: #F5F7FB;
  --surface: #FFFFFF;
  --surface-hover: #EEF2F9;
  --border: #DCE3EF;
  --text: #101826;
  --text-2: #5B6B85;
  --accent: #2D6AE0;
  --accent-text: #FFFFFF;
  --accent-soft: rgba(45, 106, 224, 0.12);
  --success: #1F9D5B;
  --warning: #B7791F;
  --danger: #D64545;
  --danger-soft: rgba(214, 69, 69, 0.1);
  --shadow: 0 1px 2px rgba(16, 24, 38, 0.06), 0 4px 16px rgba(16, 24, 38, 0.06);
  --shadow-lg: 0 12px 48px rgba(16, 24, 38, 0.22);
  --scrim: rgba(16, 24, 38, 0.38);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --r-card: 10px;
  --r-ctl: 8px;
  --r-chip: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1220;
    --surface: #141E31;
    --surface-hover: #1B2840;
    --border: #2C3D5B;
    --text: #F3F6FF;
    --text-2: #AABBD6;
    --accent: #3478F6;
    --accent-soft: rgba(52, 120, 246, 0.18);
    --success: #34C77B;
    --warning: #F5B54A;
    --danger: #F06A6A;
    --danger-soft: rgba(240, 106, 106, 0.14);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 16px 56px rgba(0, 0, 0, 0.55);
    --scrim: rgba(3, 7, 15, 0.6);
  }
}
:root[data-theme="dark"] {
  --bg: #0B1220;
  --surface: #141E31;
  --surface-hover: #1B2840;
  --border: #2C3D5B;
  --text: #F3F6FF;
  --text-2: #AABBD6;
  --accent: #3478F6;
  --accent-soft: rgba(52, 120, 246, 0.18);
  --success: #34C77B;
  --warning: #F5B54A;
  --danger: #F06A6A;
  --danger-soft: rgba(240, 106, 106, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 16px 56px rgba(0, 0, 0, 0.55);
  --scrim: rgba(3, 7, 15, 0.6);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.icon.icon-more { stroke-width: 3.2; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.logo-bg { fill: var(--accent); }
.logo-fg { fill: none; stroke: #fff; stroke-width: 1.8; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- shell ------------------------------------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 232px 1fr; height: 100%; }
.sidebar {
  display: flex; flex-direction: column; gap: 24px;
  background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; border: 0; border-radius: var(--r-ctl);
  background: none; color: var(--text-2); cursor: pointer; text-decoration: none; font-weight: 500; text-align: left;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.foot-label { font-size: 12px; color: var(--text-2); }
.foot-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-line { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-2); flex: none; }
.dot.ok { background: var(--success); }
.dot.warn { background: var(--warning); }
.dot.bad { background: var(--danger); }

.main { overflow-y: auto; min-width: 0; }
.page { max-width: 1040px; margin: 0 auto; padding: 32px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-title { font-size: 20px; font-weight: 650; letter-spacing: -0.015em; margin: 0; }
.section-title { font-size: 15px; font-weight: 600; margin: 32px 0 12px; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }

/* ---- buttons, fields ------------------------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 14px;
  border-radius: var(--r-ctl); border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 550; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--surface-hover); }
.btn.icon-only { width: 32px; padding: 0; }
.btn.lg { height: 40px; padding: 0 18px; font-size: 15px; }
.btn.block { width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-weight: 550; }
.input, .select {
  height: 36px; padding: 0 12px; border-radius: var(--r-ctl); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); outline: none; min-width: 0;
}
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.code { font: 600 20px/1 var(--mono); letter-spacing: 0.08em; text-align: center; height: 52px; text-transform: uppercase; }
.input.invalid { border-color: var(--danger); }
.hint { font-size: 12px; color: var(--text-2); }
.error-text { font-size: 12px; color: var(--danger); }

/* switch */
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 10px; background: var(--border); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.segmented { display: inline-flex; padding: 2px; border-radius: var(--r-ctl); background: var(--bg); border: 1px solid var(--border); }
.segmented button { border: 0; background: none; height: 28px; padding: 0 12px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-weight: 550; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: var(--r-chip); background: var(--bg); color: var(--text-2); font-size: 12px; font-weight: 550; }
.chip.ok { color: var(--success); }
.kbd { font: 600 12px var(--mono); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); background: var(--bg); }

/* ---- device cards ------------------------------------------------------------------------------------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 16px; }
.card {
  position: relative; display: flex; flex-direction: column; gap: 12px; padding: 16px; border-radius: var(--r-card);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); transition: border-color .12s, transform .12s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.card-top { display: flex; align-items: flex-start; gap: 12px; }
.device-glyph { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.device-glyph .icon { width: 22px; height: 22px; }
.card-name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.card-sub { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.card-id { font: 12px var(--mono); color: var(--text-2); }
.card-actions { display: flex; gap: 8px; align-items: center; }
.card-actions .btn.primary { flex: 1; }

/* empty state */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 56px 24px; border: 1px dashed var(--border); border-radius: 14px; background: var(--surface); }
.empty h2 { margin: 8px 0 0; font-size: 20px; letter-spacing: -0.015em; }
.empty p { margin: 0; max-width: 440px; color: var(--text-2); }
.illustration { width: 168px; height: 112px; }
.illustration .il-a { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.illustration .il-b { fill: var(--surface); stroke: var(--border); stroke-width: 2; }
.illustration .il-c { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-dasharray: 4 5; }
.illustration .il-d { fill: var(--accent); }

.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-card); background: var(--surface); border: 1px solid var(--border); margin-bottom: 16px; }
.notice .icon { color: var(--warning); margin-top: 1px; }
.notice.error .icon { color: var(--danger); }

/* ---- menus ---------------------------------------------------------------------------------------------- */
.menu { position: fixed; z-index: 60; min-width: 196px; padding: 6px; border-radius: var(--r-card); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; height: 32px; padding: 0 10px; border: 0; border-radius: 6px; background: none; cursor: pointer; text-align: left; }
.menu button:hover, .menu button:focus-visible { background: var(--surface-hover); outline: none; }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 4px; }

/* ---- dialogs / sheets ------------------------------------------------------------------------------------ */
.scrim { position: fixed; inset: 0; z-index: 50; background: var(--scrim); display: grid; place-items: center; padding: 16px; animation: fade .14s ease-out; }
.sheet {
  width: min(440px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg); padding: 24px; display: flex; flex-direction: column; gap: 16px;
  animation: rise .18s cubic-bezier(.2,.8,.2,1);
}
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 20px; letter-spacing: -0.015em; }
.sheet-head p { margin: 4px 0 0; color: var(--text-2); }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; }
.disclosure { border-top: 1px solid var(--border); padding-top: 12px; }
.disclosure summary { cursor: pointer; color: var(--text-2); font-weight: 550; list-style: none; display: flex; align-items: center; gap: 6px; }
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary .icon { width: 16px; height: 16px; transition: transform .15s; }
.disclosure[open] summary .icon { transform: rotate(90deg); }
.disclosure-body { display: flex; flex-direction: column; gap: 14px; padding-top: 14px; }
.inline-form { display: flex; gap: 8px; }
.inline-form .input { flex: 1; }

.progress { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 8px 0; }
.progress h3 { margin: 0; font-size: 15px; }
.progress p { margin: 0; color: var(--text-2); max-width: 340px; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.status-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; }
.status-icon.bad { background: var(--danger-soft); color: var(--danger); }
.status-icon.ok { background: var(--accent-soft); color: var(--accent); }
.status-icon .icon { width: 22px; height: 22px; }
.verify { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 20px; border-radius: var(--r-card); background: var(--bg); }
.verify-code { font: 600 28px/1.1 var(--mono); letter-spacing: 0.06em; }
.steps { display: flex; gap: 6px; }
.steps span { width: 28px; height: 4px; border-radius: 2px; background: var(--border); }
.steps span.on { background: var(--accent); }

/* ---- settings ------------------------------------------------------------------------------------------- */
.settings { display: grid; grid-template-columns: 180px 1fr; gap: 32px; align-items: start; }
.settings-nav { position: sticky; top: 0; display: flex; flex-direction: column; gap: 2px; }
.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); margin-bottom: 24px; }
.group-title { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; min-height: 56px; }
.row + .row { border-top: 1px solid var(--border); }
.row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-text .hint { max-width: 520px; }
.row .input { width: 240px; }
.relay-host { font-weight: 600; overflow-wrap: anywhere; }
.log { font: 11px/1.5 var(--mono); white-space: pre-wrap; max-height: 280px; overflow: auto; padding: 12px 16px; margin: 0; color: var(--text-2); }
.caps { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; padding: 14px 16px; }
.cap { display: flex; align-items: center; gap: 8px; }
.cap .icon { width: 16px; height: 16px; }
.cap.yes .icon { color: var(--success); }
.cap.no { color: var(--text-2); }

/* ---- toasts --------------------------------------------------------------------------------------------- */
.toasts { position: fixed; z-index: 80; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--r-card); background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-weight: 550; animation: rise .18s ease-out; max-width: min(520px, calc(100vw - 32px)); }

/* ---- stream ---------------------------------------------------------------------------------------------- */
.stage { position: fixed; inset: 0; z-index: 40; background: #000; display: grid; place-items: center; outline: none; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage canvas.video { width: 100%; height: 100%; object-fit: contain; display: block; }
.stage.hide-cursor { cursor: none; }
.remote-cursor { position: absolute; left: 0; top: 0; pointer-events: none; image-rendering: auto; display: none; }
.stream-pill {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 6px 0 12px; border-radius: 17px; background: rgba(20, 30, 49, 0.82); color: #F3F6FF;
  border: 1px solid rgba(255,255,255,.12); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 6px 24px rgba(0,0,0,.35); transition: opacity .25s, transform .25s; font-weight: 550; cursor: default;
}
.stream-pill.dim { opacity: 0.18; }
.stream-pill:hover, .stream-pill.open { opacity: 1; }
.stream-pill .btn { height: 26px; border-radius: 13px; color: #F3F6FF; background: rgba(255,255,255,.08); border-color: transparent; padding: 0 10px; }
.stream-pill .btn:hover { background: rgba(255,255,255,.16); }
.stream-pill .name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stream-menu {
  position: absolute; top: 52px; left: 50%; transform: translateX(-50%); z-index: 3; width: min(340px, calc(100vw - 24px));
  max-height: calc(100vh - 72px); overflow-y: auto; padding: 8px; border-radius: 12px; background: rgba(20, 30, 49, 0.94); color: #F3F6FF;
  border: 1px solid rgba(255,255,255,.12); box-shadow: 0 16px 56px rgba(0,0,0,.55); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.stream-menu .m-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; padding: 2px 8px; border-radius: 8px; }
.stream-menu button.m-row { width: 100%; border: 0; background: none; color: inherit; cursor: pointer; text-align: left; justify-content: flex-start; }
.stream-menu button.m-row:hover { background: rgba(255,255,255,.08); }
.stream-menu button.m-row.danger { color: #F06A6A; }
.stream-menu .m-label { display: flex; align-items: center; gap: 10px; }
.stream-menu hr { border: 0; border-top: 1px solid rgba(255,255,255,.12); margin: 6px 4px; }
.stream-menu .select { height: 28px; padding: 0 8px; background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.14); color: #F3F6FF; }
.stream-menu .select option { color: #101826; }
.stream-menu .switch span { background: rgba(255,255,255,.2); }
.stream-menu .m-head { padding: 6px 8px 8px; display: flex; flex-direction: column; gap: 2px; }
.stream-menu .m-head .small { color: #AABBD6; }
.stats {
  position: absolute; top: 10px; left: 10px; z-index: 2; padding: 8px 10px; border-radius: 8px; background: rgba(0,0,0,.62); color: #E6ECF8;
  font: 11px/1.55 var(--mono); white-space: pre; pointer-events: none;
}
.stage-overlay { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; background: rgba(0,0,0,.55); color: #F3F6FF; }
.stage-overlay .box { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding: 24px; max-width: 420px; }
.stage-overlay .box p { margin: 0; color: #AABBD6; }
.stage-overlay .spinner { border-color: rgba(255,255,255,.2); border-top-color: #fff; }
.kbd-input { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; }

/* ---- motion -------------------------------------------------------------------------------------------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0s !important; transition: none !important; } .spinner { animation: spin 1.6s linear infinite !important; } }

/* ---- small screens ----------------------------------------------------------------------------------------- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .sidebar { flex-direction: row; align-items: center; gap: 8px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; flex-direction: row; justify-content: space-around; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
  .nav-item { flex-direction: column; height: auto; gap: 2px; padding: 4px 16px; font-size: 11px; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; align-items: flex-end; }
  .sidebar-foot .foot-label, .sidebar-foot .foot-name { display: none; }
  .main { padding-bottom: 72px; }
  .page { padding: 20px 16px; }
  .page-title { font-size: 20px; }
  .settings { grid-template-columns: 1fr; gap: 16px; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; }
  .settings-nav .nav-item { flex-direction: row; font-size: 13px; padding: 0 10px; height: 32px; white-space: nowrap; }
  .row { flex-wrap: wrap; }
  .row .input { width: 100%; }
  .sheet { padding: 20px; }
  .scrim { place-items: end center; padding: 0; }
  .scrim .sheet { width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* The page's own controls over the stream never take the device's cursor (it can be hidden there). */
.stream-pill, .stream-menu, .stage-overlay { cursor: default; }
.stream-pill button, .stream-menu button, .stream-menu select, .stream-menu input, .stage-overlay button { cursor: pointer; }
