:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #64717f;
  --line: #d8dee5;
  --panel: #ffffff;
  --bg: #f4f6f8;
  --brand: #0c5cab;
  --brand-strong: #0a4a8a;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --accent: #f59e0b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button,
select,
input {
  font: inherit;
}

.topbar {
  align-items: center;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  color: var(--brand);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1 {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.15;
  margin: 0;
}

main {
  margin: 0 auto;
  max-width: 1360px;
  padding: 24px 24px 48px;
}

.upload,
.settings-shortcut {
  align-items: center;
  background: var(--brand);
  border-radius: 8px;
  border: 0;
  color: white;
  cursor: pointer;
  display: inline-flex;
  font-weight: 600;
  min-height: 44px;
  padding: 0 16px;
  transition: background 120ms ease, box-shadow 120ms ease;
}

.upload:hover,
.settings-shortcut:hover {
  background: var(--brand-strong);
}

.upload:focus-visible,
.settings-shortcut:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.upload input {
  inline-size: 1px;
  opacity: 0;
  position: absolute;
}

.status-band,
.filters,
.tabs {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 16px;
}

.status-band {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 14px 16px;
}

.status-band div {
  display: grid;
  gap: 2px;
}

.status-band span,
.status-band p,
.hint,
small {
  color: var(--muted);
}

.status-band p {
  margin: 0;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 6px;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs button,
.ghost {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  min-height: 44px;
  padding: 0 14px;
  transition: color 120ms ease, background 120ms ease;
  white-space: nowrap;
}

.tabs button:hover {
  background: #eef3f7;
  color: var(--ink);
}

.tabs button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.tabs button.active {
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}

.filters {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  padding: 16px;
}

.filters label {
  display: grid;
  gap: 6px;
}

.filters span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 44px;
  padding: 0 10px;
  width: 100%;
  cursor: pointer;
  transition: border-color 120ms ease;
}

select:hover {
  border-color: #a8b5c2;
}

select:focus-visible {
  border-color: var(--brand);
  outline: 2px solid rgba(12, 92, 171, 0.2);
  outline-offset: 0;
}

.settings-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
}

.settings-stack,
.settings-form,
.source-summary {
  display: grid;
  gap: 12px;
}

.settings-form label {
  display: grid;
  gap: 6px;
}

.settings-form span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.settings-form input {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 44px;
  padding: 0 12px;
  width: 100%;
  transition: border-color 120ms ease;
}

.settings-form input:hover {
  border-color: #a8b5c2;
}

.settings-form input:focus-visible {
  border-color: var(--brand);
  outline: 2px solid rgba(12, 92, 171, 0.2);
  outline-offset: 0;
}

.settings-form button {
  background: var(--brand);
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  padding: 0 16px;
  transition: background 120ms ease;
}

.settings-form button:hover {
  background: var(--brand-strong);
}

.settings-form button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.secondary-action {
  background: #eef3f7;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  font-weight: 500;
  min-height: 44px;
  padding: 0 16px;
  transition: background 120ms ease;
  width: fit-content;
}

.secondary-action:hover {
  background: #e2eaf2;
}

.secondary-action:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.inline-upload {
  justify-content: center;
  width: fit-content;
}

.number-setting {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(90px, 120px) 1fr;
}

.toggle-row {
  align-items: center;
  display: flex !important;
  gap: 10px;
}

.toggle-row input {
  accent-color: var(--brand);
  min-height: auto;
  width: auto;
}

.source-summary {
  color: var(--muted);
}

.source-summary strong {
  color: var(--ink);
}

.grid {
  display: grid;
  gap: 12px;
}

.kpis {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 16px;
}

.card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.card {
  display: grid;
  gap: 8px;
  min-height: 118px;
  padding: 16px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.card:hover {
  border-color: #b8c6d4;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

.card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.card strong {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.layout.two {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  min-height: 280px;
  padding: 16px;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 16px;
}

.table-note {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
}

.table-wrap {
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.data-table {
  border-collapse: collapse;
  min-width: 1120px;
  width: 100%;
}

.heatmap-table {
  min-width: unset;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 9px;
  text-align: right;
  white-space: nowrap;
}

.data-table th:first-child,
.data-table td:first-child {
  min-width: 220px;
  text-align: left;
  white-space: normal;
}

.heatmap-table th:first-child,
.heatmap-table td:first-child {
  min-width: 72px;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

.data-table tr:hover td {
  background: #f8fafc;
}

.heatmap-table tr:hover td {
  filter: brightness(0.95);
}

.data-table small {
  display: block;
  font-size: 11px;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  justify-content: center;
  min-width: 62px;
  padding: 4px 8px;
}

.badge.good {
  background: #dff3ef;
  color: #065f46;
}

.badge.warn {
  background: #fef3c7;
  color: #92400e;
}

.badge.bad {
  background: #fee2e2;
  color: #991b1b;
}

.badge.neutral {
  background: #e8edf3;
  color: var(--muted);
}

.positive {
  color: #065f46;
  font-weight: 700;
}

.negative {
  color: var(--danger);
  font-weight: 700;
}

.bars {
  display: grid;
  gap: 10px;
}

.bar-row {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(110px, 1.2fr) minmax(120px, 3fr) minmax(70px, auto);
}

.bar-row span {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row div {
  background: #e8edf3;
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.bar-row i {
  background: linear-gradient(90deg, var(--brand), var(--success));
  border-radius: inherit;
  display: block;
  height: 100%;
}

.bar-row b {
  font-size: 13px;
  font-weight: 600;
  text-align: right;
}

.empty {
  align-items: center;
  background: #f8fafc;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  display: flex;
  min-height: 160px;
  padding: 24px;
}

.model-summary {
  align-items: center;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 10px 14px;
}

.model-summary span:first-child {
  color: var(--brand-strong);
  font-weight: 600;
}

.alert-list {
  display: grid;
  gap: 8px;
}

.alert-item {
  align-items: flex-start;
  display: flex;
  gap: 8px;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
}

.alert-item.warn {
  background: #fef3c7;
  color: #92400e;
}

.alert-item.bad {
  background: #fee2e2;
  color: #991b1b;
}

.alert-item.good {
  background: #dff3ef;
  color: #065f46;
}

/* KPI card trend indicator */
.trend {
  font-size: 12px;
  font-weight: 600;
  margin: 1px 0 2px;
}

.trend.good {
  color: var(--success);
}

.trend.bad {
  color: var(--danger);
}

.trend.neutral {
  color: var(--muted);
}

/* Valuation formula breakdown */
.valuation-breakdown {
  display: grid;
  gap: 12px;
}

.formula-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 12px 14px;
}

.formula-box strong {
  display: block;
  font-size: 13px;
  margin-bottom: 8px;
}

.formula-box code {
  background: rgba(0, 0, 0, 0.04);
  border-radius: 4px;
  display: block;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  margin: 4px 0;
  padding: 4px 8px;
  white-space: pre-wrap;
}

.lever-list {
  display: grid;
  gap: 8px;
}

.lever-item {
  background: #f8fafc;
  border-left: 3px solid var(--brand);
  border-radius: 0 6px 6px 0;
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 12px;
}

.lever-item--warn {
  background: #fef9ec;
  border-left-color: var(--warning);
}

/* Product × Region matrix */
.product-area-table th:not(:first-child),
.product-area-table td:not(:first-child):not(:last-child) {
  min-width: 110px;
  text-align: center;
}

.product-area-table th:first-child,
.product-area-table td:first-child {
  min-width: 180px;
}

/* Heatmap compact zoom-out mode */
.heatmap-compact th:not(:first-child),
.heatmap-compact td:not(:first-child) {
  font-size: 11px;
  min-width: 54px;
  padding: 5px 3px;
}

.heatmap-compact th:first-child,
.heatmap-compact td:first-child {
  min-width: 70px;
}

/* Germany region map */
.germany-map-wrap {
  align-items: flex-start;
  display: flex;
  gap: 28px;
}

.map-region {
  cursor: default;
  stroke: #fff;
  stroke-width: 2;
  transition: opacity 120ms ease;
}

.map-region:hover {
  opacity: 0.82;
}

.map-legend {
  display: grid;
  flex: 1;
  gap: 14px;
}

.map-legend-row {
  align-items: center;
  display: flex;
  gap: 10px;
  font-size: 13px;
}

.map-swatch {
  border-radius: 4px;
  flex-shrink: 0;
  height: 16px;
  width: 16px;
}

/* Forecast confidence range label */
.forecast-range {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

/* AI settings env-var notice */
.ai-env-notice {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: var(--brand-strong);
  font-size: 13px;
  padding: 10px 14px;
}

.ai-env-notice code {
  background: rgba(12, 92, 171, 0.1);
  border-radius: 3px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  padding: 1px 5px;
}

/* AI Decision Coach */
.ai-response {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.65;
  margin-top: 12px;
  max-height: 340px;
  overflow-y: auto;
  padding: 12px 14px;
  white-space: pre-wrap;
}

.ai-trigger {
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  min-height: 40px;
  padding: 0 18px;
  transition: opacity 120ms ease;
}

.ai-trigger:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ai-trigger:hover:not(:disabled) {
  opacity: 0.88;
}

.ai-trigger:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1100px) {
  .kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar,
  .status-band,
  .model-summary {
    align-items: stretch;
    flex-direction: column;
  }

  main {
    padding-inline: 16px;
  }

  .kpis,
  .layout.two,
  .filters {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 1fr;
  }

  .bar-row b {
    text-align: left;
  }
}
