/* styles.css — Caromile Finances
   Concept: "Nocturne Ledger" — the accounting-ledger structure kept
   (hairline rules on tables, tabular money figures, tree-line category
   indents) but rebuilt for a dark, modern surface: charcoal-navy
   background, soft-fill surface panels instead of paper, and two
   accent colors carried from the original concept — jade green for
   income/positive, warm amber for highlights and CTAs, coral for
   expense/overdue. One deliberate moment of shine: the header and the
   "Net" stat get a soft accent glow; everything else stays quiet.
   Type: Manrope for all UI text, Lora italic reserved for the
   wordmark only, IBM Plex Mono for every money figure.
*/

@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@1,600&family=Manrope:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  color-scheme: dark;

  --bg: #14171c;
  --surface: #1a1e25;
  --surface-raised: #20252e;
  --border: rgba(237, 237, 230, 0.10);
  --border-strong: rgba(237, 237, 230, 0.20);

  --ink: #edede6;
  --ink-soft: #9aa1ab;
  --ink-faint: #6b7280;

  --green: #38c98f;
  --green-dim: rgba(56, 201, 143, 0.14);
  --gold: #eab04e;
  --gold-dim: rgba(234, 176, 78, 0.14);
  --rust: #ef7a58;
  --rust-dim: rgba(239, 122, 88, 0.14);

  --radius-sm: 6px;
  --radius-md: 10px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Manrope', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3 { font-weight: 700; margin: 0 0 0.4em; letter-spacing: -0.01em; }
h1 { font-size: 1.65rem; }
h2 {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 18px;
}
h2::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gold);
  flex-shrink: 0;
}

.figure, .money, td.income, td.expense, input[type="number"] {
  font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
}

/* ---------- layout shell ---------- */

.shell {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 20px 72px;
}

header.top {
  padding: 30px 0 20px;
  margin-bottom: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px 10px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

header.top::after {
  /* the one deliberate glow in the design */
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--green), var(--gold) 40%, transparent 75%);
  opacity: 0.9;
}

header.top .wordmark {
  font-family: 'Lora', serif;
  font-style: italic;
  font-weight: 600;
  font-size: 1.4rem;
  color: var(--ink);
  letter-spacing: -0.01em;
}

nav.pages {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

nav.pages a {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 500;
  padding: 7px 15px;
  border-radius: 999px;
  transition: color 0.15s ease, background 0.15s ease;
}

nav.pages a:hover { color: var(--ink); }
nav.pages a.current { color: var(--bg); background: var(--ink); font-weight: 600; }

/* ---------- stat row (dashboard totals) ---------- */

.stat-row {
  display: flex;
  gap: 12px;
  margin-bottom: 34px;
}

.stat {
  flex: 1;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.stat .label {
  font-size: 0.76rem;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.stat .value { font-size: 1.5rem; font-weight: 600; }

.stat.income .value { color: var(--green); }
.stat.expense .value { color: var(--rust); }
.stat:last-child {
  border-color: var(--border-strong);
  background: linear-gradient(160deg, var(--surface-raised), var(--surface));
  box-shadow: 0 0 0 1px var(--border-strong), 0 8px 24px -12px rgba(56, 201, 143, 0.25);
}

/* ---------- period / direction switchers ---------- */

.period-switcher {
  display: inline-flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 8px;
}

button[data-period-btn], button[data-direction-btn] {
  background: none;
  border: none;
  color: var(--ink-soft);
  padding: 7px 16px;
  font-family: 'Manrope', sans-serif;
  font-weight: 500;
  font-size: 0.84rem;
  cursor: pointer;
  border-radius: 999px;
  transition: color 0.15s ease, background 0.15s ease;
}

button[data-period-btn].active, button[data-direction-btn].active {
  background: var(--green);
  color: #0d1310;
}

#range-label {
  color: var(--ink-faint);
  font-size: 0.83rem;
  margin-bottom: 28px;
  display: block;
}

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }

th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--ink-faint);
  font-weight: 600;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-strong);
  padding: 8px 10px;
}

td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: rgba(237, 237, 230, 0.03); }

th.num, td.num, th:last-child, td:last-child,
th:nth-last-child(-n+3), td.income, td.expense {
  text-align: right;
}

td.income, .income { color: var(--green); }
td.expense, .expense { color: var(--rust); }

section.panel { margin-top: 40px; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 560px; }

/* ---------- forms ---------- */

form.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px 22px 20px;
  margin-bottom: 32px;
}

.field { margin-bottom: 15px; }

.field label {
  display: block;
  font-size: 0.77rem;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.92rem;
  transition: border-color 0.15s ease;
}

input::placeholder { color: var(--ink-faint); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}

.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }

.segmented {
  display: inline-flex;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 3px;
  width: fit-content;
  margin-bottom: 16px;
}
.segmented label {
  padding: 7px 18px;
  font-size: 0.87rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink-soft);
  border-radius: 999px;
  transition: color 0.15s ease, background 0.15s ease;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; width: 0; }
.segmented label:has(input:checked) { background: var(--ink); color: var(--bg); }

button.primary {
  background: var(--green);
  color: #0d1310;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 22px;
  font-family: 'Manrope', sans-serif;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: filter 0.15s ease;
}

button.primary:hover { filter: brightness(1.1); }

button.text-btn {
  background: none;
  border: none;
  color: var(--green);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 2px 6px;
}

button.text-btn.danger { color: var(--rust); }

table button {
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-left: 4px;
  transition: border-color 0.15s ease, color 0.15s ease;
}
table button:hover { border-color: var(--gold); color: var(--ink); }

#entry-status, #add-category-status, #add-debt-status {
  font-size: 0.85rem;
  color: var(--ink-soft);
  min-height: 1.2em;
  display: block;
  margin-top: 8px;
}

/* ---------- status badges (debts) ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 4px 11px 4px 9px;
  border-radius: 999px;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

tr.status-paid .badge    { color: var(--green); background: var(--green-dim); }
tr.status-pending .badge { color: var(--gold); background: var(--gold-dim); }
tr.status-overdue .badge { color: var(--rust); background: var(--rust-dim); }

/* ---------- category tree (nested ul/li built by categories.js) ---------- */

.tree-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.tree-panel ul { list-style: none; margin: 0; padding-left: 18px; }
.tree-panel > ul { padding-left: 0; }

.tree-panel li { position: relative; padding: 6px 0 6px 16px; }

.tree-panel ul ul li::before {
  content: '';
  position: absolute;
  left: -2px; top: 0; bottom: 50%;
  width: 12px;
  border-left: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
}

.tree-panel li span { font-size: 0.9rem; color: var(--ink); }
.tree-panel .income { color: var(--green); }
.tree-panel .expense { color: var(--rust); }

.tree-panel li button {
  background: none;
  border: none;
  color: var(--rust);
  opacity: 0.5;
  cursor: pointer;
  font-size: 0.8rem;
  margin-left: 8px;
  transition: opacity 0.15s ease;
}
.tree-panel li button:hover { opacity: 1; }

.tree-columns { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 30px; }
.tree-columns > div { flex: 1; min-width: 240px; }

@media (max-width: 560px) {
  .stat-row { flex-direction: column; }
  .field-row { flex-direction: column; gap: 0; }
  .tree-columns { flex-direction: column; }
}
lumn; gap: 0; }
  .tree-columns { flex-direction: column; }
}
;
  border: 3px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-hard);
}

.tree-panel ul {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

.tree-panel ul ul {
  padding-left: 22px;
  margin-top: 4px;
  border-left: 3px solid var(--border);
}

.tree-panel li {
  padding: 9px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tree-panel li span {
  font-size: 0.925rem;
  font-weight: 600;
}

.tree-panel li button {
  margin-left: auto;
  opacity: 0.5;
  transition: opacity 0.12s, color 0.12s;
  background: none;
  border: none;
  color: var(--expense);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

.tree-panel li:hover button {
  opacity: 1;
}

.tree-columns {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 32px;
}

.tree-columns > div {
  flex: 1;
  min-width: 240px;
}

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

@media (max-width: 640px) {
  .shell {
    padding: 0 16px 60px;
  }

  .stat-row {
    grid-template-columns: 1fr;
  }

  .field-row {
    flex-direction: column;
    gap: 0;
  }

  header.top {
    flex-direction: column;
    align-items: flex-start;
  }

  nav.pages {
    width: 100%;
  }

  nav.pages a {
    flex: 1;
    text-align: center;
    padding: 12px 8px;
  }

  .tree-columns {
    flex-direction: column;
  }
}
