:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --surface-2:     #f8fafc;
  --border:        #e2e8f0;
  --border-focus:  #99f6e4;
  --text:          #0f172a;
  --text-muted:    #64748b;
  --text-xmuted:   #94a3b8;
  --accent:        #0d9488;
  --accent-dark:   #0f766e;
  --accent-light:  #f0fdfa;
  --danger:        #ef4444;
  --warning:       #f59e0b;
  --indigo:        #6366f1;
  --shadow-xs:     0 1px 2px 0 rgb(0 0 0 / .05);
  --shadow-sm:     0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .06);
  --shadow-md:     0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .06);
  --radius:        12px;
  --radius-sm:     7px;
  --sidebar-w:     220px;
  --header-h:      54px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

html { scroll-behavior: smooth; scroll-padding-top: var(--header-h); }
* { box-sizing: border-box; }
body { margin: 0; }
[x-cloak] { display: none !important; }

/* ─── App shell ───────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}

.sidebar-logo {
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgb(255 255 255 / .07);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-logo-mark {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: -0.5px;
}

.sidebar-logo-name {
  color: #f1f5f9;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.2px;
  line-height: 1.25;
}

.sidebar-logo-sub {
  color: #64748b;
  font-size: 11px;
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #94a3b8;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  min-height: unset;
  letter-spacing: 0;
  text-transform: none;
  box-shadow: none;
}

.nav-link:hover:not(:disabled) {
  background: rgb(255 255 255 / .07);
  color: #e2e8f0;
  box-shadow: none;
}

.nav-link:active:not(:disabled) { transform: none; }

.nav-link.active {
  background: rgb(13 148 136 / .18);
  color: #2dd4bf;
  font-weight: 600;
}

.nav-link svg { flex-shrink: 0; }
.nav-label { flex: 1; }

.nav-badge {
  background: var(--warning);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 6px;
  min-width: 18px;
  line-height: 18px;
  text-align: center;
  display: none;
}

.nav-badge.visible { display: block; }

.sidebar-footer {
  padding: 10px 8px 14px;
  border-top: 1px solid rgb(255 255 255 / .07);
  flex-shrink: 0;
}

.classify-btn {
  width: 100%;
  background: var(--accent);
  border: 1.5px solid var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 8px;
  letter-spacing: 0;
  text-transform: none;
}

.classify-btn:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

/* ─── App content ─────────────────────────────────────────── */
.app-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ─── Header ──────────────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-xs);
  min-height: var(--header-h);
  flex-shrink: 0;
}

.header-crumb {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ─── Layout ──────────────────────────────────────────────── */
main {
  padding: 28px;
  display: grid;
  gap: 20px;
}

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-xs);
}

.subsection {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  margin-top: 24px;
}

h2 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.subsection-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 14px;
}

/* ─── Forms & Inputs ──────────────────────────────────────── */
form {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  align-items: end;
}

.logout-form {
  display: block;
}

label {
  display: grid;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

input, select, textarea {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(13 148 136 / .15);
}

textarea {
  min-height: 84px;
  resize: vertical;
}

input[type="checkbox"] {
  min-height: auto;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

input[type="number"] { appearance: textfield; }

/* ─── Buttons ─────────────────────────────────────────────── */
button {
  cursor: pointer;
  min-height: 40px;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--accent);
  background: var(--accent);
  color: #fff;
  transition: background .15s, border-color .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

button:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  box-shadow: var(--shadow-sm);
}

button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: none;
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  color: var(--accent-dark);
  border-color: var(--border);
}

button.secondary:hover:not(:disabled) {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-dark);
}

button.secondary.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-dark);
}

button.compact {
  min-height: 32px;
  padding: 4px 12px;
  font-size: 12px;
}

/* ─── Login ───────────────────────────────────────────────── */
.login-body {
  min-height: 100vh;
  background: var(--bg);
}

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

.login-panel {
  width: min(100%, 380px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.login-brand h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
  letter-spacing: 0;
}

.login-brand p {
  margin: 2px 0 0;
  color: var(--text-muted);
}

.login-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

/* ─── Toolbar ─────────────────────────────────────────────── */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.settings-tabs { justify-content: flex-end; }

/* ─── Filters ─────────────────────────────────────────────── */
.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  align-items: end;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.transaction-filters {
  grid-template-columns: minmax(180px, 1.4fr) minmax(180px, 1.2fr) minmax(120px, .7fr) auto auto auto;
}

/* ─── Metrics ─────────────────────────────────────────────── */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
}

.metric {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  background: var(--surface);
  border-top: 3px solid var(--border);
  box-shadow: var(--shadow-xs);
  transition: box-shadow .15s;
}

.metric:hover { box-shadow: var(--shadow-sm); }
.metric:nth-child(1) { border-top-color: var(--indigo); }
.metric:nth-child(2) { border-top-color: var(--warning); }
.metric:nth-child(3) { border-top-color: var(--accent); }
.metric:nth-child(4) { border-top-color: var(--danger); }

.metric { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.metric strong { display: block; font-size: 26px; font-weight: 700; color: var(--text); margin-top: 8px; letter-spacing: -0.8px; line-height: 1; }

/* ─── Section heading ─────────────────────────────────────── */
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.section-heading h2,
.section-heading .subsection-label { margin: 0; }

/* ─── Dashboard grid ──────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr);
  gap: 20px;
  align-items: start;
  margin-top: 20px;
}

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

.bar-row {
  display: grid;
  grid-template-columns: 190px minmax(160px, 1fr) 110px;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}

.bar-track {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  border-radius: 999px;
  transition: width .5s cubic-bezier(.4,0,.2,1);
}

/* ─── Tables ──────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  color: var(--text-xmuted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  background: var(--surface-2);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  color: var(--text);
}

tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: var(--accent-light); }

/* ─── Status ──────────────────────────────────────────────── */
p.status, #status {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
}

.warning-text { color: var(--warning); }

p#status {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  border: 1px solid var(--border-focus);
  color: var(--accent-dark);
  font-weight: 500;
  transition: opacity .2s;
  max-width: 500px;
}

/* ─── Review & Rules rows ─────────────────────────────────── */
.review-grid { display: grid; gap: 8px; }

.review-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 160px 180px 90px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface-2);
  transition: border-color .15s, box-shadow .15s;
}

.review-row:hover {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-xs);
}

.fx-row {
  grid-template-columns: 1.2fr 180px 180px 1fr 100px;
}

.pending-row {
  grid-template-columns: 1.2fr 1fr 180px 150px 1fr 90px;
}

.rule-form {
  grid-template-columns: 1fr 1fr 1fr 100px 110px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.category-form {
  grid-template-columns: 1fr 1fr 180px 130px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.account-form {
  grid-template-columns: 1fr 1fr 1fr 130px 110px 130px 120px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.family-member-form {
  grid-template-columns: 1fr 180px 130px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.profile-form {
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.profile-defaults {
  display: grid;
  gap: 6px;
  min-width: 130px;
}

.profile-mapping {
  width: 220px;
  min-height: 96px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.rule-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 86px 110px 1fr 120px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface-2);
  transition: border-color .15s, box-shadow .15s;
}

.rule-row:hover {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-xs);
}

/* ─── Column mapping ──────────────────────────────────────── */
.mapping-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin: 14px 0;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.import-preview-panel {
  display: grid;
  gap: 14px;
}

.import-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
}

.import-summary div {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface-2);
  min-width: 0;
}

.import-summary span,
.import-path span {
  display: block;
  color: var(--text-xmuted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.import-summary strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.import-alert {
  display: grid;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.import-alert strong {
  font-size: 13px;
  color: var(--text);
}

.import-alert span {
  color: var(--text-muted);
  font-size: 13px;
}

.import-alert.error {
  background: #fef2f2;
  border-color: #fecaca;
}

.import-alert.error strong { color: #991b1b; }

.import-alert.success {
  background: var(--accent-light);
  border-color: var(--border-focus);
}

.import-alert.success strong { color: var(--accent-dark); }

.import-path {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 10px 12px;
}

.import-path code {
  color: var(--text-muted);
  font-size: 12px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.import-detail-panel {
  border-top: 1px solid var(--border);
  margin-top: 18px;
  padding-top: 18px;
  display: grid;
  gap: 12px;
}

/* ─── Typography helpers ──────────────────────────────────── */
.review-desc { font-weight: 600; font-size: 14px; color: var(--text); }
.muted { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.inline { display: flex; gap: 8px; align-items: center; color: var(--text-muted); font-size: 13px; }
.profile-save-name {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}
.profile-save-name input {
  width: 220px;
  min-height: 32px;
}

/* ─── Upload form ─────────────────────────────────────────── */
#upload-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.upload-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: stretch;
}

.file-zone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-height: 150px;
  overflow: hidden;
  background: var(--surface-2);
  transition: border-color .2s, background .2s;
}

.file-zone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: unset;
  opacity: 0;
  cursor: pointer;
  border: none;
  background: transparent;
  z-index: 2;
}

.file-zone:hover,
.file-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}

.file-zone.has-file {
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-light);
}

.file-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
  pointer-events: none;
  z-index: 1;
}

.file-zone-inner svg { opacity: .35; transition: opacity .2s, color .2s; }
.file-zone:hover .file-zone-inner svg,
.file-zone.drag-over .file-zone-inner svg,
.file-zone.has-file .file-zone-inner svg { opacity: .9; color: var(--accent); }

.file-zone-text { display: flex; flex-direction: column; gap: 4px; }
.file-zone-text strong { font-size: 14px; font-weight: 600; color: var(--text); letter-spacing: 0; text-transform: none; }
.file-zone-text span { font-size: 12px; color: var(--text-muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.file-zone.has-file .file-zone-text strong { color: var(--accent-dark); }

.upload-meta { display: flex; flex-direction: column; gap: 12px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ─── PDF disclosure ──────────────────────────────────────── */
.pdf-options {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.pdf-options summary {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  background: var(--surface-2);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background .15s, color .15s;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.pdf-options summary::before {
  content: "▶";
  font-size: 8px;
  transition: transform .2s;
  color: var(--text-xmuted);
}

.pdf-options[open] summary::before { transform: rotate(90deg); }
.pdf-options summary:hover { background: var(--accent-light); color: var(--accent-dark); }
.pdf-options[open] summary { color: var(--accent-dark); }
.pdf-options summary::-webkit-details-marker { display: none; }

.pdf-fields-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--border);
}

/* ─── Form actions ────────────────────────────────────────── */
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ─── Empty state ─────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 52px 20px;
  color: var(--text-xmuted);
  text-align: center;
}

.empty-state svg { opacity: .25; }
.empty-state p { margin: 0; font-size: 14px; max-width: 320px; line-height: 1.7; color: var(--text-muted); }

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .sidebar-logo { padding: 10px 14px; border-bottom: none; border-right: 1px solid rgb(255 255 255 / .07); }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; padding: 6px 8px; gap: 2px; }
  .nav-label { display: none; }
  .nav-link { padding: 7px 10px; }
  .sidebar-footer { padding: 6px 8px; border-top: none; border-left: 1px solid rgb(255 255 255 / .07); margin-left: auto; }
  .classify-btn { min-height: 32px; padding: 4px 12px; font-size: 12px; }

  .app-header { padding: 0 16px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  form, .filters, .metrics, .review-row, .mapping-grid, .rule-row, .rule-form, .category-form, .account-form, .family-member-form, .profile-form, .dashboard-grid, .bar-row, .import-summary { grid-template-columns: 1fr; }
  .upload-top, .pdf-fields-grid, .field-row { grid-template-columns: 1fr; }
  .file-zone { min-height: 100px; }
  main { padding: 14px; gap: 14px; }
  table { display: block; overflow-x: auto; }
  .metric strong { font-size: 22px; }
}
