/* VANTAGE base styles + app shell (docs/06 §1.3, §2). Server-rendered first;
   JS only enhances. Enterprise shell: fixed dark sidebar with grouped nav,
   sticky topbar with search + user menu, responsive mobile drawer.
   Reads tokens.css; the component vocabulary lives in components.css.

   Backward-compat: every legacy class the templates depend on
   (.shell .sidebar .brand .nav .nav-link .main-col .topbar .content .card
   .btn .field .alert .muted ...) is preserved. */

* { box-sizing: border-box; }

html { font-size: var(--fs-base); -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-ui);
    font-size: var(--fs-base);
    line-height: var(--lh);
    color: var(--text);
    background: var(--tint);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--green-deep); text-decoration-thickness: 1px; text-underline-offset: 2px; }

h1, h2, h3, h4 { color: var(--ink); line-height: var(--lh-tight); margin: 0 0 var(--sp-3); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-base); }
h4 { font-size: var(--fs-sm); }

code, kbd { font-family: var(--font-num); font-size: .92em; }

.skip-link {
    position: absolute; left: -999px; top: 0; z-index: var(--z-menu);
    background: var(--green); color: #fff; padding: var(--sp-2) var(--sp-4);
    border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

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

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--side-bg) 0%, var(--side-bg-2) 100%);
    color: var(--side-text);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    padding: var(--sp-4) var(--sp-3);
    border-right: 1px solid var(--side-line);
    overflow-y: auto;
    transition: width var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-2) var(--sp-4); }

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--green) 0%, var(--green-deep) 100%);
    color: #fff;
    font-weight: var(--fw-bold);
    font-size: var(--fs-lg);
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}

.brand-name { font-weight: var(--fw-bold); letter-spacing: var(--tracking-wide); color: #fff; white-space: nowrap; }
.brand-sub { display: block; font-size: 10px; font-weight: var(--fw-medium); letter-spacing: .12em; color: var(--side-text-dim); text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { margin-top: var(--sp-3); }
.nav-group-label {
    font-size: 10px; font-weight: var(--fw-bold); letter-spacing: .14em;
    text-transform: uppercase; color: var(--side-text-dim);
    padding: var(--sp-2) var(--sp-2) var(--sp-1); white-space: nowrap;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 0 var(--sp-3);
    min-height: var(--touch);
    border-radius: var(--radius-sm);
    color: var(--side-text);
    text-decoration: none;
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    position: relative;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
    white-space: nowrap;
}
.nav-link .nav-ico { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link:hover .nav-ico { opacity: 1; }
.nav-link.is-active { background: rgba(20, 160, 94, .16); color: #fff; }
.nav-link.is-active .nav-ico { opacity: 1; color: var(--green-bright); }
.nav-link.is-active::before {
    content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px;
    width: 3px; border-radius: 0 3px 3px 0; background: var(--green-bright);
}
.nav-badge {
    margin-left: auto; min-width: 20px; padding: 0 6px; height: 18px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-pill); background: var(--crit); color: #fff;
    font-size: 11px; font-weight: var(--fw-bold);
}

.sidebar-foot { margin-top: auto; padding-top: var(--sp-3); border-top: 1px solid var(--side-line); }
.sidebar-foot .env-pill {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    font-size: var(--fs-xs); color: var(--side-text-dim); padding: var(--sp-1) var(--sp-2);
}
.sidebar-foot .env-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green-bright); }

/* ------------------------------------------------------------- main column */
.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    padding: 0 var(--sp-5);
    min-height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
}
.topbar-title { font-weight: var(--fw-semibold); font-size: var(--fs-lg); color: var(--ink); }

.nav-toggle {
    display: none;
    width: 40px; height: 40px; align-items: center; justify-content: center;
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-2); cursor: pointer;
}
.nav-toggle:hover { background: var(--surface-3); }

.topbar-search {
    flex: 1;
    max-width: 420px;
    display: flex; align-items: center; gap: var(--sp-2);
    background: var(--surface-inset);
    border: 1px solid var(--line-2);
    border-radius: var(--radius-pill);
    padding: 0 var(--sp-3);
    min-height: 40px;
    color: var(--muted);
}
.topbar-search input {
    flex: 1; border: none; background: transparent; font: inherit; color: var(--text);
    min-height: 38px; outline: none;
}
.topbar-search input::placeholder { color: var(--muted); }
.topbar-spacer { flex: 1; }

.topbar-user { display: flex; align-items: center; gap: var(--sp-3); margin-left: auto; }
.topbar-user-name { color: var(--text-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); }

.icon-btn {
    position: relative;
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    background: transparent; color: var(--text-2); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn .count-pill {
    position: absolute; top: 4px; right: 4px;
    min-width: 16px; height: 16px; padding: 0 4px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-pill); background: var(--crit); color: #fff;
    font-size: 10px; font-weight: var(--fw-bold); line-height: 1;
}

/* user menu (progressive enhancement; details/summary fallback) */
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-1) var(--sp-2); border-radius: var(--radius-sm); }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--surface-3); }
.avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--green-mid), var(--green-deep));
    color: #fff; font-weight: var(--fw-bold); font-size: var(--fs-sm);
}
.user-menu-panel {
    position: absolute; right: 0; top: calc(100% + 6px);
    min-width: 220px; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: var(--sp-2); z-index: var(--z-menu);
}
.user-menu-panel .um-head { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line-2); margin-bottom: var(--sp-1); }
.user-menu-panel .um-name { font-weight: var(--fw-semibold); color: var(--ink); }
.user-menu-panel .um-role { font-size: var(--fs-xs); color: var(--muted); }
.user-menu-panel a, .user-menu-panel button {
    display: flex; width: 100%; align-items: center; gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm);
    color: var(--text-2); text-decoration: none; font: inherit; font-size: var(--fs-sm);
    background: none; border: none; cursor: pointer; text-align: left;
}
.user-menu-panel a:hover, .user-menu-panel button:hover { background: var(--surface-3); color: var(--ink); }

.theme-toggle .moon, .theme-toggle .sun { display: none; }
:root:not([data-theme="dark"]) .theme-toggle .moon { display: block; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }

.content { padding: var(--sp-5); max-width: var(--content-max); width: 100%; margin: 0 auto; }

/* scrim behind the mobile drawer */
.nav-scrim {
    display: none; position: fixed; inset: 0; z-index: var(--z-overlay);
    background: rgba(11, 31, 23, .45); border: none; padding: 0; cursor: pointer;
}

/* ===================================================== responsive drawer */
@media (max-width: 900px) {
    .sidebar {
        position: fixed; left: 0; top: 0; z-index: var(--z-drawer);
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open .nav-scrim { display: block; }
    .nav-toggle { display: inline-flex; }
    .content { padding: var(--sp-4); }
    .topbar { padding: 0 var(--sp-4); }
    .topbar-search { display: none; }
}
@media (max-width: 560px) {
    .topbar-user-name { display: none; }
    .topbar-title { font-size: var(--fs-base); }
}

/* ===================================================== guest (login/2fa) */
.guest-body { background: var(--ink); }
.guest-main { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--sp-4); }
.guest-card { width: 100%; max-width: 400px; }
.guest-card .brand { margin-bottom: var(--sp-5); padding: 0; }
.guest-card .brand-name { color: var(--ink); }

/* ============================================================= components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: var(--touch);
    padding: var(--sp-2) var(--sp-4);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--green);
    color: #fff;
    font: inherit;
    font-weight: var(--fw-semibold);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
    white-space: nowrap;
}
.btn:hover { background: var(--green-deep); }
.btn:active { transform: translateY(1px); }

.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--text-2); min-height: 36px; }
.btn-ghost:hover { background: var(--surface-3); color: var(--ink); }

.inline-form { display: inline; }

.field { margin-bottom: var(--sp-4); }
.field label { display: block; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-2); margin-bottom: var(--sp-1); }
.field input {
    width: 100%;
    min-height: var(--touch);
    padding: var(--sp-2) var(--sp-3);
    font: inherit;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    transition: box-shadow var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.field input:focus { outline: none; box-shadow: var(--focus); border-color: var(--green-mid); }
.field .field-error { color: var(--crit); font-size: var(--fs-sm); margin-top: var(--sp-1); }

.alert { padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-sm); margin-bottom: var(--sp-4); font-size: var(--fs-sm); }
.alert-error { background: var(--red-soft); color: var(--crit); }
.alert-warn { background: var(--amber-soft); color: var(--amber); }
.alert-ok { background: var(--soft); color: var(--green-deep); }

.muted { color: var(--muted); }
.text-sm { font-size: var(--fs-sm); }

/* ============================================================= error pages */
.error-page { text-align: center; padding: var(--sp-6) var(--sp-2); max-width: 420px; margin: 0 auto; }
/* The numeric status IS the h1 in every error template — render it big + brand. */
.error-page h1 { font-family: var(--font-num); font-size: var(--fs-3xl); font-weight: var(--fw-bold); color: var(--green-deep); line-height: 1; margin: 0 0 var(--sp-2); }
.error-page p { color: var(--muted); margin: var(--sp-2) 0; }
.error-page .btn { margin-top: var(--sp-3); }
