:root {
  --navy: #12235C;
  --navy-light: #1B3D8F;
  --gold: #F0B429;
  --bg: #F4F5F7;
  --border: #E4E7ED;
  --border-2: #EEF0F4;
  --text: #1D2433;
  --muted: #7C8299;
  --muted-2: #9AA0AC;
  --green: #2F8F5B;
  --green-bg: #E5F3EA;
  --amber: #B07A0E;
  --amber-bg: #FDF1D8;
  --red: #B3283C;
  --red-bg: #FBE7E9;
  --gray-bg: #E9EBF2;
  --gray-text: #4B5568;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--navy-light); text-decoration: none; }
a:hover { color: var(--gold); }

button { font-family: inherit; }

/* border-collapse:collapse makes position:sticky unreliable on table cells,
   especially cells sticky in both directions (frozen corner columns).
   border-spacing:0 keeps borders looking identical since only tr borders
   are used anywhere (no per-cell borders to double up). */
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { text-align: left; }

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

.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--navy);
  color: #E7EAF3;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-badge {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  background: var(--gold); color: var(--navy);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; line-height: 1.15; text-align: center;
}
.brand-badge-img {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  object-fit: cover; background: #fff;
}
.brand-name { font-size: 13px; font-weight: 700; line-height: 1.25; color: #fff; }
.brand-sub { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: #8FA0D6; margin-top: 4px; }

.sidebar-nav { padding: 16px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px 11px 17px; border-radius: 8px;
  color: #C2CBE8; font-size: 14px; font-weight: 500;
}
.nav-link:hover { color: #fff; }
.nav-link.active {
  background: rgba(255,255,255,0.1); color: #fff; font-weight: 600;
  padding-left: 14px; border-left: 3px solid var(--gold);
}

.sidebar-foot {
  padding: 16px 20px 24px; border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; flex-direction: column; gap: 10px;
}
.sidebar-foot a { font-size: 13px; color: #9AA6CC; font-weight: 500; }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: flex-end; gap: 16px;
  padding: 16px 32px; border-bottom: 1px solid var(--border); background: #fff;
}
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--gold); color: var(--navy);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.user-name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-role { font-size: 11px; color: var(--muted); }

.main { flex: 1; padding: 32px; overflow: auto; }

.footer {
  padding: 16px 32px; border-top: 1px solid var(--border); background: #fff;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--muted-2);
}

/* Page head */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap; gap: 16px; margin-bottom: 24px;
}
.page-head h1 { margin: 0; font-size: 28px; font-weight: 800; color: var(--navy); letter-spacing: -0.01em; }
.page-head p { margin: 6px 0 0; font-size: 14px; color: #6B7280; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 8px; font-size: 13px; font-weight: 700;
  cursor: pointer; border: 1px solid transparent;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-secondary { background: #fff; border-color: #D8DCE4; color: #374151; }
.btn-sm { padding: 6px 14px; font-size: 12px; }

/* Cards / stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.card {
  background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 20px;
}
.card-hero { background: var(--navy); color: #fff; }
.card-label {
  font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted);
}
.card-hero .card-label { color: #9FB0DE; }
.card-value { font-size: 28px; font-weight: 800; margin-top: 8px; color: var(--navy); }
.card-hero .card-value { color: #fff; font-size: 34px; }
.card-amount { font-size: 13px; font-weight: 700; margin-top: 4px; color: var(--navy); }
.card-hero .card-amount { color: #fff; }
.card-note { font-size: 12px; margin-top: 6px; color: var(--muted); }
.card-note.green { color: var(--green); font-weight: 600; }
.card-note.amber { color: var(--amber); font-weight: 600; }
.card-note.red { color: var(--red); font-weight: 600; }
.card-span-2 { grid-column: span 2; }
.card-span-3 { grid-column: span 3; }
.card-span-4 { grid-column: span 4; }

.card-link {
  display: block; position: relative;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.card-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(18,35,92,0.10);
  border-color: #C9D0E0;
}
.card-hero.card-link:hover {
  box-shadow: 0 10px 26px rgba(18,35,92,0.35);
  border-color: rgba(255,255,255,0.25);
}
.card-link:focus-visible {
  outline: 2px solid var(--navy-light); outline-offset: 2px;
}
.card-hero.card-link:focus-visible { outline-color: #fff; }
.card-arrow {
  position: absolute; top: 18px; right: 20px;
  font-size: 15px; line-height: 1; color: currentColor;
  opacity: 0.35; transform: translate(-3px, 3px);
  transition: opacity .15s ease, transform .15s ease;
}
.card-link:hover .card-arrow { opacity: 0.9; transform: translate(0, 0); }

/* Search / filter bar */
.toolbar {
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  padding: 20px 24px; margin-bottom: 20px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.input {
  flex: 1; min-width: 240px; padding: 10px 14px; border: 1px solid #D8DCE4; border-radius: 8px;
  font-size: 13px; font-family: inherit; color: var(--text);
}
.dropdown { position: relative; }
.dropdown-btn {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: #fff;
  border: 1px solid #D8DCE4; border-radius: 8px; font-size: 13px; font-weight: 600; color: #374151; cursor: pointer;
}
.dropdown-btn .caret { font-size: 10px; color: var(--muted-2); }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 12px 28px rgba(18,35,92,0.14); min-width: 160px; z-index: 20; overflow: hidden;
  display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item { padding: 10px 16px; font-size: 13px; font-weight: 500; color: #374151; cursor: pointer; }
.dropdown-item:hover { background: var(--bg); }

/* Table */
.table-card { background: #fff; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.table-scroll { overflow-x: auto; }
/* Sticky thead needs its own real scrolling viewport -- `.table-card`'s
   overflow:hidden and `.table-scroll`'s own overflow-x:auto (which forces
   overflow-y to compute as auto too) otherwise become the sticky containing
   block without ever actually scrolling, so `position:sticky` never engages. */
.table-scroll-fixed-head { max-height: 65vh; overflow-y: auto; }
th.th {
  padding: 14px 16px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); white-space: nowrap; background: #F7F8FB;
  border-bottom: 1px solid var(--border);
}
th.th-sortable { cursor: pointer; user-select: none; }
th.th-sortable:hover { color: var(--navy); }
th.th-sortable.active { color: var(--navy); }
.sort-indicator { display: inline-block; margin-left: 5px; font-size: 9px; opacity: 0.35; }
th.th-sortable.active .sort-indicator { opacity: 1; }
/* border-collapse:separate means tr borders no longer render -- border lives
   on the cells themselves instead (th above, td below). */
td.td { padding: 13px 16px; font-size: 13px; color: #374151; white-space: nowrap; border-bottom: 1px solid var(--border-2); }
.td-strong { font-weight: 700; color: var(--navy); }
.td-right { text-align: right; }
.table-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted);
}
.empty-row td { padding: 32px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* Frozen columns: keep leading columns visible while scrolling a wide table horizontally */
.col-frozen {
  position: sticky; z-index: 2; box-sizing: border-box;
  overflow: hidden; text-overflow: ellipsis;
}
td.td.col-frozen { background: #fff; }
th.th.col-frozen { background: #F7F8FB; }
.col-frozen-end { box-shadow: 4px 0 6px -4px rgba(16, 24, 40, 0.25); }

/* Frozen header row: keep column headers visible while scrolling a tall table vertically */
th.th.th-sticky { position: sticky; top: 0; z-index: 4; background: #F7F8FB; }
/* Corner cells (sticky in both directions) must render above everything else,
   including plain sticky header cells -- needs 3 classes to unambiguously
   out-specificity both rules above regardless of source order. */
th.th.col-frozen.th-sticky { z-index: 6; background: #F7F8FB; }

/* Badges */
.badge {
  display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 700;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(18,35,92,0.45);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: 14px; width: 520px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
  padding: 28px; box-shadow: 0 20px 50px rgba(18,35,92,0.3);
}
.modal-title { font-size: 17px; font-weight: 800; color: var(--navy); margin-bottom: 4px; }
.modal-subtitle { font-size: 12px; color: var(--muted); margin-bottom: 20px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-grid.single { grid-template-columns: 1fr; }
.span-2 { grid-column: span 2; }
.field-label { font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.field-input {
  width: 100%; padding: 10px 12px; border: 1px solid #D8DCE4; border-radius: 8px;
  font-size: 13px; font-family: inherit; color: var(--text); background: #fff;
}
.field-input:disabled { background: var(--bg); color: var(--muted); }
.field-static { padding: 10px 12px; background: #F7F8FB; border-radius: 8px; }
.field-static .field-label { margin-bottom: 4px; }
.field-static .field-value { font-size: 13px; color: #374151; }
.field-row-static {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 12px;
  background: #F7F8FB; border-radius: 8px;
}
.field-row-static .field-label { margin-bottom: 0; font-weight: 600; color: var(--muted); }
.field-row-static .field-value { font-size: 14px; font-weight: 800; color: var(--navy); }
.choice-row { display: flex; gap: 8px; }
.choice-btn {
  flex: 1; padding: 9px 0; border-radius: 8px; font-size: 12px; font-weight: 700; cursor: pointer;
  border: 1px solid #D8DCE4; background: #fff; color: var(--muted);
}
.sort-btn { flex: none; padding: 9px 14px; }
.sort-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.modal-error { font-size: 12px; color: var(--red); margin-top: 10px; display: none; }
.modal-error.show { display: block; }

/* Reports-specific bits */
.legend { display: flex; gap: 16px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #374151; font-weight: 500; }
.legend-dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.legend-dot.round { border-radius: 50%; }

.chart-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; height: 220px; padding: 0 4px; }
.chart-col { display: flex; flex-direction: column; align-items: center; flex: 1; height: 100%; justify-content: flex-end; }
.chart-bars { display: flex; align-items: flex-end; gap: 3px; height: 190px; }
.chart-bar { width: 12px; border-radius: 3px 3px 0 0; }
.chart-month { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 8px; }

.breakdown-row + .breakdown-row { margin-top: 14px; }
.breakdown-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.breakdown-code { font-size: 13px; font-weight: 700; color: var(--navy); }
.breakdown-desc { font-weight: 500; color: var(--muted); }
.breakdown-total { font-size: 12px; color: var(--muted); font-weight: 600; }
.stack-bar { display: flex; height: 16px; border-radius: 5px; overflow: hidden; background: var(--border-2); }
.stack-bar.sm { height: 10px; border-radius: 4px; }

.watch-row { display: flex; align-items: center; gap: 12px; }
.watch-row + .watch-row { margin-top: 12px; }
.watch-rank {
  width: 24px; height: 24px; border-radius: 50%; background: var(--bg); color: var(--muted);
  font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.watch-code { font-size: 13px; font-weight: 700; color: var(--navy); }
.watch-desc { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.watch-pct { font-size: 13px; font-weight: 800; flex-shrink: 0; }

.donut-wrap { display: flex; justify-content: center; margin-bottom: 22px; }
.donut {
  width: 170px; height: 170px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.donut-hole {
  width: 118px; height: 118px; border-radius: 50%; background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.donut-total { font-size: 24px; font-weight: 800; color: var(--navy); }
.donut-label { font-size: 11px; color: var(--muted); }
.donut-legend-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.donut-legend-row + .donut-legend-row { margin-top: 12px; }
.donut-legend-left { display: flex; align-items: center; gap: 8px; color: #374151; font-weight: 500; }
.donut-legend-pct { font-weight: 700; color: var(--navy); }

.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.section-title { font-size: 16px; font-weight: 700; color: var(--navy); }
.section-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .sidebar { display: none; }
  .stat-grid { grid-template-columns: 1fr; }
  .modal-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
}

@media print {
  .sidebar, .topbar, .footer, .toolbar, .btn { display: none !important; }
  .main { padding: 0; overflow: visible; }
  body { background: #fff; }
}
