:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-muted: #edf2f4;
  --surface-strong: #e3eaee;
  --text: #172029;
  --muted: #66727e;
  --border: #dbe3e7;
  --primary: #0b6b76;
  --primary-soft: #dceff2;
  --primary-contrast: #ffffff;
  --success: #24764d;
  --success-soft: #e0f3e8;
  --warning: #a35d13;
  --warning-soft: #fff0d7;
  --danger: #b73540;
  --danger-soft: #ffe4e7;
  --blue: #315f9d;
  --shadow: 0 18px 44px rgba(22, 31, 39, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

select {
  font: inherit;
}

textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

svg {
  display: block;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 22px 16px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark,
.mini-icon,
.upload-icon,
.alert-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  background: var(--primary-soft);
  color: var(--primary);
}

.brand-title,
.brand-subtitle {
  display: block;
}

.brand-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}

.brand-subtitle,
.eyebrow,
.metric-label,
.panel-header p,
.upload-panel p,
.document-item p,
.alert-item p {
  color: var(--muted);
}

.brand-subtitle {
  margin-top: 2px;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 11px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.nav-item:hover,
.nav-item.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}

.sidebar-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.mini-icon {
  width: 36px;
  height: 36px;
  margin-bottom: 12px;
  background: var(--surface);
  color: var(--blue);
}

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-card-title {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}

.progress {
  height: 8px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(11, 107, 118, 0.12);
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.main {
  min-width: 0;
  padding: 24px;
}

.flash-message {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 16px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
}

.flash-message.success {
  border-color: rgba(36, 118, 77, 0.35);
  background: var(--success-soft);
  color: var(--success);
}

.flash-message.error {
  border-color: rgba(183, 53, 64, 0.35);
  background: var(--danger-soft);
  color: var(--danger);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin-top: 4px;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.15;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(260px, 100%);
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.btn-small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-contrast);
}

.btn-secondary:hover,
.segmented button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric-card,
.panel,
.upload-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  min-width: 0;
  padding: 16px;
}

.metric-label {
  font-size: 13px;
  line-height: 1.35;
}

.metric-value {
  margin-top: 8px;
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.metric-note {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.metric-note.is-up {
  color: var(--danger);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-header h2,
.upload-panel h2 {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.25;
}

.panel-header p,
.upload-panel p {
  margin-top: 5px;
  font-size: 13px;
  line-height: 1.45;
}

.upload-panel .upload-status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 11px;
  border-radius: 8px;
  font-weight: 500;
}

.upload-status.success {
  background: var(--success-soft);
  color: var(--success);
}

.upload-status.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.upload-status.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.segmented {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: var(--surface-muted);
}

.segmented button {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--primary);
}

.chart-wrap {
  min-height: 300px;
}

.bar-chart {
  width: 100%;
  height: auto;
}

.grid-lines line {
  stroke: var(--border);
  stroke-width: 1;
}

.axis-labels text,
.bars text {
  fill: var(--muted);
  font-size: 13px;
}

.bar.avg {
  fill: var(--surface-strong);
}

.bar.current {
  fill: var(--primary);
}

.legend {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.current {
  background: var(--primary);
}

.legend-dot.avg {
  background: var(--surface-strong);
  border: 1px solid var(--border);
}

.legend-line {
  width: 18px;
  height: 2px;
  border-radius: 99px;
  background: var(--danger);
}

.bar-list {
  display: grid;
  gap: 13px;
}

.data-bar {
  display: grid;
  grid-template-columns: minmax(96px, 0.5fr) minmax(140px, 1fr) auto;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.data-bar div {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.data-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.data-bar strong {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.alert-list {
  display: grid;
  gap: 2px;
}

.alert-item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--border);
}

.alert-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.alert-icon {
  width: 40px;
  height: 40px;
  background: var(--warning-soft);
  color: var(--warning);
}

.alert-item.high .alert-icon {
  background: var(--danger-soft);
  color: var(--danger);
}

.alert-item h3,
.document-item h3 {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.alert-item p,
.document-item p {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.45;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(360px, 1fr);
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.upload-panel {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  min-width: 0;
  padding: 18px;
}

.upload-panel.is-highlighted {
  border-color: var(--primary);
  background: linear-gradient(0deg, rgba(11, 107, 118, 0.06), rgba(11, 107, 118, 0.06)), var(--surface);
}

.upload-icon {
  width: 54px;
  height: 54px;
  background: var(--surface-muted);
  color: var(--blue);
}

.upload-fields {
  display: grid;
  grid-template-columns: minmax(130px, 180px) minmax(180px, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.upload-fields label,
.document-filters label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.upload-fields input,
.upload-fields select,
.document-filters select,
.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  min-height: 38px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
}

.upload-fields input,
.form-grid input,
.form-grid textarea {
  padding: 7px 10px;
}

.upload-fields select,
.document-filters select,
.form-grid select {
  padding: 0 10px;
}

.form-grid textarea {
  resize: vertical;
}

.selected-file {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  overflow-wrap: anywhere;
}

.selected-file.has-file {
  color: var(--primary);
  font-weight: 600;
}

.document-list {
  display: grid;
}

.document-filters {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(130px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.document-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.document-summary span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.empty-note {
  padding: 12px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.document-item {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.document-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.document-item > svg {
  color: var(--blue);
}

.document-item .document-details {
  margin-top: 2px;
  font-size: 12px;
}

.document-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.document-actions form {
  margin: 0;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
}

.data-table td {
  color: var(--text);
}

.review-panel {
  margin-top: 16px;
}

.review-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
}

.review-form {
  min-width: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.form-grid .form-wide {
  grid-column: 1 / -1;
}

.review-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.ocr-output {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.ocr-output h3 {
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
}

.ocr-output pre {
  max-height: 340px;
  margin: 0;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ocr-output details {
  color: var(--muted);
  font-size: 13px;
}

.ocr-output summary {
  cursor: pointer;
  font-weight: 600;
}

.ocr-output details pre {
  margin-top: 8px;
  max-height: 220px;
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status.success {
  background: var(--success-soft);
  color: var(--success);
}

.status.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.status.neutral {
  background: var(--surface-muted);
  color: var(--muted);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #15181d;
    --surface: #1d2229;
    --surface-muted: #262d36;
    --surface-strong: #313a46;
    --text: #eef3f6;
    --muted: #a8b3be;
    --border: #37414d;
    --primary: #5dc5cf;
    --primary-soft: #173b42;
    --primary-contrast: #081417;
    --success: #77d69d;
    --success-soft: #1c3828;
    --warning: #ebb05e;
    --warning-soft: #453119;
    --danger: #ff8088;
    --danger-soft: #4a2228;
    --blue: #83b0ee;
    --shadow: 0 18px 44px rgba(0, 0, 0, 0.18);
  }
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sidebar-card {
    margin-top: 0;
  }
}

@media (max-width: 920px) {
  .metric-grid,
  .dashboard-grid,
  .lower-grid,
  .review-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .search {
    width: 100%;
  }

  .metric-grid,
  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-header {
    flex-direction: column;
  }

  .segmented {
    align-self: stretch;
  }

  .segmented button {
    flex: 1;
  }

  .upload-panel {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .upload-panel .btn {
    grid-column: 1 / -1;
  }

  .upload-fields {
    grid-template-columns: 1fr;
  }

  .document-filters {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .metric-grid,
  .nav-list {
    grid-template-columns: 1fr;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .metric-value {
    font-size: 24px;
  }

  .document-item {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .document-item .status {
    grid-column: 2;
    justify-self: start;
  }

  .document-actions {
    grid-column: 2;
    justify-content: flex-start;
  }

  .document-filters {
    grid-template-columns: 1fr;
  }

  .data-bar {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .review-actions {
    justify-content: stretch;
  }

  .review-actions .btn {
    width: 100%;
  }
}
