:root {
  --ink: #003671;
  --muted: #686D68;
  --paper: #EFF8FE;
  --card: #FFFFFF;
  --line: #D5E3EC;
  --navy: #003671;
  --navy-2: #00285a;
  --teal: #0097D9;
  --teal-d: #0077b0;
  --gold: #65B32E;
  --gold-d: #4f8f22;
  --ok: #3d8c1f;
  --ok-bg: #E8F6DC;
  --warn: #8A6410;
  --warn-bg: #F8F0D8;
  --bad: #9C2F24;
  --bad-bg: #F8E6E3;
  --shadow: 0 1px 2px rgba(0, 54, 113, .06), 0 8px 24px rgba(0, 54, 113, .06);
  --radius: 10px;
  --side: 268px;
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: clip; }
body {
  font-family: Prompt, "Segoe UI", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  font-size: 15px;
  line-height: 1.45;
}
body.nav-open { overflow: hidden; }
img, svg, video { max-width: 100%; height: auto; }
button, a, input, select, textarea { touch-action: manipulation; }

a { color: var(--teal-d); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: flex; min-height: 100dvh; }
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 54, 113, .46);
  z-index: 70;
  backdrop-filter: blur(2px);
}
.menu-toggle {
  display: none;
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--navy);
  border-radius: 8px; cursor: pointer; flex-direction: column; justify-content: center; align-items: center; gap: 5px; flex-shrink: 0;
}
.menu-toggle span { display: block; width: 18px; height: 2px; background: var(--navy); border-radius: 1px; transition: transform .2s ease, opacity .2s ease; }
body.nav-open .menu-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.nav-open .menu-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .menu-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.sidebar-close {
  display: none;
  position: absolute; top: 14px; right: 12px;
  width: 40px; height: 40px; border: 0; background: rgba(255,255,255,.08);
  color: #fff; border-radius: 8px; font-size: 1.4rem; line-height: 1; cursor: pointer;
}

.gov-bar {
  height: 4px;
  background: linear-gradient(90deg, #003671 0 34%, #0097D9 34% 67%, #65B32E 67%);
  flex-shrink: 0;
}

.sidebar {
  width: var(--side);
  background: #003671;
  color: #E8EEF4;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  flex-shrink: 0;
  border-right: 1px solid rgba(0,151,217,.2);
}
.brand { padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.08); position: relative; }
.brand-mark { display: flex; align-items: center; gap: 12px; }
.seal {
  width: 44px; height: 44px; flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.25));
}
.brand h1 {
  font-family: Prompt, sans-serif;
  font-size: 1.45rem;
  margin: 0;
  letter-spacing: .08em;
  font-weight: 700;
  line-height: 1;
}
.brand small { display: block; color: #A8B6C6; font-size: .68rem; margin-top: 4px; letter-spacing: .04em; text-transform: uppercase; }
.brand-rep { margin: 10px 0 0; font-size: .68rem; color: #65B32E; letter-spacing: .08em; text-transform: uppercase; }

.nav { padding: 10px 12px 20px; overflow: auto; flex: 1; }
.nav-label {
  font-size: .65rem; letter-spacing: .14em; text-transform: uppercase;
  color: #8A9BB0; padding: 14px 10px 6px; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  color: #D5DEE8; padding: 8px 10px; border-radius: 6px;
  text-decoration: none; font-size: .9rem; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active {
  background: rgba(0, 151, 217, .28);
  color: #fff;
  box-shadow: inset 3px 0 0 #65B32E;
}
.nav-ico { width: 16px; height: 16px; flex-shrink: 0; opacity: .9; }
.nav .soon {
  margin-left: auto; font-size: .62rem; letter-spacing: .04em;
  background: rgba(101,179,46,.18); color: #b6e08a;
  padding: 2px 7px; border-radius: 3px; text-transform: uppercase; font-weight: 600;
}

.btn, .nav a, .card, .stat { transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.stat:hover, .card:hover { transform: translateY(-1px); }

.side-foot {
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .72rem; color: #8A9BB0; line-height: 1.5;
}
.side-foot a { color: #9ad0ef; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  background: #fff;
  position: sticky; top: 0; z-index: 5;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.topbar-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.topbar h2 { margin: 0; font-size: 1.2rem; font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .crumb { font-size: .78rem; color: var(--muted); }
.who { font-size: .85rem; color: var(--muted); display: flex; gap: 12px; align-items: center; flex-shrink: 0; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 4px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  min-width: 0;
}
.user-chip strong { display: block; color: var(--ink); font-size: .82rem; line-height: 1.2; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip span { display: block; font-size: .7rem; }
.avatar-sm {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--navy); color: #fff;
  display: grid; place-items: center;
  font-size: .72rem; font-weight: 700; letter-spacing: .04em;
}
.content { padding: 24px 28px 56px; flex: 1; }
.page-lead { margin: 0 0 18px; color: var(--muted); font-size: .92rem; }

.section-title {
  display: flex; align-items: center; gap: 10px;
  margin: 8px 0 12px;
  font-size: .72rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--navy); font-weight: 700;
}
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.flash { padding: 11px 14px; border-radius: 6px; margin-bottom: 16px; border: 1px solid transparent; font-size: .9rem; }
.flash-success { background: var(--ok-bg); color: var(--ok); border-color: #c5e4d2; }
.flash-error { background: var(--bad-bg); color: var(--bad); border-color: #ecc4be; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
  border-left: 3px solid var(--teal);
}
.stat.danger { border-left-color: var(--bad); }
.stat.gold { border-left-color: var(--gold); }
.stat span { display: block; color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; }
.stat strong { display: block; font-size: 1.4rem; margin-top: 8px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat em { font-style: normal; font-size: .8rem; color: var(--teal); display: block; margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card h3 {
  margin: 0 0 14px; font-size: .78rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--navy); font-weight: 700;
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; max-width: 100%; }
.card:has(> table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  color: var(--muted); font-weight: 700; font-size: .7rem;
  text-transform: uppercase; letter-spacing: .06em;
  background: #F7F8FB;
}
tbody tr:hover td { background: #F5F8FA; }
.code { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--navy); letter-spacing: .02em; }

.badge {
  display: inline-block; padding: 3px 8px; border-radius: 3px;
  font-size: .72rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-muted { background: #EEF1F5; color: #556070; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--navy); color: #fff; border: 0;
  padding: 9px 16px; border-radius: 999px; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; letter-spacing: .01em;
}
.btn:hover { background: var(--navy-2); text-decoration: none; color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--paper); color: var(--ink); }
.btn-gold { background: var(--gold-d); }
.btn-gold:hover { background: #7d642c; }
.btn-bad { background: var(--bad); }
.btn-sm { padding: 6px 11px; font-size: .8rem; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: end; margin-bottom: 16px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.filters > div { min-width: 0; flex: 1 1 160px; }

label { display: block; font-size: .78rem; font-weight: 650; margin-bottom: 5px; color: var(--navy); }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 5px;
  font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,92,99,.12);
}
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 16px; }
.hint { color: var(--muted); font-size: .8rem; }

.tabs { display: flex; gap: 0; margin-bottom: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs a, .tabs span {
  padding: 9px 14px; border-bottom: 2px solid transparent; margin-bottom: -1px;
  color: var(--muted); text-decoration: none; font-size: .88rem; font-weight: 600;
  white-space: nowrap; flex-shrink: 0;
}
.tabs a.active, .tabs a:hover { color: var(--navy); border-bottom-color: var(--gold); text-decoration: none; }

.pager { display: flex; gap: 6px; margin-top: 14px; }
.pager a, .pager span { padding: 6px 10px; border-radius: 4px; border: 1px solid var(--line); font-size: .85rem; background: #fff; }

.auth-body {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  background: var(--navy);
}
.auth-art {
  padding: 48px 52px;
  color: #E8F0F4;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(0,151,217,.35), transparent 55%),
    linear-gradient(165deg, #003671 0%, #002147 100%);
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative;
}
.auth-art::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0; height: 4px;
  background: linear-gradient(90deg, #003671 0 34%, #0097D9 34% 67%, #65B32E 67%);
}
.auth-kicker { font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); margin: 0 0 18px; }
.auth-art h1 {
  font-family: Prompt, sans-serif;
  font-size: 2.4rem; margin: 0; letter-spacing: 0; font-weight: 700;
}
.auth-art .org { color: #C5D0DC; margin: .5rem 0 1.6rem; font-size: 1.02rem; }
.auth-art p { max-width: 420px; line-height: 1.7; color: #C5D0DC; }
.auth-meta { font-size: .82rem; color: #8A9BB0; }
.auth-box { background: #EFF8FE; display: grid; place-items: center; padding: 36px; }
.auth-card {
  width: min(420px, 100%); background: #fff;
  border-radius: 8px; padding: 36px 32px;
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.auth-card h2 { font-family: Prompt, sans-serif; margin: 0 0 4px; font-size: 1.55rem; }
.muted { color: var(--muted); }
.auth-secure { margin-top: 22px; font-size: .75rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }

.profile-head { display: flex; gap: 18px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.avatar {
  width: 84px; height: 84px; border-radius: 8px; object-fit: cover; background: #D6E2E8;
  display: grid; place-items: center; font-weight: 700; color: var(--navy); font-size: 1.4rem;
  border: 1px solid var(--line);
}
.dl { display: grid; grid-template-columns: 180px 1fr; gap: 8px 14px; font-size: .92rem; }
.dl dt { color: var(--muted); font-weight: 600; font-size: .8rem; }

.doc-print {
  max-width: 820px; margin: 24px auto; background: #fff;
  padding: 0; border: 1px solid var(--line);
}
.print-bar {
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: #F3F5F8;
  border-bottom: 1px solid #D8DEE7;
}
.doc-brand { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }
.doc-letterhead {
  display: flex; justify-content: space-between; gap: 20px; align-items: flex-start;
  padding: 28px 36px 18px;
  border-bottom: 3px solid var(--navy);
  background: linear-gradient(#fff, #F7F8FB);
}
.doc-letterhead h1 {
  font-family: Prompt, sans-serif;
  margin: 0; letter-spacing: .16em; font-size: 1.8rem; color: var(--navy);
}
.doc-letterhead .org { margin: 4px 0 0; font-size: .92rem; color: var(--ink); }
.doc-letterhead .meta { margin: 6px 0 0; font-size: .78rem; color: var(--muted); line-height: 1.5; }
.doc-stamp {
  text-align: right; min-width: 200px;
  border: 1px solid var(--navy); padding: 10px 12px;
}
.doc-stamp strong { display: block; letter-spacing: .14em; font-size: .72rem; color: var(--navy); }
.doc-stamp .code { font-size: 1.05rem; margin-top: 4px; }
.doc-body { padding: 24px 36px 32px; }
.doc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; margin-bottom: 20px; font-size: .92rem; }
.doc-grid span { color: var(--muted); display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
.doc-total {
  margin-top: 16px; padding: 12px 14px; background: var(--navy); color: #fff;
  display: flex; justify-content: space-between; font-size: 1.05rem;
}
.doc-foot {
  margin-top: 36px; font-size: .75rem; color: var(--muted);
  border-top: 1px solid var(--line); padding-top: 12px;
  display: flex; justify-content: space-between; gap: 16px;
}
.doc-sign { margin-top: 48px; width: 240px; border-top: 1px solid var(--ink); padding-top: 6px; font-size: .82rem; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .doc-print { margin: 0; border: 0; box-shadow: none; max-width: none; }
}

.empty { text-align: center; color: var(--muted); padding: 28px; }

.chart { width: 100%; height: 180px; display: flex; align-items: flex-end; gap: 12px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-stack { width: 70%; display: flex; flex-direction: column; justify-content: flex-end; height: 150px; gap: 2px; }
.bar { width: 100%; border-radius: 2px 2px 0 0; min-height: 2px; }
.bar.inv { background: #A9C4CE; }
.bar.rec { background: var(--navy); }
.bar-col small { font-size: .68rem; color: var(--muted); }

.legend { display: flex; gap: 16px; font-size: .78rem; color: var(--muted); margin: 8px 0 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: middle; }
.legend .inv { background: #A9C4CE; }
.legend .rec { background: var(--navy); }

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

@media (max-width: 1100px) {
  .stats, .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-2, .form-grid, .form-grid-3, .doc-grid { grid-template-columns: 1fr; }
}

@media (max-width: 960px) {
  .menu-toggle, .sidebar-close { display: flex; }
  .sidebar-close { display: grid; place-items: center; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: min(300px, 86vw);
    height: 100dvh;
    z-index: 80;
    transform: translateX(-105%);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1);
    box-shadow: 12px 0 40px rgba(0, 0, 0, .22);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sidebar-backdrop { display: block; }
  .nav { display: block; overflow: auto; }
  .topbar { padding: 10px 14px; }
  .content { padding: 16px 14px calc(56px + env(safe-area-inset-bottom, 0px)); }
  .auth-body { grid-template-columns: 1fr; min-height: 100dvh; }
  .auth-art { min-height: auto; padding: 28px 22px 32px; }
  .auth-art h1 { font-size: clamp(1.55rem, 6vw, 2.2rem); }
  .auth-box { padding: 20px 16px 40px; }
  .auth-card { padding: 28px 20px; }
  .dl { grid-template-columns: 1fr; }
  .user-chip span { display: none; }
  input, select, textarea { font-size: 16px; }
  .btn { min-height: 44px; }
  .card { padding: 16px; }
  table { min-width: 620px; }
  .doc-letterhead, .doc-foot { flex-direction: column; }
  .doc-stamp { text-align: left; min-width: 0; width: 100%; }
  .doc-letterhead, .doc-body { padding: 20px 16px; }
  .doc-print { margin: 12px; }
}

@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar > .btn { width: 100%; }
  .filters { width: 100%; }
  .who { gap: 8px; }
  .who .btn { padding: 8px 10px; }
  .chart { gap: 6px; height: 150px; }
  .bar-stack { width: 90%; height: 120px; }
}

@media (max-width: 480px) {
  .user-chip { padding: 0; border: 0; background: transparent; }
  .user-chip > div:first-child { display: none; }
  .crumb { display: none; }
  .topbar h2 { font-size: 1.02rem; }
  .stat strong { font-size: 1.2rem; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .auth-art { padding: 20px 22px; }
  .sidebar { height: 100dvh; }
}
