:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-strong: #edf3fb;
  --text: #172033;
  --muted: #627089;
  --line: #dbe4f0;
  --primary: #1f6feb;
  --primary-dark: #1559c7;
  --success: #177245;
  --warning: #a05a00;
  --danger: #b42318;
  --shadow: 0 18px 44px rgba(30, 44, 75, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 700;
}

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

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(31, 111, 235, 0.22);
  outline-offset: 2px;
}

label,
legend {
  color: #344054;
  font-size: 0.9rem;
  font-weight: 700;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(31, 111, 235, 0.1), transparent 36%),
    var(--bg);
}

.login-shell {
  width: min(100%, 420px);
}

.login-panel,
.tool-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel {
  padding: 32px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.login-panel h1,
.topbar h1,
.tool-panel h2 {
  margin: 0;
}

.login-panel h1 {
  margin-top: 18px;
  margin-bottom: 24px;
  font-size: 1.9rem;
}

.stacked-form {
  display: grid;
  gap: 16px;
}

.stacked-form label,
.search-form label,
.filter-row label {
  display: grid;
  gap: 7px;
}

.form-message,
.alert-box {
  margin: 0;
  border-radius: var(--radius);
  padding: 12px 14px;
  background: #fff4f3;
  color: var(--danger);
  font-weight: 700;
}

.full-width {
  width: 100%;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

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

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar h1 {
  font-size: clamp(1.65rem, 2vw, 2.4rem);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-badge,
.source-pill,
.match-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 10px;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 800;
}

.user-badge,
.source-pill {
  background: var(--panel-strong);
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.tool-panel {
  padding: 20px;
}

.panel-heading,
.results-header,
.filter-row,
.form-actions,
.export-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.search-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.wide-field,
.condition-field {
  grid-column: 1 / -1;
}

.condition-field {
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 7px;
}

.segmented-control label {
  display: block;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  text-align: center;
  font-size: 0.88rem;
  font-weight: 800;
}

.segmented-control input:checked + span {
  border-color: var(--primary);
  background: #eaf2ff;
  color: var(--primary-dark);
}

.checkbox-row {
  align-self: end;
  min-height: 42px;
  display: flex !important;
  align-items: center;
  gap: 10px !important;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: #fff;
}

.checkbox-row input {
  width: 18px;
  min-height: 18px;
  height: 18px;
}

.primary-button {
  background: var(--primary);
  color: #fff;
  padding: 0 18px;
}

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

.secondary-button,
.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 14px;
}

.ghost-button {
  background: transparent;
}

.muted-text {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.results-panel {
  min-width: 0;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  margin: 18px 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.stat-card {
  display: grid;
  gap: 5px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfdff;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.stat-card strong {
  color: var(--text);
  font-size: 1.02rem;
  overflow-wrap: anywhere;
}

.alert-box {
  margin-bottom: 16px;
  background: #fff8eb;
  color: var(--warning);
}

.loading-state,
.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.loading-state {
  display: flex;
  justify-content: center;
  gap: 12px;
  font-weight: 800;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid #cfe0f7;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.table-wrap {
  display: none;
  overflow-x: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.results-table th,
.results-table td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
  font-size: 0.9rem;
}

.results-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.results-table th:nth-child(1),
.results-table td:nth-child(1) {
  width: 72px;
}

.results-table th:nth-child(2),
.results-table td:nth-child(2) {
  width: 26%;
}

.result-image,
.image-placeholder {
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--panel-strong);
}

.image-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
}

.result-title {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.result-title strong {
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.result-title span,
.match-reason,
.quality-line,
.group-inline {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.group-inline {
  color: #40516d;
  font-weight: 800;
}

.quality-line {
  color: #40516d;
  font-weight: 700;
}

.match-cell {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.match-badge.safe,
.match-badge.sicher {
  background: #e8f7ef;
  color: var(--success);
}

.match-badge.likely,
.match-badge.wahrscheinlich {
  background: #eaf2ff;
  color: var(--primary-dark);
}

.match-badge.unsicher {
  background: #fff8eb;
  color: var(--warning);
}

.match-badge.falsch {
  background: #fff4f3;
  color: var(--danger);
}

.offer-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--text);
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
}

.detail-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  white-space: nowrap;
}

.result-cards {
  display: grid;
  gap: 14px;
}

.result-group {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #f8fbff;
}

.group-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.group-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.group-title h3 {
  margin: 0;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.group-meta {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.group-offers {
  display: grid;
  gap: 10px;
}

.card-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
}

.card-head {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  min-width: 0;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 10px;
}

.card-result .result-image,
.card-result .image-placeholder {
  width: 86px;
  height: 86px;
}

.card-result .offer-link {
  justify-self: start;
}

.card-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.metric {
  display: grid;
  gap: 3px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfdff;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric strong {
  color: var(--text);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  justify-items: end;
  background: rgba(15, 23, 42, 0.42);
}

.detail-panel {
  width: min(760px, 100%);
  height: 100%;
  overflow-y: auto;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 20px;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.detail-head h2 {
  margin: 0;
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.detail-body {
  display: grid;
  gap: 14px;
}

.detail-section {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fbfdff;
}

.detail-section h3 {
  margin: 0;
  font-size: 0.95rem;
}

.detail-row {
  display: grid;
  grid-template-columns: minmax(120px, 190px) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.detail-row span,
.detail-list,
.raw-preview {
  color: var(--muted);
  font-size: 0.88rem;
}

.detail-row strong {
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.detail-list {
  margin: 0;
  padding-left: 20px;
}

.raw-preview {
  max-height: 300px;
  overflow: auto;
  margin: 0;
  border-radius: var(--radius);
  padding: 12px;
  background: #101828;
  color: #e6edf7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

[hidden] {
  display: none !important;
}

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

@media (max-width: 760px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .results-header,
  .topbar-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .tool-panel,
  .login-panel {
    padding: 16px;
  }

  .search-form,
  .filter-row,
  .stats-grid,
  .segmented-control {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .export-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .table-wrap {
    display: none;
  }

  .result-cards {
    display: grid;
    gap: 12px;
  }

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

@media (max-width: 520px) {
  .card-head {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .card-result .result-image,
  .card-result .image-placeholder {
    width: 64px;
    height: 64px;
  }

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

  .offer-link {
    width: 100%;
  }

  .detail-panel {
    padding: 16px;
  }

  .detail-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .card-actions,
  .detail-button {
    width: 100%;
  }
}
