:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --winner-glow: rgba(16, 185, 129, 0.25);
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.header-title-block {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.header-subtitle {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 400;
}

.verdict-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}

.verdict-strip.verdict-apartment {
  border-color: var(--success);
  box-shadow: 0 0 0 1px var(--success), var(--shadow);
}

.verdict-strip.verdict-etf {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), var(--shadow);
}

.verdict-strip.verdict-tie {
  border-color: var(--warning);
}

.verdict-main {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.verdict-winner-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

.verdict-difference {
  font-size: 1.35rem;
  font-weight: 700;
}

.verdict-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.verdict-crossover {
  color: var(--warning);
}

.input-section-title {
  margin: 0.75rem 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  grid-column: 1 / -1;
}

.input-section-title:first-child {
  margin-top: 0;
}

.nested-details {
  margin-top: 1rem;
}

.nested-details summary {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  margin-bottom: 0.5rem;
}

.match-day0-row {
  flex-wrap: wrap;
  align-items: center;
}

.etf-mirror-row {
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.etf-mirror-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.etf-mirror-toggle input {
  width: auto;
}

.etf-mirror-explanation {
  margin-top: 0.75rem;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.etf-mirror-title {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.etf-mirror-steps {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
}

.etf-mirror-steps li {
  margin-bottom: 0.35rem;
}

.etf-mirror-result {
  margin: 0 0 0.5rem;
}

.chart-subtitle {
  margin: -0.5rem 0 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

tr.crossover-row td {
  background: rgba(245, 158, 11, 0.12);
  font-weight: 600;
}

tr.crossover-row td:first-child::after {
  content: ' · kruispunt';
  font-weight: 500;
  font-size: 0.75rem;
  color: var(--warning);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.scenario-name-input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  min-width: 180px;
}

button,
.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  transition: background 0.15s, border-color 0.15s;
}

button:hover,
.btn:hover {
  background: var(--border);
}

button.primary {
  background: var(--primary);
  border-color: var(--primary);
}

button.primary:hover {
  background: var(--primary-hover);
}

button.success {
  background: var(--success);
  border-color: var(--success);
}

.errors-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  display: none;
}

.errors-banner.visible {
  display: block;
}

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

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.panel h3 {
  margin: 1rem 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.global-settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.input-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.input-group input,
.input-group select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  font-size: 0.875rem;
  width: 100%;
}

.input-group input:focus,
.input-group select:focus {
  outline: none;
  border-color: var(--primary);
}

.input-group .hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.input-group.readonly input {
  opacity: 0.7;
  cursor: not-allowed;
}

.two-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

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

.custom-costs-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.custom-cost-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr 0.8fr auto;
  gap: 0.5rem;
  align-items: end;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}

@media (max-width: 768px) {
  .custom-cost-row {
    grid-template-columns: 1fr 1fr;
  }
}

.custom-cost-row .input-group {
  min-width: 0;
}

.btn-icon {
  padding: 0.5rem;
  min-width: 36px;
  color: var(--danger);
}

.view-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.view-tab {
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
}

.view-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

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

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: relative;
}

.summary-card.winner {
  border-color: var(--success);
  box-shadow: 0 0 0 1px var(--success), 0 0 20px var(--winner-glow);
}

.summary-card h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.winner-badge {
  background: var(--success);
  color: white;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.kpi {
  background: var(--bg);
  padding: 0.75rem;
  border-radius: 6px;
}

.kpi-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.kpi-value {
  font-size: 1.1rem;
  font-weight: 600;
}

.kpi-value.positive {
  color: var(--success);
}

.kpi-value.negative {
  color: var(--danger);
}

.kpi-placeholder {
  grid-column: 1 / -1;
  margin: 0;
  padding: 0.5rem 0;
}

.errors-banner code {
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

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

.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  height: 380px;
}

.chart-container h3 {
  margin: 0 0 1rem;
  font-size: 0.95rem;
}

.chart-wrapper {
  height: calc(100% - 2rem);
  position: relative;
}

.table-panel details {
  cursor: pointer;
}

.table-panel summary {
  font-weight: 600;
  padding: 0.5rem 0;
  user-select: none;
}

.table-wrapper {
  overflow-x: auto;
  margin-top: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

th,
td {
  padding: 0.5rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--text-muted);
  font-weight: 600;
  background: var(--bg);
  position: sticky;
  top: 0;
}

tr:hover td {
  background: rgba(59, 130, 246, 0.05);
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  min-width: 320px;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h3 {
  margin: 0 0 1rem;
}

.scenario-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.scenario-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.scenario-list button {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.helper-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.collapsible-panel details {
  cursor: pointer;
}

.collapsible-panel summary {
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.collapsible-panel summary::-webkit-details-marker {
  display: none;
}

.collapsible-panel summary::before {
  content: '▸';
  display: inline-block;
  transition: transform 0.15s;
  color: var(--text-muted);
}

.collapsible-panel details[open] summary::before {
  transform: rotate(90deg);
}

.collapsible-panel .panel-content {
  margin-top: 1rem;
  cursor: default;
}

.closing-costs-field {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  font-size: 0.875rem;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.closing-costs-field:hover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.05);
}

.closing-costs-field:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.closing-costs-field span:first-child {
  font-weight: 600;
}

.closing-costs-chevron {
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
}

.drawer-overlay {
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  z-index: 9999 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  overflow: hidden;
  background: transparent;
}

.drawer-overlay[hidden] {
  display: none !important;
}

.drawer-overlay:not([hidden]) {
  display: flex !important;
  justify-content: flex-end;
  align-items: stretch;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
}

.drawer-panel {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: min(440px, 100vw);
  max-width: 100%;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  animation: drawer-slide-in 0.28s ease;
}

@keyframes drawer-slide-in {
  from {
    transform: translateX(100%);
  }

  to {
    transform: translateX(0);
  }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.drawer-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.drawer-close {
  padding: 0.35rem 0.55rem;
  font-size: 1rem;
  line-height: 1;
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

.drawer-intro {
  margin: 0 0 1.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.closing-costs-grid {
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.closing-vat-row {
  min-width: 0;
}

.closing-vat-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.closing-vat-rate {
  flex: 1 1 0;
  min-width: 0;
  max-width: 20%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.25rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

.closing-vat-amount {
  flex: 4 1 0;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  font-size: 0.875rem;
  opacity: 0.9;
  cursor: default;
  text-align: right;
}

.closing-costs-total input {
  font-weight: 600;
  font-size: 1rem;
}

.drawer-footer {
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--border);
}

.drawer-footer .primary {
  width: 100%;
}

.notes-textarea {
  width: 100%;
  min-height: 280px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.5;
}

.notes-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.drawer-open {
  overflow: hidden;
}

.chat-assistant-toggle {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9000;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  font-size: 1.35rem;
  font-weight: 700;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.chat-assistant-panel {
  position: fixed;
  bottom: 5rem;
  right: 1.25rem;
  z-index: 9001;
  width: min(420px, calc(100vw - 2rem));
  max-height: min(70vh, 560px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.chat-assistant-panel[hidden] {
  display: none !important;
}

.chat-assistant-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.chat-assistant-header h2 {
  margin: 0;
  font-size: 1rem;
}

.chat-assistant-close {
  padding: 0.25rem 0.5rem;
}

.chat-assistant-intro {
  margin: 0;
  padding: 0.5rem 1rem 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-assistant-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 200px;
}

.chat-msg {
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.45;
  max-width: 95%;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
}

.chat-msg-assistant {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
}

.chat-assistant-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
}

.chat-assistant-form input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.chat-assistant-form button {
  flex-shrink: 0;
}
