:root {
  --bg: #0b111a;
  --bg-2: #0e1622;
  --surface: #131d2b;
  --surface-2: #18243460;
  --raised: #1a2738;
  --ink: #e8eef6;
  --muted: #93a6bd;
  --faint: #6b7e95;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.16);
  --accent: #2dd4bf;
  --accent-2: #14b8a6;
  --accent-ink: #052e2b;
  --accent-soft: rgba(45, 212, 191, 0.13);
  --danger: #f87171;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 30px rgba(0, 0, 0, .28);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.65; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #283648; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #34465c; }

/* ---------- Auth ---------- */
.auth-body { display: grid; place-items: center; min-height: 100%; padding: 24px;
  background: radial-gradient(1100px 560px at 50% -10%, #15324a 0%, var(--bg) 60%); }
.auth-card { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); padding: 30px; }
.lang-switch-row { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.auth-logo { width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center; font-weight: 700; letter-spacing: .5px;
  color: var(--accent-ink); background: linear-gradient(150deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 22px rgba(45, 212, 191, .25); }
.auth-brand h1 { font-size: 18px; margin: 0; font-weight: 600; }
.auth-brand p { margin: 3px 0 0; font-size: 12px; }
.tabs { display: flex; gap: 5px; background: var(--bg-2); padding: 4px; border-radius: 11px; margin-bottom: 20px; border: 1px solid var(--line); }
.tab { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 8px; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; transition: .15s; }
.tab.active { background: var(--raised); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
.auth-form { display: grid; gap: 15px; }
.auth-form label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.auth-form input { font: inherit; font-size: 14px; padding: 12px 13px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--bg-2); color: var(--ink); transition: .15s; }
.auth-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: 11px 15px; font-size: 14px; transition: .15s; }
.btn.primary { background: linear-gradient(150deg, var(--accent), var(--accent-2)); color: var(--accent-ink); font-weight: 700; box-shadow: 0 6px 18px rgba(45, 212, 191, .22); }
.btn.primary:hover { filter: brightness(1.07); transform: translateY(-1px); }
.btn.ghost { background: transparent; border-color: var(--line-2); color: var(--ink); }
.btn.ghost:hover { background: var(--raised); border-color: #34465c; }
.msg { min-height: 18px; margin: 14px 0 0; font-size: 13px; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--accent); }
.fineprint { margin: 16px 0 0; font-size: 11px; color: var(--faint); text-align: center; }
.cf-ts:empty { display: none; }

/* ---------- Topbar ---------- */
.topbar { height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
  background: linear-gradient(180deg, #0a1019, #0c1420); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none;
  color: var(--accent-ink); background: linear-gradient(150deg, var(--accent), var(--accent-2)); box-shadow: 0 4px 14px rgba(45, 212, 191, .25); }
.brand-text { font-size: 15.5px; font-weight: 600; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text em { font-style: normal; color: var(--muted); font-weight: 400; }
.topbar-right { display: flex; align-items: center; gap: 11px; }
#search { font: inherit; font-size: 13px; padding: 8px 12px; width: 200px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--bg-2); color: var(--ink); transition: .15s; }
#search::placeholder { color: var(--faint); }
#search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); width: 230px; }
.lang-switch { font: inherit; font-size: 12.5px; padding: 7px 9px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--bg-2); color: var(--ink); cursor: pointer; }
.lang-switch:focus { outline: none; border-color: var(--accent); }
.user { font-size: 13px; color: var(--muted); }
.user::before { content: "●"; color: var(--accent); font-size: 9px; margin-right: 6px; vertical-align: middle; }
.topbar .btn.ghost { padding: 8px 13px; }

/* ---------- Tab bar ---------- */
.tabbar { display: flex; gap: 2px; align-items: center; padding: 0 16px; height: 46px;
  background: var(--bg-2); border-bottom: 1px solid var(--line); position: sticky; top: 60px; z-index: 15; overflow-x: auto; }
.mode-btn { background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font: inherit; font-size: 13.5px;
  padding: 12px 16px; cursor: pointer; white-space: nowrap; transition: .15s; }
.mode-btn:hover { color: var(--ink); }
.mode-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 290px 1fr; min-height: calc(100% - 106px); }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); padding: 16px 10px; overflow-y: auto;
  max-height: calc(100vh - 106px); position: sticky; top: 106px; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 8px 11px; border-radius: 9px; color: var(--muted); font-size: 13.5px; cursor: pointer; transition: .12s; position: relative; }
.nav-item:hover { background: var(--surface); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 3px; background: var(--accent); }
.nav-item.nav-group { font-weight: 700; text-transform: uppercase; letter-spacing: .5px; font-size: 11px; color: var(--faint); margin-top: 12px; cursor: pointer; }
.nav-ic { width: 18px; text-align: center; font-size: 13px; flex: none; }
.nav-tt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.depth-0 { font-weight: 600; color: var(--ink); }
.depth-1 { padding-left: 12px; }
.depth-2 { padding-left: 26px; }
.depth-3 { padding-left: 38px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

.content { padding: 34px 44px 90px; max-width: 920px; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.crumbs a:hover { color: var(--accent); }
.content h1.page-title { font-size: 25px; margin: 4px 0 16px; letter-spacing: -.3px; font-weight: 600; }
.badge { display: inline-block; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; padding: 3px 9px; border-radius: 20px; vertical-align: middle; border: 1px solid transparent; }
.badge.standard { background: var(--accent-soft); color: var(--accent); border-color: rgba(45, 212, 191, .25); }
.badge.procedure { background: rgba(96, 165, 250, .14); color: #93c5fd; border-color: rgba(96, 165, 250, .25); }
.badge.reference { background: rgba(167, 139, 250, .14); color: #c4b5fd; border-color: rgba(167, 139, 250, .25); }
.badge.strategy { background: rgba(251, 191, 36, .14); color: #fcd34d; border-color: rgba(251, 191, 36, .25); }
.badge.template, .badge.index, .badge.section-landing { background: rgba(148, 163, 184, .14); color: #cbd5e1; border-color: rgba(148, 163, 184, .22); }

.doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 30px 32px; box-shadow: var(--shadow); }
.doc h1 { font-size: 20px; margin: 24px 0 10px; font-weight: 600; }
.doc h2 { font-size: 17.5px; margin: 22px 0 9px; font-weight: 600; }
.doc h3 { font-size: 15px; margin: 18px 0 7px; color: #b9d8d3; font-weight: 600; }
.doc h1:first-child, .doc h2:first-child { margin-top: 4px; }
.doc p { margin: 10px 0; color: #d5dfeb; }
.doc ul { margin: 9px 0; padding-left: 22px; }
.doc li { margin: 5px 0; color: #d5dfeb; }
.doc strong { color: var(--ink); font-weight: 600; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.doc code { background: var(--bg-2); padding: 1px 6px; border-radius: 5px; font-size: 13px; color: #9be7dd; border: 1px solid var(--line); }
.doc a { color: var(--accent); }
.doc blockquote { margin: 14px 0; padding: 12px 16px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 9px 9px 0; color: #c8efe9; }
.doc blockquote p { margin: 4px 0; color: #c8efe9; }

.children { margin-top: 26px; }
.children h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--faint); margin-bottom: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 13px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 15px; box-shadow: var(--shadow-sm); cursor: pointer; transition: .15s; }
.card:hover { border-color: rgba(45, 212, 191, .4); transform: translateY(-2px); box-shadow: var(--shadow); }
.card .card-t { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.card .card-b { font-size: 11px; }
.empty { color: var(--muted); padding: 44px; text-align: center; }

/* ---------- Operations / data tables ---------- */
.ops-intro { margin: -4px 0 18px; font-size: 13px; }
.ops-form { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: var(--shadow-sm); }
.ops-form input, .ops-form select { font: inherit; font-size: 13.5px; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--bg-2); color: var(--ink); }
.ops-form input[name="title"], .ops-form input[name="name"] { flex: 1; min-width: 200px; }
.ops-form input:focus, .ops-form select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ops-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-sm); }
.ops-table th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--faint); padding: 11px 13px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.ops-table td { padding: 10px 13px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; color: #d5dfeb; }
.ops-table tr:last-child td { border-bottom: 0; }
.ops-table tr:hover td { background: rgba(255, 255, 255, .02); }
.ops-table tr.done td { color: var(--faint); }
.ops-table tr.done td:nth-child(2) { text-decoration: line-through; }
.ops-table a { color: var(--accent); }
.ops-mini { font: inherit; font-size: 12.5px; padding: 6px 9px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--bg-2); color: var(--ink); }
.ops-sum { color: var(--muted); max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ops-del { border: 0; background: transparent; color: var(--faint); font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 7px; border-radius: 6px; transition: .12s; }
.ops-del:hover { background: rgba(248, 113, 113, .14); color: var(--danger); }
.lvl { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 20px; }
.lvl-P1 { background: rgba(248, 113, 113, .16); color: #fca5a5; }
.lvl-P2 { background: rgba(251, 191, 36, .16); color: #fcd34d; }
.lvl-P3 { background: rgba(96, 165, 250, .16); color: #93c5fd; }
.lvl-P4 { background: rgba(148, 163, 184, .16); color: #cbd5e1; }

/* ---------- Versioning ---------- */
.ver-chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.ver-cell { white-space: nowrap; }
.ops-ver { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; padding: 1px 5px; border-radius: 5px; }
.ops-ver:hover { background: var(--raised); color: var(--ink); }
.ver-history { margin-top: 18px; max-width: 680px; }
.ver-history .ver-h-title { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--faint); margin-bottom: 8px; }
.ver-h-row { font-size: 13px; padding: 8px 0; border-bottom: 1px solid var(--line); color: #d5dfeb; }

/* ---------- Templates generator ---------- */
.tpl-form { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; max-width: 820px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 22px; box-shadow: var(--shadow); }
.tpl-f { display: grid; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.tpl-f.tpl-wide { grid-column: 1 / -1; }
.tpl-f input, .tpl-f select, .tpl-f textarea { font: inherit; font-size: 14px; font-weight: 400; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--bg-2); color: var(--ink); }
.tpl-f textarea { resize: vertical; min-height: 74px; line-height: 1.6; }
.tpl-f input:focus, .tpl-f select:focus, .tpl-f textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tpl-actions { grid-column: 1 / -1; display: flex; gap: 10px; margin-top: 4px; }
.tpl-bar { display: flex; align-items: center; gap: 9px; margin: 4px 0 18px; flex-wrap: wrap; }
.tpl-doc { max-width: 820px; }
@media (max-width: 820px) { .tpl-form { grid-template-columns: 1fr; } }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  #search { width: 130px; }
  #search:focus { width: 150px; }
  .content { padding: 22px; }
  .brand-text em { display: none; }
}
