:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --border: #e4e8f1;
  --text: #15192b;
  --text-muted: #6b7384;
  --accent: #5b5bf0;
  --accent-2: #19b38c;
  --warn-bg: #fff4e5;
  --warn-text: #8a5300;
  --warn-border: #f3c98b;
  --highlight-bg: #e9fbf4;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.04), 0 8px 24px rgba(20, 24, 40, 0.06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1220;
    --surface: #171b2c;
    --surface-2: #1d2236;
    --border: #2a2f45;
    --text: #e8eaf4;
    --text-muted: #9499ad;
    --accent: #8688ff;
    --accent-2: #3ddcb0;
    --warn-bg: #3a2c12;
    --warn-text: #f1c272;
    --warn-border: #5a4420;
    --highlight-bg: #103023;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1220;
  --surface: #171b2c;
  --surface-2: #1d2236;
  --border: #2a2f45;
  --text: #e8eaf4;
  --text-muted: #9499ad;
  --accent: #8688ff;
  --accent-2: #3ddcb0;
  --warn-bg: #3a2c12;
  --warn-text: #f1c272;
  --warn-border: #5a4420;
  --highlight-bg: #103023;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

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

.app { max-width: 1280px; margin: 0 auto; padding: 20px 20px 48px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.topbar__title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar__title h1 { font-size: 20px; margin: 0; font-weight: 650; }

.topbar__badge {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.panel--controls { margin-bottom: 20px; }

.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
}

.controls-row .btn { width: auto; align-self: flex-end; }

.field { margin-bottom: 0; position: relative; min-width: 150px; }
.field--grow { flex: 1 1 220px; min-width: 220px; }

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  white-space: nowrap;
}

.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
}

.field input[type="range"] {
  width: 100%;
  margin-top: 6px;
  accent-color: var(--accent);
}

.field output {
  display: inline-block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 650;
  color: var(--accent);
}

.field--selected[hidden] { display: none; }

.field--selected {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  margin-top: 14px;
}

.muted { color: var(--text-muted); }

.link-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}

.apartment-list {
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  margin-top: 4px;
}

.apartment-list:empty { display: none; }

.apartment-item {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.apartment-item:hover { background: var(--surface-2); }
.apartment-item .ap-price { color: var(--text-muted); white-space: nowrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  width: 100%;
}

.btn--ghost { background: var(--surface-2); color: var(--text); }
.btn--ghost:hover { background: var(--border); }

.warnings {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 13px;
}
.warnings ul { margin: 4px 0 0; padding-left: 18px; }

.results-wrap { max-width: 980px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 36px 36px;
}

.card h3 {
  margin: 0 0 20px;
  font-size: 19px;
  font-weight: 700;
}

.card--client h3::before { content: "●"; color: var(--accent); margin-right: 8px; }

.hero-stats {
  display: grid;
  grid-template-columns: 1.3fr 1.3fr 1fr;
  gap: 18px;
  margin-bottom: 28px;
}

@media (max-width: 760px) {
  .hero-stats { grid-template-columns: 1fr; }
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 24px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.stat__label { font-size: 14px; color: var(--text-muted); font-weight: 600; }
.stat__value { font-size: 34px; font-weight: 750; letter-spacing: -0.01em; line-height: 1.1; }

.stat--primary {
  background: linear-gradient(135deg, var(--accent), #8b8bff);
  border: none;
}
.stat--primary .stat__label { color: rgba(255, 255, 255, 0.85); }
.stat--primary .stat__value { color: #fff; }

.stat--save {
  background: var(--highlight-bg);
  border-color: var(--accent-2);
}
.stat--save .stat__value { color: var(--accent-2); }

.stat--negative {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}
.stat--negative .stat__value { color: var(--warn-text); }

dl { margin: 0; }

.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 32px;
}

@media (max-width: 600px) {
  .details-grid { grid-template-columns: 1fr; }
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: none; }

.row dt { color: var(--text-muted); font-size: 15px; }
.row dd { margin: 0; font-weight: 700; font-size: 17px; text-align: right; }

.finish-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

@media (max-width: 860px) {
  .finish-grid { grid-template-columns: 1fr; }
}

.finish-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px 22px 8px;
}

.finish-card h4 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 750;
}

.finish-card .finish-price {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.finish-card .stat {
  padding: 16px 18px;
  margin-bottom: 12px;
}

.finish-card .stat__label { font-size: 12.5px; }
.finish-card .stat__value { font-size: 22px; }

.finish-card .row { padding: 10px 0; }
.finish-card .row dt { font-size: 13px; }
.finish-card .row dd { font-size: 14px; }
