/* ===== Design tokens ===== */
:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-2: #475569;
    --muted: #64748b;
    --primary: #2457a8;
    --primary-dark: #1c4486;
    --primary-soft: #e8effa;
    --danger: #b3322b;
    --danger-soft: #fbeae9;
    --success: #1e7a40;
    --success-soft: #e4f4ea;
    --warning: #8a6116;
    --warning-soft: #faf2dd;
    --sidebar-bg: #0e1726;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(59, 130, 246, 0.18);
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.14);
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "Cascadia Code", "Segoe UI Mono", Consolas, monospace;
}

[data-theme="dark"] {
    --bg: #0b1220;
    --surface: #111a2c;
    --surface-2: #16213a;
    --border: #1f2c47;
    --border-strong: #2d3d5e;
    --text: #e6edf6;
    --text-2: #aab8cc;
    --muted: #7e8da5;
    --primary: #5b8def;
    --primary-dark: #79a2f2;
    --primary-soft: #1a2945;
    --danger: #e0635c;
    --danger-soft: #3a1d1f;
    --success: #4ec47e;
    --success-soft: #14301f;
    --warning: #d9a93e;
    --warning-soft: #332a14;
    --sidebar-bg: #090f1b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

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

h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
h2 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
code { font-family: var(--mono); font-size: 0.9em; }

/* ===== App shell ===== */
.shell { display: flex; min-height: 100vh; }

.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Topbar */
.topbar-brand {
    display: flex; align-items: center; gap: 8px;
    color: var(--text); font-weight: 700; font-size: 15.5px; letter-spacing: -0.01em;
    margin-right: 10px; white-space: nowrap;
}
.topbar-brand i { font-size: 21px; color: var(--primary); }
.topbar-brand:hover { text-decoration: none; }

.topbar {
    height: 54px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 14px;
    padding: 0 22px;
    position: sticky; top: 0; z-index: 50;
}
.breadcrumbs { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); min-width: 0; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--primary); text-decoration: none; }
.breadcrumbs .sep { opacity: 0.5; }
.breadcrumbs .current { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar .spacer { flex: 1; }

.global-search { position: relative; }
.global-search i {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--muted); font-size: 15px; pointer-events: none;
}
.topbar .global-search input[type=search] {
    width: 280px; padding: 7px 64px 7px 34px; margin: 0;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface-2); color: var(--text);
    font: inherit; font-size: 13.5px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.topbar .global-search input[type=search]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); background: var(--surface); }
.global-search kbd {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    font-family: var(--font); font-size: 10.5px; color: var(--muted);
    border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px;
    background: var(--surface);
}

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    border: none; background: transparent; border-radius: 7px;
    color: var(--muted); font-size: 18px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* User menu */
.user-menu { position: relative; }
.btn.active-admin { background: var(--primary-soft); color: var(--primary); }
.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12.5px; font-weight: 700; cursor: pointer; border: none;
}
.dropdown {
    position: absolute; right: 0; top: calc(100% + 8px);
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    display: none;
    z-index: 100;
}
.dropdown.open { display: block; }
.dropdown .dropdown-header { padding: 8px 12px 6px; border-bottom: 1px solid var(--border); margin-bottom: 5px; }
.dropdown .dropdown-header .name { font-weight: 650; font-size: 13.5px; }
.dropdown .dropdown-header .email { font-size: 12px; color: var(--muted); }
.dropdown a, .dropdown button {
    display: flex; align-items: center; gap: 9px;
    width: 100%; padding: 7px 12px;
    border: none; background: none; border-radius: 6px;
    color: var(--text); font: inherit; font-size: 13.5px; text-align: left; cursor: pointer;
}
.dropdown a:hover, .dropdown button:hover { background: var(--surface-2); text-decoration: none; }
.dropdown i { font-size: 16px; color: var(--muted); }

/* Content */
.content { padding: 26px 30px 60px; max-width: 1240px; width: 100%; margin: 0 auto; }
.content.narrow { max-width: 460px; padding-top: 8vh; }
.content.wide { max-width: none; }

.page-header { margin-bottom: 20px; }
.page-header .sub { color: var(--muted); font-size: 13.5px; margin: 2px 0 0; }

/* ===== Components ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}
.card > h2:first-child { margin-top: 0; }

.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 15px;
    background: var(--primary); color: #fff;
    border: 1px solid transparent; border-radius: var(--radius);
    font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
    transition: background 0.12s, box-shadow 0.12s;
    text-decoration: none;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--text-2); border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { filter: brightness(0.92); background: var(--danger); }
.btn.small { padding: 4px 11px; font-size: 12.5px; }
.btn i { font-size: 15px; }

label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 13px; color: var(--text-2); }
input[type=text], input[type=email], input[type=password], input[type=search], textarea, select {
    width: 100%; padding: 8px 11px; margin-bottom: 14px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    font: inherit; font-size: 14px;
    background: var(--surface); color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { min-height: 120px; resize: vertical; }

/* Tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th {
    text-align: left; padding: 9px 12px;
    color: var(--muted); font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-strong);
    position: sticky; top: 54px; background: var(--surface); z-index: 5;
}
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
table.list tr:hover td { background: var(--surface-2); }
table.list a.rowlink { font-weight: 600; color: var(--text); }
table.list a.rowlink:hover { color: var(--primary); }

/* Badges */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 9px; border-radius: 99px;
    font-size: 11.5px; font-weight: 600;
    background: var(--primary-soft); color: var(--primary);
    white-space: nowrap;
}
.badge.draft { background: var(--warning-soft); color: var(--warning); }
.badge.muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

/* Alerts → toasts */
.toast-stack { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
    display: flex; align-items: flex-start; gap: 10px;
    min-width: 300px; max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 13px 16px;
    font-size: 13.5px;
    animation: toast-in 0.25s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.success i { color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.error i { color: var(--danger); }
.toast i { font-size: 18px; margin-top: 1px; }
.toast .close { margin-left: auto; cursor: pointer; color: var(--muted); background: none; border: none; font-size: 15px; padding: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.errors {
    background: var(--danger-soft); color: var(--danger);
    border-radius: var(--radius); padding: 10px 14px 10px 30px;
    font-size: 13.5px; margin: 0 0 16px;
}

/* Tabs */
.tabs { display: flex; gap: 2px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tabs a {
    padding: 8px 15px 9px;
    color: var(--muted); font-weight: 600; font-size: 13.5px;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Toolbar */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; margin-bottom: 0; }
.toolbar input[type=search] { min-width: 240px; }

.checks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 3px 12px; margin-bottom: 14px;
    max-height: 300px; overflow-y: auto;
    padding: 4px 2px;
}
.checks label { font-weight: normal; margin: 0; color: var(--text); font-size: 13.5px; }

ul.pagination { display: flex; gap: 5px; list-style: none; padding: 0; margin: 18px 0 0; }
.pagination .page {
    display: inline-block; padding: 4px 11px;
    border: 1px solid var(--border); border-radius: 7px;
    background: var(--surface); font-size: 13px;
}
.pagination a.page:hover { text-decoration: none; background: var(--surface-2); }
.pagination .page.current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Empty state */
.empty-state { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty-state i { font-size: 44px; opacity: 0.4; display: block; margin-bottom: 12px; }
.empty-state .title { font-weight: 650; font-size: 15px; color: var(--text-2); margin-bottom: 4px; }
.empty-state .btn { margin-top: 16px; }

/* Product grid */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px; }
.product-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
    display: flex; flex-direction: column; gap: 8px;
}
.product-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-1px); }
.product-card .title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.product-card .title a { color: var(--text); }
.product-card .desc { color: var(--muted); font-size: 13px; flex: 1; }
.product-card .parts { display: flex; gap: 6px; flex-wrap: wrap; }

/* ===== Docs layout ===== */
.layout-docs { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 26px; align-items: start; }
.layout-docs.with-toc { grid-template-columns: 250px minmax(0, 1fr) 190px; }

.doc-tree { font-size: 13.5px; position: sticky; top: 78px; max-height: calc(100vh - 100px); overflow-y: auto; padding-right: 6px; }
.doc-tree ul { list-style: none; margin: 0; padding-left: 0; }
.doc-tree ul ul { padding-left: 14px; }
.doc-tree .chapter {
    font-weight: 700; font-size: 11.5px; color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.07em;
    margin: 16px 0 5px; display: block;
}
.doc-tree li { margin: 0; }
.doc-tree a {
    display: block; padding: 4px 10px;
    border-radius: 6px; color: var(--text-2);
    border-left: 2px solid transparent;
}
.doc-tree a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.doc-tree a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.doc-tree form input { margin-bottom: 6px; }

.doc-page { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: 34px 42px 28px; }
.doc-page .doc-title { font-size: 27px; margin-bottom: 18px; }
.doc-page .doc-meta {
    display: flex; gap: 14px; align-items: center;
    color: var(--muted); font-size: 12.5px;
    border-top: 1px solid var(--border); margin-top: 30px; padding-top: 14px;
}

.doc-toc { position: sticky; top: 78px; font-size: 12.5px; }
.doc-toc .toc-title { font-weight: 700; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 8px; }
.doc-toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.doc-toc li a { display: block; padding: 3px 0 3px 12px; color: var(--muted); border-left: 2px solid transparent; margin-left: -1px; }
.doc-toc li.h3 a { padding-left: 24px; }
.doc-toc li a:hover { color: var(--text); text-decoration: none; }
.doc-toc li a.active { color: var(--primary); border-left-color: var(--primary); font-weight: 600; }

.doc-pager { display: flex; gap: 14px; margin-top: 16px; }
.doc-pager a {
    flex: 1; display: flex; flex-direction: column; gap: 2px;
    padding: 13px 17px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    color: var(--text);
}
.doc-pager a:hover { border-color: var(--primary); text-decoration: none; box-shadow: var(--shadow-sm); }
.doc-pager .dir { font-size: 11.5px; color: var(--muted); }
.doc-pager .next { text-align: right; margin-left: auto; }
.doc-pager .ptitle { font-weight: 600; font-size: 13.5px; }

/* Prose (rendered markdown) */
.prose { font-size: 14.5px; line-height: 1.75; max-width: 760px; }
.prose h1, .prose h2, .prose h3 { letter-spacing: -0.01em; scroll-margin-top: 70px; }
.prose h2 { font-size: 19px; margin: 30px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 15.5px; margin: 22px 0 8px; }
.prose img { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.prose pre {
    background: #0e1726; color: #dbe4f0;
    padding: 14px 18px; border-radius: var(--radius);
    overflow-x: auto; font-size: 12.5px; line-height: 1.6;
}
[data-theme="dark"] .prose pre { background: #0a111f; border: 1px solid var(--border); }
.prose code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 5px; font-size: 0.88em; }
.prose pre code { background: none; border: none; padding: 0; font-size: inherit; }
.prose blockquote {
    border-left: 3px solid var(--primary);
    background: var(--primary-soft);
    margin: 14px 0; padding: 10px 16px;
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-2);
}
.prose blockquote p { margin: 0; }
.prose table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 13.5px; }
.prose th { background: var(--surface-2); font-weight: 600; text-align: left; }
.prose th, .prose td { border: 1px solid var(--border); padding: 7px 12px; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 26px 0; }

.meta { color: var(--muted); font-size: 12.5px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-form { display: inline; }

details > summary { cursor: pointer; }

/* Auth (guest) */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 700; margin-bottom: 22px; color: var(--text); }
.auth-brand i { font-size: 26px; color: var(--primary); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 30px 32px; }
.auth-card h1 { font-size: 19px; margin-bottom: 16px; }
.auth-card .btn { width: 100%; justify-content: center; margin-top: 4px; }
.auth-footer { margin-top: 16px; font-size: 13px; color: var(--muted); text-align: center; }

/* Responsive */
@media (max-width: 1100px) {
    .layout-docs.with-toc { grid-template-columns: 240px minmax(0, 1fr); }
    .doc-toc { display: none; }
}
@media (max-width: 860px) {
    .layout-docs, .layout-docs.with-toc { grid-template-columns: 1fr; }
    .doc-tree { position: static; max-height: none; }
    .global-search input { width: 160px; }
}
