:root {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-focus: #94a3b8;
  --accent: #0ea5e9;
  --accent-hover: #0284c7;
  --accent-light: #e0f2fe;
  --good: #059669;
  --good-bg: #d1fae5;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: min(1300px, 96vw);
  margin: 0 auto;
  padding: 24px 20px;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

h1, h2, h3, h4 { margin: 0 0 10px; color: var(--text); }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; color: var(--muted); font-weight: 600; }
p { margin: 0; color: var(--muted); font-size: 0.9375rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.toolbar-aside {
  flex-direction: column;
  width: 100%;
}
.toolbar-aside > .primary {
  width: 100%;
  justify-content: center;
}
.toolbar-aside-row {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 0;
}
.toolbar-aside-row button {
  flex: 1;
  justify-content: center;
}

button, select, input {
  font: inherit;
  font-size: 0.9375rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--bg-card);
  padding: 10px 14px;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}
button .lucide { width: 18px; height: 18px; flex-shrink: 0; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.ghost {
  background: var(--panel-2);
  color: var(--text-secondary);
}
button.ghost:hover { background: #e2e8f0; border-color: #cbd5e1; }
button.danger { border-color: var(--bad); color: var(--bad); background: var(--bad-bg); }
button.small { padding: 6px 10px; font-size: 0.875rem; }
button.small .lucide { width: 16px; height: 16px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

.field input, .field select { width: 100%; }
.full { grid-column: 1 / -1; }

.section-title {
  margin: 18px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

.mortgage-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: none;
  overflow: visible;
  padding-right: 4px;
}

.mortgage-item {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.mortgage-item:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.mortgage-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 8px;
}

.mortgage-name {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.3;
  color: var(--text);
}

.chip {
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--muted);
  background: var(--panel-2);
}

.mortgage-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 0.875rem;
  margin-bottom: 10px;
  color: var(--text-secondary);
}

.item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric-box {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  transition: border-color .15s ease;
}
.metric-box:hover { border-color: #cbd5e1; }
.metric-box .label { color: var(--muted); font-size: 0.8125rem; font-weight: 500; }
.metric-box .value { font-size: 1.0625rem; margin-top: 4px; font-weight: 700; color: var(--text); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin-top: 8px;
}
th, td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: right;
  white-space: nowrap;
}
th:first-child, td:first-child,
th:nth-child(2), td:nth-child(2) { text-align: left; }
th {
  color: var(--muted);
  background: var(--panel-2);
  position: sticky;
  top: 0;
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
tr:hover td { background: var(--bg); }

.table-wrap {
  max-height: 380px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}

.bindings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.binding-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--bg);
  display: grid;
  grid-template-columns: 1.5fr .7fr .8fr .7fr auto;
  gap: 10px;
  align-items: end;
}
#bindingsList .binding-row .binding-delete-cell .binding-delete-label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-secondary);
  height: 1.25rem;
  visibility: hidden;
}
#resultBindingsList .binding-row {
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  align-items: start;
}
#resultBindingsList .binding-row .field .muted { display: block; font-size: 0.8125rem; margin-bottom: 2px; }
#resultBindingsList .binding-row .field > div { font-weight: 600; }

.compare-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.compare-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.compare-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.875rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  font-weight: 500;
}
.compare-pill .lucide { width: 16px; height: 16px; }

.compare-table td.best {
  color: var(--good);
  font-weight: 700;
}
.compare-table td.worst {
  color: var(--bad);
}

.warning {
  margin-top: 12px;
  padding: 12px 14px;
  color: #92400e;
  background: var(--warn-bg);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.toolbar-actions {
  margin-top: 24px;
}

.main-view {
  display: none;
}
.main-view.is-visible {
  display: block;
}
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.view-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}
.back-btn {
  font-size: 0.9375rem;
}
.main-hero {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  background: var(--bg);
}
.main-hero h2 {
  color: var(--text);
  font-size: 1.25rem;
  margin: 0 0 8px;
}
.main-hero p {
  margin: 0 0 20px;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}
.main-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}
.aside-compare-wrap {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.aside-compare-wrap .ghost { width: 100%; justify-content: center; }

.result-type-block {
  margin-bottom: 20px;
  padding: 16px 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.result-type-block .label { color: var(--muted); font-size: 0.8125rem; font-weight: 500; }
.result-type-block .value { font-weight: 600; margin-top: 2px; color: var(--text); }
.result-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px 18px;
  margin-top: 10px;
}
.result-type-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.result-type-item .label { margin: 0; }
.result-type-item .value { margin: 0; }

canvas {
  width: 100%;
  height: 250px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(4px);
}
.modal-overlay.is-open {
  display: flex;
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 540px;
  width: 100%;
  max-height: calc(100vh - 48px);
  overflow: auto;
  position: relative;
  box-shadow: var(--shadow-md), 0 25px 50px -12px rgba(0, 0, 0, 0.15);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}
.modal-header h2 { margin: 0; font-size: 1.125rem; }
.modal-close {
  background: var(--panel-2);
  border: none;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color .15s ease, background .15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-close .lucide { width: 20px; height: 20px; }
.modal-close:hover {
  color: var(--text);
  background: var(--border);
}
.modal-body {
  padding: 18px 20px 24px;
}

.app-logo {
  display: inline-flex;
  align-items: center;
  margin-bottom: 4px;
  cursor: pointer;
}
.app-logo img {
  height: 72px;
  width: auto;
  display: block;
}

.intro-section {
  background: var(--accent-light);
  border: 1px solid rgba(14, 165, 233, 0.2);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 24px;
}
.intro-section h1,
.intro-section h2 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 12px;
  line-height: 1.4;
}
.intro-section p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin: 0 0 10px;
  line-height: 1.55;
}
.intro-section p:last-child { margin-bottom: 0; }
.intro-section ul {
  margin: 10px 0 0 18px;
  padding: 0;
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.6;
}

.ad-slot {
  margin: 20px 0;
  min-height: 100px;
  text-align: center;
}
.ad-slot ins { display: block; }

.site-footer {
  grid-column: 1 / -1;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.875rem;
  color: var(--muted);
}
.site-footer a {
  color: var(--accent);
  text-decoration: none;
}
.site-footer a:hover {
  text-decoration: underline;
}
.site-footer span {
  margin: 0 8px;
  color: var(--border);
}

@media (max-width: 980px) {
  .container { grid-template-columns: 1fr; padding: 16px; }
  .results-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .binding-row { grid-template-columns: 1fr 1fr; }
}
