/* ============================================================================
   Base: reset, typography, app shell, sidebar, topbar, utilities
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: var(--fw-semi); line-height: var(--lh-tight); letter-spacing: -.01em; }
h1 { font-size: var(--fs-2xl); letter-spacing: -.022em; }
h2 { font-size: var(--fs-xl); letter-spacing: -.018em; }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-base); }
p { margin: 0 0 var(--s-3); }
p:last-child { margin-bottom: 0; }

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

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-xs); }

img { max-width: 100%; display: block; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-5) 0; }
code, kbd, pre { font-family: var(--font-mono); font-size: .92em; }

::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; border: 3px solid transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---- Boot splash -------------------------------------------------------- */
.boot {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  background: var(--bg);
  transition: opacity var(--t-slow) var(--ease), visibility var(--t-slow);
}
.boot.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
.boot__inner { display: grid; justify-items: center; gap: var(--s-3); }
.boot__mark { color: var(--accent); animation: bootPulse 1.6s var(--ease) infinite; }
.boot__name { font-weight: var(--fw-semi); font-size: var(--fs-lg); letter-spacing: -.02em; }
.boot__bar { width: 190px; height: 3px; border-radius: 99px; background: var(--border); overflow: hidden; }
.boot__bar i { display: block; height: 100%; width: 40%; border-radius: 99px; background: var(--accent); animation: bootSlide 1.15s var(--ease) infinite; }
.boot__status { font-size: var(--fs-sm); color: var(--muted); min-height: 1.4em; }
@keyframes bootSlide { 0% { transform: translateX(-110%); } 100% { transform: translateX(310%); } }
@keyframes bootPulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* ---- App shell ---------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100%;
  height: 100vh; height: 100dvh;
  overflow: hidden;
}
.app[data-collapsed="true"] { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* ---- Sidebar ------------------------------------------------------------ */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  min-height: 0;
  border-right: 1px solid rgba(255, 255, 255, .06);
  position: relative;
  z-index: 30;
}
.sidebar__brand {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-4);
  height: var(--topbar-h);
  flex: 0 0 auto;
  color: var(--sidebar-ink-strong);
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  overflow: hidden;
}
.sidebar__logo {
  width: 30px; height: 30px; flex: 0 0 auto;
  border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  overflow: hidden;
}
.sidebar__logo img { width: 100%; height: 100%; object-fit: cover; }
.sidebar__logo svg { width: 22px; height: 22px; }
.sidebar__brandtext { min-width: 0; }
.sidebar__name {
  font-weight: var(--fw-semi); font-size: var(--fs-md); letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar__tag { font-size: var(--fs-2xs); color: var(--sidebar-ink); opacity: .75; letter-spacing: .06em; text-transform: uppercase; }

.sidebar__scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: var(--s-3) var(--s-2) var(--s-4); }
.sidebar__group + .sidebar__group { margin-top: var(--s-4); }
.sidebar__label {
  font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .09em;
  color: var(--sidebar-ink); opacity: .55; font-weight: var(--fw-semi);
  padding: 0 var(--s-3) var(--s-2);
}
.navitem {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-3); height: 36px;
  border-radius: var(--r-md);
  color: var(--sidebar-ink);
  font-size: var(--fs-md); font-weight: var(--fw-medium);
  white-space: nowrap; overflow: hidden;
  position: relative;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.navitem:hover { background: var(--sidebar-hover); color: var(--sidebar-ink-strong); text-decoration: none; }
.navitem.is-active { background: var(--sidebar-active); color: var(--sidebar-ink-strong); }
.navitem.is-active::before {
  content: ""; position: absolute; left: -8px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.navitem svg { width: 17px; height: 17px; flex: 0 0 auto; opacity: .85; }
.navitem.is-active svg { opacity: 1; color: var(--accent); }
.navitem__text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.navitem__count {
  font-size: var(--fs-2xs); font-weight: var(--fw-semi);
  padding: 1px 6px; border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .12); color: var(--sidebar-ink-strong);
}
.navitem__count[data-tone="danger"] { background: var(--danger); color: #fff; }
.navitem__count[data-tone="warning"] { background: var(--warning); color: #10131a; }

.sidebar__foot { flex: 0 0 auto; padding: var(--s-3); border-top: 1px solid rgba(255, 255, 255, .06); }
.sidebar__user {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; padding: var(--s-2); border: 0; background: transparent;
  border-radius: var(--r-md); color: var(--sidebar-ink); text-align: left;
  transition: background var(--t-fast) var(--ease);
}
.sidebar__user:hover { background: var(--sidebar-hover); }
.sidebar__user .avatar { flex: 0 0 auto; }
.sidebar__userinfo { min-width: 0; flex: 1 1 auto; }
.sidebar__username { font-size: var(--fs-sm); font-weight: var(--fw-semi); color: var(--sidebar-ink-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__userrole { font-size: var(--fs-2xs); opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.app[data-collapsed="true"] .sidebar__brandtext,
.app[data-collapsed="true"] .navitem__text,
.app[data-collapsed="true"] .navitem__count,
.app[data-collapsed="true"] .sidebar__label,
.app[data-collapsed="true"] .sidebar__userinfo { display: none; }
.app[data-collapsed="true"] .navitem { justify-content: center; padding: 0; }
.app[data-collapsed="true"] .sidebar__label { height: 8px; padding: 0; }
.app[data-collapsed="true"] .sidebar__brand { justify-content: center; padding: 0; }

/* An element marked hidden is hidden, whatever its class says about display. */
[hidden] { display: none !important; }

/* ---- Main column -------------------------------------------------------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

.topbar {
  flex: 0 0 auto; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-5);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: var(--z-sticky);
}
.topbar__search {
  flex: 1 1 auto; max-width: 460px;
  display: flex; align-items: center; gap: var(--s-2);
  height: 34px; padding: 0 var(--s-3);
  background: var(--surface-inset); border: 1px solid var(--border);
  border-radius: var(--r-md); color: var(--muted);
  font-size: var(--fs-md); cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.topbar__search:hover { border-color: var(--border-strong); background: var(--surface-2); }
.topbar__search svg { width: 15px; height: 15px; flex: 0 0 auto; }
.topbar__search span { flex: 1 1 auto; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar__search { min-width: 0; }
@media (max-width: 560px) { .topbar { padding: 0 var(--s-3); gap: var(--s-2); } .topbar__search { flex: 0 1 auto; } .topbar__search span:not(.kbd) { display: none; } .topbar__actions { gap: 2px; } }
.topbar__spacer { flex: 1 1 auto; }
.topbar__actions { display: flex; align-items: center; gap: var(--s-2); flex: 0 0 auto; min-width: 0; }
@media (max-width: 420px) { .topbar__actions .btn--quiet:not(.tourbtn) { padding-inline: 6px; } .topbar .langtoggle__btn { padding-inline: 6px; } }

.kbd {
  display: inline-flex; align-items: center; gap: 2px;
  font-family: var(--font-sans); font-size: var(--fs-2xs); font-weight: var(--fw-semi);
  padding: 2px 5px; border-radius: var(--r-xs);
  background: var(--surface-3); border: 1px solid var(--border);
  color: var(--muted); line-height: 1.4;
}

.viewport { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
.page { max-width: var(--page-max); margin: 0 auto; padding: var(--s-6) var(--s-6) var(--s-16); }
@media (max-width: 720px) { .page { padding: var(--s-4) var(--s-4) var(--s-12); } }

/* ---- Page header -------------------------------------------------------- */
.pagehead { display: flex; align-items: flex-start; gap: var(--s-4); margin-bottom: var(--s-5); flex-wrap: wrap; }
.pagehead__text { flex: 1 1 320px; min-width: 0; }
.pagehead__title { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; min-width: 0; }
.pagehead__title .row-tight { flex-wrap: wrap; min-width: 0; }
.pagehead__sub { color: var(--muted); font-size: var(--fs-md); margin-top: 4px; }
.pagehead__actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }

.crumbs { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--s-2); flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--ink-2); }
.crumbs svg { width: 13px; height: 13px; opacity: .6; }

/* ---- Grid helpers ------------------------------------------------------- */
.grid { display: grid; gap: var(--s-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 1280px) {
  .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-sidebar { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-5 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 620px) { .grid-4 { grid-template-columns: minmax(0, 1fr); } }

.span-2 { grid-column: span 2; }
@media (max-width: 900px) { .span-2 { grid-column: span 1; } }

/* ---- Utilities ---------------------------------------------------------- */
.row { display: flex; align-items: center; gap: var(--s-3); }
.row-tight { display: flex; align-items: center; gap: var(--s-2); }
.row-wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--s-2); }
.spacer { flex: 1 1 auto; }
.right { margin-left: auto; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mono { font-family: var(--font-mono); font-size: .93em; letter-spacing: -.02em; }
.num { font-variant-numeric: tabular-nums; }

.t-xs { font-size: var(--fs-xs); }
.t-sm { font-size: var(--fs-sm); }
.t-md { font-size: var(--fs-md); }
.t-lg { font-size: var(--fs-lg); }
.t-xl { font-size: var(--fs-xl); }
.t-2xl { font-size: var(--fs-2xl); }
.t-muted { color: var(--muted); }
.t-faint { color: var(--faint); }
.t-ink2 { color: var(--ink-2); }
.t-semi { font-weight: var(--fw-semi); }
.t-medium { font-weight: var(--fw-medium); }
.t-bold { font-weight: var(--fw-bold); }
.t-up { text-transform: uppercase; letter-spacing: .06em; }
.t-right { text-align: right; }
.t-success { color: var(--success); }
.t-danger { color: var(--danger); }
.t-warning { color: var(--warning); }
.t-accent { color: var(--accent); }

.mt-0 { margin-top: 0; } .mt-1 { margin-top: var(--s-1); } .mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); } .mt-5 { margin-top: var(--s-5); }
.mt-6 { margin-top: var(--s-6); } .mt-8 { margin-top: var(--s-8); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--s-2); } .mb-3 { margin-bottom: var(--s-3); }
.mb-4 { margin-bottom: var(--s-4); } .mb-5 { margin-bottom: var(--s-5); } .mb-6 { margin-bottom: var(--s-6); }
.hidden { display: none !important; }
.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;
}

/* ---- Mobile shell ------------------------------------------------------- */
.mobile-only { display: none; }
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .app[data-collapsed="true"] { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, var(--sidebar-w));
    transform: translateX(-102%);
    transition: transform var(--t-med) var(--ease-out);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-drawer);
  }
  .app[data-mobilenav="true"] .sidebar { transform: none; }
  .app[data-collapsed="true"] .sidebar__brandtext,
  .app[data-collapsed="true"] .navitem__text,
  .app[data-collapsed="true"] .navitem__count,
  .app[data-collapsed="true"] .sidebar__label,
  .app[data-collapsed="true"] .sidebar__userinfo { display: revert; }
  .app[data-collapsed="true"] .navitem { justify-content: flex-start; padding: 0 var(--s-3); }
  .app[data-collapsed="true"] .sidebar__brand { justify-content: flex-start; padding: 0 var(--s-4); }
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none !important; }
  .scrim {
    position: fixed; inset: 0; background: rgba(4, 7, 14, .5);
    z-index: calc(var(--z-drawer) - 1); backdrop-filter: blur(2px);
  }
}

/* One-language editions: no language switch anywhere. */
.mono-lang .langtoggle, .mono-lang .term__lang, .mono-lang .portal__lang,
.mono-lang .setup__lang, .mono-lang .lang-choice { display: none !important; }
