/* ============================================
   hreflang Validator - Styles

   Design tokens, reset, header, grid, field,
   button, card and warning styles are taken 1:1
   from the UTM Builder, which took them from the
   SERP Simulator (serp-simulator.xtraz-labs.com).
   All three tools stay visually identical.

   Anything added for this tool is marked
   "Validator addition" and is derived from the
   existing tokens only. The one genuinely new
   value is --tint-danger, formed the same way
   the UTM Builder formed its other tints.
   ============================================ */

/* --- Reset & Basis --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* The hidden attribute only sets display:none at low priority, so any
   element given display:flex below would ignore it. Several elements
   here are toggled that way, so make hidden win outright. */
[hidden] {
  display: none !important;
}

:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;   /* 1.23:1 on white -- below the 3:1 WCAG 1.4.11
                                asks for on a control boundary. Inherited from
                                the SERP Simulator; changing it would make the
                                three tools diverge, so it is a shared decision. */
  --color-text: #1e293b;
  --color-text-secondary: #64748b;
  --color-success: #16a34a;
  --color-warning: #ea580c;
  --color-danger: #dc2626;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);

  /* Carried over from the UTM Builder, unchanged. A URL is read character
     by character, so it needs fixed-width digits and an unambiguous l/1/I. */
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --tint-primary: rgba(37, 99, 235, 0.08);   /* --color-primary  @ 8%  */
  --tint-warning: rgba(234, 88, 12, 0.08);   /* --color-warning  @ 8%  */
  --tint-success: rgba(22, 163, 74, 0.10);   /* --color-success  @ 10% */
  --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.1);

  /* Validator addition: this tool reports errors, which the other two do
     not, so it needs the danger tint the same way. Same formula. */
  --tint-danger: rgba(220, 38, 38, 0.08);    /* --color-danger   @ 8%  */
}

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

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  padding: 24px 32px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.header-logo-link,
.header-spacer {
  flex: 0 0 auto;
  width: 120px;
}

.header-text {
  flex: 1;
  text-align: center;
}

.header-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
}

.header-subtitle {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.header-logo {
  height: 32px;
  width: auto;
}

.noscript-note {
  padding: 20px 32px 0;
  max-width: 1400px;
  margin: 0 auto;
}

/* --- Container / Layout --- */
.container {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 0;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 85px);
}

.input-panel {
  padding: 24px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
}

.field-group {
  margin-bottom: 20px;
}

.field-group label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field-group input[type="text"],
.field-group input[type="url"],
.field-group textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.field-group input:focus,
.field-group textarea:focus {
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}

.field-flag {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field-flag.required {
  color: var(--color-primary);
}

.field-hint {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 5px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:disabled:active {
  transform: none;
}

.btn-small {
  padding: 5px 12px;
  font-size: 12px;
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.btn-small:hover:not(:disabled) {
  background: var(--color-border);
  color: var(--color-text);
}

.btn-outline {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.btn-outline:hover:not(:disabled) {
  background: var(--color-bg);
  color: var(--color-text);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  min-height: 40px;
  padding: 8px 20px;
  font-size: 14px;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.action-buttons {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
  margin-top: 8px;
}

/* --- Rechtes Panel: Ergebnis --- */
.preview-panel {
  padding: 24px 32px;
  background: var(--color-bg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card[hidden] {
  display: none;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card-note {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.copy-feedback {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  opacity: 0;
  transition: opacity 0.15s;
}

.copy-feedback::before {
  content: '\2713\00a0';
  color: var(--color-success);
}

.copy-feedback.visible {
  opacity: 1;
}

.copy-feedback.error {
  color: var(--color-danger);   /* 4.83:1 on white, passes */
}

.copy-feedback.error::before {
  content: '';
}

/* --- Befunde (aus .warning des UTM Builders, um "error" erweitert) --- */
.warnings {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.warnings:empty {
  display: none;
}

.warning {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  line-height: 1.5;
  padding: 12px 14px;
  border-radius: var(--radius);
  color: var(--color-text);
}

/* Validator addition: the error level. The other two tools never had one
   because neither can tell a user something is broken. */
.warning-error {
  background: var(--tint-danger);
  border: 1px solid var(--color-danger);
}

.warning-warning {
  background: var(--tint-warning);
  border: 1px solid var(--color-warning);
}

.warning-info {
  background: var(--tint-primary);
  border: 1px solid var(--color-border);
}

.warning-success {
  background: var(--tint-success);
  border: 1px solid var(--color-success);
}

.warning-icon {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
}

.warning-error .warning-icon {
  background: var(--color-danger);
}

.warning-warning .warning-icon {
  background: var(--color-warning);
}

.warning-info .warning-icon {
  background: var(--color-primary);
}

.warning-success .warning-icon {
  background: var(--color-success);
}

.warning-body {
  min-width: 0;
  flex: 1;
}

.warning-body strong {
  font-weight: 600;
}

/* --- Footer --- */
.footer {
  padding: 20px 32px 32px;
  text-align: center;
  font-size: 12px;
  color: var(--color-text-secondary);
}

.footer a {
  color: var(--color-text-secondary);
}

/* ============================================
   Validator additions from here on.
   ============================================ */

/* Status while a run is in flight. A run takes seconds, so the button
   alone is not enough feedback. */
.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-top: 12px;
}

.spinner {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
}

/* Empty state, so the right-hand panel is never a blank rectangle. */
.placeholder {
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 14px;
  background: var(--color-surface);
}

.placeholder-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 8px;
}

/* Summary line above the results: counts plus where the markup came from. */
.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-secondary);
}

.badge-error {
  background: var(--tint-danger);
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.badge-warning {
  background: var(--tint-warning);
  border-color: var(--color-warning);
  color: var(--color-warning);
}

.badge-success {
  background: var(--tint-success);
  border-color: var(--color-success);
  color: #15803d;   /* --color-success darkened for text contrast on the tint */
}

/* The hint line: where the markup was found, cluster size, languages. */
.meta-line {
  font-size: 12px;
  line-height: 1.6;
  color: var(--color-text-secondary);
}

.meta-line strong {
  color: var(--color-text);
  font-weight: 600;
}

/* --- Cluster-Matrix ---
   Two renderings of the same data, swapped by media query rather than by
   JavaScript, so a resize never leaves a stale view (Fallstrick 15). */
.matrix-scroll {
  overflow-x: auto;
  /* The sticky first column needs a positioned scroll container. */
  position: relative;
  margin: 0 -20px;
  padding: 0 20px;
}

.matrix {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  min-width: 100%;
}

.matrix th,
.matrix td {
  border-bottom: 1px solid var(--color-border);
  padding: 8px 10px;
  text-align: center;
  white-space: nowrap;
}

.matrix thead th {
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

/* The URL column stays put while the language columns scroll. Without it
   a wide cluster becomes unreadable: you scroll to a cell and no longer
   know which page the row belongs to. */
.matrix .matrix-url {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--color-surface);
  text-align: left;
  max-width: 320px;
  min-width: 180px;
  white-space: normal;
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 11px;
  /* Marks the boundary while the rest scrolls underneath. */
  box-shadow: 1px 0 0 var(--color-border);
}

.matrix thead .matrix-url {
  z-index: 4;
  font-family: inherit;
  font-size: 12px;
}

.matrix tbody tr:hover .matrix-url,
.matrix tbody tr:hover td {
  background: var(--color-bg);
}

.matrix-seed {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-primary);
}

.matrix-status {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 10px;
  color: var(--color-text-secondary);
}

/* Cell states. Every one carries a glyph as well as a colour, so the
   matrix is readable without colour vision and in a printed report. */
.cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.cell-self    { background: var(--color-primary); color: #fff; }
.cell-ok      { background: var(--tint-success); color: #15803d; }
.cell-variant { background: var(--tint-warning); color: #c2410c; }
.cell-ignored { background: var(--tint-warning); color: #c2410c; }
.cell-external{ background: var(--color-bg); color: var(--color-text-secondary); }
.cell-invalid { background: var(--tint-danger); color: var(--color-danger); }
.cell-missing { background: var(--color-bg); color: #94a3b8; }
/* Distinct from "missing" on purpose: a page we could not fetch tells us
   nothing, and drawing that as a hole would invent a finding. */
.cell-unknown { background: repeating-linear-gradient(45deg, var(--color-bg), var(--color-bg) 3px, #eef2f7 3px, #eef2f7 6px); color: #94a3b8; }

.matrix-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
  font-size: 11px;
  color: var(--color-text-secondary);
}

.matrix-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}


/* Mobile rendering: one block per page. A table with eight language
   columns is not readable on a phone at any font size, so it is replaced
   rather than shrunk. */
.matrix-cards {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.matrix-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--color-bg);
}

.matrix-card-url {
  font-family: var(--font-mono);
  font-size: 11px;
  word-break: break-all;
  margin-bottom: 8px;
  color: var(--color-text);
}

.matrix-card-values {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

/* An hreflang value comes from a page we do not control and can be any
   length, so the chip has to wrap rather than stretch. test/ui.test.html
   asserts the page does not scroll sideways at 390px; these rules are what
   keeps that true for a value nobody anticipated. */
.matrix-card-value {
  display: inline-flex;
  align-items: flex-start;
  gap: 5px;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

/* --- Befundliste --- */
.finding-url {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-text-secondary);
  word-break: break-all;
  display: block;
  margin-bottom: 4px;
}

.finding-recommendation {
  margin-top: 6px;
  font-size: 13px;
}

.finding-recommendation strong {
  font-weight: 600;
}

.finding-explanation {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--color-border);
  font-size: 12px;
  line-height: 1.6;
  color: var(--color-text-secondary);
}

.finding-source {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: 1px;
}

/* --- Detailansicht pro URL --- */
.detail {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--color-bg);
}

.detail > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  font-size: 12px;
  font-family: var(--font-mono);
  word-break: break-all;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.detail > summary::-webkit-details-marker {
  display: none;
}

.detail > summary::before {
  content: '\25B8';
  flex: 0 0 auto;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--color-text-secondary);
  transition: transform 0.15s;
}

.detail[open] > summary::before {
  transform: rotate(90deg);
}

.detail > summary:hover {
  background: var(--color-border);
}

.detail-body {
  padding: 0 12px 12px;
  font-size: 12px;
}

.detail-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 8px;
  padding: 5px 0;
  border-top: 1px solid var(--color-border);
}

.detail-key {
  color: var(--color-text-secondary);
  font-weight: 600;
}

.detail-value {
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 11px;
}

.detail-value.plain {
  font-family: inherit;
  font-size: 12px;
}

.detail-status {
  font-weight: 700;
}

.detail-status.good { color: #15803d; }
.detail-status.bad { color: var(--color-danger); }

.detail-alt {
  display: block;
  padding: 1px 0;
}

.detail-alt code {
  font-weight: 700;
  color: var(--color-primary);
}

/* --- Responsive --- */
@media (max-width: 900px) {
  .container {
    grid-template-columns: 1fr;
    /* Stacked, the container's min-height would hand the leftover space
       to the input panel and push the result a screen further down. */
    min-height: 0;
  }

  .input-panel {
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .preview-panel {
    padding: 24px 16px;
  }
}

@media (max-width: 700px) {
  /* Fallstrick 15: below this width the table stops being readable no
     matter how it is scrolled, so the card rendering takes over. Both are
     in the DOM already; only which one is shown changes. */
  .matrix-scroll,
  .matrix-legend {
    display: none;
  }

  .matrix-cards {
    display: flex;
  }

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

@media (max-width: 500px) {
  /* Same deviation the UTM Builder made: the SERP Simulator's two fixed
     120px header columns collide with the logo below ~520px. */
  .header {
    padding: 16px;
    gap: 12px;
  }

  .header-spacer {
    display: none;
  }

  .header-logo-link {
    width: auto;
  }

  .header-logo {
    height: 26px;
  }

  .header-text {
    text-align: left;
    min-width: 0;
  }

  .header-title {
    font-size: 18px;
  }

  .header-subtitle {
    font-size: 12px;
  }

  .input-panel {
    padding: 16px;
  }

  .card {
    padding: 16px;
  }

  .footer {
    padding: 16px;
  }
}
