:root {
    color-scheme: light;
    --background: #F7F8FA;
    --surface: #FFFFFF;
    --border: #E5E7EB;
    --navy: #1B2C54;
    --blue: #3984C4;
    --text: #344054;
    --muted: #667085;
    --green: #147D64;
    --green-bg: #EAF7F2;
    --amber: #9A6700;
    --amber-bg: #FFF6D8;
    --red: #B42318;
    --red-bg: #FFF0EE;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--background); }
body { margin: 0; color: var(--text); background: var(--background); font-size: 15px; line-height: 1.5; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid rgba(57, 132, 196, .35); outline-offset: 2px; }
.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; background: var(--navy); color: white; padding: 10px 14px; border-radius: 8px; }
.skip-link:focus { top: 12px; }
.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; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px 16px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--navy); font-weight: 700; line-height: 1.2; }
.brand-mark { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 9px; background: var(--navy); color: #fff; font-size: 14px; }
.sidebar nav { margin-top: 32px; display: grid; gap: 4px; }
.nav-link { padding: 10px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 600; }
.nav-link:hover { color: var(--navy); background: var(--background); }
.nav-link.is-active { color: var(--navy); background: #EEF4FA; }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding: 16px 10px 0; display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.link-button { border: 0; background: transparent; color: var(--blue); padding: 0; cursor: pointer; text-align: left; }
.content-shell { min-width: 0; }
.topbar { min-height: 96px; display: flex; align-items: center; gap: 16px; justify-content: space-between; padding: 20px clamp(20px, 4vw, 48px); border-bottom: 1px solid var(--border); background: rgba(255, 255, 255, .94); }
.topbar h1 { margin: 1px 0 0; color: var(--navy); font-size: clamp(22px, 3vw, 28px); line-height: 1.2; }
.eyebrow { margin: 0; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.nav-toggle { display: none; border: 1px solid var(--border); background: var(--surface); color: var(--navy); border-radius: 9px; padding: 8px 11px; font-weight: 700; }
.main-content { width: 100%; max-width: 1440px; margin: 0 auto; padding: 28px clamp(20px, 4vw, 48px) 56px; }

.metric-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.metric span { display: block; min-height: 42px; color: var(--muted); font-size: 13px; }
.metric strong { display: block; color: var(--navy); font-size: 28px; line-height: 1; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.section-heading { padding: 20px 22px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); }
.section-heading h2 { color: var(--navy); margin: 0; font-size: 18px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 13px 16px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: #FCFCFD; font-size: 12px; font-weight: 700; letter-spacing: .02em; }
tbody tr:last-child td { border-bottom: 0; }
td strong, td small { display: block; }
td small { margin-top: 2px; color: var(--muted); }
td code { font-size: 12px; overflow-wrap: anywhere; }
.details-cell { max-width: 320px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.actions { text-align: right; white-space: nowrap; }
.actions form { display: inline; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 700; }
.badge-success { color: var(--green); background: var(--green-bg); }
.badge-warning { color: var(--amber); background: var(--amber-bg); }
.badge-danger { color: var(--red); background: var(--red-bg); }

.button { display: inline-flex; min-height: 38px; align-items: center; justify-content: center; gap: 6px; padding: 8px 13px; border: 1px solid transparent; border-radius: 9px; font-weight: 700; text-decoration: none; cursor: pointer; line-height: 1.2; }
.button-primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.button-primary:hover { background: #2D72AC; }
.button-secondary { color: var(--navy); background: var(--surface); border-color: #D0D5DD; }
.button-secondary:hover, .button-quiet:hover { background: var(--background); }
.button-quiet { color: var(--muted); background: transparent; border-color: transparent; }
.button-danger { color: var(--red); background: var(--surface); border-color: #FDA29B; }
.button-danger:hover { background: var(--red-bg); }
.button-small { min-height: 32px; padding: 6px 10px; font-size: 13px; }
.button-full { width: 100%; }

.filter-bar { display: flex; gap: 8px; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.filter-bar input { max-width: 420px; }
input, select, textarea { width: 100%; border: 1px solid #D0D5DD; border-radius: 9px; background: var(--surface); color: var(--text); padding: 10px 12px; }
input[readonly] { background: var(--background); color: var(--muted); }
textarea { resize: vertical; min-height: 100px; }
label { display: grid; gap: 6px; color: var(--text); font-weight: 650; font-size: 13px; }
.hint { color: var(--muted); font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; padding: 22px; }
.span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.inline-form { padding: 18px 22px; }
.checkbox-row { grid-template-columns: auto 1fr; align-items: start; }
.checkbox-row input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--blue); }
.checkbox-row span, .checkbox-row small { display: block; }
.checkbox-row small { color: var(--muted); font-weight: 400; margin-top: 2px; }
.danger-zone { border-color: #FED3CF; }
.notice { margin-bottom: 18px; padding: 12px 14px; border: 1px solid; border-radius: 10px; }
.notice ul { margin: 6px 0 0 18px; padding: 0; }
.notice-success { color: var(--green); background: var(--green-bg); border-color: #A6E1D1; }
.notice-error { color: var(--red); background: var(--red-bg); border-color: #FDA29B; }
.notice-warning { color: var(--amber); background: var(--amber-bg); border-color: #F1D382; }
.muted { color: var(--muted); }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 420px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(16, 24, 40, .07); padding: 32px; }
.brand-login { margin-bottom: 36px; }
.login-card h1 { margin: 6px 0; color: var(--navy); font-size: 28px; }
.login-card > .muted { margin: 0 0 24px; }
.stack-form { display: grid; gap: 16px; }

@media (max-width: 1050px) {
    .metric-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: min(84vw, 280px); transform: translateX(-105%); box-shadow: 12px 0 30px rgba(16, 24, 40, .12); }
    .nav-open .sidebar { transform: translateX(0); }
    .nav-toggle { display: inline-flex; }
    .topbar { justify-content: flex-start; padding: 16px 20px; }
    .main-content { padding: 20px 16px 40px; }
    .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .section-heading { align-items: flex-start; flex-direction: column; }
    .section-heading > .button, .section-heading > form, .section-heading > form .button { width: 100%; }
    .form-grid { grid-template-columns: 1fr; padding: 18px; }
    .span-2 { grid-column: auto; }
    .filter-bar { flex-wrap: wrap; }
    .filter-bar input { max-width: none; flex: 1 0 100%; }
}

@media (max-width: 430px) {
    .metric-strip { grid-template-columns: 1fr; }
    .metric span { min-height: auto; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .button { width: 100%; }
    .login-card { padding: 24px; }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; }
}
