:root {
  --ink: #172033;
  --muted: #687189;
  --line: #dfe4ed;
  --line-strong: #cbd3e0;
  --surface: #ffffff;
  --canvas: #f5f7fb;
  --primary: #2457e6;
  --primary-dark: #183fb4;
  --primary-soft: #edf2ff;
  --positive: #157347;
  --positive-soft: #e9f7ef;
  --warning: #9b5b00;
  --warning-soft: #fff4dc;
  --negative: #b42318;
  --negative-soft: #feeeec;
  --shadow: 0 16px 50px rgba(30, 48, 84, .08);
  --radius: 16px;
  --radius-small: 10px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(36, 87, 230, .24);
  outline-offset: 2px;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(28px, 4vw, 42px); line-height: 1.12; letter-spacing: -.035em; }
h2 { margin-bottom: 6px; font-size: 20px; line-height: 1.25; letter-spacing: -.015em; }
h3 { margin-bottom: 6px; font-size: 17px; }
.shell { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }
.page { min-height: calc(100vh - 142px); padding-block: 42px 70px; }
.skip-link { position: fixed; z-index: 99; top: 8px; left: 8px; padding: 9px 12px; transform: translateY(-150%); background: var(--ink); color: white; border-radius: 8px; }
.skip-link:focus { transform: none; }
.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; }
.muted { color: var(--muted); }

.topbar { position: sticky; z-index: 20; top: 0; border-bottom: 1px solid rgba(203, 211, 224, .8); background: rgba(255, 255, 255, .92); backdrop-filter: blur(14px); }
.topbar-inner { min-height: 72px; display: flex; align-items: center; gap: 28px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-size: 17px; font-weight: 750; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; width: 34px; height: 34px; place-items: center; color: white; background: var(--primary); border-radius: 10px; font-size: 17px; }
.main-nav { display: flex; align-items: center; gap: 4px; margin-right: auto; }
.main-nav a { padding: 9px 12px; color: #49536a; border-radius: 8px; font-weight: 600; }
.main-nav a:hover { color: var(--ink); background: var(--canvas); text-decoration: none; }
.logout-form { margin: 0; }
.nav-toggle { display: none; margin-left: auto; border: 1px solid var(--line); border-radius: 8px; background: white; padding: 8px 11px; }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 30px; }
.page-heading > div { max-width: 760px; }
.page-heading p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: 16px; }
.eyebrow { margin-bottom: 8px; color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }

.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border: 1px solid transparent; border-radius: 10px; cursor: pointer; font-weight: 700; line-height: 1.25; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.button:hover { text-decoration: none; transform: translateY(-1px); }
.button-primary { color: white; background: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: var(--ink); border-color: var(--line-strong); background: white; }
.button-secondary:hover { border-color: #aeb8c9; background: #fbfcfe; }
.button-quiet { color: #4f596e; background: transparent; }
.button-quiet:hover { background: var(--canvas); }
.button-danger { color: white; background: var(--negative); }
.button-danger:hover { background: #8f1b13; }
.button-light { color: var(--primary-dark); background: white; }
.button-light:hover { background: #f7f9ff; }
.button-small { min-height: 36px; padding: 7px 11px; font-size: 14px; }
.button-full { width: 100%; }

.metric-grid { display: grid; gap: 14px; margin-bottom: 20px; }
.metric-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metric-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric-grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.metric-card { min-height: 148px; display: flex; flex-direction: column; padding: 21px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 5px 22px rgba(30, 48, 84, .04); }
.metric-card > span { color: var(--muted); font-weight: 600; }
.metric-card strong { margin: 9px 0 3px; font-size: 26px; line-height: 1.2; letter-spacing: -.025em; }
.metric-card small { color: var(--muted); }
.metric-card a { margin-top: auto; font-weight: 650; }

.panel { margin-bottom: 20px; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 5px 22px rgba(30, 48, 84, .035); }
.panel-narrow { max-width: 760px; }
.panel-form { max-width: 820px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 20px; }
.panel-heading p { margin: 0; color: var(--muted); }
.split-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); gap: 20px; }
.split-grid-wide { grid-template-columns: minmax(0, .85fr) minmax(360px, 1.15fr); }
.long-text { color: #384359; white-space: normal; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 12px; border-bottom: 1px solid #e8ecf3; text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfe; }

.status { display: inline-flex; min-height: 27px; align-items: center; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 750; white-space: nowrap; }
.status-positive { color: var(--positive); background: var(--positive-soft); }
.status-warning { color: var(--warning); background: var(--warning-soft); }
.status-negative { color: var(--negative); background: var(--negative-soft); }
.status-neutral { color: #596277; background: #edf0f5; }
.status-large { min-height: 34px; padding: 7px 12px; font-size: 13px; }

.request-stack { display: grid; }
.request-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 15px 2px; border-bottom: 1px solid #e8ecf3; color: var(--ink); }
.request-row:last-child { border-bottom: 0; }
.request-row:hover { text-decoration: none; }
.request-row div { display: grid; }
.request-row span:not(.status) { color: var(--muted); font-size: 13px; }
.empty-state { padding: 32px 12px; color: var(--muted); text-align: center; }

.definition-list { margin: 0; }
.definition-list > div { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 16px; padding: 14px 0; border-bottom: 1px solid #e8ecf3; }
.definition-list > div:last-child { border-bottom: 0; }
.definition-list dt { color: var(--muted); }
.definition-list dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.form-stack { display: grid; gap: 17px; }
.field { display: grid; gap: 7px; }
.field > label:not(.check-row) { font-weight: 700; }
.field input:not([type="checkbox"]), .field textarea, .field select, .search-bar input {
  width: 100%; min-height: 46px; padding: 10px 12px; color: var(--ink); border: 1px solid var(--line-strong); border-radius: 9px; background: white;
}
.field textarea { min-height: 132px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus, .search-bar input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(36, 87, 230, .1); outline: none; }
.check-row { display: flex; align-items: flex-start; gap: 10px; font-weight: 600; }
.check-row input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); }
.field-help { margin: 0; color: var(--muted); font-size: 13px; }
.field-error-text, .form-errors { margin: 0; color: var(--negative); font-size: 13px; }
.form-errors ul { margin: 0; padding-left: 18px; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.search-bar { display: flex; gap: 10px; margin-bottom: 18px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: white; }

.balance-hero { display: grid; grid-template-columns: 1.25fr .75fr; margin-bottom: 20px; overflow: hidden; color: white; border-radius: 20px; background: linear-gradient(120deg, #183fb4, #3568ed); box-shadow: 0 20px 50px rgba(29, 72, 190, .2); }
.balance-hero > div { display: flex; flex-direction: column; justify-content: center; padding: 30px; }
.balance-hero > div + div { background: rgba(9, 30, 95, .2); }
.balance-hero span, .balance-hero small { color: rgba(255, 255, 255, .78); }
.balance-hero strong { margin: 8px 0; font-size: 34px; letter-spacing: -.03em; }
.balance-action form { margin-top: 14px; }
.balance-action .status { width: fit-content; margin-top: 14px; background: rgba(255,255,255,.15); color: white; }

.confirmation-box { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; padding: 18px; border: 1px solid #d8def0; border-radius: 12px; background: #f7f9ff; }
.confirmation-box p { margin: 0; font-size: 16px; font-weight: 650; }
.confirmation-box small { color: var(--muted); }
.messages { display: grid; gap: 10px; margin-bottom: 20px; }
.notice { padding: 13px 15px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.notice-success { color: var(--positive); border-color: #bce5cb; background: var(--positive-soft); }
.notice-error { color: var(--negative); border-color: #f3c4bf; background: var(--negative-soft); }
.notice-warning { color: var(--warning); border-color: #efd69b; background: var(--warning-soft); }
.notice-info { color: #2049b4; border-color: #c9d7fb; background: var(--primary-soft); }

.auth-page { min-height: calc(100vh - 76px); display: grid; place-items: center; padding: 48px 20px; background: radial-gradient(circle at 20% 0%, #e9efff 0, transparent 35%), var(--canvas); }
.auth-card, .result-card { width: min(460px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 22px; background: white; box-shadow: var(--shadow); }
.auth-card-wide { width: min(620px, 100%); }
.auth-brand { margin-bottom: 34px; }
.auth-heading { margin-bottom: 24px; }
.auth-heading p:last-child, .auth-note { color: var(--muted); }
.auth-links { display: flex; justify-content: space-between; gap: 12px; margin-top: 22px; }
.auth-note { margin: 20px 0 0; text-align: center; }
.result-card { margin-inline: auto; text-align: center; }
.result-icon { display: grid; width: 50px; height: 50px; place-items: center; margin: 0 auto 18px; color: white; background: var(--positive); border-radius: 50%; font-size: 24px; font-weight: 800; }

.footer { color: var(--muted); border-top: 1px solid var(--line); background: white; font-size: 13px; }
.footer-inner { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }

@media (max-width: 980px) {
  .metric-grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split-grid, .split-grid-wide { grid-template-columns: 1fr; }
  .balance-hero { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .shell { width: min(100% - 26px, 1180px); }
  .page { padding-block: 28px 50px; }
  .topbar-inner { min-height: 64px; gap: 12px; }
  .nav-toggle { display: inline-flex; }
  .main-nav { position: absolute; top: 64px; right: 13px; left: 13px; display: none; flex-direction: column; align-items: stretch; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: white; box-shadow: var(--shadow); }
  .main-nav.is-open { display: flex; }
  .logout-form { margin-left: 0; }
  .logout-form .button { padding-inline: 8px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 16px; }
  .metric-grid-2, .metric-grid-3, .metric-grid-5 { grid-template-columns: 1fr 1fr; }
  .panel { padding: 18px; }
  .definition-list > div { grid-template-columns: 1fr; gap: 4px; }
  .footer-inner { align-items: flex-start; flex-direction: column; padding-block: 18px; }
}

@media (max-width: 520px) {
  .brand > span:last-child { display: none; }
  .metric-grid-2, .metric-grid-3, .metric-grid-5 { grid-template-columns: 1fr; }
  .metric-card { min-height: 125px; }
  .auth-card, .result-card { padding: 25px 20px; border-radius: 17px; }
  .auth-links, .form-actions, .search-bar { align-items: stretch; flex-direction: column; }
  .search-bar .button { width: 100%; }
  .balance-hero > div { padding: 24px 20px; }
  .balance-hero strong { font-size: 28px; }
}

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