:root {
  --bg: #14161a;
  --panel: #1c1f24;
  --panel-2: #252931;
  --line: #2f343d;
  --text: #e9eaec;
  --muted: #9aa1ac;
  --accent: #e8b04a;
  --accent-ink: #1a1405;
  --danger: #ef6b6b;
  --add: #7fd18b;
  --del: #f08585;
  --hunk: #7cb7ff;
  --add-bg: rgba(127, 209, 139, 0.1);
  --del-bg: rgba(240, 133, 133, 0.1);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
}

/* --- top bar ------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  padding: 6px 14px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.tab.active { background: var(--panel-2); color: var(--text); }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.conn.on { background: var(--add); }
.conn.off { background: var(--danger); }
.icon-btn {
  background: none; border: 0; font-size: 22px; line-height: 1;
  padding: 4px 8px; color: var(--muted); cursor: pointer;
}

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* --- session chips ------------------------------------------------------ */
.sessbar {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.chip .sub { color: var(--muted); font-size: 12px; }
.chip.active .sub { color: var(--accent-ink); opacity: 0.7; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.chip.active .dot { display: none; }
.chip-add { font-size: 18px; padding: 4px 12px; }

/* --- terminal ----------------------------------------------------------- */
#term-wrap { position: relative; flex: 1; min-height: 0; background: #0f1114; }
#term { position: absolute; inset: 4px 2px 0 6px; }
#term .xterm-viewport { overscroll-behavior: contain; }
.empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  color: var(--muted);
}

.keys {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 5px 6px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: none;
  scrollbar-width: none;
}
.keys::-webkit-scrollbar { display: none; }
.keys button {
  flex: none;
  min-width: 40px;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
}
.keys button:active { background: var(--accent); color: var(--accent-ink); }

.compose {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: var(--panel);
  flex: none;
}
.compose textarea {
  flex: 1;
  resize: none;
  max-height: 40vh;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 16px; /* 16px stops iOS zooming on focus */
  line-height: 1.35;
}

/* --- buttons, dialogs --------------------------------------------------- */
.btn {
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; }

dialog.sheet {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  width: min(460px, calc(100vw - 24px));
  padding: 18px;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog.sheet h2 { margin: 0 0 14px; font-size: 18px; }
dialog.sheet label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
dialog.sheet select, dialog.sheet input {
  display: block; width: 100%; margin-top: 4px;
  padding: 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); font-size: 16px; color: var(--text);
}
dialog.sheet .row { display: flex; gap: 8px; justify-content: flex-end; }
dialog.sheet .stack { display: flex; flex-direction: column; gap: 8px; }
dialog.sheet hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 4px 0; }
dialog.full {
  width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
  margin: 0; border-radius: 0; padding: 0;
  display: none; flex-direction: column;
}
dialog.full[open] { display: flex; }
.sheet-head { display: flex; gap: 8px; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; margin: 0 !important; }
.hist {
  flex: 1; overflow: auto; margin: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  font: 12.5px/1.4 var(--mono); white-space: pre-wrap; word-break: break-word;
  user-select: text; -webkit-user-select: text;
}
.err { color: var(--danger); margin: 0 0 10px; }

/* --- git view ----------------------------------------------------------- */
.git { flex: 1; overflow-y: auto; padding: 10px 10px calc(16px + env(safe-area-inset-bottom)); }
.git h1 { font-size: 18px; margin: 4px 0 10px; display: flex; align-items: center; gap: 8px; }
.git h1 .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { text-decoration: none; color: var(--muted); font-size: 22px; padding: 0 6px 0 0; }
.cards { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: block;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}
.card .title { font-weight: 600; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.card .meta { color: var(--muted); font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted);
}
.badge.warn { background: rgba(232, 176, 74, 0.18); color: var(--accent); }
.badge.ok { background: rgba(127, 209, 139, 0.14); color: var(--add); }
.badge.ref { background: rgba(124, 183, 255, 0.15); color: var(--hunk); }
.subtabs { display: flex; gap: 4px; margin-bottom: 10px; }
.subtabs a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; }
.subtabs a.active { background: var(--panel-2); color: var(--text); }
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list a, .list div.li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit; background: var(--panel);
}
.list > :last-child { border-bottom: 0; }
.list .xy { font-family: var(--mono); font-size: 12px; color: var(--accent); width: 22px; flex: none; }
.list .path { font-family: var(--mono); font-size: 13px; word-break: break-all; }
.list .main { flex: 1; min-width: 0; }
.list .subj { overflow-wrap: anywhere; }
.list .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.list .sha { font-family: var(--mono); font-size: 12px; color: var(--muted); flex: none; }
.more { margin: 10px auto; display: block; }
.msg { white-space: pre-wrap; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0 0 10px; font-size: 14px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 13px; margin: 8px 0; }

details.file { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; }
details.file > summary {
  padding: 8px 10px; background: var(--panel); cursor: pointer;
  font: 12.5px var(--mono); word-break: break-all; list-style-position: inside;
}
.diff { margin: 0; font: 12px/1.45 var(--mono); overflow-x: auto; background: #0f1114; }
.diff div { padding: 0 8px; white-space: pre-wrap; word-break: break-all; min-height: 1.45em; }
.diff .a { background: var(--add-bg); color: var(--add); }
.diff .d { background: var(--del-bg); color: var(--del); }
.diff .h { color: var(--hunk); }
.diff .m { color: var(--muted); }
pre.stat { font: 12px/1.4 var(--mono); white-space: pre-wrap; word-break: break-all; color: var(--muted); margin: 0 0 10px; }

/* --- login -------------------------------------------------------------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 16px; }
.login { display: flex; flex-direction: column; gap: 12px; width: min(320px, 100%); text-align: center; }
.login h1 { margin: 0 0 8px; font-size: 20px; }
.login img { align-self: center; }
.login input {
  padding: 12px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel); font-size: 16px;
}

/* --- file editor -------------------------------------------------------- */
.editor {
  display: block; width: 100%;
  height: calc(100dvh - 250px); min-height: 240px;
  padding: 10px; border-radius: var(--radius); border: 1px solid var(--line);
  background: #0f1114; color: var(--text);
  font: 13px/1.45 var(--mono); resize: vertical; white-space: pre-wrap;
}
.commitbar { display: flex; gap: 6px; margin-top: 8px; }
.commitbar input {
  flex: 1; min-width: 0; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); font-size: 16px;
}

/* --- files -------------------------------------------------------------- */
.crumbs { font: 12.5px var(--mono); color: var(--muted); margin: -4px 0 10px; overflow-wrap: anywhere; }
.crumbs a { color: var(--hunk); text-decoration: none; }
.list .ico { width: 10px; flex: none; color: var(--muted); font-size: 11px; }
.list .path.dir { color: var(--hunk); }
.empty .note { max-width: 280px; text-align: center; }
