:root {
  --bg: #10141a;
  --bg-soft: #161c24;
  --bg-panel: #1a222c;
  --bg-input: #0d1117;
  --line: #263241;
  --line-soft: #1f2a36;
  --text: #dfe7f0;
  --text-dim: #8fa1b8;
  --accent: #4fa3ff;
  --accent-soft: #1d3a5c;
  --ok: #3fb96f;
  --warn: #d9a441;
  --err: #e2685e;
  --mono: "DejaVu Sans Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: "DejaVu Sans", system-ui, -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  overflow: hidden;
}

button, select, input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 5px 9px;
}

button {
  cursor: pointer;
  background: var(--bg-panel);
  transition: background 0.12s, border-color 0.12s;
}

button:hover { background: #223041; border-color: #35506e; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent-soft); border-color: #2c6ba8; color: #dbeaff; }
button.primary:hover { background: #24507c; }
button.danger { background: #3a1f21; border-color: #6b3230; color: #ffd7d2; }
button.ghost { background: transparent; }
button.tiny, select.tiny { padding: 2px 6px; font-size: 12px; }

input:focus, textarea:focus, select:focus, button:focus { outline: 1px solid #2f6ea8; outline-offset: 0; }

a { color: var(--accent); }

.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.spacer { flex: 1; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.wrap { flex-wrap: wrap; }

/* ---------- login ---------- */
.login-body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(1100px 500px at 15% -10%, #1c2a3a 0%, transparent 60%),
    radial-gradient(900px 400px at 90% 110%, #212a35 0%, transparent 55%),
    var(--bg);
}

.login-card {
  width: min(430px, 94vw);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 26px 26px 20px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}

.login-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: 0.3px; }
.login-card .sub { color: var(--text-dim); margin: 0 0 18px; font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: var(--text-dim); margin: 12px 0 4px; }
.login-card input { width: 100%; padding: 8px 10px; }
.login-card .actions { margin-top: 18px; display: flex; gap: 10px; }
.login-card .actions button { flex: 1; padding: 9px; }
.login-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.login-tabs button { flex: 1; padding: 7px; }
.login-tabs button.active { background: var(--accent-soft); border-color: #2c6ba8; }
.notice { margin-top: 14px; padding: 9px 11px; border-radius: 6px; font-size: 13px; display: none; }
.notice.show { display: block; }
.notice.error { background: #341e1e; border: 1px solid #5e302c; color: #ffd5cf; }
.notice.info { background: #17301f; border: 1px solid #2c5738; color: #cdf0d6; }
.login-foot { margin-top: 16px; font-size: 12px; color: var(--text-dim); display: flex; justify-content: space-between; }

/* ---------- app shell ---------- */
.shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; letter-spacing: 0.4px; }
.brand .dot { color: var(--accent); }
a.brand { color: inherit; text-decoration: none; }
a.brand:hover { text-decoration: underline; text-underline-offset: 4px; }

.main {
  display: grid;
  grid-template-columns: 264px 6px minmax(320px, 1fr) 6px minmax(280px, 42%);
  flex: 1;
  min-height: 0;
}

.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-soft); }
.pane-header {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-bottom: 1px solid var(--line-soft);
  background: var(--bg-panel); font-size: 12px; color: var(--text-dim);
}
.pane-body { flex: 1; min-height: 0; overflow: auto; }

.tabs { display: flex; border-bottom: 1px solid var(--line-soft); background: var(--bg-panel); }
.tabs button {
  border: none; border-radius: 0; background: transparent; flex: 1;
  padding: 8px 4px; font-size: 12px; color: var(--text-dim); border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.splitter { position: relative; z-index: 2; background: var(--line); cursor: col-resize; flex: none; }
.splitter:hover { background: var(--accent); }
.splitter::before { content: ""; display: block; position: absolute; inset: 0 -3px; }
body.resizing { user-select: none; cursor: col-resize; }
body.resizing .overlay-shield { position: fixed; inset: 0; z-index: 9999; }

/* ---------- file tree ---------- */
.tree { padding: 4px 0; font-size: 13px; }
.tree-row {
  display: flex; align-items: center; gap: 5px;
  padding: 2px 8px 2px calc(8px + var(--depth, 0) * 12px);
  cursor: pointer; white-space: nowrap;
}
.tree-row:hover { background: #1d2836; }
.tree-row.active { background: #21374d; }
.tree-row .kind { width: 14px; text-align: center; color: var(--text-dim); font-size: 11px; }
.tree-row .kind.entry { color: var(--warn); font-size: 12px; }
.tree-row.dir .kind { color: var(--accent); font-size: 12px; }
.tree-row.collapsed .name { color: var(--text-dim); }
.tree-toolbar { flex-wrap: wrap; row-gap: 4px; }
.tree-row.entry .name { color: var(--warn); font-weight: 600; }
.tree-row .name { overflow: hidden; text-overflow: ellipsis; }
.tree-row .flags { margin-left: auto; font-size: 11px; color: var(--text-dim); }
.tree-row.git-mod .name { color: #e8c07d; }
.tree-row.git-new .name { color: #8fd6a0; }
.tree-row.git-conflict .name { color: #ff9c92; }

/* ---------- editor ---------- */
.filebar {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; background: var(--bg-panel); border-bottom: 1px solid var(--line-soft);
  font-size: 12px; color: var(--text-dim);
}
.filebar .path { color: var(--text); font-family: var(--mono); }

.insertbar { display: flex; align-items: center; gap: 6px; padding: 4px 8px; background: var(--bg-panel); border-bottom: 1px solid var(--line-soft); }
.picker-list { display: flex; flex-direction: column; gap: 2px; max-height: 44vh; overflow: auto; }
.picker-item { display: flex; align-items: baseline; gap: 10px; text-align: left; padding: 5px 8px; font-family: var(--mono); font-size: 12.5px; }
.picker-item .pick-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-item .pick-hint { margin-left: auto; color: var(--text-dim); font-size: 11px; white-space: nowrap; }

.editor-wrap { position: relative; flex: 1; min-height: 0; display: flex; background: var(--bg-input); }
.gutter {
  width: 46px; flex: 0 0 46px; overflow: hidden; background: #0b0f14;
  border-right: 1px solid var(--line-soft); color: #5b6c80; font-family: var(--mono);
  font-size: 13px; line-height: 1.55; padding-top: 8px; text-align: right; user-select: none;
}
.gutter div { padding-right: 8px; }
.code-area { position: relative; flex: 1; min-width: 0; }
#highlight, #editor {
  position: absolute; inset: 0; margin: 0; padding: 8px 10px;
  font-family: var(--mono); font-size: 13px; line-height: 1.55;
  white-space: pre; tab-size: 2; border: 0;
  scrollbar-gutter: stable;
}
#highlight { overflow: hidden; pointer-events: none; color: var(--text); background: transparent; }
#editor {
  background: transparent; color: transparent; caret-color: #7fc4ff; resize: none;
  overflow: auto; white-space: pre; outline: none;
}
#editor.soft-wrap, #highlight.soft-wrap { white-space: pre-wrap; overflow-wrap: break-word; }
#editor.soft-wrap { overflow-x: hidden; }
#highlight .hl-row { margin: 0; padding: 0; }
#editor::selection { background: rgba(79, 163, 255, 0.28); }
.t-kw { color: #7fc4ff; }
.t-fn { color: #e8c07d; }
.t-str { color: #9fd68f; }
.t-num { color: #d8a0d0; }
.t-head { color: #ffd166; font-weight: 700; }
.t-comment { color: #63788f; font-style: italic; }
.t-label { color: #c3a0ff; }
.t-ref { color: #6fd0c0; }
.t-op { color: #ff9f7f; }
.t-mark { color: #ff7b72; font-weight: 700; }

/* ---------- preview ---------- */
.preview-body { flex: 1; min-height: 0; overflow: auto; background: #0a0d11; padding: 10px; }
#pdfView { display: flex; flex-direction: column; align-items: center; gap: 10px; min-height: 100%; }
#pdfView.hidden { display: none; }
.pdf-page { background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.55); flex: none; }
.pdf-page canvas { display: block; }
.image-viewer { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; }
.image-bar { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid var(--line-soft); background: var(--bg-panel); font-size: 12px; color: var(--text-dim); }
.image-stage { flex: 1; min-height: 0; overflow: auto; display: grid; place-items: center; padding: 14px; background: #0a0d11; }
.image-stage img { max-width: 100%; max-height: 100%; background: #fff; box-shadow: 0 2px 14px rgba(0, 0, 0, 0.5); }
.image-stage img.missing { display: none; }
.pages-view { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.pages-view img { max-width: 100%; background: #fff; box-shadow: 0 2px 14px rgba(0, 0, 0, 0.5); }
.diags { border-top: 1px solid var(--line); background: var(--bg-panel); max-height: 34%; overflow: auto; }
.diag {
  display: grid; grid-template-columns: 46px 1fr; gap: 6px;
  padding: 5px 8px; border-bottom: 1px solid var(--line-soft); font-size: 12px; cursor: pointer;
}
.diag:hover { background: #1f2b39; }
.diag .sev { font-weight: 700; }
.diag.error .sev { color: var(--err); }
.diag.warning .sev { color: var(--warn); }
.diag.info .sev { color: var(--text-dim); }
.diag .msg { white-space: pre-wrap; }
.diag .loc { color: var(--text-dim); font-family: var(--mono); font-size: 11px; }
.compiling { color: var(--warn); }

/* ---------- git panel ---------- */
.git-section { border-bottom: 1px solid var(--line-soft); padding: 8px; }
.git-section h3 {
  margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
}
.git-entry {
  display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 12px;
  font-family: var(--mono); white-space: nowrap; cursor: pointer;
}
.git-entry:hover { background: #1d2836; }
.git-entry .st { width: 14px; text-align: center; }
.git-entry .st.M { color: #e8c07d; }
.git-entry .st.A, .git-entry .st.\?\? { color: #8fd6a0; }
.git-entry .st.D { color: #ff9c92; }
.git-entry .st.U { color: #ff7b72; font-weight: 700; }
.git-entry .p { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.git-entry .act { display: flex; gap: 2px; opacity: 0.6; }
.git-entry:hover .act { opacity: 1; }
.git-entry .act button { padding: 0 4px; font-size: 11px; line-height: 1.4; }
.commit-box textarea {
  width: 100%; min-height: 56px; resize: vertical; font-family: var(--sans); font-size: 13px;
}
.log-entry { padding: 5px 8px; border-bottom: 1px solid var(--line-soft); cursor: pointer; font-size: 12px; }
.log-entry:hover { background: #1d2836; }
.log-entry .sha { font-family: var(--mono); color: var(--accent); }
.log-entry .refs { color: var(--text-dim); font-size: 11px; }
.diff {
  font-family: var(--mono); font-size: 12px; white-space: pre; padding: 8px; background: var(--bg-input);
  overflow: auto; height: 100%;
}
.diff .add { color: #8fd6a0; }
.diff .del { color: #ff9c92; }
.diff .hunk { color: #7fc4ff; }
.diff .meta { color: var(--text-dim); }

.badge {
  font-size: 11px; padding: 2px 6px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-input); color: var(--text-dim); white-space: nowrap;
}
.badge.ok { color: #a6e0bb; border-color: #2c5738; }
.badge.warn { color: #f0d69a; border-color: #6b5626; }
.badge.err { color: #ffc0b8; border-color: #6b3230; }

.statusbar {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px; background: var(--bg-panel); border-top: 1px solid var(--line);
  font-size: 12px; color: var(--text-dim);
}
.dot-indicator { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--ok); }
.dot-yellow { background: var(--warn); }
.dot-red { background: var(--err); }
.dot-grey { background: #4b5b6e; }

.avatars { display: flex; gap: -4px; }
.avatar {
  width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 11px; color: #0b0f14; font-weight: 700; margin-left: -4px; border: 1px solid #0b0f14;
}

/* ---------- modals ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(5, 8, 12, 0.62);
  display: grid; place-items: center; z-index: 50;
}
.modal {
  width: min(760px, 94vw); max-height: 88vh; overflow: auto;
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
}
.modal header {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg-panel); z-index: 1;
}
.modal header h2 { margin: 0; font-size: 16px; flex: 1; }
.modal .content { padding: 14px 16px; }
.modal .footer { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; }
.field textarea { min-height: 90px; font-family: var(--mono); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.modal nav { display: flex; gap: 4px; padding: 8px 16px 0; }
.modal nav button { padding: 6px 10px; font-size: 13px; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; }
.modal nav button.active { border-bottom-color: var(--accent); color: var(--text); }

.toasts { position: fixed; right: 12px; bottom: 34px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--bg-panel); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  padding: 8px 12px; border-radius: 6px; font-size: 13px; max-width: 380px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.toast.error { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }

.empty { padding: 14px; color: var(--text-dim); font-size: 13px; }
.hidden { display: none !important; }
kbd {
  font-family: var(--mono); font-size: 11px; background: var(--bg-input);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 4px;
}
details summary { cursor: pointer; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.list-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12px; }
.list-row .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; }
progress { width: 100%; height: 6px; }

/* ---------- start page ---------- */
a.button { text-decoration: none; display: inline-flex; align-items: center; }
.dash { flex: 1; min-height: 0; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; background: var(--bg-soft); }
.dash .tabs { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.dash-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.proj-card { background: var(--bg-panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; }
.proj-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.proj-title { font-weight: 600; font-size: 15px; color: var(--text); text-decoration: none; }
.proj-title:hover { color: var(--accent); }
.proj-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; overflow: hidden; }
.dash-new { border-bottom: 1px solid var(--line-soft); padding-bottom: 12px; }
.dash-new h3 { margin: 0 0 8px; font-size: 14px; }
.dash-new input, .dash-new select { padding: 6px 8px; }
.dash-new input { min-width: 180px; }
