:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #d9e0e8;
  --text: #172033;
  --muted: #667085;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #15803d;
  --danger: #dc2626;
  --warning: #b45309;
  --shadow: 0 12px 28px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

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

a { color: inherit; }
button, input, select, textarea { font: inherit; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.8rem; line-height: 1.2; }
h2 { font-size: 1.06rem; line-height: 1.3; }

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}

.auth-form { margin-top: 18px; }

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions, .btn-group, .row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #344054;
  background: white;
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { cursor: not-allowed; opacity: .65; transform: none; }
.btn-primary { color: white; background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-secondary, .btn-ghost { border-color: var(--border); background: var(--surface); }
.btn-ghost { min-height: 34px; padding: 0 12px; color: var(--primary); }
.btn-danger { color: white; background: var(--danger); border-color: var(--danger); }
.btn-small { min-height: 32px; padding: 0 10px; border-radius: 6px; font-size: .88rem; }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.35fr) repeat(3, minmax(150px, .55fr));
  gap: 16px;
  margin-bottom: 16px;
}

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

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

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

.panel { padding: 18px; }

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

.panel-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: .92rem;
}

.metric-card {
  min-height: 146px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric-card.compact { min-height: 112px; }
.metric-card span, .metric-card small, .muted { color: var(--muted); }
.metric-card strong { display: block; margin: 12px 0 4px; font-size: 1.65rem; line-height: 1.15; }
.upload-panel { min-height: 146px; }

.upload-form, .text-entry-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: stretch;
}

.entry-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.tab-button {
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}

.tab-button.is-active {
  color: var(--primary);
  background: white;
  box-shadow: 0 1px 4px rgba(15, 23, 42, .08);
}

.upload-form input[type="file"] {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-picker {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px dashed #9aa8ba;
  border-radius: 8px;
  background: var(--surface-soft);
  cursor: pointer;
}

.file-picker strong, .file-picker small { display: block; }
.file-picker small { margin-top: 2px; color: var(--muted); }

.file-icon {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: white;
  background: var(--primary);
  font-weight: 800;
}

.status-text {
  min-height: 24px;
  margin-top: 12px;
  color: var(--muted);
  font-size: .92rem;
}

.status-text.is-success { color: var(--success); }
.status-text.is-error { color: var(--danger); }
.status-text.is-loading { color: var(--warning); }

.text-entry-form textarea {
  min-height: 96px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  resize: vertical;
  color: var(--text);
  background: var(--surface-soft);
}

.chart-box { position: relative; height: 310px; }
.chart-panel:not(.wide) .chart-box { height: 280px; }

.compact-select {
  min-height: 36px;
  min-width: 120px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  background: white;
}

.breakdown-list {
  display: grid;
  gap: 12px;
}

.breakdown-row {
  display: grid;
  gap: 8px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.breakdown-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.breakdown-meta strong {
  overflow-wrap: anywhere;
}

.breakdown-meta span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: .88rem;
}

.breakdown-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.breakdown-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.recent-list { display: grid; gap: 10px; }

.recent-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  background: var(--surface-soft);
}

.recent-item strong, .recent-item span, .recent-amount strong, .recent-amount span { display: block; }
.recent-item span, .recent-amount span { margin-top: 3px; color: var(--muted); font-size: .88rem; }
.recent-amount { text-align: right; }

.records-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.records-tools { align-items: center; }

.search-box {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px 120px 120px;
  align-items: center;
  gap: 10px;
}

.search-box input, .search-box select, .form-group input, .form-group textarea, .form-group select {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
  color: var(--text);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
  background: white;
}

th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef2f7;
  color: #344054;
  font-size: .88rem;
  font-weight: 800;
}

tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: 0; }

.thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.items-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 360px;
}

.item-chip {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  max-width: 180px;
  padding: 5px 8px;
  border-radius: 7px;
  background: #eef6ff;
  color: #1e3a8a;
  overflow-wrap: anywhere;
}

.item-chip em {
  color: #52637a;
  font-style: normal;
  font-size: .78rem;
}

.status-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: #344054;
  background: #eef2f7;
  font-size: .78rem;
  font-style: normal;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge.success { color: #166534; background: #dcfce7; }
.status-badge.failed { color: #991b1b; background: #fee2e2; }

.error-note, .raw-text {
  width: 100%;
  padding: 8px 10px;
  border-radius: 7px;
  overflow-wrap: anywhere;
}

.error-note { color: #991b1b; background: #fef2f2; }
.raw-text { color: #344054; background: #f8fafc; }

.empty-state {
  padding: 24px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.hidden { display: none; }

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  padding: 24px;
  background: rgba(15, 23, 42, .52);
}

.modal.is-open { display: block; }

.modal-content {
  width: min(680px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  margin: 32px auto;
  padding: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(15, 23, 42, .28);
}

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

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: #344054;
  font-weight: 700;
}

.form-group input, .form-group textarea, .form-group select { width: 100%; }
.form-group textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; }
.btn-group { justify-content: flex-end; margin-top: 8px; }

.token-output {
  margin: 12px 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .dashboard-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .upload-panel { grid-column: 1 / -1; }
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 24px, 1180px);
    padding-top: 18px;
  }

  .topbar, .panel-heading, .records-tools, .recent-item {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions, .search-box, .upload-form, .records-summary, .content-grid, .dashboard-grid, .form-grid {
    grid-template-columns: 1fr;
  }

  .search-box, .top-actions {
    display: grid;
    width: 100%;
  }

  .search-box input, .search-box select, .btn, .upload-form .btn, .text-entry-form .btn {
    width: 100%;
  }

  .compact-select {
    width: 100%;
  }

  .entry-tabs, .text-entry-form { width: 100%; }
  .entry-tabs, .text-entry-form, .upload-form { grid-template-columns: 1fr; }
  .metric-card { min-height: 116px; }
  .chart-box, .chart-panel:not(.wide) .chart-box { height: 260px; }
  .recent-amount { text-align: left; }

  .table-wrap {
    border: 0;
    overflow: visible;
  }

  table, thead, tbody, th, td, tr {
    display: block;
  }

  table {
    min-width: 0;
    background: transparent;
  }

  thead { display: none; }

  tbody {
    display: grid;
    gap: 12px;
  }

  tbody tr {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 10px;
    padding: 10px 12px;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

  .items-cell { max-width: none; }
  .breakdown-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .breakdown-meta span {
    flex: 1 1 auto;
  }

  .row-actions { align-items: stretch; }
  .modal { padding: 12px; }
  .modal-content { margin: 0 auto; max-height: calc(100vh - 24px); }
}
