/* Ledger — Design System */
:root {
  --bg: #FAF9F7;
  --surface: #FFFFFF;
  --primary: #1A1814;
  --accent: #CC6B3D;
  --success: #4A7C59;
  --muted: #8A8680;
  --danger: #B94040;
  --border: rgba(26,24,20,0.12);
  --radius: 12px;
  --sidebar-w: 240px;
  --panel-w: 320px;
  --font-ui: 'Inter', system-ui, sans-serif;
  --font-num: 'Lora', Georgia, serif;
  --shadow: 0 1px 4px rgba(26,24,20,0.08);
}

[data-theme="dark"] {
  --bg: #1A1814;
  --surface: #242220;
  --primary: #F0EDE8;
  --accent: #E8845A;
  --success: #6AAF7E;
  --muted: #6A6660;
  --border: rgba(240,237,232,0.12);
  --shadow: 0 1px 4px rgba(0,0,0,0.3);
}

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

html, body {
  height: 100%;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
}

#main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}

.module { display: none; }
.module.active { display: block; }

/* ── Sidebar ── */
.sidebar-logo {
  padding: 20px 16px 12px;
  border-bottom: 0.5px solid var(--border);
}
.sidebar-logo h1 {
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: -0.5px;
}
.sidebar-logo span { color: var(--accent); }

.nav-section { padding: 8px 0; }
.nav-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 16px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  border-radius: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  transition: color 0.15s, background 0.15s;
  border-left: 2px solid transparent;
  user-select: none;
}
.nav-item:hover { color: var(--primary); background: rgba(26,24,20,0.04); }
.nav-item.active { color: var(--accent); border-left-color: var(--accent); background: rgba(204,107,61,0.06); font-weight: 500; }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title { font-size: 13px; font-weight: 500; color: var(--muted); }
.card-value { font-family: var(--font-num); font-size: 28px; font-weight: 400; }
.card-delta { font-size: 12px; margin-top: 2px; }
.card-delta.pos { color: var(--success); }
.card-delta.neg { color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }
.form-input, .form-select {
  width: 100%;
  padding: 8px 10px;
  border: 0.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--primary);
  font-family: var(--font-ui);
  font-size: 13px;
  transition: border-color 0.15s;
  outline: none;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-input.error { border-color: var(--danger); }
.form-error { font-size: 11px; color: var(--danger); margin-top: 3px; }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.88; }
.btn-ghost { background: transparent; color: var(--primary); border: 0.5px solid var(--border); }
.btn-ghost:hover { background: rgba(26,24,20,0.05); }
.btn-danger { background: transparent; color: var(--danger); border: 0.5px solid rgba(185,64,64,0.3); }
.btn-danger:hover { background: rgba(185,64,64,0.08); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; border-radius: 8px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 0.5px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 10px 14px; font-size: 13px; border-bottom: 0.5px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(26,24,20,0.02); }
.amount-pos { color: var(--success); font-weight: 500; }
.amount-neg { color: var(--danger); }
.amount-neutral { color: var(--primary); }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  background: rgba(204,107,61,0.1);
  color: var(--accent);
}

/* ── Progress bar ── */
.progress { height: 6px; background: rgba(26,24,20,0.08); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.4s; }
.progress-fill.success { background: var(--success); }

/* ── Toast notifications ── */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(26,24,20,0.15);
  font-size: 13px;
  min-width: 240px;
  animation: toast-in 0.2s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--accent); }
@keyframes toast-in { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:none; } }

/* ── Module headings ── */
.module-header { margin-bottom: 20px; }
.module-header h2 { font-size: 20px; font-weight: 400; font-family: var(--font-num); }
.module-header p { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ── Tabs ── */
.tabs { display: flex; gap: 2px; margin-bottom: 20px; background: rgba(26,24,20,0.05); padding: 3px; border-radius: 10px; width: fit-content; }
.tab-btn { padding: 7px 16px; border-radius: 8px; border: none; background: transparent; font-family: var(--font-ui); font-size: 13px; color: var(--muted); cursor: pointer; transition: all 0.15s; }
.tab-btn.active { background: var(--surface); color: var(--primary); font-weight: 500; box-shadow: var(--shadow); }

/* ── Drag and drop zone ── */
.drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--muted);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(204,107,61,0.04);
  color: var(--accent);
}

/* ── Slider ── */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: rgba(26,24,20,0.1);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow);
}

/* ── Empty state ── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 13px; }

/* ── Divider ── */
.divider { height: 0.5px; background: var(--border); margin: 16px 0; }

/* ── Chart container ── */
.chart-container { position: relative; }

/* ── Mobile ── */
@media (max-width: 768px) {
  #app { flex-direction: column; }
  #sidebar {
    width: 100%;
    min-width: unset;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 0.5px solid var(--border);
  }
  .sidebar-logo { display: none; }
  .nav-section { display: flex; flex-direction: row; padding: 4px; }
  .nav-label { display: none; }
  .nav-item { flex-direction: column; gap: 3px; padding: 8px 12px; font-size: 10px; border-left: none; border-bottom: 2px solid transparent; white-space: nowrap; }
  .nav-item.active { border-left-color: transparent; border-bottom-color: var(--accent); }
  #main { padding: 16px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; }
  .sidebar-footer { display: none; }
}

/* ── Utility ── */
.text-muted { color: var(--muted); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-mono { font-family: var(--font-num); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.w-full { width: 100%; }
.hidden { display: none !important; }
