/* Self-hosted fonts (no CDN races). Geist = distinctive grotesk for the
   minimal dev-tool direction; Geist Mono for the terminal, labels, numerals. */
@font-face {
  font-family: 'Geist';
  src: url('/vendor/fonts/Geist-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/vendor/fonts/GeistMono-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  /* fonts */
  --font-sans: 'Geist', -apple-system, system-ui, "Segoe UI", sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, Menlo, Consolas, monospace;

  /* layered graphite surfaces (base -> panel -> elevated) */
  --bg: #0a0b0d;
  --panel: #121419;
  --panel-2: #1a1d23;
  --elevated: #20242b;
  --border: #272b33;
  --border-soft: #1c1f26;
  --text: #e7e9ee;
  --muted: #939aa8;
  --faint: #6b7280;

  /* one accent (iris/indigo), used sparingly */
  --accent: #7c8cff;
  --accent-press: #6675f2;
  --accent-weak: rgba(124, 140, 255, 0.14);
  --on-accent: #0a0b12;

  --danger: #f1707b;
  --ok: #4ade80;
  --warn: #fbbf24;

  /* radii, motion, depth */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 12px 32px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);
  --dur: 160ms;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, even over component display rules
   (.modal/.tabpane/.project-chats set display, which would otherwise show
   a hidden element). One global safeguard instead of per-component fixes. */
[hidden] { display: none !important; }

html {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

body {
  margin: 0;
  padding: 0;
  position: fixed;
  inset: 0;
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  /* No text selection on the app chrome (stops Android's word-lookup popup
     when tapping the title/buttons). Terminal output and inputs stay selectable. */
  user-select: none;
  -webkit-user-select: none;
}
.terminal, .xterm, .xterm-rows, .xterm-screen, input, textarea {
  user-select: text;
  -webkit-user-select: text;
}

.screen {
  position: absolute;
  inset: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Never let any descendant push the layout wider than the screen. */
.screen > * { max-width: 100%; }

/* xterm internals must stay inside the terminal box. */
.terminal, .xterm, .xterm-viewport, .xterm-screen {
  max-width: 100%;
}

/* Keep xterm's hidden input at 16px so focusing the terminal never zooms. */
.xterm-helper-textarea {
  font-size: 16px !important;
}
.screen[hidden] { display: none; }

.muted { color: var(--muted); }
.center { text-align: center; }
.error {
  color: var(--danger);
  margin-top: 12px;
  font-size: 14px;
  text-align: center;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--r);
  padding: 14px 18px;
  font-size: 16px;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform .05s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.btn.primary:active { background: var(--accent-press); }
.btn.ghost { background: transparent; }
.btn.ghost:active { background: var(--panel-2); }
.btn.small { padding: 8px 11px; font-size: 14px; border-radius: var(--r-sm); }
/* inline icon wrapper + raw svgs inherit text color */
.ic { display: inline-flex; align-items: center; }
.btn svg, .key svg, .chat-act svg, .chip-x svg, .repo-vis svg, .chev svg, .sbtn svg { display: block; }
.chat-act svg { width: 18px; height: 18px; }
.repo-vis svg { width: 16px; height: 16px; }
.repo-vis { display: inline-flex; color: var(--faint); }
.chat-add { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
#notif-btn { color: var(--muted); }
#notif-btn.on { color: var(--accent); }
#notif-btn.on { opacity: 1; filter: none; }

/* ---------- login ---------- */
#login-screen { align-items: center; justify-content: center; padding: 24px; }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.brand { font-size: 40px; font-weight: 800; letter-spacing: -1px; color: var(--accent); }
#login-form { margin-top: 24px; display: flex; flex-direction: column; gap: 12px; }
#password {
  padding: 16px;
  font-size: 17px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}

/* ---------- form controls ---------- */
input:not([type=checkbox]):not([type=radio]), textarea {
  font-family: var(--font-sans);
  -webkit-appearance: none;
  appearance: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r);
}
input[type=checkbox] { accent-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
/* Override Chrome's white autofill background so login fields stay dark. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--panel-2) inset;
  caret-color: var(--text);
  transition: background-color 9999s ease-in-out 0s;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.topbar .title {
  flex: 1;
  font-weight: 600;
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* collapsible terminal header */
#terminal-screen.header-collapsed .topbar { display: none; }
.header-expand {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  left: 8px;
  z-index: 40;
  width: 40px;
  height: 28px;
  padding: 0;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(17, 21, 31, 0.45);
  color: var(--text);
  font-size: 14px;
  line-height: 1;
  opacity: 0.55;
}
.header-expand:active { opacity: 1; background: var(--panel-2); }
.header-expand[hidden] { display: none; }
.warn {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: #7c2d12;
  color: #fed7aa;
  font-size: 13px;
  text-align: center;
}
.dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--muted); flex: 0 0 auto;
}
.dot.connected { background: var(--ok); }
.dot.connecting { background: #fbbf24; }
.dot.offline { background: var(--danger); }

/* ---------- projects ---------- */
.projects-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.project-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
}
.project-card:active { background: var(--panel-2); }
.project-card .name { flex: 1; font-size: 17px; font-weight: 600; }
.card-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.status { font-size: 13px; color: var(--muted); }
.status.running { color: var(--ok); }
.chev { display: inline-flex; color: var(--muted); transition: transform var(--dur) var(--ease); }
.chev svg { width: 18px; height: 18px; }
.chev.open { transform: rotate(180deg); }

/* chats: expander under a project, and the sessions modal list */
.project-chats {
  margin: 6px 0 2px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-list { display: flex; flex-direction: column; gap: 6px; max-height: 60dvh; overflow-y: auto; }
.chat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.chat-row:active { background: var(--panel); }
.cdot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.cdot.running { background: var(--ok); }
.chat-name { flex: 1; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-act {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.chat-act:active { color: var(--text); background: var(--elevated); }
.chat-add {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--accent);
  border-radius: 10px;
  padding: 11px;
  font-size: 15px;
  cursor: pointer;
}
.small { font-size: 13px; }

/* ---------- terminal ---------- */
.terminal {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  padding: 6px 6px 0 6px;
  touch-action: none;
  overflow: hidden;
}

/* floating history scroll buttons */
.scrollctl {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
}
.sbtn {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background: rgba(22, 27, 39, 0.82);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.sbtn:active { background: var(--accent); color: #04201c; }
.terminal .xterm { height: 100%; }

/* key row */
.keyrow {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: nowrap; /* one row by default; the ⋯ toggle reveals the rest */
  gap: 6px;
  padding: 8px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.keyrow.show-more { flex-wrap: wrap; }
/* the mode key has the longest label; give it extra width so it isn't clipped */
.key[data-key="shifttab"] { flex-grow: 2.2; }
.key {
  flex: 1 1 0; /* equal widths so the row always fits without wrapping */
  min-width: 0;
  text-align: center;
  padding: 10px 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
}
.key:active { background: var(--accent); color: #04201c; }
/* rare keys hidden until the ⋯ toggle is pressed */
.keyrow .key-rare { display: none; }
.keyrow.show-more .key-rare { display: block; }
.key.key-toggle { flex: 0 0 auto; min-width: 44px; color: var(--muted); }
.keyrow.show-more .key-toggle { background: var(--panel); color: var(--text); }

/* compose */
.compose {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
#compose-input {
  flex: 1 1 0;
  min-width: 0;
  resize: none;
  max-height: 120px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  line-height: 1.3;
  font-family: inherit;
}
.btn.send {
  flex: 0 0 auto;
  width: 52px;
  height: 48px;
  padding: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn.attach {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  padding: 0;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* attached upload chips */
.attach-chips {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 8px 0;
  background: var(--panel);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 70vw;
  padding: 5px 6px 5px 10px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 13px;
}
.chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip.uploading { opacity: 0.6; }
.chip.error { border-color: #b23b3b; color: #ff9a9a; }
.chip-x {
  display: inline-flex;
  align-items: center;
  border: none;
  background: transparent;
  color: var(--muted);
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}
.terminal.dropping { outline: 2px dashed var(--accent); outline-offset: -6px; }

/* new project */
.btn.newproj { margin: 12px; flex: 0 0 auto; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
/* The hidden attribute must win over the display:flex above. */
.modal[hidden] { display: none; }
.modal-box {
  width: 100%;
  max-width: 520px;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 14px;
  gap: 12px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.tabs { display: flex; gap: 8px; }
.tab {
  flex: 1 1 0;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
}
.tab.active { background: var(--accent); color: #04201c; border-color: transparent; font-weight: 600; }
.tabpane { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
/* hidden tab must win over the display:flex above (same fix as .screen/.modal) */
.tabpane[hidden] { display: none; }
.tabpane input[type="text"] {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
}
.check-row { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.check-row input { width: 18px; height: 18px; }
.repo-list { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; max-height: 55dvh; }
.repo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  text-align: left;
}
.repo-row:active { background: var(--accent); color: #04201c; }
.repo-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.repo-vis { flex: 0 0 auto; opacity: 0.8; }
.status-msg { font-size: 14px; color: var(--muted); }
.status-msg.error { color: #ff9a9a; }
