:root {
  /* One look with the HQ dashboard: James navy, cyan accent (same tokens as yt-channel's dashboard page). */
  --bg: #0b2a4f;
  --bg2: #0e3766;
  --panel: #123f73;
  --panel2: #184b86;
  --ink: #f2f7ff;
  --muted: #a9c3e6;
  --line: rgba(255, 255, 255, .14);
  --accent: #7fd4ff;
  --accent-ink: #06213f;
  --bubble-in: #123f73;
  --bubble-out: #7fd4ff;
  --bubble-out-ink: #06213f;
  --ok: #6fe3a1;
  --warn: #ffc857;
  --danger: #ff8a8a;
  --shadow: none;
  --radius: 18px;
  --tabbar-h: 58px;
  /* bottom inset; app.js sets 0 when the web view already ends above the home indicator (iOS standalone, see fitShell) */
  --sab: env(safe-area-inset-bottom);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  background-image: radial-gradient(120% 80% at 50% 0, #1c5aa0 0, var(--bg2) 45%, var(--bg) 100%);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
/* The shell is 100dvh; .short-view (app.js) drops the bottom inset when the web view stops above the home indicator; while the phone keyboard is up app.js sets --app-h/--app-top from the visual viewport. */
#app { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: 100dvh; height: var(--app-h, 100dvh); display: flex; flex-direction: column; overflow: hidden; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: var(--accent); padding: 10px; cursor: pointer; font-size: 15px; }
.link.center { display: block; margin: 8px auto; }
.icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn:active { background: var(--line); }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn svg, .send-btn svg { width: 24px; height: 24px; }
.icon-btn.small svg { width: 18px; height: 18px; }

/* ---------- login ---------- */
#login { align-items: center; justify-content: center; padding: 24px 16px calc(24px + var(--sab)); }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-avatar { margin: 0 auto 4px; border-radius: 22px; box-shadow: 0 6px 24px rgba(0,0,0,.35); }
.login-card h1 { margin: 0; font-size: 28px; letter-spacing: -.01em; }
.login-card p { margin: 0 0 8px; }
.code-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; text-align: left; }
.label { font-size: 13px; color: var(--muted); font-weight: 600; }
#code-input {
  min-height: 50px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); font-size: 22px; letter-spacing: .25em; text-align: center; font-variant-numeric: tabular-nums;
}
.msg { min-height: 1.4em; font-size: 14px; color: var(--muted); margin: 0; }
.msg.error { color: var(--danger); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px 16px;
  background: rgba(11, 42, 79, .92);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.avatar { border-radius: 50%; flex: none; }
.who { flex: 1; min-width: 0; }
.name { font-weight: 700; font-size: 17px; }
.status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.online .dot { background: var(--ok); }
.status.offline .dot { background: var(--warn); }

.banner {
  display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 16px; font-size: 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.banner span { flex: 1; }

/* ---------- messages ---------- */
#messages { flex: 1; overflow-y: auto; padding: 12px 12px 8px; -webkit-overflow-scrolling: touch; }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0 8px; font-weight: 600; }
.row { display: flex; gap: 8px; margin: 2px 0; align-items: flex-end; }
.row.user { justify-content: flex-end; }
.row.gap { margin-top: 10px; }
.row .mini { width: 28px; height: 28px; border-radius: 50%; flex: none; }
.row .mini.spacer { visibility: hidden; }
.stack { display: flex; flex-direction: column; max-width: min(78%, 520px); gap: 4px; }
.row.user .stack { align-items: flex-end; }
.bubble {
  padding: 9px 13px; border-radius: var(--radius); background: var(--bubble-in); box-shadow: var(--shadow);
  overflow-wrap: anywhere; white-space: normal;
}
.row.assistant .bubble { border-bottom-left-radius: 6px; }
.row.user .bubble { background: var(--bubble-out); color: var(--bubble-out-ink); border-bottom-right-radius: 6px; }
.bubble p { margin: 0 0 6px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0; padding-left: 22px; }
.bubble code { font: 13.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: color-mix(in srgb, currentColor 10%, transparent); padding: 1px 5px; border-radius: 5px; }
.bubble pre { margin: 6px 0; padding: 8px 10px; border-radius: 10px; overflow-x: auto; background: color-mix(in srgb, currentColor 8%, transparent); }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: inherit; text-decoration: underline; }
.meta { font-size: 11px; color: var(--muted); padding: 0 6px; display: flex; gap: 4px; align-items: center; }
.meta svg { width: 14px; height: 14px; }
.meta .ok { color: var(--accent); }
.reactions { font-size: 15px; margin-top: -10px; padding: 0 6px; z-index: 1; }
.reactions span { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0 6px; }

.media { display: grid; gap: 4px; grid-template-columns: repeat(2, 1fr); }
.media.one { grid-template-columns: 1fr; }
.media img {
  display: block; width: 100%; max-width: 260px; max-height: 320px; object-fit: cover; border-radius: 14px;
  background: var(--line); cursor: zoom-in; aspect-ratio: auto;
}
.media:not(.one) img { height: 130px; max-width: 130px; }
.file {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; text-decoration: none;
  background: var(--bubble-in); color: var(--ink); border: 1px solid var(--line); min-width: 200px; max-width: 280px;
}
.file .ficon { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; flex: none; }
.file .fname { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .fsize { font-size: 12px; color: var(--muted); }
.file .ftext { min-width: 0; flex: 1; }
.file svg { width: 20px; height: 20px; color: var(--muted); flex: none; }

.perm { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px; margin: 10px auto; max-width: 360px; }
.perm h3 { margin: 0 0 4px; font-size: 15px; }
.perm p { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.perm pre { font-size: 12px; max-height: 140px; overflow: auto; background: var(--bg); padding: 8px; border-radius: 8px; margin: 0 0 10px; white-space: pre-wrap; }
.perm .actions { display: flex; gap: 8px; } .perm .actions .btn { flex: 1; }
.perm .result { font-weight: 600; font-size: 14px; }

.typing-bubble { display: flex; gap: 4px; padding: 13px 14px; margin-left: 36px; }
.typing-bubble span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing-bubble span:nth-child(2) { animation-delay: .2s; } .typing-bubble span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.pill {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--tabbar-h) + var(--sab));
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 20px; padding: 8px 16px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.18);
}

/* ---------- composer ---------- */
.composer { border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 92%, transparent); padding: 8px; }
#app:not(.tabs) .composer { padding-bottom: calc(8px + var(--sab)); }
.composer-row { display: flex; align-items: flex-end; gap: 2px; }
#input {
  flex: 1; resize: none; max-height: 140px; min-height: 40px; padding: 9px 14px; margin: 0 4px;
  border-radius: 20px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font: inherit; font-size: 16px; line-height: 1.35;
}
.send-btn { width: 40px; height: 40px; flex: none; border-radius: 50%; border: 0; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); cursor: pointer; }
.send-btn:disabled { opacity: .35; }
.pending { display: flex; gap: 8px; overflow-x: auto; padding: 4px 4px 8px; }
.chip { position: relative; flex: none; }
.chip img, .chip .chip-file { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); font-size: 11px; padding: 4px; text-align: center; overflow: hidden; word-break: break-all; }
.chip button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--ink); color: var(--bg); font-size: 14px; line-height: 22px; padding: 0; cursor: pointer; }

/* ---------- sheet, viewer, toast ---------- */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; z-index: 20; }
.sheet-panel { width: 100%; background: var(--panel); border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + var(--sab)); }
.sheet-item { display: block; width: 100%; text-align: left; padding: 15px 4px; border: 0; border-bottom: 1px solid var(--line); background: none; font-size: 16px; cursor: pointer; }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel { border: 0; text-align: center; font-weight: 600; color: var(--muted); }
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: calc(100dvh - 120px); object-fit: contain; }
.viewer-bar { position: absolute; bottom: calc(16px + var(--sab)); display: flex; gap: 10px; }
.toast { position: fixed; top: calc(64px + env(safe-area-inset-top)); left: 16px; right: 16px; margin: 0 auto; max-width: 360px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 14px; text-align: center; z-index: 40; }
#code-input::placeholder { letter-spacing: normal; font-size: 17px; }
.pending { padding-top: 10px; }

/* ---------- app shell: bottom tabs + HQ dashboard ---------- */
.tabbar {
  flex: none; display: flex; gap: 4px; padding: 6px 6px calc(6px + var(--sab));
  background: rgba(11, 42, 79, .97); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.tabbar button {
  position: relative; flex: 1 1 auto; min-width: 0; min-height: 52px; padding: 4px 6px; border-radius: 14px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tabbar button[aria-selected="true"] { background: var(--panel2); color: var(--ink); border-color: var(--accent); }
.tabbar .ti { width: 24px; height: 24px; display: grid; place-items: center; }
.tabbar .ti svg { width: 24px; height: 24px; }
.tabbar .tl { font-size: 11.5px; letter-spacing: -.01em; font-weight: 600; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tabbar .badge {
  position: absolute; top: 3px; left: calc(50% + 6px); min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  font-size: 12px; font-weight: 700; line-height: 19px; text-align: center; background: var(--warn); color: #1b1300;
}
.tabbar .badge.unread { background: var(--accent); color: var(--accent-ink); }
#app.kb .tabbar { display: none; }
#dash { background: var(--bg); padding-top: env(safe-area-inset-top); }
#dash-frame { flex: 1; width: 100%; border: 0; display: block; background: var(--bg); }
#app.short-view { --sab: 0px; }
