@font-face {
  font-family: "JetBrainsMono Nerd Font";
  src: url("/vendor/fonts/jetbrainsmono-nerd.woff2") format("woff2");
  font-weight: normal; font-style: normal; font-display: block;
}
@font-face { font-family: "Noto Symbols Fallback"; src: url("/vendor/fonts/noto-symbols2.woff2") format("woff2"); font-display: block; }
@font-face { font-family: "Noto Symbols Fallback 1"; src: url("/vendor/fonts/noto-symbols.woff2") format("woff2"); font-display: block; }

:root {
  --bg: #0d0f12;
  --panel: #15181d;
  --panel-2: #1b1f26;
  --elevated: #20252e;
  --border: #262b34;
  --border-strong: #333b47;
  --text: #e7e9ee;
  --muted: #949cab;
  --faint: #69707c;
  --accent: #d97757;
  --accent-hover: #e0855f;
  --accent-soft: rgba(217, 119, 87, .14);
  --ok: #5bbd7e;
  --ok-soft: rgba(91, 189, 126, .14);
  --warn: #e0b64d;
  --warn-soft: rgba(224, 182, 77, .14);
  --err: #e8726e;
  --err-soft: rgba(232, 114, 110, .14);
  --info: #79a6f6;
  --info-soft: rgba(121, 166, 246, .14);
  --mono: "JetBrainsMono Nerd Font", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  --r-sm: 7px; --r-md: 10px; --r-lg: 14px;
  --sh: 0 6px 24px rgba(0,0,0,.4);
  --sh-lg: 0 16px 48px rgba(0,0,0,.55);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.error, .err { color: var(--err); font-size: 13px; min-height: 1em; }
.mono { font-family: var(--mono); }
code { font-family: var(--mono); background: var(--panel-2); padding: 1.5px 6px; border-radius: 5px; font-size: .92em; border: 1px solid var(--border); }
a { color: var(--accent); }
h1,h2,h3,h4 { margin: 0; font-weight: 650; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2b313b; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #3a424f; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  background: var(--accent); color: #241206; border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 8px 14px; font-weight: 600; font-size: 13px; cursor: pointer; font-family: inherit;
  transition: background .13s, border-color .13s, color .13s, transform .05s; white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--err); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--err-soft); border-color: var(--err); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: var(--r-sm); color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ---- badges / chips / dots ---- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
  padding: 2.5px 9px; border-radius: 999px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.badge.accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.badge.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.badge.err { color: var(--err); background: var(--err-soft); border-color: transparent; }
.badge.info { color: var(--info); background: var(--info-soft); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; flex: none; }
/* Per-account login status badge (central refresher health). */
.badge.auth-badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.err { background: var(--err); box-shadow: 0 0 0 3px var(--err-soft); }
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, #3a4150, #262b34); color: var(--text); font-weight: 700; font-size: 13px; }
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }

/* ---- login ---- */
.login { position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #171b22, var(--bg)); }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 30px; width: 360px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--sh-lg); }
.login-brand { font-size: 22px; font-weight: 700; }
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld > span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* ---- inputs ---- */
input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--border-strong); color: var(--text);
  border-radius: var(--r-sm); padding: 9px 11px; font-size: 13.5px; font-family: inherit; outline: none; width: 100%;
  transition: border-color .13s, box-shadow .13s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23949cab' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

/* ---- app shell ---- */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 22px; padding: 0 20px; height: 56px;
  border-bottom: 1px solid var(--border); background: var(--panel); flex: none; }
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 7px; }
.brand span { letter-spacing: -.01em; }
.nav { display: flex; gap: 2px; }
.nav-btn { background: transparent; color: var(--muted); border: 0; padding: 8px 14px; border-radius: var(--r-sm);
  font-weight: 600; font-size: 13.5px; cursor: pointer; font-family: inherit; }
.nav-btn:hover { color: var(--text); background: var(--panel-2); }
.nav-btn.active { color: var(--text); background: var(--accent-soft); }
.topbar-right { margin-left: auto; }
.user-chip { display: flex; align-items: center; gap: 9px; background: transparent; border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 6px 4px 12px; color: var(--text); cursor: pointer; font-weight: 600; font-size: 13px; }
.user-chip:hover { background: var(--panel-2); }

.main-content { flex: 1; min-height: 0; overflow-y: auto; }
.view { max-width: 1160px; margin: 0 auto; padding: 26px 28px 60px; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 4px; }
.view-head h2 { font-size: 21px; }
.view-sub { color: var(--muted); margin: 4px 0 22px; font-size: 13.5px; }

/* ---- grid + cards ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-md); padding: 16px;
  display: flex; flex-direction: column; gap: 10px; transition: border-color .13s, transform .08s, box-shadow .13s; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--border-strong); box-shadow: var(--sh); }
.card.active { border-color: var(--accent); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
/* min-width:0 (not overflow:hidden) lets the title flex-shrink so .name can
   ellipsize — while keeping overflow visible so the leading status dot's
   box-shadow ring isn't clipped into a squished oval. */
.card-title { font-weight: 650; font-size: 15px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-title .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.card-meta { color: var(--muted); font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.card-meta b { color: var(--text); font-weight: 600; }
.id { font-family: var(--mono); color: var(--faint); font-size: 11.5px; }
.notes-box { font-size: 12.5px; white-space: pre-wrap; color: #c3cad4; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 8px 10px; min-height: 34px; }
.card-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; }
.card-foot .spacer { flex: 1; }

/* ---- provider usage meters (Claude session/weekly rate-limit windows) ---- */
.usage { display: flex; flex-direction: column; gap: 8px; }
.usage-item { display: flex; flex-direction: column; gap: 2px; }
.usage-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.usage-reset { font-size: 11px; padding-left: 60px; }
.usage-label { color: var(--muted); width: 52px; flex: none; }
.usage-bar { flex: 1; height: 6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.usage-fill { height: 100%; border-radius: 999px; background: var(--ok); transition: width .3s ease; }
.usage-fill.warn { background: var(--warn); }
.usage-fill.err { background: var(--err); }
.usage-pct { width: 34px; flex: none; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.usage-na { flex: 1; }
.usage-err { font-size: 12px; color: var(--muted); }

/* ---- table ---- */
.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--panel-2); }
.u-cell { display: flex; align-items: center; gap: 11px; }
.u-cell .un { font-weight: 600; }

/* ---- dropdown menu ---- */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px; background: var(--elevated);
  border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--sh-lg); padding: 6px; z-index: 60; }
.menu button { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; background: transparent;
  border: 0; color: var(--text); padding: 8px 10px; border-radius: var(--r-sm); font-size: 13px; cursor: pointer; font-family: inherit; }
.menu button:hover { background: var(--panel-2); }
.menu button.danger { color: var(--err); }
.menu button.danger:hover { background: var(--err-soft); }
.menu .sep { height: 1px; background: var(--border); margin: 5px 2px; }
.menu .mhead { padding: 5px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); }

/* ---- modal ---- */
.modal-root { position: fixed; inset: 0; background: rgba(6,8,11,.66); display: grid; place-items: center; z-index: 100; backdrop-filter: blur(2px); }
.modal-card { background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  padding: 24px; width: 480px; max-width: 94vw; max-height: 88vh; overflow-y: auto; box-shadow: var(--sh-lg); }
.modal-card h3 { font-size: 18px; margin-bottom: 6px; }
.modal-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; line-height: 1.5; }
.modal-card label.fld { margin-top: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; align-items: center; }
.modal-actions .spacer { flex: 1; }

/* ---- empty state ---- */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg); background: var(--panel); }
.empty .em-icon { font-size: 34px; margin-bottom: 10px; }
.empty h3 { font-size: 16px; margin-bottom: 6px; color: var(--text); }

/* ---- toasts ---- */
.toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: var(--elevated); border: 1px solid var(--border-strong); border-left: 3px solid var(--accent);
  border-radius: var(--r-md); padding: 12px 16px; min-width: 240px; max-width: 380px; box-shadow: var(--sh-lg);
  font-size: 13.5px; animation: slidein .18s ease; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
@keyframes slidein { from { opacity: 0; transform: translateX(16px); } }

/* ---- members list (project detail) ---- */
.member-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.member-row:last-child { border-bottom: 0; }
.member-row .un { font-weight: 600; }
.member-row .spacer { flex: 1; }
.member-row select { width: auto; }
.add-row { display: flex; gap: 8px; margin-top: 14px; }
.add-row input { flex: 1; }
.add-row select { width: 130px; }

/* ---- session create fields ---- */
.form-grid { display: grid; gap: 14px; }

/* ---- terminal overlay ---- */
.term-overlay { position: fixed; inset: 0; z-index: 90; background: #000; display: flex; flex-direction: column; }
/* Mobile key accessory bar — hidden on desktop, revealed in the mobile media query. */
.term-keys { display: none; }
.term-bar { display: flex; align-items: center; justify-content: space-between; padding: 9px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border); flex: none; }
.term-title { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.term-actions { display: flex; gap: 8px; }
.terminal { flex: 1; min-height: 0; padding: 8px 10px; }

/* install-cli modal */
.copybox { display: flex; align-items: stretch; gap: 6px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 8px 8px 8px 12px; }
.copybox code { flex: 1; background: transparent; border: 0; padding: 0; white-space: pre-wrap; word-break: break-all;
  font-size: 12.5px; line-height: 1.6; align-self: center; }
.copybox .icon-btn { align-self: flex-start; flex: none; }
.dl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dl-link { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 9px 11px; font-size: 13px; }
.dl-link:hover { border-color: var(--border-strong); background: var(--elevated); }
.dl-link .ico { color: var(--muted); }

/* claude/shell segmented toggle in the terminal bar */
.seg-group { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 2px; }
.seg { background: transparent; border: 0; color: var(--muted); padding: 4px 12px; font-size: 12.5px; font-weight: 600; border-radius: 5px; cursor: pointer; font-family: inherit; }
.seg:hover { color: var(--text); }
.seg.active { background: var(--accent); color: #241206; }

/* file browser */
.files-modal { width: 100%; display: flex; flex-direction: column; max-height: 80vh; }
.files-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.files-head h3 { display: flex; align-items: center; gap: 6px; }
.file-path { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; font-size: 13px; }
.crumb { background: transparent; border: 0; color: var(--accent); cursor: pointer; padding: 2px 4px; font-family: var(--mono); font-size: 12.5px; }
.crumb:hover { text-decoration: underline; }
.crumb-sep { color: var(--faint); }
.file-list { border: 1px solid var(--border); border-radius: var(--r-md); overflow-y: auto; flex: 1; min-height: 200px; background: var(--bg); }
.file-list.drop { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent-soft); }
.file-row { display: grid; grid-template-columns: 24px 1fr auto auto; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.file-row:last-child { border-bottom: 0; }
.file-row:hover { background: var(--panel-2); }
.file-ic { color: var(--muted); display: inline-flex; }
.file-ic.dir { color: var(--accent); }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.file-name.link { cursor: pointer; }
.file-name.link:hover { color: var(--accent); }
.file-size { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.file-acts { display: flex; gap: 2px; }
.modal-card.wide { width: 680px; }

/* library type picker + inject toggles */
.type-grid { display: grid; gap: 10px; margin: 14px 0; }
.type-card { text-align: left; background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: var(--r-md); padding: 14px; cursor: pointer; color: var(--text); }
.type-card:hover { border-color: var(--accent); background: var(--elevated); }
.inj-toggle-list { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-sm); padding: 6px; background: var(--bg); }
.inj-toggle { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: var(--r-sm); cursor: pointer; }
.inj-toggle:hover { background: var(--panel-2); }
.inj-toggle input { width: auto; }
.inj-toggle .ico { color: var(--muted); flex: none; }
.inj-name { flex: 1; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* =====================================================================
   Mobile / narrow-viewport (<=768px). Scoped so desktop is untouched.
   ===================================================================== */
@media (max-width: 768px) {
  /* Prevent iOS zoom-on-focus (triggers when a focused field is < 16px). */
  input, select, textarea { font-size: 16px; }

  /* Top bar: compact, brand shrinks, nav scrolls horizontally. */
  .topbar { gap: 10px; padding: 0 12px; height: 52px; }
  .brand { font-size: 14px; flex: none; }
  .nav { gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; flex: 1; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-btn { padding: 8px 11px; white-space: nowrap; }
  .user-chip { padding: 4px; }
  .user-chip .uname { display: none; } /* keep just the avatar */

  /* Views: tighter padding, headers stack. */
  .view { padding: 16px 14px 48px; }
  .view-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .view-head h2 { font-size: 19px; }
  .view-head .btn { width: 100%; }

  /* Session cards already collapse (minmax 300px); ensure single column. */
  .grid { grid-template-columns: 1fr; }

  /* Tables scroll horizontally rather than overflow the page. */
  .tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-md); }
  .tbl { min-width: 520px; }
  .tbl th, .tbl td { padding: 10px 12px; }

  /* Modals: anchor near the top so the soft keyboard can't hide inputs. */
  .modal-root { place-items: start center; padding: 10px 8px calc(env(safe-area-inset-bottom) + 10px); overflow-y: auto; }
  .modal-card { width: 100%; max-width: 560px; padding: 18px; max-height: none; }
  .modal-card.wide { width: 100%; }
  .modal-actions { flex-wrap: wrap; }

  /* Terminal bar: let actions wrap and compress. */
  .term-bar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; padding-top: calc(env(safe-area-inset-top) + 8px); }
  .term-title { flex: 1 1 100%; font-size: 14px; }
  .term-actions { flex: 1 1 100%; gap: 6px; }
  .term-actions .btn-sm { padding: 6px 9px; }
  .terminal { padding: 4px 6px; }
  /* xterm's hidden input must be >=16px or iOS zooms when the terminal is focused. */
  .xterm-helper-textarea { font-size: 16px !important; }

  /* Reveal the key accessory bar; keys send Esc/Tab/Ctrl/arrows. */
  .term-keys { display: flex; gap: 6px; padding: 7px 8px calc(env(safe-area-inset-bottom) + 7px);
    background: var(--panel); border-top: 1px solid var(--border); flex: none; overflow-x: auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .term-keys::-webkit-scrollbar { display: none; }
  .tkey { flex: 1 0 auto; min-width: 44px; min-height: 40px; background: var(--panel-2);
    border: 1px solid var(--border-strong); border-radius: var(--r-sm); color: var(--text);
    font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent;
    touch-action: manipulation; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  /* Held keys (scroll + arrows) take over all touch gestures so iOS doesn't
     hijack the long-press as a selection/callout (which cancels the repeat). */
  .tkey-hold { touch-action: none; }
  .tkey:active { background: var(--accent-soft); }
  .tkey.on { background: var(--accent); color: #241206; border-color: transparent; }
}

/* Slightly finer tuning on very small phones. */
@media (max-width: 380px) {
  .term-actions .seg { padding: 4px 9px; }
  .tkey { min-width: 40px; font-size: 13px; }
}
