@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=JetBrains+Mono:wght@400;500;600;700&family=DM+Sans:wght@400;500;600&display=swap');

:root {
  --bg: #111110;
  --surface: #1a1a18;
  --surface2: #222220;
  --surface3: #2a2a27;
  --border: #33332e;
  --border-light: #44443d;
  --text: #e8e5df;
  --text-mid: #b0ada5;
  --text-dim: #7a7770;
  --amber: #e5a946;
  --amber-soft: #d4993a;
  --amber-glow: rgba(229, 169, 70, 0.08);
  --teal: #5cb9a5;
  --teal-soft: rgba(92, 185, 165, 0.12);
  --coral: #e06b5e;
  --coral-soft: rgba(224, 107, 94, 0.12);
  --blue: #6b9fcc;
  --radius: 6px;
  --radius-lg: 10px;
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

.app {
  max-width: 1600px;
  margin: 0 auto;
  padding: 32px 28px;
  animation: fadeUp 0.6s ease-out;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--text);
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-top: 4px;
  letter-spacing: 0.01em;
}

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 32px;
  align-items: start;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .settings-panel { position: static !important; max-height: none !important; }
}

/* ── Settings Panel ── */

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.setting-group {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.setting-group:last-child {
  border-bottom: none;
}

.setting-group h2 {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--amber);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.setting-group h2::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 10px;
  background: var(--amber);
  border-radius: 1px;
}

.setting-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.8rem;
  color: var(--text-mid);
}

.setting-group label > span:first-child {
  flex: 1;
  min-width: 0;
}

.setting-group input[type="number"] {
  width: 88px;
  padding: 5px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-align: right;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.setting-group input[type="number"]:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 2px var(--amber-glow);
}

.setting-group input[type="number"]::-webkit-inner-spin-button {
  opacity: 0;
}

.setting-group input[type="number"]:hover::-webkit-inner-spin-button {
  opacity: 1;
}

.unit {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  width: 14px;
}

.checkbox-label {
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  appearance: none;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border-light);
  border-radius: 3px;
  background: var(--bg);
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
}

.checkbox-label input[type="checkbox"]:checked {
  background: var(--amber);
  border-color: var(--amber);
}

.checkbox-label input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3.5px;
  top: 1px;
  width: 4px;
  height: 7px;
  border: solid var(--bg);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

/* ── Profiles ── */

.profile-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.profile-controls select {
  flex: 1;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  cursor: pointer;
}

.profile-controls select:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 2px var(--amber-glow);
}

.btn-profile {
  padding: 5px 8px !important;
  background: var(--surface2) !important;
  border: 1px solid var(--border) !important;
  font-size: 0.82rem !important;
  line-height: 1;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

.btn-profile:hover {
  border-color: var(--amber) !important;
  background: var(--amber-glow) !important;
}

.btn-profile-delete:hover {
  border-color: var(--coral) !important;
  background: var(--coral-soft) !important;
}

.profile-new {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.profile-new input[type="text"] {
  flex: 1;
  padding: 5px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.profile-new input[type="text"]:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 2px var(--amber-glow);
}

.profile-new .btn-add {
  width: auto;
  margin-top: 0;
  white-space: nowrap;
  padding: 5px 10px;
  font-size: 0.68rem;
}

/* ── Plan Cards ── */

.plan-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  transition: border-color 0.2s;
}

.plan-card:hover {
  border-color: var(--border-light);
}

.plan-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.plan-name {
  flex: 1;
  padding: 2px 0;
  background: transparent;
  border: none;
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.plan-name:focus {
  outline: none;
}

.btn-remove-plan {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  line-height: 1;
  transition: all 0.15s;
}

.btn-remove-plan:hover {
  color: var(--coral);
  background: var(--coral-soft);
}

.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: all 0.2s;
}

.btn-add {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  margin-top: 4px;
}

.btn-add:hover {
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-glow);
}

/* ── Results Panel ── */

.results-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

.results-panel > section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  animation: fadeUp 0.6s ease-out both;
}

.results-panel > section:nth-child(1) { animation-delay: 0.05s; }
.results-panel > section:nth-child(2) { animation-delay: 0.1s; }
.results-panel > section:nth-child(3) { animation-delay: 0.15s; }
.results-panel > section:nth-child(4) { animation-delay: 0.2s; }
.results-panel > section:nth-child(5) { animation-delay: 0.25s; }
.results-panel > section:nth-child(6) { animation-delay: 0.3s; }

.results-panel h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 400;
  margin-bottom: 20px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

/* ── KPI Grid ── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

.kpi-card {
  background: var(--surface2);
  padding: 16px 18px;
}

.kpi-card .kpi-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.3;
}

.kpi-card .kpi-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.02em;
  color: var(--text);
}

.kpi-card .kpi-sub {
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 2px;
  font-family: var(--font-mono);
}

.kpi-value.positive { color: var(--teal); }
.kpi-value.negative { color: var(--coral); }

/* ── Waterfall ── */

.waterfall {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.waterfall-row {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.82rem;
  padding: 4px 0;
}

.waterfall-row .wf-label {
  width: 200px;
  flex-shrink: 0;
  color: var(--text-mid);
  font-size: 0.78rem;
}

.waterfall-row .wf-bar-container {
  flex: 1;
  height: 22px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.waterfall-row .wf-bar {
  height: 100%;
  border-radius: 3px;
  min-width: 3px;
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.waterfall-row .wf-value {
  width: 130px;
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.wf-bar.income { background: linear-gradient(90deg, var(--teal), #7dd4c1); }
.wf-bar.expense { background: linear-gradient(90deg, var(--coral), #e8938a); opacity: 0.8; }
.wf-bar.result { background: linear-gradient(90deg, var(--amber), #edc06a); }

.waterfall-row:last-child {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.waterfall-row:last-child .wf-label {
  color: var(--text);
  font-weight: 600;
}

.breakdown-month {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  font-weight: 400;
  font-style: normal;
}

.positive { color: var(--teal); }
.negative { color: var(--coral); }

/* ── Charts ── */

.chart-section canvas {
  width: 100%;
  height: 300px;
}

/* ── Projection Table ── */

.projection-table-section {
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  margin: 0 -24px;
  padding: 0 24px;
}

#projection-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  white-space: nowrap;
}

#projection-table th,
#projection-table td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

#projection-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border-light);
}

#projection-table td:first-child,
#projection-table th:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  text-align: left;
  z-index: 1;
  font-weight: 500;
  color: var(--text-mid);
  padding-right: 20px;
}

#projection-table tr.section-header td {
  color: var(--amber);
  font-weight: 700;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding-top: 18px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

#projection-table tr.highlight td {
  color: var(--text);
  font-weight: 700;
}

#projection-table tr.highlight td:first-child {
  color: var(--text);
}

#projection-table tr.positive td:not(:first-child) { color: var(--teal); }
#projection-table tr.negative td:not(:first-child) { color: var(--coral); }

#projection-table tbody tr {
  transition: background 0.1s;
}

#projection-table tbody tr:hover {
  background: var(--surface2);
}

#projection-table tbody tr:hover td:first-child {
  background: var(--surface2);
}
