:root {
  --navy: #142d54;
  --navy-2: #0c2345;
  --blue: #2864f0;
  --purple: #7657df;
  --green: #16856d;
  --ink: #17243a;
  --muted: #607089;
  --line: #dce4ef;
  --surface: #ffffff;
  --page: #f4f7fb;
  --soft: #eef3fa;
  --danger: #b42318;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(24, 43, 76, .09);
}

* { box-sizing: border-box; }
html { font-size: 17px; }
body { margin: 0; color: var(--ink); background: var(--page); font-family: Inter, "Segoe UI", Arial, sans-serif; }
strong { font-weight: 650; }
h1, h2, h3 { font-weight: 650; }
a { color: #174da8; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 28px 20px; color: white; background: linear-gradient(170deg, var(--navy), var(--navy-2)); }
.brand { display: flex; align-items: center; gap: 13px; color: white; text-decoration: none; margin-bottom: 38px; }
.brand-mark { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 15px; font-size: 1.15rem; font-weight: 700; background: linear-gradient(145deg, #4e83ff, #1e55d1); box-shadow: 0 10px 24px rgba(0,0,0,.18); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.12rem; }
.brand small { margin-top: 3px; color: #becde3; font-size: .76rem; }
.sidebar nav { display: grid; gap: 8px; }
.nav-link { padding: 14px 16px; color: #dbe6f6; text-decoration: none; font-weight: 600; border-radius: 12px; }
.nav-link:hover, .nav-link:focus { color: white; background: rgba(255,255,255,.11); outline: none; }
.sidebar-user { margin-top: auto; padding: 18px; border: 1px solid rgba(255,255,255,.12); border-radius: 16px; background: rgba(255,255,255,.06); }
.sidebar-user strong, .sidebar-user span, .sidebar-user small { display: block; }
.sidebar-user span { margin-top: 4px; color: #9ec1ff; font-weight: 600; }
.sidebar-user small { margin-top: 3px; color: #c5d2e6; }
.link-button { margin-top: 12px; padding: 0; border: 0; color: white; background: transparent; text-decoration: underline; cursor: pointer; }

.main-area { min-width: 0; }
.topbar { min-height: 86px; display: flex; align-items: center; gap: 16px; padding: 16px clamp(20px, 4vw, 56px); background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); }
.topbar > div { margin-right: auto; }
.topbar strong, .topbar small { display: block; }
.topbar strong { font-size: 1.05rem; }
.topbar small { margin-top: 3px; color: var(--muted); }
.menu-button { display: none; width: 44px; height: 44px; border: 1px solid var(--line); background: white; border-radius: 11px; }
.page-content { padding: clamp(24px, 4vw, 56px); }

.page-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 28px; }
.page-heading h1 { margin: 4px 0 8px; font-size: clamp(2rem, 3vw, 3rem); line-height: 1.05; letter-spacing: -.04em; font-weight: 650; }
.page-heading p { max-width: 800px; margin: 0; color: var(--muted); font-size: 1.05rem; line-height: 1.55; }
.eyebrow { color: var(--blue); font-size: .78rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }

.button { display: inline-flex; min-height: 48px; align-items: center; justify-content: center; padding: 12px 20px; border: 1px solid transparent; border-radius: 12px; font-weight: 650; text-decoration: none; cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: white; background: var(--blue); box-shadow: 0 9px 24px rgba(40, 100, 240, .24); }
.button.secondary { color: var(--navy); border-color: #c9d5e5; background: white; }
.button.compact { min-height: 42px; padding: 9px 15px; font-size: .92rem; }
.button.large { min-height: 56px; padding-inline: 26px; }
.button.wide { width: 100%; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }

.message { margin-bottom: 22px; padding: 15px 18px; border: 1px solid #b9e2d7; border-radius: 12px; color: #075d4a; background: #e9faf4; font-weight: 600; }
.form-error, .error { color: var(--danger); }
.form-error { margin-bottom: 18px; padding: 14px; border-radius: 10px; background: #fff0ee; }
.error { font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 26px; }
.stat-card { position: relative; overflow: hidden; min-height: 172px; padding: 25px; color: white; border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-card::after { content: ""; position: absolute; width: 140px; height: 140px; right: -45px; top: -45px; border-radius: 50%; background: rgba(255,255,255,.12); }
.stat-card.blue { background: linear-gradient(140deg, #2159d8, #3a7bf9); }
.stat-card.purple { background: linear-gradient(140deg, #6544ce, #8a69ee); }
.stat-card.green { background: linear-gradient(140deg, #08705d, #20a384); }
.stat-card span, .stat-card strong, .stat-card small { display: block; position: relative; z-index: 1; }
.stat-card span { font-weight: 600; }
.stat-card strong { margin: 10px 0 6px; font-size: 2.9rem; letter-spacing: -.05em; font-weight: 650; }
.stat-card small { opacity: .82; }

.dashboard-charts { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(310px, .85fr); gap: 18px; margin-bottom: 26px; }
.chart-card { min-height: 340px; padding: 25px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.chart-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 24px; }
.chart-heading h2 { margin: 4px 0 0; color: var(--navy); font-size: 1.4rem; }
.chart-kicker { color: var(--blue); font-size: .72rem; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; }
.chart-scope { padding: 7px 10px; border-radius: 999px; color: #4d5f79; background: #edf3fb; font-size: .74rem; white-space: nowrap; }
.bar-chart { height: 225px; display: grid; grid-template-columns: repeat(6, minmax(52px, 1fr)); gap: clamp(10px, 2vw, 22px); align-items: end; padding: 8px 8px 0; border-bottom: 1px solid #cfdae9; background: repeating-linear-gradient(to top, transparent 0, transparent 54px, #edf2f8 55px); }
.bar-column { height: 100%; display: grid; grid-template-rows: 25px minmax(120px, 1fr) 22px 17px; align-items: end; text-align: center; }
.bar-value { color: #42526a; font-size: .78rem; }
.bar-track { height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bar-fill { width: min(44px, 72%); height: var(--bar-height); min-height: 5px; border-radius: 9px 9px 3px 3px; background: linear-gradient(180deg, #4d7bf1, #275edc); box-shadow: 0 8px 18px rgba(39,94,220,.18); }
.bar-label { color: var(--navy); font-size: .82rem; font-weight: 600; }
.bar-column small { color: #7a879a; font-size: .66rem; }
.composition-card { background: linear-gradient(145deg, #fff, #f8fbff); }
.donut-layout { min-height: 220px; display: grid; grid-template-columns: minmax(150px, .9fr) minmax(165px, 1.1fr); gap: 22px; align-items: center; }
.donut-chart { width: 172px; aspect-ratio: 1; display: grid; place-items: center; justify-self: center; border-radius: 50%; background: conic-gradient(#2864f0 0 var(--official-share), #16856d var(--official-share) var(--note-end-share), #8d69df var(--note-end-share) 100%); box-shadow: 0 16px 35px rgba(44,72,130,.13); }
.donut-chart::before { content: ""; grid-area: 1 / 1; width: 112px; aspect-ratio: 1; border-radius: 50%; background: white; box-shadow: inset 0 0 0 1px #edf1f6; }
.donut-chart > div { z-index: 1; grid-area: 1 / 1; text-align: center; }
.donut-chart strong, .donut-chart span { display: block; }
.donut-chart strong { color: var(--navy); font-size: 1.75rem; font-weight: 650; }
.donut-chart span { margin-top: 2px; color: var(--muted); font-size: .8rem; }
.chart-legend { display: grid; gap: 12px; margin: 0; }
.chart-legend > div { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.chart-legend dt { display: flex; align-items: center; gap: 9px; color: #42526a; font-size: .84rem; }
.chart-legend dd { margin: 0; color: var(--navy); font-size: 1.1rem; font-weight: 650; }
.legend-dot { width: 10px; height: 10px; display: inline-block; border-radius: 50%; }
.legend-dot.official { background: #2864f0; }
.legend-dot.note { background: #16856d; }
.legend-dot.legacy { background: #8d69df; }

.panel, .form-card, .record-summary { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel { overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 23px 25px; border-bottom: 1px solid var(--line); }
.panel-heading h2, .section-heading h2, .record-summary h2 { margin: 0; font-size: 1.38rem; }
.panel-heading p, .section-heading p { margin: 5px 0 0; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { padding: 16px 18px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--navy); background: #f3f6fa; font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; }
th { font-weight: 650; }
tbody tr:hover { background: #f8faff; }
.empty-state { padding: 40px; color: var(--muted); text-align: center; }
.badge { display: inline-flex; padding: 4px 9px; border-radius: 999px; color: #0c5d50; background: #dff7ef; font-size: .8rem; font-weight: 650; }
code { color: #6744b8; font-weight: 600; }
.dispatch-number { font-weight: 600; }

.search-panel { display: grid; grid-template-columns: minmax(220px, .7fr) minmax(300px, 1.3fr) auto; gap: 16px; align-items: end; margin-bottom: 24px; padding: 22px; border: 1px solid #cfdced; border-radius: var(--radius); background: linear-gradient(135deg, #eff5ff, #f8faff); }
.date-range-fields { display: grid; grid-template-columns: repeat(2, minmax(180px, 1fr)); gap: 12px; }
.search-actions { display: flex; gap: 8px; }
.search-error { margin-top: -10px; }

label { display: grid; gap: 8px; color: var(--navy); font-weight: 600; }
label small { color: var(--muted); font-weight: 500; line-height: 1.4; }
.field-group { display: grid; gap: 8px; color: var(--navy); }
.field-group > small { color: var(--muted); font-size: .78rem; line-height: 1.4; }
input:not([type=checkbox]), select, textarea { width: 100%; min-height: 50px; padding: 12px 14px; color: var(--ink); border: 1px solid #bdcbe0; border-radius: 11px; background: white; outline: none; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(40,100,240,.12); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--blue); }

.letter-form { display: grid; gap: 20px; }
.form-card { display: grid; gap: 20px; padding: clamp(20px, 3vw, 32px); }
.form-card.emphasis { border-color: #a9c5ff; background: linear-gradient(135deg, #f7faff, #edf4ff); }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.section-heading > div { display: flex; align-items: center; gap: 12px; }
.step { width: 37px; height: 37px; display: grid; place-items: center; border-radius: 11px; color: white; background: var(--blue); font-weight: 700; }
.format-grid { display: grid; grid-template-columns: minmax(230px, 2fr) repeat(5, minmax(130px, 1fr)); gap: 15px; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.check-row { display: flex; flex-wrap: wrap; gap: 22px; }
.check-row label { display: flex; align-items: center; gap: 8px; }
.form-actions { display: flex; gap: 12px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: white; box-shadow: var(--shadow); }
.list-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -8px; }
.list-toolbar button { min-height: 38px; padding: 7px 12px; border: 1px solid #c6d3e5; border-radius: 9px; color: var(--navy); background: #f5f8fd; font-size: .82rem; font-weight: 600; cursor: pointer; }
.list-toolbar button:hover, .list-toolbar button:focus { border-color: var(--blue); color: #174da8; background: #edf4ff; outline: none; }
.autocomplete { position: relative; }
.autocomplete input { padding-right: 52px; }
.autocomplete-toggle { position: absolute; z-index: 2; top: 4px; right: 4px; width: 42px; height: 42px; padding: 0; border: 0; border-radius: 9px; color: var(--navy); background: #edf3fb; font-size: 1.25rem; cursor: pointer; }
.autocomplete-menu { position: absolute; z-index: 30; top: calc(100% + 7px); right: 0; left: 0; max-height: 330px; overflow-y: auto; padding: 7px; border: 1px solid #bdcbe0; border-radius: 12px; background: white; box-shadow: 0 20px 45px rgba(24,43,76,.18); }
.autocomplete-menu button { width: 100%; padding: 10px 12px; border: 0; border-radius: 8px; color: var(--ink); background: transparent; text-align: left; cursor: pointer; }
.autocomplete-menu button:hover, .autocomplete-menu button.active { color: #174da8; background: #edf4ff; }
.narrow-form { max-width: 760px; }
.account-limit-banner, .security-note { padding: 14px 17px; border: 1px solid #cbd9ec; border-radius: 12px; color: #334b6d; background: #f3f7fd; line-height: 1.5; }
.account-limit-banner { margin: -10px 0 20px; }
.security-note { font-size: .9rem; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .6fr); gap: 22px; align-items: start; }
.branding-preview { justify-items: center; text-align: center; }
.branding-preview img { width: min(220px, 80%); max-height: 190px; object-fit: contain; }
.branding-preview .logo-placeholder { margin-inline: auto; }
.branding-preview > strong { line-height: 1.45; }
.branding-preview > small { color: var(--muted); line-height: 1.5; }
.dispatch-format-preview { padding: 20px; border: 1px solid #cbd9ec; border-radius: 14px; background: #f3f7fd; }
.dispatch-format-preview small, .dispatch-format-preview strong { display: block; }
.dispatch-format-preview strong { margin: 8px 0; overflow-wrap: anywhere; font-size: 1.3rem; }
.dispatch-format-preview p { margin: 0; color: var(--muted); }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 22px; align-items: start; }
.letter-preview { min-height: 1100px; padding: clamp(28px, 5vw, 70px); color: #111; background: white; box-shadow: var(--shadow); }
.official-header { display: grid; grid-template-columns: 130px 1fr 150px; gap: 18px; align-items: center; text-align: center; }
.official-logo { width: 118px; height: 118px; object-fit: contain; }
.logo-placeholder { width: 110px; height: 110px; display: grid; place-items: center; border: 3px solid #111; border-radius: 50%; font: 900 1.35rem Arial; }
.qr-mini span { display: block; margin-bottom: 5px; font: 700 10px Arial; }
.qr-mini img { width: 125px; height: 125px; image-rendering: pixelated; }
.dispatch-line { display: flex; justify-content: space-between; gap: 25px; margin: 10px 0 58px; }
.note-header-space { height: 28px; }
.letter-fields { display: grid; grid-template-columns: 105px 1fr; gap: 22px 14px; }
.letter-fields dt { font-weight: 650; }
.letter-fields dd { margin: 0; }
.letter-body { margin-top: 12px; white-space: normal; }
.body-paragraph { margin: 0 0 .75em; text-indent: 119px; }
.letter-body.justify .body-paragraph { text-align: justify; }
.letter-body.align-right .body-paragraph { text-align: right; }
.body-list { display: grid; gap: .25em; margin: .35em 0 .8em 119px; }
.body-list-item { display: grid; grid-template-columns: 48px 1fr; gap: 8px; align-items: start; }
.body-list-item span { text-align: right; }
.body-list-item p { margin: 0; text-align: start !important; text-indent: 0 !important; }
.signature-space { min-height: 145px; display: flex; align-items: flex-end; justify-content: flex-end; text-align: center; }
.signature-space strong { width: 48%; }
.copy-to { margin-top: 34px; }
.copy-to .cc-list { margin-left: 0; }
.record-summary { position: sticky; top: 105px; padding: 24px; }
.record-summary dl { display: grid; grid-template-columns: 1fr; gap: 4px; }
.record-summary dt { margin-top: 12px; color: var(--muted); font-size: .78rem; font-weight: 650; text-transform: uppercase; }
.record-summary dd { margin: 0; font-weight: 600; }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 12px; }
.export-button { display: grid; gap: 3px; min-height: 78px; align-content: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; color: var(--navy); text-decoration: none; background: #f8faff; }
.export-button:hover { border-color: var(--blue); transform: translateY(-1px); }
.export-button strong { font-size: 1.05rem; }
.export-button small { color: var(--muted); }
.export-button.pdf { border-top: 4px solid #cc3d35; }
.export-button.word { border-top: 4px solid #2b579a; }
.export-button.png { border-top: 4px solid #16856d; }
.export-button.jpeg { border-top: 4px solid #7657df; }
.file-list { padding: 0; list-style: none; }
.file-list li { padding: 11px 0; border-bottom: 1px solid var(--line); }
.file-list small { display: block; margin-top: 3px; color: var(--muted); }

.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.2fr .8fr; background: radial-gradient(circle at 15% 20%, #356cdd, transparent 32%), linear-gradient(135deg, #0c2345 0 55%, #f4f7fb 55%); }
.login-intro { align-self: center; max-width: 760px; padding: 10vw; color: white; }
.login-intro .eyebrow { color: #9ec2ff; }
.login-intro h1 { margin: 12px 0 20px; font-size: clamp(2.7rem, 5vw, 5.6rem); line-height: .98; letter-spacing: -.065em; }
.login-intro p { max-width: 650px; font-size: 1.25rem; line-height: 1.55; color: #cbd8ec; }
.login-card { align-self: center; justify-self: center; width: min(440px, 86%); padding: 38px; border: 1px solid var(--line); border-radius: 24px; background: white; box-shadow: 0 30px 80px rgba(13,35,69,.18); }
.login-card h2 { margin: 0; font-size: 2rem; }
.login-card > p { color: var(--muted); }
.stack-form { display: grid; gap: 18px; margin-top: 28px; }
.login-help-link { display: inline-block; margin-top: 20px; color: #2458bd; font-weight: 600; }

@media (max-width: 1180px) {
  .format-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  .wide-field { grid-column: span 2; }
  .detail-grid { grid-template-columns: 1fr; }
  .record-summary { position: static; }
  .dashboard-charts { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  html { font-size: 16px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; width: 280px; transform: translateX(-105%); transition: transform .2s ease; }
  .menu-open .sidebar { transform: translateX(0); }
  .menu-button { display: grid; place-items: center; }
  .stat-grid { grid-template-columns: 1fr; }
  .dashboard-charts { grid-template-columns: 1fr; }
  .search-panel { grid-template-columns: 1fr; }
  .login-page { grid-template-columns: 1fr; padding: 30px 0; background: linear-gradient(155deg, #0c2345 0 45%, #f4f7fb 45%); }
  .login-intro { padding: 55px 7vw; }
}

@media (max-width: 640px) {
  .topbar { padding: 12px 15px; }
  .topbar > div { display: none; }
  .topbar .button { margin-left: auto; }
  .page-content { padding: 22px 15px 45px; }
  .page-heading, .section-heading { display: grid; }
  .page-heading .button { width: 100%; }
  .page-heading h1 { font-size: 2.15rem; }
  .format-grid, .two-column { grid-template-columns: 1fr; }
  .date-range-fields { grid-template-columns: 1fr; }
  .chart-card { min-height: auto; padding: 20px 16px; }
  .chart-heading { display: grid; }
  .chart-scope { justify-self: start; }
  .bar-chart { gap: 6px; padding-inline: 0; }
  .bar-column { grid-template-rows: 24px minmax(105px, 1fr) 20px 16px; }
  .donut-layout { grid-template-columns: 1fr; }
  .wide-field { grid-column: auto; }
  .form-actions { display: grid; }
  .official-header { grid-template-columns: 75px 1fr 85px; font-size: .72rem; }
  .logo-placeholder { width: 65px; height: 65px; font-size: .8rem; }
  .official-logo { width: 70px; height: 70px; }
  .qr-mini img { width: 78px; height: 78px; }
  .dispatch-line { margin-bottom: 45px; font-size: .72rem; }
  .letter-preview { padding: 22px 16px; min-height: 900px; }
  .letter-fields { grid-template-columns: 70px 1fr; }
  .body-paragraph { text-indent: 84px; }
  .body-list { margin-left: 84px; }
  .copy-to .cc-list { margin-left: 0; }
}
