:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #232732;
  --border: #2c313d;
  --text: #e6e8ee;
  --muted: #9aa1af;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --accent: #22c55e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 16px;
}
.sidebar-header h1 { font-size: 20px; margin: 0 0 12px; color: var(--accent); }
.month-nav h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 8px; }
#monthSelect {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  margin-bottom: 12px;
}
.month-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; }
.month-item {
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  border: 1px solid transparent;
  font-size: 14px;
}
.month-item:hover { background: var(--panel-2); color: var(--text); }
.month-item.active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.sidebar-footer { display: flex; flex-direction: column; gap: 8px; }

/* Buttons */
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 14px;
  transition: filter 0.15s;
}
.btn:hover { filter: brightness(1.15); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #052e16; font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-danger-ghost { background: transparent; border-color: var(--red); color: var(--red); }
.btn-block { width: 100%; }
.btn-small { padding: 6px 10px; font-size: 13px; }

/* Main */
.main { flex: 1; padding: 22px 28px; max-width: 1080px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.month-title { font-size: 26px; font-weight: 700; }
.month-title:focus { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 6px; }
.month-title:hover { cursor: text; }
.topbar-actions { display: flex; gap: 8px; }

/* Tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 16px;
  cursor: pointer;
  font-size: 15px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Balance banner */
.warn-banner {
  background: rgba(239,68,68,0.12);
  border: 1px solid var(--red);
  color: #fecaca;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-weight: 500;
}
.warn-banner.hidden { display: none; }

.playbook-strip {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.playbook-pill {
  flex: 1;
  min-width: 150px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
}
.playbook-pill .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 4px; }
.playbook-pill .value { font-size: 18px; font-weight: 700; color: var(--accent); }
.playbook-pill .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.playbook-pill .action { margin-top: 8px; }

.settings-divider {
  margin: 18px 0 4px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Gauge */
.gauge { margin: 10px 0; }
.gauge .gauge-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.gauge .gauge-track { background: var(--panel-2); border-radius: 10px; height: 16px; overflow: hidden; }
.gauge .gauge-fill { height: 100%; border-radius: 10px; transition: width 0.3s; }
.gauge-full .gauge-fill { background: var(--green) !important; }

.plan-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.plan-item:last-child { border-bottom: none; }
.plan-item .plan-label { font-weight: 600; }
.plan-item .plan-sub { font-size: 12px; color: var(--muted); }
.plan-item .plan-val { font-weight: 700; color: var(--accent); }

.check-grid { list-style: none; padding: 0; margin: 8px 0; }
.check-grid li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--border); }
.check-grid li:last-child { border-bottom: none; }
.check-grid .num {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  background: var(--green); color: #052e16; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.balance-banner {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.balance-item {
  flex: 1;
  min-width: 150px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.balance-item .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 6px; }
.balance-item .value { font-size: 22px; font-weight: 700; }
.balance-item .value.positive { color: var(--green); }
.balance-item .value.negative { color: var(--red); }

/* Section cards */
.section-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 18px;
}
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 17px; }
.section-card h2 { margin: 0 0 12px; font-size: 17px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

.carryover { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.carryover label { color: var(--muted); }
.money-input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  width: 130px;
}

/* Tables */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 8px 8px 8px 0;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.data-table td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr.paid-row { background: rgba(34,197,94,0.07); }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.data-table tfoot td { font-weight: 600; padding-top: 10px; }
.total-cell { color: var(--accent); font-weight: 700; }

.cell-input {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  width: 100%;
  min-width: 60px;
}
.cell-input:hover, .cell-input:focus { border-color: var(--border); outline: none; background: var(--panel-2); }
td.money .cell-input { text-align: right; }
  .cell-input.cat { min-width: 110px; }

/* Paid toggle */
.paid-toggle {
  width: 34px;
  height: 20px;
  border-radius: 20px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
}
.paid-toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: all 0.2s;
}
.paid-toggle.on { background: var(--green); border-color: var(--green); }
.paid-toggle.on::after { left: 16px; background: #052e16; }

.row-delete {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 6px;
}
.row-delete:hover { color: var(--red); background: rgba(239,68,68,0.1); }

/* Analytics */
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.section-card.wide { grid-column: 1 / -1; }
.stat-big { font-size: 28px; font-weight: 700; margin: 8px 0; }
.stat-big .sub { font-size: 14px; font-weight: 400; color: var(--muted); display: block; margin-bottom: 4px; }

.bar-row { display: flex; gap: 24px; margin-top: 14px; }
.bar-col { flex: 1; }
.bar-col .bar-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.bar-track { background: var(--panel-2); border-radius: 8px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 8px; }
.bar-fill.green { background: var(--green); }
.bar-fill.red { background: var(--red); }
.bar-val { font-size: 13px; font-weight: 600; margin-top: 4px; }

.legend-list { list-style: none; padding: 0; margin: 8px 0 0; }
.legend-list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.legend-list .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; }
.legend-list .amt { font-weight: 600; }

.table-mini { width: 100%; border-collapse: collapse; }
.table-mini th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--border); }
.table-mini td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--border); }

.forecast-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-top: 10px; }
.forecast-item { background: var(--panel-2); border-radius: 10px; padding: 12px; }
.forecast-item .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.forecast-item .value { font-size: 18px; font-weight: 600; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 420px;
  max-width: 92vw;
}
.modal-box label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.modal-box input { width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 9px 10px; font-size: 14px; }
.modal-box small { color: var(--muted); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }
.form-row { display: flex; gap: 14px; }
.form-row > div { flex: 1; }
.form-row label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.form-row select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
}

select.cell-input { min-width: 130px; }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .month-list { max-height: 160px; }
  .main { max-width: 100%; }
  .analytics-grid { grid-template-columns: 1fr; }
  .data-table { font-size: 13px; }
}
