:root {
  color-scheme: light;
  --ink-950: #12142b;
  --ink-800: #292d4f;
  --ink-650: #555c78;
  --ink-500: #727993;
  --line: #dfe3ef;
  --line-strong: #c9cede;
  --surface: #ffffff;
  --surface-soft: #f7f8fc;
  --surface-muted: #eef1f7;
  --brand-800: #40348f;
  --brand-700: #5146b8;
  --brand-600: #6657d8;
  --brand-100: #efedff;
  --navy-950: #151936;
  --navy-900: #1b2044;
  --success-700: #176443;
  --success-100: #e7f7ef;
  --warning-700: #875400;
  --warning-100: #fff3d4;
  --danger-700: #982b34;
  --danger-100: #ffebed;
  --info-700: #205f92;
  --info-100: #e8f4ff;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgb(18 20 43 / 8%);
  --shadow-md: 0 16px 44px rgb(18 20 43 / 10%);
  --focus: 0 0 0 3px rgb(102 87 216 / 28%);
  --sidebar: 252px;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--surface-soft); color: var(--ink-950); font-family: var(--font-sans); line-height: 1.5; }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { color: inherit; font: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--brand-700);
  outline-offset: 3px;
  box-shadow: var(--focus);
}

.skip-link { position: fixed; top: -6rem; left: 1rem; z-index: 100; padding: .7rem 1rem; border-radius: var(--radius-sm); background: #fff; color: var(--ink-950); font-weight: 800; }
.skip-link:focus { top: 1rem; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.app-shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.app-sidebar { position: sticky; top: 0; display: flex; flex-direction: column; min-width: 0; height: 100vh; padding: 1rem; overflow-y: auto; background: linear-gradient(180deg, var(--navy-950), #11152f); color: #fff; }
.app-brand { display: grid; gap: .1rem; padding: .65rem .7rem 1rem; color: #fff; text-decoration: none; }
.app-brand strong { font-size: 1.08rem; letter-spacing: .12em; }
.app-brand span { color: rgb(255 255 255 / 58%); font-size: .72rem; }
.workspace-switcher { display: grid; gap: .35rem; margin: .5rem 0 1rem; padding: .75rem; border: 1px solid rgb(255 255 255 / 10%); border-radius: var(--radius-md); background: rgb(255 255 255 / 6%); }
.workspace-switcher label, .nav-group-title { color: rgb(255 255 255 / 52%); font-size: .65rem; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.workspace-switcher select { width: 100%; min-height: 40px; border: 1px solid rgb(255 255 255 / 16%); border-radius: var(--radius-sm); background: #262b55; color: #fff; }
.workspace-switcher span { color: rgb(255 255 255 / 68%); font-size: .75rem; }
.app-nav { display: grid; gap: .18rem; }
.nav-group-title { margin: 1rem .65rem .3rem; }
.app-nav a { display: flex; align-items: center; justify-content: space-between; gap: .6rem; min-height: 42px; padding: .62rem .7rem; border: 1px solid transparent; border-radius: var(--radius-sm); color: rgb(255 255 255 / 76%); font-size: .82rem; font-weight: 750; text-decoration: none; }
.app-nav a:hover { background: rgb(255 255 255 / 7%); color: #fff; }
.app-nav a[aria-current="page"] { border-color: rgb(143 163 255 / 26%); background: linear-gradient(135deg, rgb(73 89 210 / 48%), rgb(102 87 216 / 25%)); color: #fff; box-shadow: inset 3px 0 0 #8bd7ff; }
.nav-lock { padding: .14rem .4rem; border-radius: 999px; background: rgb(255 255 255 / 12%); color: #d8dcff; font-size: .62rem; font-weight: 850; }
.sidebar-foot { display: grid; gap: .5rem; margin-top: auto; padding-top: 1rem; }
.sidebar-foot a, .sidebar-foot button { min-height: 40px; border: 1px solid rgb(255 255 255 / 12%); border-radius: var(--radius-sm); background: transparent; color: rgb(255 255 255 / 72%); font-size: .78rem; text-align: left; text-decoration: none; }
.sidebar-foot a { padding: .6rem .7rem; }
.sidebar-foot button { padding: .55rem .7rem; cursor: not-allowed; }

.app-frame { min-width: 0; }
.app-topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 70px; padding: .8rem clamp(1rem, 2.2vw, 2rem); border-bottom: 1px solid var(--line); background: rgb(255 255 255 / 92%); backdrop-filter: blur(14px); }
.app-topbar h1 { margin: 0; font-size: 1.25rem; }
.app-topbar p { margin: .12rem 0 0; color: var(--ink-650); font-size: .75rem; }
.topbar-actions { display: flex; align-items: center; gap: .55rem; }
.button.mobile-menu-button { display: none; }
.app-main { width: min(1380px, 100%); min-width: 0; padding: clamp(1rem, 2.6vw, 2.5rem); }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-header .eyebrow { margin: 0 0 .25rem; color: var(--brand-700); font-size: .72rem; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.page-header h2 { margin: 0; font-size: clamp(1.75rem, 3.5vw, 2.8rem); line-height: 1.06; letter-spacing: -.035em; }
.page-header p:not(.eyebrow) { max-width: 760px; margin: .55rem 0 0; color: var(--ink-650); }

.status { display: inline-flex; align-items: center; gap: .42rem; min-height: 1.7rem; padding: .28rem .6rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-soft); color: var(--ink-800); font-size: .72rem; font-weight: 820; line-height: 1.1; }
.status::before { width: .46rem; height: .46rem; border-radius: 50%; background: currentColor; content: ""; }
.status[data-tone="success"] { color: var(--success-700); background: var(--success-100); border-color: #b9e2cb; }
.status[data-tone="warning"] { color: var(--warning-700); background: var(--warning-100); border-color: #ecd08f; }
.status[data-tone="danger"] { color: var(--danger-700); background: var(--danger-100); border-color: #efbec3; }
.status[data-tone="info"] { color: var(--info-700); background: var(--info-100); border-color: #bddcf3; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: .62rem .9rem; border: 1px solid var(--brand-700); border-radius: var(--radius-sm); background: var(--brand-700); color: #fff; font-size: .8rem; font-weight: 800; text-decoration: none; cursor: pointer; }
.button:hover { background: var(--brand-800); }
.button.secondary { border-color: var(--line-strong); background: #fff; color: var(--ink-800); }
.button:disabled, .button[aria-disabled="true"] { border-color: var(--line); background: var(--surface-muted); color: var(--ink-500); cursor: not-allowed; }

.metric-grid, .card-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 1rem; }
.metric { grid-column: span 3; display: grid; gap: .25rem; min-width: 0; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.metric span { color: var(--ink-650); font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.metric strong { font-size: 1.65rem; line-height: 1.15; }
.metric small { color: var(--ink-650); }
.card { grid-column: span 6; min-width: 0; padding: 1.15rem; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.card.full { grid-column: 1 / -1; }
.card.third { grid-column: span 4; }
.card h3 { margin: 0 0 .35rem; font-size: 1.02rem; }
.card p { margin: .35rem 0; color: var(--ink-650); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .8rem; margin-bottom: .8rem; }

.callout { padding: .9rem 1rem; border: 1px solid #cec9ff; border-left: 4px solid var(--brand-600); border-radius: var(--radius-sm); background: var(--brand-100); color: var(--ink-800); }
.callout.warning { border-color: #efd08e; border-left-color: #b87900; background: var(--warning-100); }
.callout.danger { border-color: #efbec3; border-left-color: var(--danger-700); background: var(--danger-100); }
.state-panel { display: grid; gap: .25rem; padding: 1rem; border: 1px dashed var(--line-strong); border-radius: var(--radius-md); background: var(--surface-soft); }
.state-panel p { margin: 0; color: var(--ink-650); }
.skeleton { min-height: 1rem; border-radius: 5px; background: linear-gradient(90deg, #edf0f6 25%, #f8f9fc 50%, #edf0f6 75%); background-size: 200% 100%; animation: skeleton 1.2s linear infinite; }
@keyframes skeleton { to { background-position-x: -200%; } }

.data-region { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; }
.data-table { width: 100%; min-width: 720px; border-collapse: collapse; }
.data-table caption { text-align: left; }
.data-table th, .data-table td { padding: .75rem .8rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data-table th { background: var(--surface-soft); color: var(--ink-650); font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; }
.data-table td { color: var(--ink-800); font-size: .8rem; }
.data-table tr:last-child td { border-bottom: 0; }
.table-note { display: block; margin-top: .18rem; color: var(--ink-500); font-size: .72rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.field { display: grid; gap: .35rem; }
.field.full { grid-column: 1 / -1; }
.field span { color: var(--ink-800); font-size: .76rem; font-weight: 800; }
.field small { color: var(--ink-650); }
.field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: .62rem .7rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; }
.field [aria-invalid="true"] { border-color: var(--danger-700); }

.tab-list { display: flex; max-width: 100%; gap: .3rem; margin-bottom: 1rem; overflow-x: auto; }
.tab-list button { flex: 0 0 auto; min-height: 40px; padding: .55rem .75rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--ink-650); font-weight: 760; }
.tab-list button[aria-selected="true"] { border-color: var(--brand-600); background: var(--brand-100); color: var(--brand-800); }
.readonly-row { display: grid; gap: .18rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.readonly-row:last-child { border-bottom: 0; }
.readonly-row span { color: var(--ink-650); font-size: .68rem; font-weight: 850; text-transform: uppercase; letter-spacing: .06em; }

.toast-region { position: fixed; right: 1rem; bottom: 1rem; z-index: 50; width: min(360px, calc(100vw - 2rem)); }
.toast { padding: .9rem 1rem; border: 1px solid var(--line); border-radius: var(--radius-md); background: #fff; box-shadow: var(--shadow-md); }
.mobile-backdrop { display: none; }

@media (max-width: 1100px) {
  .metric { grid-column: span 6; }
  .card.third { grid-column: span 6; }
}

@media (max-width: 899px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(300px, calc(100vw - 48px)); height: 100dvh; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow-md); }
  .app-sidebar.is-open { transform: translateX(0); }
  .mobile-backdrop { position: fixed; inset: 0; z-index: 30; display: block; border: 0; background: rgb(11 14 34 / 52%); }
  .button.mobile-menu-button { display: inline-flex; }
  .app-topbar { min-height: 62px; }
}

@media (max-width: 767px) {
  .metric, .card, .card.third { grid-column: 1 / -1; }
  .page-header { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .topbar-actions .button.secondary:not(.mobile-menu-button) { display: none; }
}

@media (max-width: 390px) {
  .app-main { padding: .9rem; }
  .app-topbar { padding-inline: .75rem; }
  .metric-grid, .card-grid { gap: .75rem; }
}

@media (forced-colors: active) {
  .card, .metric, .status, .callout, .button { border: 1px solid CanvasText; }
}

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