/* ==========================================================================
   CC Pilot — mobile-first control surface for Claude Code
   ========================================================================== */

:root {
  --bg: #0d0e12;
  --bg-elev: #14161d;
  --surface: #1a1d26;
  --surface-2: #222634;
  --surface-3: #2b3041;
  --border: #2c3140;
  --border-soft: #232734;
  --text: #e8eaf0;
  --text-dim: #a3aabb;
  --text-faint: #6d7488;
  --accent: #d97757;
  --accent-soft: #d9775722;
  --accent-text: #eda183;
  --ok: #56d364;
  --warn: #e3b341;
  --danger: #f85149;
  --info: #6cb6ff;
  --purple: #b083f0;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;

  --tap: 44px;
  --sb-h: 46px;
  --tab-h: 56px;

  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  --ease: cubic-bezier(.2, .8, .3, 1);
}

html[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --surface-3: #e2e6ec;
  --border: #d5dae2;
  --border-soft: #e6e9ef;
  --text: #16181d;
  --text-dim: #5a6272;
  --text-faint: #8a92a3;
  --accent: #c2603c;
  --accent-soft: #c2603c1a;
  --accent-text: #a04d2e;
  --ok: #1a7f37;
  --warn: #9a6700;
  --danger: #cf222e;
  --info: #0969da;
  --purple: #8250df;
  --shadow: 0 8px 24px rgba(20, 25, 40, .12);
}

@media (prefers-color-scheme: light) {
  html[data-theme="auto"] {
    --bg: #f6f7f9;
    --bg-elev: #ffffff;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --surface-3: #e2e6ec;
    --border: #d5dae2;
    --border-soft: #e6e9ef;
    --text: #16181d;
    --text-dim: #5a6272;
    --text-faint: #8a92a3;
    --accent: #c2603c;
    --accent-soft: #c2603c1a;
    --accent-text: #a04d2e;
    --ok: #1a7f37;
    --warn: #9a6700;
    --danger: #cf222e;
    --info: #0969da;
    --purple: #8250df;
    --shadow: 0 8px 24px rgba(20, 25, 40, .12);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--info); text-decoration: none; }
a:active { opacity: .7; }

::selection { background: var(--accent); color: #fff; }

/* Scrollbars — visible on desktop, invisible on touch */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Boot splash ---------- */
.boot {
  position: fixed; inset: 0; display: grid; place-content: center; gap: 18px;
  justify-items: center; background: var(--bg); z-index: 999;
}
.boot-logo {
  width: 54px; height: 54px; border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #b8503a);
  animation: pulse 1.6s var(--ease) infinite;
}
.boot-text { color: var(--text-faint); font-size: 14px; letter-spacing: .02em; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1 } 50% { transform: scale(.9); opacity: .6 } }

/* ---------- App frame ---------- */
#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  padding-left: var(--sal);
  padding-right: var(--sar);
}

/* ---------- Status bar ---------- */
.statusbar {
  position: relative;
  padding: calc(var(--sat) + 5px) 10px 5px;
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border-soft);
  display: flex; flex-direction: column; gap: 5px;
  z-index: 20;
}
.sb-row { display: flex; align-items: center; gap: 7px; min-height: 26px; }
.sb-row.scroll {
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  -webkit-overflow-scrolling: touch; padding-bottom: 1px;
}
.sb-row.scroll::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border-soft);
  font-size: 11.5px; font-weight: 500; white-space: nowrap; flex: 0 0 auto;
  color: var(--text-dim); line-height: 1.35;
}
.chip b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip.tap { cursor: pointer; }
.chip.tap:active { background: var(--surface-2); }
.chip.accent { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.chip.danger { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.chip.warn { border-color: var(--warn); color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.chip.ok { border-color: var(--ok); color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.chip.mono b { font-family: var(--mono); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: 0 0 auto; }
.dot.live { background: var(--ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 70%, transparent); animation: ring 2.2s ease-out infinite; }
.dot.warn { background: var(--warn); }
.dot.dead { background: var(--danger); }
@keyframes ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent) } 70% { box-shadow: 0 0 0 7px transparent } 100% { box-shadow: 0 0 0 0 transparent } }

.meter { width: 30px; height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; flex: 0 0 auto; }
.meter > i { display: block; height: 100%; background: var(--info); transition: width .35s var(--ease), background .3s; }
.meter > i.hot { background: var(--warn); }
.meter > i.crit { background: var(--danger); }

/* thin progress line for the running turn */
.sb-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; overflow: hidden; }
.sb-progress > i {
  display: block; height: 100%; width: 34%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: slide 1.4s linear infinite;
}
@keyframes slide { from { transform: translateX(-100%) } to { transform: translateX(320%) } }

/* ---------- View ---------- */
.view { overflow: hidden; position: relative; display: flex; flex-direction: column; min-height: 0; }
/* Each view mounts its own .view inside #view; it has to claim the height. */
.view > .view { flex: 1 1 auto; min-height: 0; }
.scroller {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain;
  padding: 12px 12px 8px;
}
.scroller.pad-bottom { padding-bottom: 24px; }

/* ---------- Tab bar ---------- */
.tabbar {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--bg-elev) 94%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--border-soft);
  padding-bottom: var(--sab);
  z-index: 20;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: var(--tab-h); color: var(--text-faint);
  font-size: 10.5px; font-weight: 500; position: relative; transition: color .18s;
}
.tab svg { width: 21px; height: 21px; stroke-width: 1.9; }
.tab[aria-selected="true"] { color: var(--accent); }
.tab:active { background: var(--surface); }
.tab .badge {
  position: absolute; top: 6px; left: 50%; margin-left: 6px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  display: grid; place-content: center;
}

/* ---------- Generic bits ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: var(--tap); padding: 0 16px; border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  font-size: 15px; font-weight: 600; border: 1px solid var(--border);
  transition: transform .12s var(--ease), background .16s;
}
.btn:active { transform: scale(.97); background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: color-mix(in srgb, var(--accent) 85%, #000); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 34px; padding: 0 11px; font-size: 13px; border-radius: var(--radius-sm); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn svg { width: 18px; height: 18px; stroke-width: 2; flex: 0 0 auto; }

.card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 10px;
}
.card-head {
  display: flex; align-items: center; gap: 9px; padding: 11px 13px;
  font-size: 13.5px; font-weight: 600;
}
.card-body { padding: 0 13px 12px; }
.card-body.tight { padding: 0; }

.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.tiny { font-size: 11.5px; }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.nums { font-variant-numeric: tabular-nums; }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.breakall { word-break: break-all; overflow-wrap: anywhere; }
.hidden { display: none !important; }

.section-title {
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-faint); margin: 18px 3px 8px;
}
.section-title:first-child { margin-top: 4px; }

.list { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  padding: 11px 13px; min-height: var(--tap); border-bottom: 1px solid var(--border-soft);
  background: none;
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--surface-2); }
.list-item .ico { width: 20px; height: 20px; flex: 0 0 auto; color: var(--text-dim); }
.list-item .ico svg { width: 20px; height: 20px; stroke-width: 1.8; }

.empty { text-align: center; padding: 44px 20px; color: var(--text-faint); }
.empty svg { width: 42px; height: 42px; opacity: .4; margin-bottom: 12px; stroke-width: 1.5; }

.field { margin-bottom: 13px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 10px 13px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 16px; /* 16px stops iOS from zooming on focus */
}
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
/* Stays at 16px: anything smaller makes iOS Safari zoom in on focus. */
.textarea { min-height: 96px; resize: vertical; font-family: var(--mono); font-size: 16px; line-height: 1.5; }
.select { appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a3aabb' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
.switch { position: relative; width: 46px; height: 28px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; }
.switch i {
  position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3);
  transition: background .2s var(--ease);
}
.switch i::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: transform .2s var(--ease);
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }

.seg {
  display: flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 3px;
  overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 0 auto; min-height: 34px; padding: 0 12px; border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--text-dim); white-space: nowrap;
  transition: background .16s, color .16s;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }

/* ---------- Chat ---------- */
.chat-scroller { padding: 10px 10px 6px; }

.msg { margin-bottom: 12px; animation: fade .22s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(5px) } to { opacity: 1; transform: none } }

.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  max-width: 88%; background: var(--accent); color: #fff;
  padding: 9px 13px; border-radius: 17px 17px 5px 17px;
  font-size: 15px; overflow-wrap: anywhere;
}
.msg.user .bubble pre { background: rgba(0,0,0,.22); }

.msg.assistant .prose { font-size: 15.3px; }

.msg .who {
  display: flex; align-items: center; gap: 6px; margin-bottom: 5px;
  font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-faint);
}
.msg .who .agent { color: var(--purple); text-transform: none; letter-spacing: 0; font-weight: 600; }

/* thinking */
.think {
  border-left: 2px solid var(--purple); background: color-mix(in srgb, var(--purple) 7%, transparent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin: 8px 0; overflow: hidden;
}
.think > summary {
  padding: 8px 12px; font-size: 12.5px; font-weight: 600; color: var(--purple);
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 7px;
}
.think > summary::-webkit-details-marker { display: none; }
.think[open] > summary { border-bottom: 1px solid color-mix(in srgb, var(--purple) 18%, transparent); }
.think .prose { padding: 9px 12px; font-size: 13.5px; color: var(--text-dim); font-style: italic; }

/* tool cards */
.tool {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); margin: 7px 0; overflow: hidden;
}
.tool.running { border-color: var(--accent); }
.tool.err { border-color: var(--danger); }
.tool > summary {
  display: flex; align-items: center; gap: 8px; padding: 9px 11px;
  cursor: pointer; list-style: none; min-height: 40px; font-size: 13.5px;
}
.tool > summary::-webkit-details-marker { display: none; }
.tool .tname { font-weight: 700; flex: 0 0 auto; }
.tool .targ { color: var(--text-dim); font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.tool .tico { width: 17px; height: 17px; flex: 0 0 auto; color: var(--text-dim); }
.tool .tico svg { width: 17px; height: 17px; stroke-width: 2; }
.tool.running .tico { color: var(--accent); animation: spin 1.4s linear infinite; }
.tool.ok .tico { color: var(--ok); }
.tool.err .tico { color: var(--danger); }
@keyframes spin { to { transform: rotate(360deg) } }
.tool-body { border-top: 1px solid var(--border-soft); padding: 9px 11px; }
.tool-label { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); margin: 8px 0 4px; }
.tool-label:first-child { margin-top: 0; }

/* turn footer */
.turn-meta {
  display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 14px;
  padding-top: 8px; border-top: 1px dashed var(--border-soft);
}

/* code */
pre {
  background: var(--bg-elev); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 10px 12px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; margin: 8px 0;
  tab-size: 2;
}
pre code { background: none; padding: 0; font-size: inherit; }
code {
  font-family: var(--mono); font-size: .88em; padding: 1.5px 5px;
  background: var(--surface-2); border-radius: 5px; overflow-wrap: anywhere;
}
.codewrap { position: relative; }
.codewrap > .copy {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  padding: 4px 8px; font-size: 11px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  opacity: .85;
}
.codewrap > .copy:active { background: var(--surface-3); }
.codewrap > .lang {
  position: absolute; top: 8px; left: 10px; font-size: 10px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-faint); pointer-events: none;
}
.codewrap.has-lang pre { padding-top: 24px; }

/* syntax colors */
.hl-key { color: #ff7b72; } .hl-str { color: #a5d6ff; } .hl-num { color: #79c0ff; }
.hl-com { color: var(--text-faint); font-style: italic; } .hl-fn { color: #d2a8ff; }
.hl-typ { color: #ffa657; } .hl-punc { color: var(--text-dim); } .hl-attr { color: #7ee787; }
html[data-theme="light"] .hl-key { color: #cf222e; }
html[data-theme="light"] .hl-str { color: #0a3069; }
html[data-theme="light"] .hl-num { color: #0550ae; }
html[data-theme="light"] .hl-fn { color: #8250df; }
html[data-theme="light"] .hl-typ { color: #953800; }
html[data-theme="light"] .hl-attr { color: #116329; }
@media (prefers-color-scheme: light) {
  html[data-theme="auto"] .hl-key { color: #cf222e; }
  html[data-theme="auto"] .hl-str { color: #0a3069; }
  html[data-theme="auto"] .hl-num { color: #0550ae; }
  html[data-theme="auto"] .hl-fn { color: #8250df; }
  html[data-theme="auto"] .hl-typ { color: #953800; }
  html[data-theme="auto"] .hl-attr { color: #116329; }
}

/* diff */
.diff { font-family: var(--mono); font-size: 12px; line-height: 1.5; overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border-soft); }
.diff .dl { display: flex; white-space: pre; min-width: max-content; }
.diff .dl > .n { flex: 0 0 auto; width: 40px; padding: 0 6px; text-align: right; color: var(--text-faint); background: var(--bg-elev); user-select: none; font-size: 11px; }
.diff .dl > .c { flex: 1; padding: 0 10px 0 6px; }
.diff .add { background: color-mix(in srgb, var(--ok) 15%, transparent); }
.diff .add > .c { color: var(--ok); }
.diff .del { background: color-mix(in srgb, var(--danger) 13%, transparent); }
.diff .del > .c { color: var(--danger); }
.diff .hunk { background: var(--surface-2); color: var(--info); }
.diff .meta { color: var(--text-faint); }

/* prose */
.prose { overflow-wrap: anywhere; }
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }
.prose p { margin: .55em 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 1em 0 .45em; line-height: 1.3; font-weight: 700; }
.prose h1 { font-size: 1.32em; } .prose h2 { font-size: 1.18em; } .prose h3 { font-size: 1.06em; } .prose h4 { font-size: 1em; }
.prose ul, .prose ol { margin: .5em 0; padding-left: 1.35em; }
.prose li { margin: .22em 0; }
.prose li::marker { color: var(--text-faint); }
.prose blockquote { margin: .6em 0; padding: .1em 0 .1em .9em; border-left: 3px solid var(--border); color: var(--text-dim); }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 1.1em 0; }
.prose table { border-collapse: collapse; width: 100%; font-size: .9em; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border-soft); padding: 6px 9px; text-align: left; }
.prose th { background: var(--surface-2); font-weight: 600; }
.prose img { max-width: 100%; border-radius: var(--radius-sm); }
.prose a { text-decoration: underline; text-underline-offset: 2px; }

.caret::after {
  content: ''; display: inline-block; width: 7px; height: 1.05em; margin-left: 2px;
  background: var(--accent); vertical-align: text-bottom; border-radius: 1px;
  animation: blink 1.05s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0 } }

/* ---------- Composer ---------- */
.composer {
  border-top: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--bg-elev) 96%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 7px 9px calc(7px + var(--sab));
  display: flex; flex-direction: column; gap: 7px;
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; min-height: 42px; max-height: 40dvh; padding: 10px 13px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 21px;
  font-size: 16px; line-height: 1.4; resize: none; overflow-y: auto;
  font-family: var(--sans);
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-content: center;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  transition: transform .12s var(--ease);
}
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 20px; height: 20px; stroke-width: 2; }
.icon-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.icon-btn:disabled { opacity: .4; pointer-events: none; }

.quickbar { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 1px; }
.quickbar::-webkit-scrollbar { display: none; }

.attach-strip { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; }
.attach-strip::-webkit-scrollbar { display: none; }
.attach {
  position: relative; width: 58px; height: 58px; border-radius: var(--radius-sm);
  overflow: hidden; flex: 0 0 auto; border: 1px solid var(--border);
}
.attach img { width: 100%; height: 100%; object-fit: cover; }
.attach button {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.65); color: #fff; display: grid; place-content: center; font-size: 13px;
}

/* slash palette */
.palette {
  position: absolute; left: 8px; right: 8px; bottom: 100%; margin-bottom: 6px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 44dvh; overflow-y: auto; z-index: 30;
}
.palette-item { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--border-soft); }
.palette-item:last-child { border-bottom: none; }
.palette-item[aria-selected="true"], .palette-item:active { background: var(--surface-2); }
.palette-item .p-name { font-family: var(--mono); font-size: 13.5px; font-weight: 600; color: var(--accent-text); }
.palette-item .p-desc { font-size: 12px; color: var(--text-dim); }

/* ---------- Permission sheet ---------- */
.perm {
  border: 1.5px solid var(--warn); border-radius: var(--radius);
  background: color-mix(in srgb, var(--warn) 8%, var(--surface));
  margin: 10px 0; overflow: hidden;
  animation: rise .26s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }
.perm-head { display: flex; align-items: center; gap: 9px; padding: 11px 13px 8px; }
.perm-head .ico { color: var(--warn); }
.perm-head .ico svg { width: 21px; height: 21px; stroke-width: 2; }
.perm-title { font-weight: 700; font-size: 14.5px; }
.perm-sub { font-size: 12px; color: var(--text-dim); }
.perm-body { padding: 0 13px 10px; }
.perm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 13px 13px; }
.perm-actions .wide { grid-column: 1 / -1; }

/* ---------- Sheets / modals ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 100;
  animation: fadein .2s var(--ease); backdrop-filter: blur(2px);
}
@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 101;
  background: var(--bg-elev); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-top: 1px solid var(--border); box-shadow: var(--shadow);
  max-height: 92dvh; display: flex; flex-direction: column;
  padding-bottom: var(--sab);
  animation: slideup .28s var(--ease);
}
@keyframes slideup { from { transform: translateY(100%) } to { transform: none } }
.sheet-grab { width: 38px; height: 4px; border-radius: 2px; background: var(--surface-3); margin: 8px auto 4px; flex: 0 0 auto; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 6px 14px 10px; border-bottom: 1px solid var(--border-soft); flex: 0 0 auto; }
.sheet-title { font-size: 16px; font-weight: 700; }
/* flex:1 + min-height:0 — without them the body refuses to shrink below its
   content and slides underneath the action row. */
.sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 13px 14px; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 14px; border-top: 1px solid var(--border-soft); display: flex; gap: 9px; flex: 0 0 auto; }

/* ---------- Toasts ---------- */
.toast-host {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--sab) + 14px); z-index: 200;
  display: flex; flex-direction: column; gap: 7px; align-items: center;
  pointer-events: none; width: min(94vw, 460px);
}
.toast {
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  padding: 9px 15px; border-radius: 999px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow); animation: toastin .25s var(--ease);
  max-width: 100%; text-align: center;
}
.toast.ok { border-color: var(--ok); color: var(--ok); }
.toast.err { border-color: var(--danger); color: var(--danger); }
@keyframes toastin { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: none } }

/* ---------- Terminal ---------- */
.term-wrap { flex: 1; min-height: 0; background: #000; position: relative; }
.term-host { position: absolute; inset: 0; padding: 5px 4px 0 9px; }
html[data-theme="light"] .term-wrap { background: #14161d; }
.term-keys {
  display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none;
  padding: 6px 8px; background: var(--bg-elev); border-top: 1px solid var(--border-soft);
}
.term-keys::-webkit-scrollbar { display: none; }
.term-keys button {
  flex: 0 0 auto; min-width: 40px; height: 36px; padding: 0 10px;
  border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--text-dim);
}
.term-keys button:active, .term-keys button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.term-input {
  position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px;
}

/* ---------- Login ---------- */
.login {
  display: grid; place-content: center; justify-items: center; gap: 20px;
  height: 100dvh; padding: 28px; text-align: center;
}
.login-logo { width: 68px; height: 68px; border-radius: 20px; background: linear-gradient(135deg, var(--accent), #b8503a); box-shadow: var(--shadow); }
.login h1 { margin: 0; font-size: 25px; letter-spacing: -.02em; }
.login p { margin: 0; color: var(--text-dim); max-width: 33ch; font-size: 14.5px; }
.login .btn { min-width: 230px; }

/* ---------- File browser ---------- */
.crumbs { display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 8px; font-size: 12.5px; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs button { padding: 4px 8px; border-radius: 7px; background: var(--surface); border: 1px solid var(--border-soft); color: var(--text-dim); white-space: nowrap; font-family: var(--mono); font-size: 12px; }
.crumbs button:last-child { color: var(--text); border-color: var(--border); }

.fsize { font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; flex: 0 0 auto; }

.gstat { display: inline-block; width: 17px; text-align: center; font-family: var(--mono); font-size: 11px; font-weight: 700; flex: 0 0 auto; }
.gstat.m { color: var(--warn); } .gstat.a { color: var(--ok); } .gstat.d { color: var(--danger); } .gstat.u { color: var(--info); }

/* ---------- Misc ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; font-size: 13px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.spark { display: block; width: 100%; height: 30px; }

.banner {
  display: flex; align-items: center; gap: 9px; padding: 10px 13px;
  border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 11px;
}
.banner.warn { background: color-mix(in srgb, var(--warn) 13%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); color: var(--warn); }
.banner.danger { background: color-mix(in srgb, var(--danger) 13%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.banner.info { background: color-mix(in srgb, var(--info) 12%, transparent); border: 1px solid color-mix(in srgb, var(--info) 35%, transparent); color: var(--info); }
.banner svg { width: 19px; height: 19px; flex: 0 0 auto; stroke-width: 2; }

.skel { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%); background-size: 400% 100%; animation: shimmer 1.3s linear infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { from { background-position: 100% 0 } to { background-position: 0 0 } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (min-width: 760px) {
  #app { max-width: 900px; margin: 0 auto; border-left: 1px solid var(--border-soft); border-right: 1px solid var(--border-soft); }
  .scroller, .chat-scroller { padding-left: 18px; padding-right: 18px; }
  .msg.user .bubble { max-width: 74%; }
}
