* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: var(--bg); font-family: var(--font); font-size: 14px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.app-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; width: var(--sidebar-width); display: flex; flex-direction: column; background: var(--sidebar); color: var(--sidebar-text); border-right: 1px solid var(--sidebar-border); }
.sidebar-brand { min-height: 76px; display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--sidebar-border); }
.sidebar-brand strong { display: block; color: var(--sidebar-strong); font-size: 14px; }
.sidebar-brand small { display: block; color: var(--sidebar-muted); font-size: 12px; margin-top: 2px; }
.brand-mark { flex: 0 0 auto; width: 38px; height: 38px; display: grid; place-items: center; color: #fff; background: var(--primary); border-radius: 9px; font-weight: 700; letter-spacing: -0.02em; }
.brand-mark-large { width: 54px; height: 54px; font-size: 18px; }
.brand-logo { flex: 0 0 auto; width: 38px; height: 38px; object-fit: contain; border-radius: 9px; }
.brand-logo-large { width: 54px; height: 54px; border-radius: 12px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px; scrollbar-width: none; }
.sidebar-nav::-webkit-scrollbar { display: none; }
.nav-heading { margin: 18px 10px 7px; color: var(--sidebar-muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.13em; }
.nav-link { width: 100%; display: flex; align-items: center; gap: 11px; min-height: 42px; padding: 9px 11px; color: var(--sidebar-text); text-decoration: none; border: 0; border-radius: 7px; background: transparent; cursor: pointer; text-align: left; transition: background 0.15s, color 0.15s; }
.nav-link svg { width: 18px; height: 18px; color: var(--sidebar-icon); }
.nav-link:hover { color: var(--sidebar-strong); background: var(--sidebar-hover); }
.nav-link.active { color: var(--sidebar-strong); background: var(--sidebar-active); }
.nav-link.active svg { color: var(--sidebar-icon); }
.nav-button { font: inherit; }
.sidebar-footer { padding: 10px; border-top: 1px solid var(--sidebar-border); }
.sidebar-footer form { margin: 0; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 13px 10px 4px; }
.user-chip > span { width: 30px; height: 30px; display: grid; place-items: center; color: var(--sidebar-strong); border: 1px solid var(--sidebar-border); border-radius: 50%; font-weight: 600; }
.user-chip strong, .user-chip small { display: block; }
.user-chip strong { color: var(--sidebar-strong); font-size: 11px; }
.user-chip small { color: var(--sidebar-muted); font-size: 11px; }

.app-main { min-height: 100vh; margin-left: var(--sidebar-width); transition: padding-right 0.2s ease; }
body.agent-open .app-main { padding-right: var(--agent-width); }
.page-topbar { min-height: 84px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 28px; background: var(--surface); border-bottom: 1px solid var(--border); }
.page-topbar h1 { margin: 1px 0 0; font-size: 24px; line-height: 1.2; letter-spacing: -0.025em; }
.eyebrow { margin: 0; color: var(--text-muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.14em; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.page-content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 24px 28px 50px; }
.flash-stack { position: fixed; top: 92px; left: calc(var(--sidebar-width) + 28px); z-index: 80; display: grid; gap: 8px; }
.flash { max-width: 440px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.flash.success { color: var(--success); background: var(--success-soft); border-color: var(--success-border); }
.flash.error { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }

.mobile-topbar { display: none; }
.sidebar-overlay, .modal-overlay { position: fixed; inset: 0; z-index: 45; display: none; background: rgba(17, 24, 39, 0.38); }
.modal-overlay { z-index: 89; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-shell { width: min(980px, 100%); display: grid; grid-template-columns: 1.1fr 0.9fr; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.auth-intro { padding: 58px; color: #fff; background: #001233; }
.auth-intro h1 { margin: 24px 0 14px; font-size: clamp(30px, 4vw, 48px); line-height: 1.08; letter-spacing: -0.04em; }
.auth-intro p { color: rgba(255, 255, 255, 0.8); max-width: 560px; }
.auth-intro .eyebrow { color: rgba(255, 255, 255, 0.75); margin-top: 22px; }
.auth-meta { display: grid; gap: 5px; margin-top: 50px; color: rgba(255, 255, 255, 0.62); font-size: 11px; }
.auth-card { padding: 52px; display: flex; flex-direction: column; justify-content: center; gap: 30px; }
.auth-card h2 { margin: 4px 0; font-size: 28px; }
.muted { color: var(--text-muted); }

@media (max-width: 1180px) {
    body.agent-open .app-main { padding-right: 0; }
    .agent-panel { box-shadow: -6px 0 20px rgba(15, 23, 42, 0.12); }
}

@media (max-width: 820px) {
    .app-sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
    body.sidebar-open .app-sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { display: block; }
    .app-main { margin-left: 0; padding-top: 58px; }
    .mobile-topbar { position: fixed; inset: 0 0 auto 0; z-index: 40; height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.mobile-brand { display: flex; align-items: center; gap: 9px; text-decoration: none; font-weight: 600; font-size: 12px; }
.mobile-brand .brand-logo { width: 32px; height: 32px; border-radius: 7px; }
.mobile-brand .brand-logo-light { display: none; }
[data-theme="dark"] .mobile-brand .brand-logo-dark { display: none; }
[data-theme="dark"] .mobile-brand .brand-logo-light { display: inline; }
.toggle { position: relative; display: inline-block; flex: 0 0 auto; height: 42px; width: 42px; cursor: pointer; }
.toggle:before { box-shadow: 0; border-radius: 35.5px; background: #fff; position: absolute; margin-left: -15px; margin-top: -15px; opacity: 0.2; content: ''; height: 30px; width: 30px; left: 50%; top: 50%; }
.toggle .button { transition: all 300ms cubic-bezier(0.23, 1, 0.32, 1); box-shadow: 0 15px 25px -4px rgba(0, 0, 0, 0.5), inset 0 -3px 4px -1px rgba(0, 0, 0, 0.2), 0 -10px 15px -1px rgba(255, 255, 255, 0.6), inset 0 3px 4px -1px rgba(255, 255, 255, 0.2), inset 0 0 5px 1px rgba(255, 255, 255, 0.8), inset 0 20px 30px 0 rgba(255, 255, 255, 0.2); border-radius: 29px; position: absolute; background: #eaeaea; margin-left: -14.5px; margin-top: -14.5px; display: block; height: 29px; width: 29px; left: 50%; top: 50%; }
.toggle:hover .button { transform: scale(1.06); }
.toggle .label { transition: color 300ms ease-out; line-height: 42px; text-align: center; position: absolute; font-weight: 700; font-size: 15px; display: block; opacity: 0.9; height: 100%; width: 100%; color: rgba(0, 0, 0, 0.9); }
.toggle .label::before { content: '\2600'; }
.toggle input:checked ~ .label::before { content: '\263E'; }
.toggle input[type='checkbox'] { opacity: 0; position: absolute; cursor: pointer; z-index: 1; height: 100%; width: 100%; left: 0; top: 0; margin: 0; padding: 0; display: block; background: transparent; border: 0; appearance: none; }
.toggle input:active ~ .button { filter: blur(0.5px); box-shadow: 0 12px 25px -4px rgba(0, 0, 0, 0.4), inset 0 -8px 30px 1px rgba(255, 255, 255, 0.9), 0 -10px 15px -1px rgba(255, 255, 255, 0.6), inset 0 8px 25px 0 rgba(0, 0, 0, 0.4), inset 0 0 10px 1px rgba(255, 255, 255, 0.6); }
.toggle input:active ~ .label { font-size: 13px; color: rgba(0, 0, 0, 0.45); }
.toggle input:checked ~ .button { filter: blur(0.5px); box-shadow: 0 10px 25px -4px rgba(0, 0, 0, 0.4), inset 0 -8px 25px -1px rgba(255, 255, 255, 0.9), 0 -10px 15px -1px rgba(255, 255, 255, 0.6), inset 0 8px 20px 0 rgba(0, 0, 0, 0.2), inset 0 0 5px 1px rgba(255, 255, 255, 0.6); }
.toggle input:checked ~ .label { color: rgba(0, 0, 0, 0.8); }
.toggle input:focus-visible ~ .button { outline: 2px solid var(--primary); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
    .toggle .button, .toggle .label { transition: none; }
}
    .page-topbar { min-height: 74px; padding: 15px 18px; align-items: flex-start; }
    .page-topbar h1 { font-size: 20px; }
    .page-topbar .agent-toggle { display: none; }
    .page-content { padding: 18px 14px 40px; }
    .flash-stack { top: 68px; left: 14px; right: 14px; }
    .auth-shell { grid-template-columns: 1fr; }
    .auth-intro { display: none; }
    .auth-card { padding: 34px 24px; }
}

@media (max-width: 560px) {
    .page-topbar { display: block; }
    .topbar-actions { margin-top: 12px; flex-wrap: wrap; }
    .topbar-actions .button { flex: 1 1 auto; }
}

body.dialog-open { overflow: hidden; }

/* Enterprise hierarchical navigation */
.nav-primary-link { margin-bottom: 6px; font-weight: 600; }
.nav-group { margin: 2px 0; }
.nav-group-toggle { position: relative; font-weight: 500; }
.nav-group-toggle .nav-group-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-group-toggle .nav-chevron { flex: 0 0 auto; width: 14px; height: 14px; margin-left: auto; color: var(--sidebar-muted); transition: transform 0.18s ease; }
.nav-group.is-open > .nav-group-toggle .nav-chevron { transform: rotate(180deg); }
.nav-group.is-active > .nav-group-toggle { color: var(--sidebar-strong); background: rgba(255, 255, 255, 0.08); }
.nav-group.is-active > .nav-group-toggle:before { position: absolute; inset: 10px auto 10px 0; width: 2px; content: ''; background: var(--primary); border-radius: 2px; }
.nav-children { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows 0.2s ease, opacity 0.15s ease; }
.nav-group.is-open > .nav-children { grid-template-rows: 1fr; opacity: 1; }
.nav-children-inner { min-height: 0; overflow: hidden; padding: 0 0 0 13px; }
.nav-child-link { position: relative; min-height: 36px; gap: 9px; padding: 7px 9px 7px 16px; color: var(--sidebar-muted); font-size: 11px; }
.nav-child-link:before { position: absolute; left: 4px; top: 50%; width: 5px; height: 5px; content: ''; border: 1px solid var(--sidebar-border); border-radius: 50%; transform: translateY(-50%); }
.nav-child-link svg { width: 15px; height: 15px; opacity: 0.86; }
.nav-child-link span:not(.nav-badge) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-child-link.active { color: var(--sidebar-strong); background: var(--sidebar-active); }
.nav-child-link.active:before { border-color: #fff; background: #fff; }
.nav-badge { flex: 0 0 auto; min-width: 19px; height: 19px; display: inline-grid; place-items: center; margin-left: auto; padding: 0 5px; color: #fff; background: var(--primary); border-radius: 999px; font-size: 11px; font-weight: 700; line-height: 1; }
.nav-group-toggle .nav-badge + .nav-chevron { margin-left: 0; }

@media (prefers-reduced-motion: reduce) {
    .nav-group-toggle .nav-chevron, .nav-children { transition: none; }
}
