:root {
  --brand-blue: #103b69;
  --brand-blue-strong: #08294a;
  --brand-blue-soft: #eaf2fb;
  --brand-yellow: #f2c94c;
  --success: #198754;
  --danger: #c2414a;
  --warning: #ad6b00;
  --info: #2166a5;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #172033;
  --text-muted: #62708a;
  --border: #dfe6ef;
  --shadow: 0 18px 50px rgba(24, 49, 83, 0.09);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --topbar-height: 76px;
}

[data-theme="dark"] {
  --bg: #0d1522;
  --surface: #131f30;
  --surface-muted: #17263a;
  --text: #eef5ff;
  --text-muted: #a9b8ca;
  --border: #2b3b50;
  --brand-blue-soft: #172f4a;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.topbar {
  position: sticky;
  z-index: 50;
  top: 0;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 28px;
  color: white;
  background: linear-gradient(120deg, var(--brand-blue-strong), var(--brand-blue));
  box-shadow: 0 8px 30px rgba(8, 41, 74, 0.18);
}

.brand,
.top-actions,
.panel-title,
.hero,
.connection-status {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: var(--brand-blue-strong);
  background: var(--brand-yellow);
  font-size: 24px;
  font-weight: 900;
}

.brand strong {
  display: block;
  font-size: 18px;
}

.topbar .eyebrow {
  color: rgba(255, 255, 255, 0.72);
}

.top-actions {
  gap: 10px;
}

.page-shell {
  width: min(1800px, 100%);
  min-height: calc(100vh - var(--topbar-height));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
}

.filter-panel {
  align-self: start;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  padding: 28px 24px 40px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.panel-heading h1,
.hero h2,
.empty-state h2,
.panel-title h3 {
  margin: 0;
  line-height: 1.2;
}

.panel-heading h1 {
  margin-top: 3px;
  font-size: 25px;
}

.panel-heading p,
.empty-state p,
.report-footer p {
  color: var(--text-muted);
}

.eyebrow {
  display: block;
  color: var(--info);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

form {
  margin-top: 24px;
}

.field,
.field-row {
  display: grid;
  gap: 8px;
}

.field {
  margin-bottom: 17px;
}

.field-row {
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field > span {
  font-size: 13px;
  font-weight: 750;
}

.field small {
  color: var(--text-muted);
  font-size: 11px;
}

input,
select,
textarea {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--surface-muted);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

input,
select {
  height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #4b85bd;
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(33, 102, 165, 0.12);
}

.button,
.icon-button {
  border: 0;
  border-radius: 11px;
  font-weight: 750;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}

.button:hover:not(:disabled),
.icon-button:hover {
  transform: translateY(-1px);
}

.button {
  min-height: 42px;
  padding: 10px 16px;
}

.button-primary {
  color: white;
  background: linear-gradient(120deg, var(--brand-blue), #1762a5);
  box-shadow: 0 10px 25px rgba(16, 59, 105, 0.2);
}

.button-secondary {
  color: var(--brand-blue-strong);
  background: white;
}

.button-full {
  width: 100%;
  min-height: 48px;
}

.icon-button {
  width: 42px;
  height: 42px;
  color: var(--brand-blue-strong);
  background: white;
}

.connection-status {
  gap: 10px;
  margin-top: 24px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-muted);
}

.connection-status strong,
.connection-status small {
  display: block;
}

.connection-status strong {
  font-size: 12px;
}

.connection-status small {
  color: var(--text-muted);
  font-size: 11px;
}

.status-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 99px;
  background: var(--warning);
  box-shadow: 0 0 0 5px rgba(173, 107, 0, 0.12);
}

.connection-status.connected .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(25, 135, 84, 0.12);
}

.dashboard-area {
  min-width: 0;
  padding: 30px;
}

.hero {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  padding: 25px 28px;
  color: white;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 92% 12%, rgba(242, 201, 76, 0.26), transparent 26%),
    linear-gradient(125deg, var(--brand-blue-strong), var(--brand-blue));
  box-shadow: var(--shadow);
}

.hero .eyebrow {
  color: var(--brand-yellow);
}

.hero h2 {
  margin-top: 5px;
  font-size: clamp(25px, 3vw, 38px);
}

.hero p {
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.75);
}

.hero-meta {
  flex: 0 0 auto;
  padding: 13px 16px;
  text-align: right;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.08);
}

.hero-meta span,
.hero-meta strong {
  display: block;
}

.hero-meta span {
  color: rgba(255, 255, 255, 0.67);
  font-size: 11px;
}

.empty-state {
  min-height: 480px;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 40px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.empty-state p {
  max-width: 570px;
}

.empty-icon {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 22px;
  color: var(--brand-blue);
  background: var(--brand-blue-soft);
  font-size: 34px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.kpi-card,
.panel {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-card {
  min-width: 0;
  position: relative;
  overflow: hidden;
  padding: 20px;
  border-radius: var(--radius-md);
}

.kpi-card::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 54px;
  height: 5px;
  border-radius: 0 0 0 8px;
  background: var(--brand-yellow);
}

.kpi-label,
.kpi-helper {
  display: block;
  color: var(--text-muted);
}

.kpi-label {
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  display: block;
  overflow: hidden;
  margin-top: 8px;
  font-size: clamp(22px, 2vw, 31px);
  font-weight: 850;
  letter-spacing: -0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kpi-helper {
  margin-top: 6px;
  font-size: 11px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  min-width: 0;
  border-radius: var(--radius-lg);
}

.chart-panel,
.analysis-panel,
.validation-panel {
  padding: 21px;
}

.chart-panel-wide {
  grid-column: span 2;
}

.panel-title {
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 18px;
}

.panel-title h3 {
  margin-top: 3px;
  font-size: 18px;
}

.chart-wrapper {
  position: relative;
  min-height: 280px;
}

.chart-wrapper-medium {
  min-height: 330px;
}

.chart-wrapper-large {
  min-height: 390px;
}

.table-search input {
  min-width: 240px;
}

.table-scroll {
  overflow: auto;
  border-top: 1px solid var(--border);
}

.panel > .panel-title.panel-title-responsive {
  padding: 21px 21px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  background: var(--surface-muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tbody tr:hover {
  background: var(--brand-blue-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 800;
}

.badge-comparable {
  color: #0c5d3b;
  background: #dff6eb;
}

.badge-non-comparable {
  color: #7a4a00;
  background: #fff0c7;
}

.value-positive {
  color: var(--success);
  font-weight: 800;
}

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

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.7fr);
  gap: 18px;
  margin-top: 18px;
}

.analysis-text {
  color: var(--text);
  white-space: pre-wrap;
}

.analysis-text p:first-child {
  margin-top: 0;
}

.validation-list {
  display: grid;
  gap: 11px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.validation-item {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.validation-ok {
  color: var(--success);
  font-weight: 800;
}

.validation-warning {
  color: var(--warning);
  font-weight: 800;
}

.report-footer {
  margin-top: 18px;
  padding: 18px 4px 4px;
  font-size: 11px;
  text-align: center;
}

.loading-overlay {
  position: fixed;
  z-index: 1000;
  inset: 0;
  place-items: center;
  background: rgba(7, 20, 36, 0.66);
  backdrop-filter: blur(5px);
}

.loading-overlay:not([hidden]) {
  display: grid;
}

.loading-card {
  width: min(390px, calc(100% - 30px));
  display: grid;
  justify-items: center;
  gap: 9px;
  padding: 30px;
  text-align: center;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--brand-blue-soft);
  border-top-color: var(--brand-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.toast {
  position: fixed;
  z-index: 1200;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100% - 40px));
  padding: 14px 17px;
  color: white;
  border-radius: 12px;
  background: var(--brand-blue-strong);
  box-shadow: var(--shadow);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1180px) {
  .page-shell {
    grid-template-columns: 290px minmax(0, 1fr);
  }

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

@media (max-width: 880px) {
  :root {
    --topbar-height: auto;
  }

  .topbar {
    position: relative;
    min-height: 76px;
    flex-wrap: wrap;
    padding: 14px 18px;
  }

  .page-shell {
    display: block;
  }

  .filter-panel {
    position: static;
    height: auto;
    padding: 24px 20px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .dashboard-area {
    padding: 20px;
  }

  .chart-grid,
  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .chart-panel-wide {
    grid-column: span 1;
  }
}

@media (max-width: 600px) {
  .top-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 42px 1fr 1fr;
  }

  .button {
    padding-inline: 10px;
    font-size: 12px;
  }

  .field-row,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-area {
    padding: 14px;
  }

  .hero {
    align-items: flex-start;
    flex-direction: column;
    padding: 22px;
  }

  .hero-meta {
    width: 100%;
    text-align: left;
  }

  .panel-title-responsive {
    align-items: stretch;
    flex-direction: column;
  }

  .table-search input {
    min-width: 0;
  }
}

@page {
  size: A4 landscape;
  margin: 10mm;
}

@media print {
  :root {
    --bg: #fff;
    --surface: #fff;
    --surface-muted: #f5f7fa;
    --text: #172033;
    --text-muted: #5c677a;
    --border: #d9dee7;
    --shadow: none;
  }

  body {
    background: white;
    font-size: 10px;
  }

  .no-print,
  .loading-overlay,
  .toast,
  .empty-state {
    display: none !important;
  }

  .page-shell {
    display: block;
  }

  .dashboard-area {
    padding: 0;
  }

  .hero,
  .panel,
  .kpi-card {
    box-shadow: none;
  }

  .hero {
    margin-bottom: 10px;
    padding: 15px 18px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .hero h2 {
    font-size: 24px;
  }

  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 9px;
  }

  .kpi-card {
    padding: 12px;
  }

  .kpi-value {
    font-size: 18px;
  }

  .chart-grid {
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin-bottom: 9px;
  }

  .chart-panel,
  .analysis-panel,
  .validation-panel {
    padding: 12px;
  }

  .chart-panel-wide {
    grid-column: span 2;
  }

  .chart-wrapper {
    min-height: 200px;
  }

  .chart-wrapper-large {
    min-height: 250px;
  }

  .chart-wrapper-medium {
    min-height: 220px;
  }

  .panel,
  .kpi-card,
  .chart-panel,
  .analysis-panel,
  .validation-panel,
  table,
  tr {
    break-inside: avoid;
  }

  .analysis-grid {
    grid-template-columns: 1.7fr 0.7fr;
    gap: 9px;
    margin-top: 9px;
  }

  th,
  td {
    padding: 7px 9px;
    font-size: 9px;
  }

  .report-footer {
    margin-top: 8px;
  }
}
