/* ── Design tokens ─────────────────────────────────── */
:root {
  --accent:       #4F46E5;
  --accent-light: #EEF2FF;
  --buy-color:    #2E86AB;
  --rent-color:   #06A77D;
  --danger:       #D62828;

  --bg:           #F8F9FC;
  --surface:      #FFFFFF;
  --surface2:     #F1F3F9;
  --border:       #E5E7EB;
  --text:         #111827;
  --text-muted:   #6B7280;

  --radius:       10px;
  --shadow:       0 1px 4px rgba(0,0,0,.08);
  --shadow-md:    0 4px 16px rgba(0,0,0,.10);
  --sidebar-w:    340px;
  --font:         'Inter', system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg:         #0F1117;
  --surface:    #1A1D27;
  --surface2:   #22263A;
  --border:     #2D3148;
  --text:       #F3F4F6;
  --text-muted: #9CA3AF;
  --accent-light:#1E1B4B;
  --shadow:     0 1px 4px rgba(0,0,0,.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,.5);
}

/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }

/* ── Navbar ─────────────────────────────────────────── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1.5rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.nav-brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; color: var(--accent); }
.nav-brand svg { color: var(--accent); }
.btn-icon {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  padding: .4rem; cursor: pointer; color: var(--text-muted); display: flex; align-items: center;
  transition: border-color .15s, color .15s;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"]  .icon-sun  { display: none; }

/* ── Hero ───────────────────────────────────────────── */
.hero { text-align: center; padding: 2.5rem 1rem 1.5rem; }
.hero h1 { font-size: 1.9rem; font-weight: 700; color: var(--text); }
.hero p  { margin-top: .4rem; color: var(--text-muted); max-width: 520px; margin-inline: auto; }

/* ── Layout ─────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 0;
  max-width: 1400px;
  margin: 0 auto 3rem;
  padding: 0 1.5rem;
  align-items: start;
}

/* ── Inputs Panel ───────────────────────────────────── */
.inputs-panel {
  position: sticky; top: 58px;
  max-height: calc(100vh - 70px); overflow-y: scroll;
  padding: 1rem 1rem 1rem 0;
  scrollbar-width: thin;
}
.inputs-panel::-webkit-scrollbar { width: 6px; }
.inputs-panel::-webkit-scrollbar-track { background: var(--bg); }
.inputs-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.inputs-panel::-webkit-scrollbar-thumb:hover { background: var(--accent); }
* { scrollbar-width: thin; scrollbar-color: var(--border) var(--bg); }

.input-section {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: .75rem;
}
.input-section h3 { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 0; }
.section-toggle { display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; padding-bottom: 0; }
.section-toggle:hover { color: var(--accent); }
.chevron { font-style: normal; font-size: .85rem; transition: transform .2s; display: inline-block; }
.input-section .section-body { overflow: hidden; max-height: 0; transition: max-height .3s ease, margin-top .2s; }
.input-section.open .section-body { max-height: 1000px; margin-top: .75rem; }
.input-section.open .chevron { transform: rotate(0deg); }
.input-section:not(.open) .chevron { transform: rotate(-90deg); }

.field { margin-bottom: .75rem; }
.field:last-child { margin-bottom: 0; }
.field label { display: flex; justify-content: space-between; font-size: .83rem; font-weight: 500; margin-bottom: .3rem; color: var(--text); }
.val-label { font-weight: 600; color: var(--accent); }
.field-hint { font-size: .73rem; color: var(--text-muted); margin-top: .2rem; }

input[type="range"] {
  width: 100%; height: 4px; appearance: none;
  background: var(--border); border-radius: 4px; cursor: pointer; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface); box-shadow: 0 0 0 2px var(--accent);
}

.input-prefix {
  display: flex; align-items: center;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface);
}
.input-prefix span {
  padding: .4rem .6rem; background: var(--surface2);
  color: var(--text-muted); font-size: .83rem; border-right: 1px solid var(--border);
}
.input-prefix input, input[type="number"], select {
  width: 100%; padding: .4rem .6rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: .85rem; font-family: var(--font); outline: none;
  transition: border-color .15s;
}
.input-prefix input { border: none; flex: 1; }
.input-prefix input:focus, input[type="number"]:focus, select:focus { border-color: var(--accent); }

select { cursor: pointer; }

.btn-calculate {
  width: 100%; padding: .75rem;
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  font-size: .95rem; font-weight: 600; font-family: var(--font);
  cursor: pointer; transition: background .15s, transform .1s;
  margin-top: .25rem;
}
.btn-calculate:hover  { background: #4338CA; }
.btn-calculate:active { transform: scale(.98); }

/* ── Results Panel ──────────────────────────────────── */
.results-panel { padding: 1rem 0 1rem 1.5rem; min-height: 60vh; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem; min-height: 50vh; text-align: center; color: var(--text-muted);
}
.empty-state h3 { font-size: 1.1rem; color: var(--text); }
.empty-state p  { max-width: 340px; font-size: .9rem; line-height: 1.5; }

.hidden { display: none !important; }

/* Summary Banner */
.summary-banner {
  border-radius: var(--radius); padding: .9rem 1.25rem;
  font-weight: 600; font-size: .95rem; margin-bottom: 1.25rem;
  display: flex; align-items: center; gap: .6rem;
}
.summary-banner.buy  { background: #DBEAFE; color: #1D4ED8; }
.summary-banner.rent { background: #D1FAE5; color: #065F46; }
[data-theme="dark"] .summary-banner.buy  { background: #1E3A5F; color: #93C5FD; }
[data-theme="dark"] .summary-banner.rent { background: #064E3B; color: #6EE7B7; }

/* Metrics */
.metrics-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: .75rem; margin-bottom: 1.25rem;
}
.metric-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; box-shadow: var(--shadow);
}
.metric-card.highlight-buy  { border-top: 3px solid var(--buy-color); }
.metric-card.highlight-rent { border-top: 3px solid var(--rent-color); }
.metric-label { font-size: .75rem; color: var(--text-muted); font-weight: 500; margin-bottom: .3rem; }
.metric-value { font-size: 1.2rem; font-weight: 700; color: var(--text); }
.metric-value.small { font-size: 1rem; }

/* Section titles */
.section-title { font-size: 1rem; font-weight: 700; margin: 1.5rem 0 .75rem; color: var(--text); }

/* Charts */
.chart-full {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}
.chart-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: .75rem; margin-bottom: 1.25rem;
}
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}

/* Tables */
.tables-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1.25rem; }
.table-wrapper { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table-wrapper h4 { padding: .75rem 1rem; font-size: .85rem; font-weight: 600; border-bottom: 1px solid var(--border); background: var(--surface2); }
.table-scroll { overflow-x: auto; max-height: 300px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: .78rem; }
th { position: sticky; top: 0; background: var(--surface2); color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: .7rem; letter-spacing: .04em; padding: .5rem .75rem; text-align: right; border-bottom: 1px solid var(--border); }
th:first-child { text-align: left; }
td { padding: .45rem .75rem; text-align: right; border-bottom: 1px solid var(--border); color: var(--text); }
td:first-child { text-align: left; font-weight: 600; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

/* Export */
.export-bar { display: flex; gap: .75rem; padding-bottom: 1rem; }
.btn-export {
  padding: .5rem 1.1rem; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); border-radius: var(--radius);
  font-size: .85rem; font-family: var(--font); cursor: pointer; font-weight: 500;
  transition: border-color .15s, color .15s;
}
.btn-export:hover { border-color: var(--accent); color: var(--accent); }

/* Loading */
.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 50vh; gap: 1rem; color: var(--text-muted); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 0 1rem; }
  .inputs-panel { position: static; max-height: none; padding: 0 0 1rem; }
  .results-panel { padding: 0; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .chart-grid, .tables-grid { grid-template-columns: 1fr; }
}
@media (max-width: 500px) {
  .metrics-grid { grid-template-columns: 1fr; }
}
