/* Soki Live Browser. Tokens follow the Soki desk (crm/engine/oe/portal.py). */
:root {
  --bg: #0a0a0a;
  --s1: #161617;
  --s2: #111112;
  --line: #232325;
  --hair: #1a1a1c;
  --fg: #f5f5f7;
  --mut: #8a8a8f;
  --mut2: #6e6e73;
  --brand: #d8ff62;
  --brand-fg: #d8ff62;
  --brand-dim: rgba(216, 255, 98, 0.12);
  --brand-ink: #0a0a0a;
  --amber: #ff9f0a;
  --amber-dim: rgba(255, 159, 10, 0.14);
  --red: #ff6961;
  --blue: #64d2ff;
  --stage: #050505;
  --r: 12px;
  --pill: 980px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #fbfbfd;
    --s1: #f0f0f3;
    --s2: #f6f6f8;
    --line: #dcdce0;
    --hair: #e8e8ec;
    --fg: #1d1d1f;
    --mut: #5e5e63;
    --mut2: #76767b;
    --brand-fg: #4a6b00;
    --brand-dim: rgba(120, 160, 0, 0.12);
    --amber: #b25d00;
    --amber-dim: rgba(255, 159, 10, 0.16);
    --red: #d70015;
    --blue: #0066cc;
    --stage: #e9e9ed;
    color-scheme: light;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", sans-serif;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app { display: flex; flex-direction: column; height: 100dvh; }

/* ---------------------------------------------------------------- top bar */
.bar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--hair); background: var(--bg);
  min-height: 52px;
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 0 1 auto; }
.who b { font-weight: 600; white-space: nowrap; }
.profile { color: var(--mut); font: 12px/1 ui-monospace, "SF Mono", Menlo, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mut2); flex: none; }
.app[data-live="1"] .dot { background: var(--brand); box-shadow: 0 0 0 3px var(--brand-dim); }
.app[data-state="waiting"] .dot { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-dim); }
.status {
  flex: 1; min-width: 0; color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center;
}
.status strong { color: var(--fg); font-weight: 600; }
.right { display: flex; align-items: center; gap: 8px; flex: none; }
.viewers, .clock { color: var(--mut2); font: 12px/1 ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }
.clock.low { color: var(--amber); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 14px; border-radius: var(--pill);
  border: 1px solid var(--line); background: var(--s1); color: var(--fg);
  font-size: 13.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 80ms;
}
.btn:hover { border-color: var(--mut2); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--mut); }
.btn.ghost:hover { color: var(--fg); background: var(--s1); }
.btn.icon { width: 32px; padding: 0; }
.btn.tiny { height: 22px; width: 22px; padding: 0; font-size: 16px; }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* ---------------------------------------------------------------- banner */
.banner {
  display: flex; align-items: center; gap: 12px; padding: 9px 16px;
  background: var(--amber-dim); color: var(--fg); border-bottom: 1px solid rgba(255, 159, 10, 0.35);
}
.banner.mine { background: var(--brand-dim); border-bottom-color: rgba(216, 255, 98, 0.35); }
.banner .msg { flex: 1; min-width: 0; }
.banner .msg em { font-style: normal; color: var(--mut); }

/* ---------------------------------------------------------------- browser chrome (drawn here, not captured) */
.chrome { background: var(--s2); border-bottom: 1px solid var(--hair); }
.tabs { display: flex; gap: 2px; padding: 6px 10px 0; overflow-x: auto; scrollbar-width: none; }
.tabs:empty { display: none; }
.tab {
  display: flex; align-items: center; gap: 6px; max-width: 220px; min-width: 0;
  padding: 6px 10px; border-radius: 8px 8px 0 0; color: var(--mut); background: transparent; border: 0;
  font-size: 12.5px; cursor: default;
}
.tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.on { background: var(--bg); color: var(--fg); }
.app[data-mine="1"] .tab { cursor: pointer; }
.app[data-mine="1"] .tab:not(.on):hover { color: var(--fg); background: var(--s1); }
.tab .x { opacity: 0; font-size: 14px; line-height: 1; padding: 0 2px; border-radius: 4px; }
.app[data-mine="1"] .tab:hover .x { opacity: 0.7; }
.tab .x:hover { opacity: 1; background: var(--line); }
.tab.add { color: var(--mut2); padding: 6px 10px; }
.nav { display: flex; align-items: center; gap: 4px; padding: 6px 10px; background: var(--bg); }
.url {
  flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0;
  height: 32px; padding: 0 12px; border-radius: var(--pill); background: var(--s1); border: 1px solid transparent;
  color: var(--mut2);
}
.url:focus-within { border-color: var(--blue); }
.url input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--fg); font-size: 13px; }
.url input[readonly] { color: var(--mut); cursor: default; }

/* ---------------------------------------------------------------- the stream */
.stage {
  position: relative; flex: 1; min-height: 0; background: var(--stage);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.screen { position: relative; flex: none; background: #000; box-shadow: 0 0 0 1px var(--hair); transition: box-shadow 0.2s; }
.app[data-mine="1"] .screen { box-shadow: 0 0 0 2px var(--brand), 0 0 0 6px var(--brand-dim); }
.screen canvas, .screen video { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.screen video { object-fit: fill; background: #000; }
.hit { position: absolute; inset: 0; outline: none; cursor: default; touch-action: none; }
.app[data-mine="1"] .hit { cursor: auto; }
.app[data-can-take="1"]:not([data-mine="1"]) .hit { cursor: pointer; }
.keys {
  /* the focus target for keys, IME and the phone keyboard: on the stream, invisible */
  position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; resize: none;
  font-size: 16px; /* iOS: no zoom on focus */ pointer-events: none; caret-color: transparent; color: transparent; background: transparent;
}
.agent-cursor {
  position: absolute; left: 0; top: 0; pointer-events: none; z-index: 2;
  transform: translate(-3px, -2px); transition: left 90ms linear, top 90ms linear;
  display: flex; align-items: flex-start; gap: 2px;
}
.agent-cursor span {
  margin-top: 16px; padding: 1px 6px; border-radius: 6px; background: var(--brand); color: var(--brand-ink);
  font-size: 11px; font-weight: 600;
}
.agent-cursor.click svg { animation: pulse 0.35s ease-out; }
@keyframes pulse { 0% { transform: scale(1); } 40% { transform: scale(0.8); } 100% { transform: scale(1); } }

.overlay {
  position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 5, 5, 0.62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); padding: 16px;
}
.card {
  width: min(420px, 100%); background: var(--s1); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px 22px 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); text-align: left;
}
.card h2 { margin: 0 0 6px; font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.card p { margin: 0 0 16px; color: var(--mut); }
.card .row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--brand); animation: spin 0.8s linear infinite; display: inline-block; vertical-align: -4px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- toasts, stats, dialogs */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 14px; border-radius: 12px;
  background: var(--s1); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: rise 0.18s ease-out; max-width: 440px;
}
.toast .msg { flex: 1; min-width: 0; }
.toast.warn { border-color: rgba(255, 159, 10, 0.5); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.stats {
  position: fixed; right: 16px; top: 64px; z-index: 15; width: 260px;
  background: var(--s1); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  font: 12px/1.5 ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums;
}
.stats-h { display: flex; justify-content: space-between; align-items: center; color: var(--mut); margin-bottom: 4px; font-family: inherit; }
.stats dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; }
.stats dt { color: var(--mut2); }
.stats dd { margin: 0; text-align: right; color: var(--fg); }
.stats-f { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--hair); }
.stats select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; margin-left: 6px; }

.dlg {
  border: 1px solid var(--line); border-radius: 16px; background: var(--s1); color: var(--fg);
  padding: 22px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.dlg::backdrop { background: rgba(0, 0, 0, 0.5); }
.dlg h2 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.dlg p { margin: 0 0 14px; color: var(--mut); white-space: pre-wrap; word-break: break-word; }
.dlg input { width: 100%; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 0 12px; margin-bottom: 14px; }
.dlg input:focus { outline: none; border-color: var(--blue); }
.dlg .row { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------------------------------------------------------------- phones */
@media (max-width: 720px) {
  .bar { gap: 8px; padding: 8px 12px; flex-wrap: wrap; }
  .who { order: 1; flex: 1; }
  .right { order: 2; }
  .status { order: 3; flex-basis: 100%; text-align: left; font-size: 12.5px; }
  .profile, .viewers { display: none; }
  .btn { height: 34px; }
  .nav { padding: 6px; }
  .kbd-btn { display: inline-flex; }
  .stats { left: 16px; right: 16px; width: auto; }
  .toasts { left: 16px; right: 16px; }
  .toast { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
