/* ==========================================================================
   RateOptimizer — application stylesheet
   Vanilla CSS, no framework. Design system: light "studio" theme —
   indigo accent, white surfaces, Instrument Sans UI + JetBrains Mono data.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Fonts (self-hosted variable woff2, latin + latin-ext; CSP stays 'self')
   -------------------------------------------------------------------------- */

@font-face {
    font-family: 'Instrument Sans';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('../fonts/InstrumentSans-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'Instrument Sans';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('../fonts/InstrumentSans-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'JetBrains Mono';
    font-style: normal;
    font-weight: 400 800;
    font-display: swap;
    src: url('../fonts/JetBrainsMono-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'JetBrains Mono';
    font-style: normal;
    font-weight: 400 800;
    font-display: swap;
    src: url('../fonts/JetBrainsMono-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* --------------------------------------------------------------------------
   Design tokens
   -------------------------------------------------------------------------- */

:root {
    /* palette */
    --bg: #f6f7f9;
    --surface: #ffffff;
    --header-bg: rgba(255, 255, 255, .86);
    --field: #fbfbfd;
    --border: #e7e8ee;
    --border-strong: #d3d5df;
    --text: #151824;
    --muted: #5c6274;
    --faint: #8d92a3;
    --chip: #f2f3f7;
    --thead: #fafbfc;
    --track: #eceef3;
    --row-hover: #fafafd;

    --accent: #3f3ac4;
    --accent-strong: #2a2596;
    --accent-soft: rgba(63, 58, 196, .16);
    --accent-tint: #f4f4fd;
    --accent-line: #dedcfa;

    /* status */
    --ok-tint: #e8f5ee;
    --ok-text: #166b45;
    --ok-live: #1f9d6a;
    --info-tint: #eef1fb;
    --info-text: #3f3ac4;
    --warn-tint: #fdf0e0;
    --warn-text: #94601a;
    --warn-solid: #b8721a;
    --warn-banner-tint: #fdf5e8;
    --warn-banner-line: #f0dfbc;
    --danger-tint: #fdeee9;
    --danger-text: #b8391f;
    --danger-strong: #9c2f18;
    --neutral-tint: #f1f2f6;
    --neutral-text: #5c6274;

    /* sidebar */
    --side: #ffffff;
    --side-border: #e7e8ee;
    --side-text: #151824;
    --side-faint: #8d92a3;
    --side-hover: #f4f4fa;
    --side-chip: #f2f3f7;
    --sidebar-width: 252px;
    --sidebar-rail: 76px;

    --avatar-bg: #eceafb;
    --avatar-text: #3f3ac4;

    /* shape + depth */
    --radius: 12px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(16, 20, 35, .04);
    --shadow-lift: 0 10px 26px rgba(16, 20, 35, .09);
    --shadow-pop: 0 30px 70px rgba(12, 16, 28, .28);

    /* type */
    --font: 'Instrument Sans', system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --header-h: 58px;

    /* legacy alias kept for older inline styles */
    --c-warning: #b8721a;
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

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

html { -webkit-text-size-adjust: 100%; }

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

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

::selection { background: #dcdafc; }

.icon { vertical-align: -0.18em; flex: none; }

.mono { font-family: var(--font-mono); font-size: 0.93em; }
.muted { color: var(--faint); }
.nowrap { white-space: nowrap; }

.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;
}

@keyframes riseIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pulseDot { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.8); } }

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

.app { display: flex; min-height: 100vh; }

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
}

.app-content {
    flex: 1;
    width: 100%;
    max-width: 1460px;
    padding: clamp(18px, 2.4vw, 28px) clamp(18px, 3vw, 34px) 56px;
    animation: riseIn .35s ease both;
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--side);
    border-right: 1px solid var(--side-border);
}

.sidebar-brand { padding: 18px 18px 12px; }

.brand-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--side-text);
    min-width: 0;
}
.brand-link:hover { color: var(--side-text); }

.brand-mark {
    width: 30px;
    height: 30px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
}

.brand-mark-lg { width: 40px; height: 40px; border-radius: 12px; font-size: 19px; }

.brand-name { min-width: 0; }
.brand-title {
    font-weight: 600;
    font-size: 14px;
    letter-spacing: -.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.brand-sub { font-size: 11.5px; color: var(--side-faint); }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 2px 12px 12px;
}
.sidebar-nav::-webkit-scrollbar { width: 10px; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(15, 20, 35, .14);
    border-radius: 20px;
    border: 3px solid transparent;
    background-clip: content-box;
}

.sidebar-nav ul { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.nav-group-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--side-faint);
    padding: 10px 10px 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    color: var(--side-text);
    transition: background .15s ease, color .15s ease;
}
.nav-link:hover { background: var(--side-hover); color: var(--side-text); }
.nav-link.is-active {
    background: var(--accent-tint);
    color: var(--accent);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px var(--accent-line);
}
.nav-link .icon { color: var(--side-faint); }
.nav-link:hover .icon { color: var(--muted); }
.nav-link.is-active .icon { color: var(--accent); }
.nav-link span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
    padding: 12px 14px 16px;
    border-top: 1px solid var(--side-border);
}

.sidebar-env {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--side-chip);
    font-size: 11.5px;
    font-weight: 600;
    color: var(--side-text);
}
.env-meta {
    display: block;
    margin-top: 3px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 400;
    color: var(--side-faint);
}
.env-dot {
    width: 7px;
    height: 7px;
    flex: none;
    border-radius: 50%;
    align-self: flex-start;
    margin-top: 5px;
    animation: pulseDot 1.8s ease-in-out infinite;
}
.env-development { background: var(--warn-solid); }
.env-staging     { background: var(--accent); }
.env-production  { background: var(--ok-live); }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    color: var(--side-text);
    min-width: 0;
}
.sidebar-user:hover { color: var(--side-text); }
.sidebar-user:hover .sidebar-user-name { color: var(--accent); }
.sidebar-user-body { min-width: 0; flex: 1; }
.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-sub {
    font-size: 11.5px;
    color: var(--side-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(16, 20, 32, .42);
    backdrop-filter: blur(3px);
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--header-h);
    padding: 0 clamp(18px, 3vw, 34px);
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.icon-btn.sidebar-toggle { display: none; }

.header-title { min-width: 0; }
.header-kicker {
    font-size: 11.5px;
    color: var(--faint);
    letter-spacing: .02em;
}
.header-page {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -.015em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 9px;
    height: 40px;
    padding: 0 4px;
    border: none;
    background: transparent;
    border-radius: 999px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
}
.user-menu-btn:hover .avatar { box-shadow: 0 0 0 3px var(--accent-soft); }
.user-menu-btn .icon:last-child { color: var(--faint); }
.user-menu-name { max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.avatar {
    width: 34px;
    height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--avatar-bg);
    color: var(--avatar-text);
    font-size: 12.5px;
    font-weight: 600;
    transition: box-shadow .15s ease;
}
.avatar-sm { width: 30px; height: 30px; font-size: 11.5px; }
.avatar-lg { width: 48px; height: 48px; font-size: 17px; }

/* --------------------------------------------------------------------------
   Dropdown
   -------------------------------------------------------------------------- */

.dropdown { position: relative; }

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 30;
    min-width: 220px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lift);
    display: none;
    animation: riseIn .15s ease both;
}
.dropdown.is-open .dropdown-menu { display: block; }

.dropdown-header {
    padding: 8px 10px 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
}
.dropdown-header strong { display: block; font-size: 13px; font-weight: 600; }
.dropdown-header small { display: block; font-size: 11.5px; color: var(--faint); margin-top: 2px; }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 8px 10px;
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}
.dropdown-item:hover { background: var(--chip); color: var(--text); }
.dropdown-item .icon { color: var(--faint); }

/* --------------------------------------------------------------------------
   Breadcrumbs
   -------------------------------------------------------------------------- */

.breadcrumbs { margin: 0 0 14px; }
.breadcrumbs ol {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 12px;
    color: var(--faint);
}
.breadcrumbs li { display: flex; align-items: center; gap: 4px; }
.breadcrumbs li + li::before { content: "/"; color: var(--border-strong); }
.breadcrumbs a { color: var(--faint); }
.breadcrumbs a:hover { color: var(--accent); }
.breadcrumbs [aria-current] { color: var(--muted); font-weight: 500; }

/* --------------------------------------------------------------------------
   Page head
   -------------------------------------------------------------------------- */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.page-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -.015em;
}
.page-sub { margin: 3px 0 0; font-size: 12.5px; color: var(--faint); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card + .card { margin-top: 14px; }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
}
.card-head h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}
.card-head h2 .icon { color: var(--faint); }
.card-head-link { font-size: 12.5px; font-weight: 500; white-space: nowrap; }

.card-form { padding: 20px; }
.card-form .card-head { margin: -20px -20px 20px; }
.card-form > .page-sub { margin: -8px 0 18px; }
.card-narrow { max-width: 720px; }

.empty-note { padding: 26px 18px; margin: 0; text-align: center; font-size: 13px; color: var(--faint); }

/* --------------------------------------------------------------------------
   Banners (inline notices above content)
   -------------------------------------------------------------------------- */

.banner {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 16px 18px;
    border-radius: var(--radius);
    margin-bottom: 14px;
}
.banner-warn { background: var(--warn-banner-tint); border: 1px solid var(--warn-banner-line); }

.banner-icon {
    width: 30px;
    height: 30px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 9px;
    color: #fff;
}
.banner-warn .banner-icon { background: var(--warn-solid); }

.banner-body { flex: 1; min-width: 0; }
.banner-title { font-size: 13.5px; font-weight: 600; margin-bottom: 3px; }
.banner-text { font-size: 13px; color: var(--muted); line-height: 1.55; }
.banner-text strong { color: var(--text); font-weight: 600; }

/* --------------------------------------------------------------------------
   Stat / KPI cards
   -------------------------------------------------------------------------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.stat-card { position: relative; padding: 18px 18px 16px; overflow: visible; }

.stat-label { font-size: 12.5px; font-weight: 600; color: var(--muted); }

.stat-value {
    display: block;
    margin-top: 10px;
    font-family: var(--font-mono);
    font-size: 27px;
    font-weight: 600;
    letter-spacing: -.03em;
    line-height: 1;
}

.stat-note { font-size: 11.5px; color: var(--faint); margin-top: 7px; }

.stat-link {
    position: absolute;
    top: 14px;
    right: 14px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    color: var(--faint);
}
.stat-link:hover { background: var(--accent-tint); color: var(--accent); }

/* --------------------------------------------------------------------------
   Dashboard columns + activity feed
   -------------------------------------------------------------------------- */

.dash-columns {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}
.dash-columns .card { margin: 0; }

.activity-list { list-style: none; margin: 0; padding: 6px 0; }

.activity-item {
    display: flex;
    gap: 12px;
    padding: 11px 18px;
    transition: background .15s ease;
}
.activity-item:hover { background: var(--row-hover); }
.activity-item + .activity-item { border-top: 1px solid var(--border); }

.activity-dot {
    width: 7px;
    height: 7px;
    flex: none;
    margin-top: 6px;
    border-radius: 50%;
}
.activity-dot-ok      { background: var(--ok-live); }
.activity-dot-warning { background: var(--warn-solid); }
.activity-dot-danger  { background: var(--danger-text); }

.activity-body { min-width: 0; }
.activity-desc { display: block; font-size: 13px; line-height: 1.5; }
.activity-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 3px;
    font-size: 11.5px;
    color: var(--faint);
}

/* --------------------------------------------------------------------------
   Table toolbar
   -------------------------------------------------------------------------- */

.table-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}

.search-box { position: relative; flex: 1; min-width: 220px; max-width: 340px; }
.search-box .icon {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--faint);
    pointer-events: none;
}
.search-box input {
    width: 100%;
    height: 34px;
    padding: 0 12px 0 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
}

.table-toolbar select {
    height: 34px;
    padding: 0 30px 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
}

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
.table-wrap::-webkit-scrollbar { height: 10px; }
.table-wrap::-webkit-scrollbar-thumb {
    background: rgba(15, 20, 35, .14);
    border-radius: 20px;
    border: 3px solid transparent;
    background-clip: content-box;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table th,
.table td { padding: 11px 14px; text-align: left; vertical-align: middle; }
.table th:first-child,
.table td:first-child { padding-left: 18px; }
.table th:last-child,
.table td:last-child { padding-right: 18px; }

.table thead th {
    background: var(--thead);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--faint);
    white-space: nowrap;
}

.table tbody tr { border-top: 1px solid var(--border); transition: background .15s ease; }
.table tbody tr:hover { background: var(--row-hover); }

.table .num { text-align: right; font-family: var(--font-mono); font-size: 12.5px; }
.table thead .num { font-family: var(--font); font-size: 11.5px; }

.table-compact th,
.table-compact td { padding: 9px 12px; }

.actions-col { text-align: right; width: 1%; white-space: nowrap; }
.row-actions { display: inline-flex; align-items: center; gap: 4px; }
.inline-form { display: inline-flex; }

.cell-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-user-lg { gap: 14px; }
.cell-title { display: block; font-weight: 500; color: var(--text); }
a.cell-title:hover { color: var(--accent); }
.cell-sub { display: block; font-size: 11.5px; color: var(--faint); margin-top: 2px; }

.currency-symbol {
    width: 32px;
    height: 32px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--chip);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
}

/* --------------------------------------------------------------------------
   Table footer + pagination
   -------------------------------------------------------------------------- */

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
}

.pagination-info { font-size: 12px; color: var(--faint); font-family: var(--font-mono); }

.pagination { display: flex; align-items: center; gap: 4px; }

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    font-weight: 500;
    font-family: var(--font-mono);
    color: var(--muted);
    transition: background .15s ease, color .15s ease;
}
a.page-link:hover { background: var(--chip); color: var(--text); }
.page-link.is-current { background: var(--accent); color: #fff; font-weight: 600; }
.page-link.is-disabled { color: var(--border-strong); }
.page-link.is-gap { color: var(--faint); }

/* --------------------------------------------------------------------------
   Badges (status pills)
   -------------------------------------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .01em;
    white-space: nowrap;
}
.badge-sm { padding: 1px 7px; font-size: 10.5px; }

.badge-success { background: var(--ok-tint); color: var(--ok-text); }
.badge-danger  { background: var(--danger-tint); color: var(--danger-text); }
.badge-warning { background: var(--warn-tint); color: var(--warn-text); }
.badge-amber   { background: var(--warn-tint); color: var(--warn-text); }
.badge-violet  { background: var(--info-tint); color: var(--info-text); }
.badge-muted,
.badge-neutral { background: var(--neutral-tint); color: var(--neutral-text); }
.badge-code {
    background: var(--chip);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 11px;
    border-radius: 7px;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 34px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: filter .15s ease, border-color .15s ease, background .15s ease, color .15s ease;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); color: #fff; }

.btn-secondary {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
    font-weight: 500;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--text); }

.btn-danger { background: var(--danger-text); color: #fff; }
.btn-danger:hover { background: var(--danger-strong); color: #fff; }

.btn-ghost { background: transparent; color: var(--muted); font-weight: 500; }
.btn-ghost:hover { background: var(--chip); color: var(--text); }

.btn-block { display: flex; width: 100%; height: 40px; font-size: 14px; }

.btn-link {
    display: inline;
    height: auto;
    padding: 0;
    border: none;
    background: none;
    font-family: inherit;
    font-size: inherit;
    font-weight: 500;
    color: var(--accent);
    cursor: pointer;
}
.btn-link:hover { color: var(--accent-strong); }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: var(--faint);
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--chip); color: var(--text); }
.icon-btn-danger:hover { background: var(--danger-tint); color: var(--danger-text); }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-group { margin-bottom: 16px; }
.form-grid .form-group { margin-bottom: 0; }
.form-group-wide { grid-column: 1 / -1; }

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}
.req { color: var(--danger-text); }

.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--field);
    font-family: inherit;
    font-size: 13.5px;
    color: var(--text);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-group textarea { resize: vertical; min-height: 90px; }
.form-group select { cursor: pointer; }

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

input.is-invalid,
select.is-invalid,
textarea.is-invalid { border-color: var(--danger-text); }
input.is-invalid:focus-visible,
select.is-invalid:focus-visible,
textarea.is-invalid:focus-visible { box-shadow: 0 0 0 3px rgba(184, 57, 31, .16); }

input[disabled], select[disabled], textarea[disabled] {
    background: var(--chip);
    color: var(--faint);
    cursor: not-allowed;
}
input[readonly] { background: var(--chip); }

input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

.field-error { margin: 6px 0 0; font-size: 12px; font-weight: 500; color: var(--danger-text); }
.field-hint { margin: 6px 0 0; font-size: 12px; color: var(--faint); line-height: 1.5; }

.form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.form-fieldset {
    margin: 20px 0 0;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.form-fieldset legend {
    padding: 0 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--faint);
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 8px;
}

.checkbox-item {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.checkbox-item:hover { border-color: var(--accent-line); background: var(--row-hover); }
.checkbox-item:has(input:checked) {
    border-color: var(--accent-line);
    background: var(--accent-tint);
}
.checkbox-item input { margin-top: 2px; }
.checkbox-item small { display: block; font-weight: 400; font-size: 11.5px; color: var(--faint); margin-top: 2px; }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

.perm-matrix { display: flex; flex-direction: column; gap: 12px; }

.perm-module {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.perm-module-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    background: var(--thead);
    border-bottom: 1px solid var(--border);
}
.perm-module-name {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}
.perm-module .checkbox-grid { padding: 12px 14px; }

.input-affix { position: relative; }
.input-affix input { padding-right: 42px; }
.affix-btn {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    border-radius: 7px;
    color: var(--faint);
    cursor: pointer;
}
.affix-btn:hover { background: var(--chip); color: var(--text); }

/* --------------------------------------------------------------------------
   Notes + detail lists
   -------------------------------------------------------------------------- */

.note {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    line-height: 1.55;
}
.note .icon { margin-top: 1px; }
.note-info { background: var(--info-tint); color: var(--info-text); }

.detail-list { margin: 0; }
.detail-list > div {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    gap: 14px;
    padding: 12px 18px;
}
.detail-list > div + div { border-top: 1px solid var(--border); }
.detail-list dt { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.detail-list dd { margin: 0; font-size: 13px; }

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */

.toast-stack {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 70;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: max-content;
    max-width: min(560px, calc(100vw - 32px));
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 100%;
    padding: 11px 14px 11px 18px;
    border-radius: 999px;
    background: var(--text);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 12px 32px rgba(12, 16, 28, .28);
    animation: toastIn .22s ease both;
    transition: opacity .2s ease, transform .2s ease;
}
.toast.is-hiding { opacity: 0; transform: translateY(8px); }

.toast-icon { display: grid; place-items: center; flex: none; }
.toast-success .toast-icon { color: #7ee0ab; }
.toast-error   .toast-icon { color: #ff9d8a; }
.toast-warning .toast-icon { color: #f5c97b; }
.toast-info    .toast-icon { color: #a9b4ff; }

.toast-text { min-width: 0; }

.toast-close {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    flex: none;
    border: none;
    background: transparent;
    border-radius: 50%;
    color: rgba(255, 255, 255, .55);
    cursor: pointer;
}
.toast-close:hover { background: rgba(255, 255, 255, .12); color: #fff; }

/* --------------------------------------------------------------------------
   Modals
   -------------------------------------------------------------------------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 12vh 16px 16px;
    background: rgba(16, 20, 32, .42);
    backdrop-filter: blur(3px);
    overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }

.modal {
    width: min(440px, 100%);
    height: fit-content;
    padding: 22px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-pop);
    animation: riseIn .18s ease both;
}

.modal-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    margin-bottom: 14px;
    border-radius: 12px;
    background: var(--warn-banner-tint);
    color: var(--warn-solid);
}

.modal-title { margin: 0 0 6px; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.modal-text { margin: 0 0 18px; font-size: 13px; color: var(--muted); line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal .form-group:last-of-type { margin-bottom: 0; }
.modal .modal-actions { margin-top: 18px; }

/* --------------------------------------------------------------------------
   Auth (login)
   -------------------------------------------------------------------------- */

.auth-body { background: var(--surface); }

.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.05fr .95fr;
}

.auth-pane {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 40px;
    padding: 56px clamp(32px, 6vw, 96px);
    background: var(--surface);
}

.auth-brand { display: flex; align-items: center; gap: 10px; }
.auth-brand-name { font-weight: 600; font-size: 14.5px; letter-spacing: -.01em; }

.auth-form-wrap { max-width: 380px; width: 100%; }
.auth-title {
    margin: 0 0 8px;
    font-size: 40px;
    font-weight: 600;
    letter-spacing: -.025em;
    line-height: 1.08;
}
.auth-lead { margin: 0 0 28px; color: var(--muted); font-size: 14px; line-height: 1.6; }

.auth-foot { margin: 0; font-size: 12px; color: var(--faint); }

.auth-art {
    display: flex;
    align-items: flex-end;
    padding: 56px;
    background: linear-gradient(160deg, #eceafb 0%, #f6f7f9 60%, #e6f0f5 100%);
}

.auth-art-card {
    max-width: 360px;
    padding: 22px 24px;
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(6px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.auth-art-kicker {
    margin-bottom: 10px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--accent);
}
.auth-art-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -.015em;
    line-height: 1.25;
    color: var(--text);
}
.auth-art-text { margin-top: 6px; font-size: 13px; color: var(--muted); line-height: 1.6; }

/* --------------------------------------------------------------------------
   Focus + motion
   -------------------------------------------------------------------------- */

.btn:focus-visible,
a:focus-visible,
.icon-btn:focus-visible,
.affix-btn:focus-visible,
.toast-close:focus-visible,
.dropdown-item:focus-visible,
.user-menu-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-soft);
}

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

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

/* Tablet: collapse sidebar to an icon rail */
@media (max-width: 1180px) and (min-width: 761px) {
    .app-main { margin-left: var(--sidebar-rail); }
    .sidebar { width: var(--sidebar-rail); }
    .sidebar-brand { padding-left: 14px; padding-right: 14px; }
    .brand-name,
    .nav-group-label,
    .nav-link span,
    .sidebar-env,
    .sidebar-user { display: none; }
    .sidebar-nav { padding-left: 10px; padding-right: 10px; }
    .nav-link { justify-content: center; padding: 10px; }
    .sidebar-footer { display: flex; justify-content: center; padding: 12px 8px 16px; }
    .sidebar-footer::before {
        content: "";
        width: 7px;
        height: 7px;
        border-radius: 50%;
        animation: pulseDot 1.8s ease-in-out infinite;
    }
    .sidebar-footer.env-is-development::before { background: var(--warn-solid); }
    .sidebar-footer.env-is-staging::before     { background: var(--accent); }
    .sidebar-footer.env-is-production::before  { background: var(--ok-live); }
}

@media (max-width: 1024px) {
    .dash-columns { grid-template-columns: 1fr; }
}

/* Mobile: off-canvas drawer (toggled by .sidebar-open on body) */
@media (max-width: 760px) {
    .app-main { margin-left: 0; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: none;
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: var(--shadow-lift);
    }

    .icon-btn.sidebar-toggle { display: inline-grid; }

    .header-kicker { display: none; }
    .user-menu-name { display: none; }
    .user-menu-btn .icon:last-child { display: none; }

    .form-grid { grid-template-columns: 1fr; }
    .detail-list > div { grid-template-columns: 1fr; gap: 3px; }

    .auth-shell { grid-template-columns: 1fr; }
    .auth-art { display: none; }
    .auth-pane { padding: 36px 24px; }
    .auth-title { font-size: 32px; }

    .toast-stack { bottom: 16px; }
}
