/* ======================================================
   Home Accounting — Stylesheet
   ====================================================== */

:root {
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --muted:        #64748b;
  --primary:      #2563eb;
  --primary-h:    #1d4ed8;
  --danger:       #ef4444;
  --success:      #16a34a;
  --warning:      #d97706;
  --nav-bg:       #0f172a;
  --nav-link:     #94a3b8;
  --nav-active:   #f1f5f9;
  --radius:       6px;
  --shadow:       0 1px 3px rgba(0,0,0,.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* -------------------------------------------------- Navigation */

.nav {
  background: var(--nav-bg);
  display: flex;
  align-items: center;
  height: 52px;
  padding: 0 1.25rem;
  gap: .25rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  color: #f8fafc;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.3px;
  white-space: nowrap;
  margin-right: .75rem;
  flex-shrink: 0;
}

.nav a {
  color: var(--nav-link);
  text-decoration: none;
  padding: .4rem .75rem;
  border-radius: 5px;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color .12s, background .12s;
}
.nav a:hover  { color: #e2e8f0; background: rgba(255,255,255,.08); }
.nav a.active { color: var(--nav-active); background: rgba(255,255,255,.13); font-weight: 500; }

.nav-spacer { flex: 1; }

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  margin-left: 3px;
  vertical-align: middle;
}

.nav-group {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding-left: .65rem;
  margin-left: .25rem;
  border-left: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.nav-group:first-of-type { border-left: 0; padding-left: 0; margin-left: 0; }
.nav-spacer + .nav-group { border-left: 0; padding-left: 0; margin-left: 0; }

.nav-dropdown { position: relative; flex-shrink: 0; }

.nav-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  border: 0;
  background: transparent;
  color: var(--nav-link);
  padding: .4rem .55rem .4rem .75rem;
  border-radius: 5px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .12s, background .12s;
}
.nav-dropdown-trigger:hover  { color: #e2e8f0; background: rgba(255,255,255,.08); }
.nav-dropdown-trigger.active { color: var(--nav-active); background: rgba(255,255,255,.13); font-weight: 500; }

.nav-dropdown-arrow {
  font-size: 9px;
  line-height: 1;
  opacity: .7;
  transition: transform .15s;
}
.nav-dropdown.is-open .nav-dropdown-arrow { transform: rotate(180deg); }

.nav-dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  background: var(--nav-bg);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius);
  padding: .25rem;
  display: none;
  box-shadow: 0 6px 16px rgba(0,0,0,.35);
  z-index: 101;
}
.nav-dropdown.is-open .nav-dropdown-panel { display: block; }
.nav-dropdown-panel.is-right { right: 0; left: auto; }
.nav-dropdown-panel a {
  display: block;
  padding: .4rem .65rem;
  border-radius: 4px;
}

/* -------------------------------------------------- Layout */

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.page-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.3px;
}

/* -------------------------------------------------- Cards */

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

.card + .card { margin-top: 1rem; }

.card-header {
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  flex-wrap: wrap;
}

.card-header h2 { font-size: .95rem; font-weight: 600; }

.card-body { padding: 1rem; }

/* -------------------------------------------------- Tables */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

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

thead th {
  padding: .55rem .75rem;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid #f3f4f6; transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

td { padding: .5rem .75rem; vertical-align: middle; }

.text-right  { text-align: right !important; }
.text-center { text-align: center !important; }
.text-muted  { color: var(--muted); }
.text-small  { font-size: 12px; }

/* -------------------------------------------------- Amounts */

.amount-debit  { color: var(--danger);  font-variant-numeric: tabular-nums; font-weight: 500; }
.amount-credit { color: var(--success); font-variant-numeric: tabular-nums; font-weight: 500; }
td.amount-debit, td.amount-credit { text-align: right; }

/* -------------------------------------------------- Badges */

.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.badge-gray   { background: #f1f5f9; color: var(--muted); }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef9c3; color: #92400e; }

/* -------------------------------------------------- Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .9rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

.btn-primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-h); border-color: var(--primary-h); }

.btn-danger   { background: var(--danger);  color: #fff; border-color: var(--danger); }
.btn-danger:hover  { background: #dc2626; border-color: #dc2626; }

.btn-success  { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #15803d; border-color: #15803d; }

.btn-warning  { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-warning:hover { background: #b45309; }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }

.btn-sm { padding: .3rem .6rem; font-size: 12px; }
.btn-lg { padding: .65rem 1.35rem; font-size: 15px; }
.btn-full { width: 100%; justify-content: center; }

.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* -------------------------------------------------- Forms */

.form-group { margin-bottom: .875rem; }
.form-group:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: .3rem;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.form-control {
  display: block;
  width: 100%;
  padding: .45rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 72px; }

.form-hint { font-size: 11px; color: var(--muted); margin-top: .25rem; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .75rem;
}

/* -------------------------------------------------- Alerts */

.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: 13px;
  border: 1px solid transparent;
}

.alert + .alert, .alert + .card, .card + .alert { margin-top: .75rem; }

.alert-success { background: #f0fdf4; border-color: #86efac; color: #15803d; }
.alert-danger  { background: #fef2f2; border-color: #fca5a5; color: #b91c1c; }
.alert-warning { background: #fffbeb; border-color: #fcd34d; color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #93c5fd; color: #1e40af; }

/* -------------------------------------------------- Step indicator */

.steps {
  display: flex;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.step {
  flex: 1;
  text-align: center;
  padding: .55rem .5rem;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  color: var(--muted);
  border-right: 1px solid var(--border);
}
.step:last-child { border-right: none; }
.step.active     { background: var(--primary); color: #fff; }
.step.done       { background: #dbeafe; color: var(--primary); }

/* -------------------------------------------------- Stats strip */

.stats-strip {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.stat-card {
  flex: 1;
  min-width: 130px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .875rem 1.1rem;
  box-shadow: var(--shadow);
}

.stat-value { font-size: 1.45rem; font-weight: 700; line-height: 1.2; }
.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-top: .15rem;
}

/* -------------------------------------------------- Pagination */

.pagination {
  display: flex;
  gap: .35rem;
  align-items: center;
  justify-content: center;
  padding-top: 1rem;
  flex-wrap: wrap;
}

.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  transition: background .1s;
}

.pagination a:hover   { background: var(--bg); }
.pagination .current  { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled { color: var(--muted); pointer-events: none; }

/* -------------------------------------------------- Filter bar */

.filter-bar {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: .75rem 1rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.filter-bar .form-group { margin-bottom: 0; flex-shrink: 0; }
.filter-bar label       { font-size: 10px; }
.filter-bar .form-control { font-size: 12px; padding: .35rem .5rem; }

/* -------------------------------------------------- Analytics filters */

.analytics-filters {
  padding: 1rem 1.25rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.analytics-filters .filter-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.analytics-filters .filter-row + .filter-row {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px dashed var(--border);
}

.analytics-filters .form-group { margin-bottom: 0; }
.analytics-filters .form-control { font-size: 13px; padding: .4rem .55rem; }

.analytics-filters .category-pickers {
  align-items: stretch;
}

.analytics-filters .category-pickers .cat-picker-group {
  flex: 1 1 320px;
  min-width: 280px;
}

.analytics-filters .filter-actions-row {
  gap: .5rem;
  align-items: center;
  justify-content: flex-end;
}

.cat-picker-count {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: .35rem;
  vertical-align: middle;
  letter-spacing: 0;
  text-transform: none;
}

/* -------------------------------------------------- Category picker */

.cat-picker { position: relative; }

.cat-picker-trigger {
  display: flex;
  align-items: center;
  gap: .35rem;
  min-height: 36px;
  padding: .25rem .4rem .25rem .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s;
}
.cat-picker-trigger:hover { border-color: #cbd5e1; }
.cat-picker.is-open .cat-picker-trigger,
.cat-picker-trigger:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.cat-picker-content {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  flex: 1 1 auto;
  min-width: 0;
}

.cat-picker-placeholder {
  color: var(--muted);
  font-size: 13px;
  padding: .15rem .15rem;
}

.cat-picker-arrow {
  color: var(--muted);
  font-size: 11px;
  flex-shrink: 0;
  transition: transform .15s;
}
.cat-picker.is-open .cat-picker-arrow { transform: rotate(180deg); }

.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  padding: .15rem .15rem .15rem .5rem;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.4;
  max-width: 100%;
}
.cat-chip > span:first-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.cat-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: #1e40af;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  border-radius: 999px;
  padding: 0;
}
.cat-chip-remove:hover { background: rgba(30,64,175,.15); }

.cat-picker-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(15,23,42,.15);
  padding: .5rem;
  display: flex;
  flex-direction: column;
  max-height: 360px;
}
.cat-picker-panel[hidden] { display: none; }

.cat-picker-search {
  width: 100%;
  padding: .4rem .55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  margin-bottom: .35rem;
}
.cat-picker-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.cat-picker-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 .25rem .35rem;
  font-size: 11px;
}
.cat-picker-summary {
  text-transform: none;
  letter-spacing: 0;
  font-weight: normal;
}
.cat-picker-clear {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  font-family: inherit;
}
.cat-picker-clear:hover { text-decoration: underline; }

.cat-picker-list {
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.cat-option {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .3rem .4rem;
  font-size: 13px;
  font-weight: normal;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
  margin-bottom: 0;
}
.cat-option:hover { background: #f1f5f9; }
.cat-option input { margin: 0; cursor: pointer; }
.cat-option.is-parent { font-weight: 600; }
.cat-option.is-child { padding-left: 1.6rem; }
.cat-option.is-hidden { display: none; }

/* -------------------------------------------------- Login */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  text-align: center;
}

/* -------------------------------------------------- Category tree */

.cat-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  border-bottom: 1px solid #f3f4f6;
}
.cat-row:last-child { border-bottom: none; }
.cat-row.is-child   { padding-left: 2.5rem; background: #fafafa; }
.cat-name { flex: 1; font-size: 13px; }

/* -------------------------------------------------- Rules */

.rule-cond { font-size: 12px; color: var(--muted); }
.rule-pattern {
  font-family: ui-monospace, 'SFMono-Regular', monospace;
  font-size: 12px;
  background: #f1f5f9;
  padding: .1rem .4rem;
  border-radius: 3px;
}

/* -------------------------------------------------- Diff / preview */

.diff-before { color: var(--danger); }
.diff-after  { color: var(--success); }
.diff-arrow  { color: var(--muted); padding: 0 .3rem; }

/* -------------------------------------------------- Misc utilities */

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.flex             { display: flex; }
.flex-wrap        { flex-wrap: wrap; }
.items-center     { align-items: center; }
.justify-between  { justify-content: space-between; }
.gap-1            { gap: .5rem; }
.w-full           { width: 100%; }

.font-mono  { font-family: ui-monospace, 'SFMono-Regular', monospace; }
.font-bold  { font-weight: 700; }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}
.empty-state p { margin-top: .5rem; font-size: 13px; }

/* -------------------------------------------------- Analytics */

.analytics-parent td { background: #f8fafc; font-size: 13px; }

.pct-bar-wrap {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 120px;
}
.pct-bar {
  height: 6px;
  background: var(--danger);
  border-radius: 3px;
  flex-shrink: 0;
}
.pct-label { font-size: 12px; white-space: nowrap; }

.chart-wrap {
  padding: 1rem;
  position: relative;
  height: 640px;
}

/* -------------------------------------------------- Responsive */

@media (max-width: 640px) {
  main        { padding: 1rem .75rem 2rem; }
  .form-row   { grid-template-columns: 1fr; }
  .stats-strip { gap: .5rem; }
  .stat-value  { font-size: 1.2rem; }
  .truncate    { max-width: 180px; }
}
