:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --brand: #195b87;
  --brand-strong: #0f3f65;
  --teal: #168a93;
  --green: #047857;
  --amber: #b45309;
  --red: #b42318;
  --shadow: 0 10px 24px rgba(15, 23, 42, .07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, .link-button { min-height: 40px; }
[hidden] { display: none !important; }

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: #eef4f8;
}

.auth-card {
  width: min(620px, 100%);
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-brand {
  align-items: center;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.auth-brand h1 {
  color: var(--brand-strong);
  font-size: 2rem;
}

.auth-form {
  display: grid;
  gap: .75rem;
}

.user-badge {
  display: grid;
  gap: .1rem;
  min-width: 150px;
  padding: .45rem .65rem;
  border: 1px solid rgba(255,255,255,.34);
  border-radius: 8px;
  background: rgba(255,255,255,.12);
}

.user-badge strong { font-size: .9rem; }
.user-badge span { font-size: .74rem; color: rgba(255,255,255,.78); }

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem clamp(1rem, 3vw, 2rem);
  background: #113d5c;
  color: white;
  border-bottom: 5px solid var(--teal);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.brand-logo {
  width: clamp(76px, 9vw, 112px);
  aspect-ratio: 1;
  object-fit: contain;
  flex: 0 0 auto;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .3rem; font-size: clamp(2rem, 4vw, 3rem); letter-spacing: 0; }
h2 { margin-bottom: .35rem; font-size: 1.6rem; }
h3 { margin-bottom: .85rem; font-size: 1rem; }
.subtitle { margin-bottom: 0; max-width: 760px; color: rgba(255,255,255,.86); }
.eyebrow { margin-bottom: .25rem; text-transform: uppercase; letter-spacing: .08em; font-size: .74rem; font-weight: 800; color: rgba(255,255,255,.82); }
.eyebrow.dark { color: var(--teal); }
.hint { color: var(--muted); margin-bottom: .75rem; }

.header-actions { display: flex; align-items: flex-start; gap: .5rem; flex-wrap: wrap; }
.year-picker {
  min-width: 160px;
  color: rgba(255,255,255,.9);
  font-size: .82rem;
  font-weight: 800;
}
.year-picker select {
  margin-top: .25rem;
  min-height: 40px;
  border-color: rgba(255,255,255,.38);
}
.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 2rem) 2rem;
}

.sidebar {
  position: sticky;
  top: 1rem;
  align-self: start;
  display: grid;
  gap: .35rem;
  padding: .5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.nav-item, .primary, .secondary, .ghost, .ghost-dark, .small, .icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: .65rem .85rem;
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
}

.nav-item {
  text-align: left;
  color: #344054;
  background: transparent;
}
.nav-item:hover, .nav-item.active { background: #e8f2f6; color: var(--brand-strong); }
.primary { background: var(--brand); color: white; }
.primary:hover { background: var(--brand-strong); }
.secondary { background: #e8f2f6; color: var(--brand-strong); border-color: #c2dbe7; }
.ghost { background: rgba(255,255,255,.12); color: white; border-color: rgba(255,255,255,.38); }
.ghost-dark { background: white; color: var(--brand); border-color: var(--line); }
.small { min-height: 32px; padding: .35rem .55rem; font-size: .85rem; background: var(--brand); color: white; }
.small.danger { background: var(--red); color: white; }
.small.danger:hover { background: #8f1b13; }
.icon-button { width: 40px; padding: 0; font-size: 1.5rem; background: var(--surface-soft); color: var(--ink); border-color: var(--line); }
.link-button { display: inline-flex; align-items: center; }

.content { min-width: 0; }
.panel { display: none; }
.panel.active { display: block; }
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}
.section-heading.compact { margin-bottom: .35rem; }

.page-error {
  padding: .85rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid #f3b4ad;
  border-radius: 8px;
  background: #fff1f0;
  color: var(--red);
  font-weight: 700;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.kpi-card, .surface, .form-surface {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.kpi-card { padding: .9rem; min-height: 96px; }
.kpi-card span { display: block; color: var(--muted); font-size: .83rem; font-weight: 700; }
.kpi-card strong { display: block; margin-top: .35rem; font-size: 2rem; line-height: 1; }
.kpi-card:nth-child(2) { border-top: 4px solid var(--teal); }
.kpi-card:nth-child(3) { border-top: 4px solid var(--brand); }
.kpi-card:nth-child(4) { border-top: 4px solid var(--red); }
.kpi-card:nth-child(5) { border-top: 4px solid var(--green); }
.kpi-card:nth-child(6), .kpi-card:nth-child(7) { border-top: 4px solid var(--amber); }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, .7fr);
  gap: 1rem;
}
.surface, .form-surface { padding: 1rem; }
.metric-list { display: grid; gap: .3rem; }
.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .65rem 0;
  border-bottom: 1px solid var(--line);
}
.alerts p {
  padding: .7rem;
  margin-bottom: .5rem;
  border-radius: 8px;
  background: #fff7ed;
  color: var(--amber);
  font-weight: 750;
}
.ok-text { color: var(--green); font-weight: 750; }

.empty-state, .empty-table {
  display: grid;
  gap: .45rem;
  padding: 1rem;
  margin-bottom: 1rem;
  border: 1px dashed #a7c4d8;
  border-radius: 8px;
  background: #f6fbfd;
  color: #244154;
}
.empty-state.compact { margin: 0; }
.empty-state button { justify-self: start; }

.toolbar {
  display: flex;
  align-items: flex-end;
  gap: .65rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: .85rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.field { display: grid; gap: .3rem; color: #344054; font-weight: 750; min-width: 170px; }
.field.grow { flex: 1; min-width: min(340px, 100%); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .7rem .75rem;
  background: white;
  color: var(--ink);
}
input[readonly] { background: #eef4f8; color: var(--muted); }
textarea { resize: vertical; }

.table-wrap {
  overflow: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; min-width: 980px; }
th, td { text-align: left; padding: .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #eef4f8; color: #1f3c55; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: #f8fafc; }
.compact-table table { min-width: 620px; }
.actions { white-space: nowrap; }
.actions button + button { margin-left: .35rem; }
.link-row {
  border: 0;
  padding: 0;
  min-height: 0;
  background: transparent;
  color: var(--brand);
  font-weight: 800;
  cursor: pointer;
}

.badge {
  display: inline-flex;
  max-width: 100%;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 800;
  background: #e0f2fe;
  color: #075985;
  white-space: normal;
}
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.ok { background: #dcfce7; color: #166534; }

.form-surface { max-width: 1120px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: .85rem;
  margin: 1rem 0;
}
.compact-form { align-items: end; }
.form-actions { display: flex; align-items: end; min-height: 100%; }
.summary-box {
  margin-top: 1rem;
  padding: .85rem;
  border: 1px solid #c2dbe7;
  border-radius: 8px;
  background: #f6fbfd;
  color: #244154;
  font-weight: 750;
}
label { font-weight: 750; color: #344054; display: grid; gap: .35rem; }
.span-2 { grid-column: 1 / -1; }
.single { margin: 1rem 0; max-width: 380px; }
.single.wide { max-width: 720px; }
.score-grid {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 120px 120px 120px minmax(130px, 1fr);
  gap: .5rem;
  align-items: center;
  overflow-x: auto;
  margin: 1rem 0;
}
.score-grid > * { min-width: 0; }
output {
  padding: .65rem;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 40px;
}

.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 40, .55);
}
.modal-panel {
  position: relative;
  width: min(980px, 100%);
  max-height: min(760px, 92vh);
  overflow: auto;
  background: white;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
}
.modal-header h2 { margin-bottom: 0; }
.profile-tabs {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.profile-tab {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: #344054;
  padding: .45rem .65rem;
  cursor: pointer;
  font-weight: 750;
}
.profile-tab.active { background: var(--brand); color: white; border-color: var(--brand); }
.profile-content { padding: 1rem; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: .65rem;
}
.detail-item {
  min-width: 0;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .75rem;
}
.detail-item strong {
  display: block;
  margin-bottom: .25rem;
  font-size: .74rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.detail-item span { overflow-wrap: anywhere; }
.timeline-item {
  padding: .85rem;
  margin-bottom: .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}
.timeline-item strong, .timeline-item span, .timeline-item em { display: block; }
.timeline-item span { color: var(--muted); margin-top: .2rem; }
.timeline-item p { margin: .5rem 0; }

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  max-width: min(420px, calc(100vw - 2rem));
  padding: .9rem 1rem;
  background: #111827;
  color: white;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(10px);
  transition: .2s ease;
  pointer-events: none;
  font-weight: 750;
}
.toast.error { background: var(--red); }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-header, .section-heading { flex-direction: column; }
  .brand-lockup { align-items: flex-start; }
  .brand-logo { width: 76px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-item { text-align: center; }
  .score-grid { grid-template-columns: 110px 90px 90px 100px 130px; }
}
