:root {
  --bg: #f4f7fb;
  --sidebar-bg: #13233a;
  --sidebar-hover: #213650;
  --sidebar-active: #284970;
  --primary: #2158b1;
  --primary-hover: #18468e;
  --border: #dce3ed;
  --shadow: 0 1px 3px rgb(25 46 72 / 5%);
}

button:focus-visible, a:focus-visible, [tabindex]:focus-visible, summary:focus-visible {
  outline: 3px solid #6799ea;
  outline-offset: 2px;
}

.login-shell { min-height: 100dvh; background: #eaf0f7; }
.login-card { max-width: 410px; border: 1px solid var(--border); box-shadow: 0 12px 36px rgb(25 46 72 / 10%); }
.login-brand h1 { font-size: clamp(17px, 4vw, 21px); }
.login-brand .brand-badge, .sidebar .brand-badge { background: var(--primary); }
.captcha-row > input { min-width: 0; }
.captcha-refresh { padding: 0; background: none; border: 0; border-radius: 7px; flex: 0 0 auto; }
.captcha-refresh img { display: block; }

.sidebar { width: 224px; height: 100dvh; }
.sidebar-header { min-height: 66px; }
.sidebar-header .sidebar-title { color: #eff6ff; }
.nav-list { gap: 2px; padding: 10px; overscroll-behavior: contain; }
.nav-section { margin: 10px 10px 3px; font-size: 11px; color: #abbcd2; font-weight: 600; }
.nav-item { min-height: 38px; padding: 8px 10px; border-left: 3px solid transparent; border-radius: 6px; }
.nav-item.active { border-left-color: #90bdff; }
.sidebar-footer { padding: 12px 15px; }
.topbar { min-height: 66px; gap: 16px; }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h2 { font-size: 19px; line-height: 1.3; }
.topbar-right { flex-wrap: wrap; justify-content: flex-end; }
.mobile-menu-toggle, .mobile-nav-close, .nav-scrim { display: none; }
.content-area { width: 100%; margin-inline: auto; max-width: 1680px; }
.panel, .kpi-card, .two-col > * { min-width: 0; }
.panel-head h3 { line-height: 1.4; }
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.kpi-value { overflow-wrap: anywhere; }
.toolbar > *, .form-row > *, .form-group { min-width: 0; }
.form-row { grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.toolbar input[type="month"], .period-control { font: inherit; color: var(--text); border: 1px solid #cbd5e1; border-radius: 7px; padding: 7px 9px; background: white; }
.modal-backdrop { overscroll-behavior: contain; }
.modal-dialog { max-height: min(90vh, 90dvh); }
.modal-body { overflow: auto; min-height: 0; overscroll-behavior: contain; }
body.overlay-open { overflow: hidden; }
.status-text { color: var(--muted); }

.workbench-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 15px; }
.workbench-actions .btn { min-height: 38px; }
.workbench-actions .task-count { font-variant-numeric: tabular-nums; border-radius: 10px; padding: 0 6px; background: rgb(146 64 14 / 12%); }
.workbench-section-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 9px; }
.workbench-section-head h3 { margin: 0; font-size: 15px; }
.workbench-section-head p { margin: 0; color: var(--muted); font-size: 12px; }
.workbench-details > summary { cursor: pointer; font-weight: 600; }
.workbench-details[open] > summary { margin-bottom: 14px; }
.workbench-details > .panel:last-child { margin-bottom: 0; }
.filter-count { font-size: 12px; color: var(--muted); margin: 0 0 8px; }

.analysis-header { align-items: flex-start; }
.analysis-filters { align-items: end; }
.analysis-filters label, .trend-metric { display: grid; gap: 4px; font-size: 12px; color: #43546a; }
.analysis-note { font-size: 12px; margin: 8px 0; color: var(--muted); }
.analysis-result { overflow-wrap: anywhere; }
.comparison-rate { display: inline-block; margin-inline-start: 5px; font-size: 11px; color: var(--muted); }
.comparison-rate.up { color: #056046; }
.comparison-rate.down { color: #a23434; }
.analysis-trend { margin-top: 18px; }
.analysis-trend .panel-head { margin-bottom: 6px; }
.analysis-trend .table-wrap { margin-top: 8px; }
.trend-scroll { overflow-x: auto; overscroll-behavior-inline: contain; padding-bottom: 4px; }
.trend-plot {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(54px, 1fr);
  gap: 8px; min-height: 166px; align-items: end;
}
.trend-point { min-width: 0; text-align: center; display: grid; grid-template-rows: 126px auto; gap: 4px; }
.trend-bar-area { display: flex; align-items: flex-end; justify-content: center; background: #f1f5fa; border-radius: 5px; }
.trend-bar { width: 60%; min-height: 3px; background: #487bc6; border-radius: 4px 4px 0 0; }
.trend-point.current .trend-bar { background: #156c70; }
.trend-point.missing .trend-bar-area { background: #f8fafc; }
.trend-period { color: #536681; font-size: 11px; white-space: nowrap; }
.analysis-details { margin-top: 12px; }
.analysis-details > summary { cursor: pointer; color: #214b88; font-weight: 600; }
.ledger-guide > summary { cursor: pointer; color: #334d6a; font-weight: 600; }
.ledger-guide p:last-child { margin-bottom: 0; }

@media (max-width: 850px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(296px, 82vw); height: 100dvh; z-index: 40;
    transform: translateX(-100%); visibility: hidden; transition: transform 160ms ease, visibility 160ms;
  }
  .sidebar.is-open { transform: translateX(0); visibility: visible; }
  .sidebar-header { justify-content: flex-start; }
  .mobile-nav-close { display: inline-flex; margin-left: auto; }
  .mobile-menu-toggle { display: inline-flex; }
  .mobile-menu-toggle, .mobile-nav-close { min-width: 42px; min-height: 40px; padding: 5px 9px; }
  .nav-item { min-height: 42px; }
  .nav-scrim.is-open { display: block; position: fixed; inset: 0; z-index: 39; background: rgb(11 24 45 / 46%); }
  .topbar { min-height: 58px; padding: 8px 13px; }
  .content-area { padding: 12px 13px 32px; }
  .topbar .ip-badge { display: none; }
}

@media (max-width: 580px) {
  html, body { font-size: 14px; }
  .topbar { gap: 5px; }
  .topbar-left { gap: 8px; }
  .topbar h2 { font-size: 17px; }
  .topbar .subtitle { display: none; }
  .content-area { padding-inline: 10px; }
  .panel { padding: 12px; margin-bottom: 12px; }
  .panel-head { gap: 8px; margin-bottom: 10px; }
  .panel-head .toolbar { width: 100%; }
  .panel-head .btn, .form-group .btn, .analysis-filters .btn { min-height: 38px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
  .kpi-card { padding: 10px; }
  .kpi-value { font-size: clamp(15px, 4.5vw, 20px); }
  .kpi-label, .kpi-sub { font-size: 11px; }
  .two-col { gap: 0; }
  input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="month"], select, textarea { font-size: 16px; }
  .toolbar input, .toolbar select { max-width: 100%; min-width: 0; }
  .toolbar input[type="text"] { flex: 1 1 100%; width: 100%; }
  .toolbar select { flex: 1 1 110px; min-width: 0 !important; }
  .form-row { gap: 8px; }
  .modal-backdrop { padding: 8px; }
  .modal-dialog { max-height: calc(100dvh - 16px); }
  .modal-header { gap: 10px; padding: 11px 12px; }
  .modal-close { min-width: 42px; min-height: 40px; }
  .modal-body { padding: 12px; }
  .contract-preview { padding: 12px; }
  .toast-box { top: 8px; right: 8px; left: 8px; }
  .toast { max-width: none; }
  .login-shell { padding: 12px; }
  .login-card { padding: 21px 17px; }
  .captcha-row { gap: 7px; }
  .captcha-row img { max-width: 95px; }
  .analysis-filters label { flex: 1 1 108px; }
  .analysis-filters .period-control { width: 100%; }
  .trend-scroll { padding-bottom: 8px; }

  .ledger-table-ready, .ledger-table-ready tbody, .ledger-table-ready tr { display: block; min-width: 0; }
  .ledger-table-ready thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .ledger-table-ready tbody > tr { border: 1px solid var(--border); border-radius: 8px; padding: 4px 9px; margin-bottom: 8px; }
  .ledger-table-ready td[data-label] {
    display: grid; grid-template-columns: minmax(74px, 35%) minmax(0, 1fr); align-items: start; gap: 6px;
    padding: 6px 0; position: static; min-width: 0 !important; max-width: none; width: auto;
    text-align: left; border-bottom: 1px solid #eef2f7; box-shadow: none; white-space: normal;
  }
  .ledger-table-ready td[data-label]::before { content: attr(data-label); font-size: 12px; color: #51637a; }
  .ledger-table-ready td[data-label]:last-child { border-bottom: 0; }
  .ledger-table-ready td .ledger-cell-content { overflow-wrap: anywhere; min-width: 0; }
  .ledger-table-ready td.empty-state { display: block; border: 0; }
  .ledger-table-ready .action-group { max-width: none; min-width: 0; }
  .ledger-table-ready .btn { min-height: 36px; margin-block: 2px; }
  .ledger-table-ready .wx-target-sel { width: 100%; }
}

@media (prefers-reduced-motion: reduce) { .sidebar, .btn { transition: none; } }
