/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root, [data-theme="light"] {
  --color-bg:             #f7f6f2;
  --color-surface:        #ffffff;
  --color-surface-2:      #f9f8f6;
  --color-surface-offset: #f1eeea;
  --color-border:         #e2deda;
  --color-divider:        #ece9e5;
  --color-text:           #1a1917;
  --color-text-muted:     #6b6966;
  --color-text-faint:     #b0ada8;
  --color-primary:        #01696f;
  --color-primary-hover:  #0c4e54;
  --color-primary-bg:     #e6f2f2;
  --color-debit:          #166534;
  --color-debit-bg:       #dcfce7;
  --color-credit:         #9a3412;
  --color-credit-bg:      #fef3c7;
  --color-gold:           #b45309;
  --color-gold-bg:        #fef3c7;
  --color-blue:           #1d4ed8;
  --color-blue-bg:        #eff6ff;
  --color-purple:         #6d28d9;
  --color-purple-bg:      #f5f3ff;
  --color-success:        #166534;
  --color-success-bg:     #dcfce7;
  --color-danger:         #991b1b;
  --color-danger-bg:      #fee2e2;
  --color-warning:        #92400e;
  --color-warning-bg:     #fffbeb;
  --sidebar-width:        240px;
  --topbar-h:             56px;
  --radius-sm:            4px;
  --radius-md:            8px;
  --radius-lg:            12px;
  --shadow-sm:            0 1px 3px rgba(0,0,0,.07);
  --shadow-md:            0 4px 12px rgba(0,0,0,.09);
  --font-body:            'Inter', system-ui, sans-serif;
  --font-mono:            'JetBrains Mono', 'Fira Code', monospace;
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --transition: 150ms ease;
}

[data-theme="dark"] {
  --color-bg:             #111110;
  --color-surface:        #1c1b19;
  --color-surface-2:      #222120;
  --color-surface-offset: #2a2926;
  --color-border:         #333230;
  --color-divider:        #2c2b29;
  --color-text:           #e8e6e3;
  --color-text-muted:     #8a8784;
  --color-text-faint:     #504e4b;
  --color-primary:        #4f98a3;
  --color-primary-hover:  #6ab4bf;
  --color-primary-bg:     #1a2e30;
  --color-debit:          #4ade80;
  --color-debit-bg:       #052e16;
  --color-credit:         #fb923c;
  --color-credit-bg:      #2c1503;
  --color-gold:           #fbbf24;
  --color-gold-bg:        #1c1500;
  --color-blue:           #60a5fa;
  --color-blue-bg:        #0f1f3d;
  --color-purple:         #a78bfa;
  --color-purple-bg:      #1e1040;
  --color-success:        #4ade80;
  --color-success-bg:     #052e16;
  --color-danger:         #f87171;
  --color-danger-bg:      #2c0a0a;
  --shadow-sm:            0 1px 3px rgba(0,0,0,.3);
  --shadow-md:            0 4px 12px rgba(0,0,0,.4);
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }
body { font-family: var(--font-body); font-size: var(--text-sm); color: var(--color-text); background: var(--color-bg); min-height: 100dvh; }
img, svg { display: block; max-width: 100%; }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
table { border-collapse: collapse; width: 100%; }
a { color: inherit; text-decoration: none; }
input, select, textarea { font: inherit; color: inherit; }

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

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100dvh;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-width))); }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--color-divider);
}
.logo-text { display: flex; flex-direction: column; }
.logo-title { font-weight: 700; font-size: var(--text-base); color: var(--color-text); line-height: 1.2; }
.logo-sub   { font-size: var(--text-xs); color: var(--color-text-muted); }

.sidebar-nav { flex: 1; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 450;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.nav-item:hover { background: var(--color-surface-offset); color: var(--color-text); }
.nav-item.active { background: var(--color-primary-bg); color: var(--color-primary); font-weight: 600; }
.nav-divider { height: 1px; background: var(--color-divider); margin: 6px 4px; }

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--color-divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-version { font-size: 10px; color: var(--color-text-faint); }
.theme-btn {
  padding: 6px; border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
}
.theme-btn:hover { background: var(--color-surface-offset); color: var(--color-text); }

/* ── Main Content ────────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  transition: margin-left var(--transition);
}
.sidebar.collapsed ~ .main-content { margin-left: 0; }

/* ── Topbar ──────────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-weight: 600; font-size: var(--text-base); flex: 1; }
.topbar-actions { display: flex; gap: 8px; }
.sidebar-toggle {
  padding: 6px; border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: background var(--transition);
}
.sidebar-toggle:hover { background: var(--color-surface-offset); }

/* ── Page Body ───────────────────────────────────────────────────────────────── */
.page-body { padding: 20px; flex: 1; }

/* ── Alerts ──────────────────────────────────────────────────────────────────── */
.alert {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  font-size: var(--text-sm);
}
.alert-success  { background: var(--color-success-bg);  color: var(--color-success); }
.alert-danger   { background: var(--color-danger-bg);   color: var(--color-danger); }
.alert-warning  { background: var(--color-warning-bg);  color: var(--color-warning); }
.alert-close { font-size: 1.1rem; line-height: 1; opacity: .7; }
.alert-close:hover { opacity: 1; }

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-divider);
}
.card-header h2 { font-size: var(--text-base); font-weight: 600; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }

/* ── Stats Grid ──────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}
.stat-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon.green  { background: var(--color-debit-bg);  color: var(--color-debit); }
.stat-icon.blue   { background: var(--color-blue-bg);   color: var(--color-blue); }
.stat-icon.gold   { background: var(--color-gold-bg);   color: var(--color-gold); }
.stat-icon.purple { background: var(--color-purple-bg); color: var(--color-purple); }
.stat-body { display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-size: var(--text-lg); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-label { font-size: var(--text-xs); color: var(--color-text-muted); }

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { font-size: var(--text-sm); }
thead tr { background: var(--color-surface-2); }
th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--color-divider);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-surface-2); }
tfoot td {
  background: var(--color-surface-offset);
  border-top: 2px solid var(--color-border);
  border-bottom: none;
  font-size: var(--text-sm);
}
.text-right { text-align: right; }
.table-footer {
  padding: 8px 14px;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  border-top: 1px solid var(--color-divider);
  background: var(--color-surface-2);
}
.empty-cell {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-muted);
}

/* ── Typography helpers ──────────────────────────────────────────────────────── */
.mono       { font-family: var(--font-mono); font-size: 0.82em; }
.small      { font-size: var(--text-xs); color: var(--color-text-muted); }
.text-muted { color: var(--color-text-muted); }
.debit      { color: var(--color-debit); }
.credit     { color: var(--color-credit); }
.link       { color: var(--color-primary); text-decoration: underline; text-underline-offset: 2px; }
.link:hover { color: var(--color-primary-hover); }

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
}
.badge-asset       { background: var(--color-blue-bg);   color: var(--color-blue); }
.badge-liability   { background: var(--color-credit-bg); color: var(--color-credit); }
.badge-income      { background: var(--color-debit-bg);  color: var(--color-debit); }
.badge-expenditure { background: var(--color-gold-bg);   color: var(--color-gold); }
.badge-owners_equity { background: var(--color-purple-bg); color: var(--color-purple); }
.badge-success     { background: var(--color-success-bg); color: var(--color-success); }
.badge-danger      { background: var(--color-danger-bg);  color: var(--color-danger); }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: 500;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.btn-primary  { background: var(--color-primary); color: #fff; }
.btn-primary:hover  { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-surface-offset); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: var(--color-divider); }
.btn-ghost { color: var(--color-text-muted); border: 1px solid transparent; }
.btn-ghost:hover { background: var(--color-surface-offset); color: var(--color-text); }
.btn-icon {
  display: inline-flex; align-items: center; padding: 5px; border-radius: var(--radius-sm);
  color: var(--color-text-faint); transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--color-surface-offset); color: var(--color-primary); }
.actions-cell { display: flex; gap: 4px; }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-card { padding: 24px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px 20px;
  margin-bottom: 20px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: var(--text-sm); font-weight: 500; color: var(--color-text-muted); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

.input {
  width: 100%;
  padding: 8px 10px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-bg); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6966' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.file-input { padding: 6px 10px; }

/* ── Filter Bar ──────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-divider);
}
.filter-bar .input { width: auto; flex: 1; min-width: 160px; max-width: 260px; }
.filter-label { font-size: var(--text-sm); color: var(--color-text-muted); white-space: nowrap; }

/* ── Import Info ─────────────────────────────────────────────────────────────── */
.import-info {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 20px;
}
.import-info h3 { font-size: var(--text-sm); font-weight: 600; margin-bottom: 8px; }
.import-info p, .import-info li { font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.6; }
.import-info ul { padding-left: 16px; margin-bottom: 8px; }
.import-info code { font-family: var(--font-mono); font-size: .8em; background: var(--color-surface-offset); padding: 1px 5px; border-radius: 3px; }
.import-info .note { color: var(--color-warning); font-size: var(--text-xs); margin-top: 8px; }

/* ── Ledger Header ────────────────────────────────────────────────────────────── */
.ledger-meta {
  display: flex; flex-wrap: wrap; gap: 20px 32px;
  padding: 14px 18px;
}
.meta-label { font-size: var(--text-xs); color: var(--color-text-faint); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }
.balance-large { font-size: var(--text-lg); font-weight: 700; }

/* ── Trial Balance ────────────────────────────────────────────────────────────── */
.tb-section { margin-bottom: 0; }
.tb-component {
  padding: 10px 14px;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-primary);
  background: var(--color-primary-bg);
  border-bottom: 1px solid var(--color-border);
}
.tb-grand-total {
  padding: 14px 18px;
  border-top: 2px solid var(--color-border);
  display: flex; flex-direction: column; gap: 8px;
}
.tb-grand-row {
  display: flex; gap: 40px;
  font-weight: 700; font-size: var(--text-base);
}
.tb-grand-row span:first-child { flex: 1; }
.tb-balanced {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--color-success-bg);
  color: var(--color-success);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: 600;
}
.tb-unbalanced {
  padding: 6px 12px;
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: 600;
}

/* ── Empty State ──────────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 48px 20px; gap: 12px;
  color: var(--color-text-faint); text-align: center;
}
.empty-state svg { color: var(--color-text-faint); }
.empty-state p { font-size: var(--text-sm); color: var(--color-text-muted); max-width: 36ch; }

/* ── Responsive ───────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .filter-bar .input { max-width: 100%; }
  .page-body { padding: 14px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid  { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .sidebar-toggle, .filter-bar, .btn, .actions-cell { display: none !important; }
  .main-content { margin-left: 0; }
  .card { border: none; box-shadow: none; }
  body { background: white; color: black; }
}
