/* CaspianERP Documentation.

   Light is the default and is not tied to the reader's OS: documentation is
   read for long stretches, and a manual that flips to dark because someone's
   laptop did is a manual that looks broken. Dark is a deliberate choice, made
   with the header toggle and remembered per browser (`data-theme` on <html>).

   Colours are the app's, warmed slightly: the same indigo accent, but on a
   paper ground rather than pure white, so long reading is easier on the eye. */

:root {
  --indigo-50:  #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;

  --bg:        #ffffff;
  --bg-page:   #fbfcfd;   /* the ground behind the reading column */
  --bg-subtle: #f7f9fb;
  --bg-sunken: #eef2f6;
  --border:    #e4e9ef;
  --border-strong: #cbd5e1;
  --text:      #16202b;
  --text-muted:#5b6b7c;
  --text-soft: #8b9aa8;
  --primary:   var(--indigo-600);
  --primary-contrast: #ffffff;
  --accent-bg: var(--indigo-50);
  --danger:    #b91c1c;
  --danger-bg: #fef2f2;
  --warn-bg:   #fffbeb;
  --warn-border:#fde68a;
  --warn-text: #92400e;

  --ok:        #1b7a4b;
  --ok-bg:     #edf7f1;
  --ok-border: #bfe3ce;
  --info-bg:   #eff4fb;
  --info-border:#cfdff2;

  --topbar-h: 58px;
  --sidebar-w: 276px;
  --toc-w: 228px;
  --radius: 10px;
  --measure: 74ch;        /* the reading column's comfortable width */

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
          "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: light;
}

/* Dark is opt-in only — never `prefers-color-scheme`. */
:root[data-theme="dark"] {
  --bg:        #0f1620;
  --bg-page:   #0b1119;
  --bg-subtle: #141d29;
  --bg-sunken: #1b2734;
  --border:    #223041;
  --border-strong: #33475c;
  --text:      #e4ebf2;
  --text-muted:#9aabbb;
  --text-soft: #6b7d8e;
  --primary:   #8b95f8;
  --primary-contrast: #0f1620;
  --accent-bg: #1d2145;
  --danger:    #fca5a5;
  --danger-bg: #2a1416;
  --warn-bg:   #2a2010;
  --warn-border:#5a4213;
  --warn-text: #fcd34d;
  --ok:        #6ee7a8;
  --ok-bg:     #10241a;
  --ok-border: #1f4733;
  --info-bg:   #14202f;
  --info-border:#24384f;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--text-muted); }
[hidden] { display: none !important; }

/* --- Brand ---------------------------------------------------------- */

.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none; flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand-name { font-weight: 600; letter-spacing: -0.01em; font-size: 16px; }
.brand-lg { justify-content: center; margin-bottom: 20px; }
.brand-lg .brand-name { font-size: 20px; }
.brand-sub {
  color: var(--text-muted); font-size: 14px;
  padding-left: 10px; margin-left: 2px; border-left: 1px solid var(--border);
}
/* The mark and name go to the product site; "Documentation" is this site's
   own home. Two destinations, so they are two links, not one. */
a.brand-sub { color: var(--text-muted); }
a.brand-sub:hover { color: var(--text); text-decoration: none; }
a.brand-sub[aria-current="page"] { color: var(--text); font-weight: 500; }

/* --- Full-screen states (boot / sign-in / denied) -------------------- */

.screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg-subtle);
}
.screen-inner { width: 100%; max-width: 380px; text-align: center; }
.screen-title { font-size: 20px; font-weight: 600; margin: 0 0 8px; letter-spacing: -0.01em; }

.card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px 28px;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.04), 0 8px 24px rgb(15 23 42 / 0.06);
}

/* --- Buttons and form fields ---------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 10px 16px; border-radius: 8px; font: inherit;
  font-weight: 500; cursor: pointer; border: 1px solid transparent;
  transition: background-color .12s, border-color .12s;
}
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--indigo-700); }
.btn-google, .btn-secondary {
  background: var(--bg); color: var(--text); border-color: var(--border-strong);
}
.btn-google:hover, .btn-secondary:hover { background: var(--bg-sunken); }
.btn-ghost {
  width: auto; background: transparent; color: var(--text-muted);
  padding: 6px 10px; font-size: 13px;
}
.btn-ghost:hover { background: var(--bg-sunken); color: var(--text); }

.field { display: block; text-align: left; margin-bottom: 14px; }
.field > span {
  display: block; font-size: 13px; font-weight: 500;
  color: var(--text-muted); margin-bottom: 5px;
}
.field input {
  width: 100%; padding: 9px 12px; font: inherit;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
.field input:focus-visible,
.btn:focus-visible,
.lang-select:focus-visible,
.search input:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}

.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0; color: var(--text-soft); font-size: 13px;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.error {
  margin-top: 16px; padding: 10px 12px; border-radius: 8px;
  background: var(--danger-bg); color: var(--danger);
  font-size: 13.5px; text-align: left;
}

.lang-row { display: flex; justify-content: center; gap: 4px; margin-top: 22px; }
.lang-row button {
  background: none; border: 0; font: inherit; font-size: 13px; cursor: pointer;
  color: var(--text-muted); padding: 4px 10px; border-radius: 6px;
}
.lang-row button:hover { background: var(--bg-sunken); color: var(--text); }
.lang-row button[aria-current="true"] { color: var(--primary); font-weight: 600; }

/* --- Top bar --------------------------------------------------------- */

/* Three columns rather than a flex row: the search is centred on the page,
   not merely "after the brand", so it stays put as the ends change width. */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: grid; grid-template-columns: 1fr minmax(0, 520px) 1fr;
  align-items: center; gap: 16px;
  padding: 0 20px; background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-start { display: flex; align-items: center; gap: 10px; min-width: 0; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.only-mobile { display: none; }

/* One button, two glyphs: show the theme you would switch *to*. */
#btn-theme .ico-moon { display: none; }
:root[data-theme="dark"] #btn-theme .ico-sun { display: none; }
:root[data-theme="dark"] #btn-theme .ico-moon { display: inline; }

.topbar-end { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }

.badge {
  font-size: 11.5px; font-weight: 500; letter-spacing: .01em;
  color: var(--text-muted); background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 9px;
}

.lang-select {
  font: inherit; font-size: 13px; padding: 5px 8px; cursor: pointer;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}

/* --- Search ---------------------------------------------------------- */

.search { position: relative; display: flex; align-items: center; }
.search > svg {
  position: absolute; left: 11px; color: var(--text-soft); pointer-events: none;
}
.search input {
  width: 100%; padding: 8px 40px 8px 34px; font: inherit; font-size: 14px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-subtle); color: var(--text);
  transition: border-color .12s, background-color .12s;
}
.search input::placeholder { color: var(--text-soft); }
.search input:hover { border-color: var(--border-strong); }
.search input:focus { background: var(--bg); }

/* The shortcut exists; the hint is what makes anyone use it. */
.search-kbd {
  position: absolute; right: 9px; pointer-events: none;
  font-family: var(--mono); font-size: 11px; line-height: 1;
  color: var(--text-soft); background: var(--bg);
  border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 5px; padding: 3px 6px;
}
.search input:focus ~ .search-kbd,
.search input:not(:placeholder-shown) ~ .search-kbd { display: none; }

.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  max-height: 60vh; overflow-y: auto; z-index: 50;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px;
  box-shadow: 0 10px 30px rgb(15 23 42 / 0.12);
}
.search-results a {
  display: block; padding: 8px 10px; border-radius: 7px; color: var(--text);
}
.search-results a:hover, .search-results a.active {
  background: var(--accent-bg); text-decoration: none;
}
.search-results .r-title { font-weight: 500; font-size: 14px; }
.search-results .r-group { font-size: 12px; color: var(--text-muted); }
.search-results .r-snippet {
  font-size: 12.5px; color: var(--text-muted); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.search-results mark {
  background: var(--accent-bg); color: inherit; font-weight: 600;
  padding: 0 1px; border-radius: 2px;
}
.search-empty { padding: 12px 10px; color: var(--text-muted); font-size: 13.5px; }

/* --- Layout ---------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  align-items: start;
  max-width: 1440px; margin: 0 auto;
}

.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding: 20px 12px 40px; border-right: 1px solid var(--border);
}

.sidebar-org {
  font-size: 12px; color: var(--text-muted);
  padding: 0 10px 14px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.sidebar-org strong { color: var(--text); font-weight: 600; display: block; }

.nav-group + .nav-group { margin-top: 4px; }

/* The group heading is a real button: nine groups of pages is a long rail,
   and the one you are reading is usually the only one you want open. */
.nav-group-label {
  display: flex; align-items: center; gap: 7px; width: 100%;
  font: inherit; font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-soft);
  padding: 7px 10px; margin: 0; border: 0; border-radius: 7px;
  background: none; cursor: pointer; text-align: left;
}
.nav-group-label:hover { background: var(--bg-sunken); color: var(--text-muted); }
.nav-group-label .chev {
  flex: none; transition: transform .16s ease; color: var(--text-soft);
}
.nav-group-label[aria-expanded="false"] .chev { transform: rotate(-90deg); }
.nav-group-label .count {
  margin-left: auto; font-size: 11px; font-weight: 500; letter-spacing: 0;
  color: var(--text-soft); opacity: 0;
}
.nav-group-label[aria-expanded="false"] .count { opacity: 1; }

.nav-group ul { list-style: none; margin: 0 0 6px; padding: 0 0 0 9px; }
.nav-group ul[hidden] { display: none; }
.nav-group li { border-left: 1px solid var(--border); }
.nav-group a {
  display: block; padding: 5px 10px; margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--text-muted); font-size: 14px; line-height: 1.45;
}
.nav-group a:hover { color: var(--text); text-decoration: none; border-left-color: var(--border-strong); }
.nav-group a[aria-current="page"] {
  color: var(--primary); font-weight: 500; border-left-color: var(--primary);
  background: linear-gradient(90deg, var(--accent-bg), transparent 92%);
}

.main { min-width: 0; padding: 40px 52px 90px; background: var(--bg-page); }

.toc {
  position: sticky; top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding: 36px 20px 40px;
}
.toc-title {
  font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-soft); margin: 0 0 8px;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: block; padding: 3px 0; font-size: 13px;
  color: var(--text-muted); line-height: 1.5;
}
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.active { color: var(--primary); font-weight: 500; }

.sidebar-scrim {
  position: fixed; inset: var(--topbar-h) 0 0; z-index: 25;
  background: rgb(15 23 42 / 0.4);
}

/* --- Document content ------------------------------------------------ */

.doc { max-width: var(--measure); font-size: 15.5px; line-height: 1.72; }

.doc h1 {
  font-size: 33px; font-weight: 650; letter-spacing: -0.022em;
  margin: 0 0 10px; line-height: 1.2;
}
.doc .doc-group {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--primary); margin: 0 0 8px;
}
/* A rule under the title separates "what this page is" from the page. */
.doc > h1 + p, .doc > h1 { padding-bottom: 0; }
.doc h1 + h3 { margin-top: 30px; }

.doc h3 {
  font-size: 20px; font-weight: 620; letter-spacing: -0.012em;
  margin: 40px 0 12px; padding-top: 8px;
  scroll-margin-top: calc(var(--topbar-h) + 20px);
  border-top: 1px solid var(--border);
}
.doc h3:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.doc h4 {
  font-size: 16px; font-weight: 620; margin: 26px 0 7px;
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}
.doc h5 { font-size: 14.5px; font-weight: 620; margin: 20px 0 5px; color: var(--text-muted); }
.doc p { margin: 0 0 15px; }
.doc ul, .doc ol { margin: 0 0 14px; padding-left: 22px; }
.doc li { margin-bottom: 5px; }
.doc li > ul, .doc li > ol { margin-top: 5px; }
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 32px 0; }
/* Section headings now carry their own rule, so anything that already ends in
   one — a manual `---`, the meta strip — drew a second line with a gap
   between. Keep whichever comes first and drop the heading's. */
.doc hr + h3,
.doc .doc-meta + h3 { border-top: 0; padding-top: 0; }
.doc hr + h3 { margin-top: 26px; }
.doc .doc-meta + h3 { margin-top: 30px; }
.doc strong { font-weight: 600; color: var(--text); }

.doc code {
  font-family: var(--mono); font-size: .875em;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 5px;
}
.doc pre {
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  overflow-x: auto; margin: 0 0 18px;
}
.doc pre code { background: none; border: 0; padding: 0; font-size: 13px; }

/* The Department / Route / Permissions line each page opens with: facts about
   the page, so a quiet strip rather than a callout competing with the asides. */
.doc .doc-meta {
  margin: 0 0 26px; padding: 12px 0 14px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  font-size: 13.5px; color: var(--text-muted);
}
.doc .doc-meta p { margin: 0; }
.doc .doc-meta strong { color: var(--text-soft); font-weight: 600; }
.doc .doc-meta code {
  background: var(--bg-subtle); border-color: var(--border);
  color: var(--text-muted); font-size: .86em;
}

/* Blockquotes in this manual are asides — "worth knowing", "do this first" —
   so they read as a card with a marker rather than a quotation. */
.doc blockquote {
  margin: 0 0 20px; padding: 14px 18px 14px 44px; position: relative;
  background: var(--info-bg); border: 1px solid var(--info-border);
  border-radius: var(--radius); font-size: 14.5px;
}
.doc blockquote::before {
  content: ""; position: absolute; left: 17px; top: 18px;
  width: 15px; height: 15px; border-radius: 50%;
  border: 1.5px solid var(--primary); opacity: .75;
  background:
    linear-gradient(var(--primary), var(--primary)) center 3px / 1.5px 1.5px no-repeat,
    linear-gradient(var(--primary), var(--primary)) center 7.5px / 1.5px 5px no-repeat;
}
.doc blockquote > :last-child { margin-bottom: 0; }
.doc blockquote strong:first-child { color: var(--text); }

.table-scroll {
  overflow-x: auto; margin: 0 0 22px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg);
}
.doc table {
  border-collapse: collapse; width: 100%; font-size: 14px;
}
.doc th, .doc td {
  text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.doc th {
  background: var(--bg-subtle); font-weight: 600; white-space: nowrap;
  font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted);
}
.doc tbody tr:last-child td { border-bottom: 0; }
.doc tbody tr:hover td { background: var(--bg-subtle); }
/* A field table's first column is the field name — worth the emphasis. */
.doc td:first-child strong { color: var(--text); }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px; margin: 0 0 22px; border-radius: var(--radius);
  background: var(--warn-bg); border: 1px solid var(--warn-border);
  color: var(--warn-text); font-size: 13.5px;
}

/* --- Prev / next ------------------------------------------------------ */

.pager {
  display: flex; gap: 12px; max-width: 780px;
  margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border);
}
.pager a {
  flex: 1; min-width: 0; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text);
}
.pager a:hover { border-color: var(--primary); text-decoration: none; }
.pager .p-dir { display: block; font-size: 12px; color: var(--text-muted); }
.pager .p-title {
  display: block; font-weight: 500; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pager .p-next { text-align: right; margin-left: auto; }

/* --- Responsive ------------------------------------------------------- */

@media (max-width: 1180px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .only-mobile { display: inline-flex; }
  .brand-sub { display: none; }
  .badge { display: none; }
  .main { padding: 24px 20px 64px; }

  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; z-index: 30;
    width: var(--sidebar-w); background: var(--bg);
    transform: translateX(-100%); transition: transform .18s ease;
  }
  .sidebar.open { transform: translateX(0); }
}

@media (max-width: 560px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .brand-name { display: none; }
  .doc h1 { font-size: 25px; }
  .pager { flex-direction: column; }
}

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