/* Caipi app design system: custom, no framework. Pairs with the landing.
   Fonts (loaded in base.html): JetBrains Mono only.
   JetBrains Mono = UI chrome, labels, code. System sans = document prose. */

:root {
  --bg: #0a0a0b;
  --surface: #141417;        /* sidebar, cards, code */
  --surface-2: #1c1c20;      /* hover / raised */
  --ink: #ededeb;
  --dim: #8a8a86;
  --dimmer: #5a5a57;
  --line: #242427;
  --accent: #9ad814;
  --accent-ink: #0a0a0b;     /* text on accent fills */
  --danger: #e5484d;
  --radius: 2px;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 3.25rem;
  --side-w: 16rem;
}

:root[data-theme="light"] {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f0f0f1;
  --ink: #18181b;
  --dim: #6e6e76;
  --dimmer: #a1a1aa;
  --line: #e6e6e9;
  --accent-ink: #0a0a0b;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-2: #f0f0f1;
    --ink: #18181b;
    --dim: #6e6e76;
    --dimmer: #a1a1aa;
    --line: #e6e6e9;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }
::selection { background: var(--accent); color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-family: var(--mono); font-size: 0.88em; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.05em 0.32em; }

/* ---------- shared bits ---------- */
.label {
  font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--dimmer);
}
.muted { color: var(--dim); }

button, input, select, textarea { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.02em;
  border: 1px solid var(--line); background: none; color: var(--ink);
  border-radius: 999px; padding: 0.45rem 0.9rem; cursor: pointer;
  text-decoration: none; transition: border-color .15s, color .15s, background .15s;
}
.btn:hover { border-color: var(--dim); }
.btn-accent {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-weight: 600;
}
.btn-accent:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { border-color: transparent; color: var(--dim); padding-inline: 0.6rem; }
.btn-ghost:hover { color: var(--ink); border-color: transparent; }

/* ---------- top nav ---------- */
.topnav {
  position: sticky; top: 0; z-index: 20;
  height: var(--nav-h);
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topnav .brand {
  font-family: var(--mono); font-weight: 600; font-size: 0.95rem; letter-spacing: 0;
  text-decoration: none; color: var(--ink); white-space: nowrap;
}
.topnav .brand .slash { color: var(--dimmer); }
.topnav .spacer { flex: 1; }
.topnav .actions { display: flex; align-items: center; gap: 0.5rem; }

.hamburger {
  display: inline-grid; place-items: center;
  width: 2rem; height: 2rem; flex: none;
  background: none; border: 1px solid transparent; border-radius: var(--radius);
  color: var(--dim); cursor: pointer; transition: color .15s, border-color .15s;
}
.hamburger:hover { color: var(--ink); border-color: var(--line); }

/* ---------- layout: sidebar + main ---------- */
.shell { display: flex; align-items: stretch; min-height: calc(100dvh - var(--nav-h)); }
.sidebar {
  flex: none; width: var(--side-w);
  border-right: 1px solid var(--line);
  background: var(--bg);
  overflow-y: auto;
  padding: 1.1rem 0.9rem;
  transition: margin-left .2s ease;
}
.shell.collapsed .sidebar { margin-left: calc(-1 * var(--side-w)); }
.sidebar .side-label { margin: 0 0.4rem 0.7rem; }
.main { flex: 1; min-width: 0; }

/* ---------- file tree: plain nested lists, no accordions ---------- */
.tree, .tree ul { list-style: none; }
.tree ul { padding-left: 0.85rem; border-left: 1px solid var(--line); margin-left: 0.45rem; }
.tree li { margin: 0.05rem 0; }
.tree details > summary {
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0.2rem 0.4rem; font-size: 0.78rem; letter-spacing: 0.02em;
  color: var(--dim); cursor: pointer; list-style: none; user-select: none;
}
.tree details > summary::-webkit-details-marker { display: none; }
.tree details > summary::before {
  content: ""; flex: none;
  width: 0; height: 0;
  border-left: 6px solid var(--dimmer);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  transform-origin: center;
  transition: transform .15s ease;
}
.tree details[open] > summary::before { transform: rotate(90deg); }
.tree details > summary:hover { color: var(--ink); }
.tree a {
  display: block; padding: 0.2rem 0.4rem; border-radius: var(--radius);
  font-size: 0.82rem; color: var(--dim); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color .12s, background .12s;
}
.tree a:hover { color: var(--ink); background: var(--surface-2); }
.tree a[aria-current="page"] { color: var(--ink); background: var(--surface-2); box-shadow: inset 2px 0 0 var(--accent); }

/* ---------- document / prose (neutral, agent docs bring their own styling) ---------- */
.doc { max-width: 48rem; margin: 0 auto; padding: 2.5rem 1.5rem 5rem; }
/* neutral defaults only — agent-authored documents bring their own styling */
.prose { font-family: var(--sans); font-size: 1rem; line-height: 1.65; color: var(--ink); }
.prose > * + * { margin-top: 1rem; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--sans); font-weight: 600; line-height: 1.25; letter-spacing: -0.01em;
  margin-top: 2rem;
}
.prose h1 { font-size: 1.9rem; }
.prose h2 { font-size: 1.4rem; }
.prose h3 { font-size: 1.15rem; }
.prose h1:first-child, .prose h2:first-child { margin-top: 0; }
.prose a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--dim); text-underline-offset: 2px; }
.prose a:hover { text-decoration-color: var(--ink); }
.prose strong { font-weight: 600; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin-top: 0.35rem; }
.prose blockquote { border-left: 3px solid var(--line); padding-left: 1rem; color: var(--dim); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }
.prose img { max-width: 100%; height: auto; border-radius: var(--radius); }
.prose code {
  font-family: var(--mono); font-size: 0.86em;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.1em 0.35em;
}
.prose pre {
  font-family: var(--mono); font-size: 0.85rem; line-height: 1.55;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; overflow-x: auto;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.prose table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 0.85rem; }
.prose th, .prose td { border: 1px solid var(--line); padding: 0.5rem 0.7rem; text-align: left; }
.prose th { color: var(--dim); font-weight: 500; background: var(--surface); }

/* ---------- auth / centered pages ---------- */
.center-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1.5rem;
  padding: 2rem 1.5rem; text-align: center;
}
.center-wrap .brand { font-family: var(--mono); font-weight: 600; font-size: 1.3rem; text-decoration: none; }
.center-wrap .brand .dot { color: var(--accent); }
.card {
  width: 100%; max-width: 26rem; text-align: left;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 1.6rem;
}
.card h1 { font-family: var(--mono); font-weight: 600; font-size: 1.25rem; margin-bottom: 0.4rem; }
.card p { color: var(--dim); font-size: 0.92rem; margin-bottom: 1.2rem; }

/* url-style reserve field (matches landing) */
.urlfield { display: flex; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 0.6rem; transition: border-color .2s; }
.urlfield:focus-within { border-color: var(--accent); }
.urlfield .host { color: var(--dimmer); }
.urlfield input { flex: 1; min-width: 0; background: none; border: 0; outline: none; caret-color: var(--accent); padding: 0 0.2rem; }
.urlfield input::placeholder { color: var(--dimmer); }

/* ---------- theme toggle (lightbulb) ---------- */
.theme {
  display: inline-grid; place-items: center;
  width: 2rem; height: 2rem; flex: none;
  background: none; border: 1px solid transparent; border-radius: var(--radius);
  color: var(--dim); cursor: pointer; transition: color .2s, border-color .15s;
}
.theme:hover { color: var(--ink); border-color: var(--line); }
.theme svg { width: 17px; height: 17px; display: block; }
.theme.fixed { position: fixed; top: 1.25rem; right: 1.25rem; z-index: 30; }

/* ---------- forms ---------- */
.field { display: grid; gap: 0.5rem; margin-bottom: 1.1rem; }
.field > label { font-size: 0.78rem; color: var(--dim); letter-spacing: 0.02em; }
/* :where() keeps zero specificity so .urlfield input (underline style) still wins */
:where(input[type="text"], input[type="file"], textarea) {
  width: 100%; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.55rem 0.7rem; font-family: var(--mono); font-size: 0.9rem;
}
:where(input[type="text"], textarea):focus { outline: none; border-color: var(--accent); }
input[type="file"] { cursor: pointer; padding: 0.4rem; font-size: 0.85rem; color: var(--dim); }
input[type="file"]::file-selector-button {
  font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.02em;
  background: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 0.35rem 0.85rem; margin-right: 0.8rem; cursor: pointer;
  transition: border-color .15s, color .15s;
}
input[type="file"]::file-selector-button:hover { border-color: var(--dim); }
.hint { list-style: none; font-size: 0.78rem; color: var(--dim); }
.hint li { margin-top: 0.25rem; }

/* alert */
.alert {
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line));
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger); padding: 0.7rem 0.9rem; border-radius: var(--radius); font-size: 0.85rem;
}

/* google sign-in slot */
.gsi { display: flex; justify-content: center; min-height: 44px; }
.gsi:empty { display: none; }

/* utilities */
.stack { display: grid; gap: 1rem; }
.row { display: flex; gap: 0.6rem; align-items: center; }

/* public page (no app chrome) */
.public { max-width: 48rem; margin: 0 auto; padding: 3rem 1.5rem 5rem; }
.sitemark { margin-top: 4rem; padding-top: 1.2rem; border-top: 1px solid var(--line); text-align: center; font-size: 0.8rem; }
.sitemark a { color: var(--dim); text-decoration: none; }
.sitemark a:hover { color: var(--ink); }

/* upload result list */
.upload-list { list-style: none; }
.upload-list li { padding: 0.35rem 0; border-bottom: 1px solid var(--line); font-size: 0.85rem; }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  :root { --side-w: 15rem; }
  /* off-canvas: hidden by default, opens via .shell.open */
  .sidebar {
    position: fixed; top: var(--nav-h); bottom: 0; left: 0; z-index: 15;
    margin-left: calc(-1 * var(--side-w));
  }
  .shell.open .sidebar { margin-left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .doc { padding: 2rem 1.2rem 4rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
