:root {
  color-scheme: light;
  --accent: #00aae3;
  --accent-strong: #0089b8;
  --accent-soft: #dcf0f8;
  --bg: #e9ecef;
  --surface: #f5f6f8;
  --text: #262b31;
  --muted: #6b7280;
  --border: #d5dadf;
  --ok: #1f9d55;
  --ok-soft: #dff0e6;
  --bad: #d64545;
  --bad-soft: #f5e1e1;
  /* Strefa testowa: ciepły, przygaszony odcień odróżniający ją od głównych wyników. */
  --test-bg: #ede6d8;
  --test-surface: #f5f0e6;
  --test-border: #d6c9ae;
  --test-ink: #8a6d2f;
  --radius: 12px;
  /* Minimalna wysokość elementów dotykowych (tablet). */
  --touch: 48px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Projekt pod tablet (pion ~768–834 px, poziom ~1024–1194 px); desktop korzysta z tych samych rozmiarów. */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 24px; }

/* Tablet poziomo / desktop: dwie kolumny, żeby formularz i wyniki zmieściły się na jednym ekranie. */
@media (min-width: 1000px) {
  .wrap { max-width: 1240px; }
  .layout { display: grid; grid-template-columns: minmax(0, 11fr) minmax(0, 9fr); gap: 20px; align-items: start; }
  .layout .card { margin-bottom: 0; }
  .output { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .steps { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .wrap { padding: 0 16px; }
}

button, select, summary, .btn { touch-action: manipulation; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 60px; padding-top: 6px; padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 18px; }
.brand-logo { width: auto; height: 72px; display: block; }

/* Okno logowania */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}
.login-box { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; margin: 0; }
.login-box .brand { margin-bottom: 8px; }
.login-box .error { margin: 0; }

/* Lokalizacja użytkownika w górnej belce */
.location { display: flex; gap: 12px; margin-left: auto; margin-right: 16px; }
.location-field { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.location-field input {
  font: inherit;
  font-size: 15px;
  width: 150px;
  min-height: 40px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
@media (max-width: 760px) {
  .topbar-inner { height: auto; flex-wrap: wrap; gap: 8px; padding-top: 8px; padding-bottom: 8px; }
  .location { margin: 0; width: 100%; }
  .location-field { flex: 1; }
  .location-field input { width: 100%; min-width: 0; }
}

/* Przełącznik widoku Prod / Test (tylko gdy serwer działa z TEST_MODE) */
.mode-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--test-bg);
  border: 1px solid var(--test-border);
}
.mode-switch button {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  border: 0;
  background: transparent;
  color: var(--test-ink);
  min-height: 40px;
  min-width: 72px;
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
}
.mode-switch button[aria-pressed="true"] { background: var(--test-ink); color: #fff; }
.mode-switch button[data-view="prod"][aria-pressed="true"] { background: var(--text); }

/* Elementy testowe znikają w widoku Prod */
body:not(.test-view) .test-only { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

h2 { font-size: 20px; margin: 0 0 14px; }

.field { display: block; margin-bottom: 16px; }
.label { display: block; font-weight: 600; font-size: 16px; margin-bottom: 8px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 14px; }
.tabular { font-variant-numeric: tabular-nums; }

textarea, input, select {
  width: 100%;
  font: inherit;
  color: inherit;
  background: #fbfbfc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  /* 16 px+ — Safari na iPadzie nie powiększa wtedy strony przy wpisywaniu. */
  font-size: 17px;
}
input, select { min-height: var(--touch); }
textarea { resize: vertical; }
textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.links { display: grid; gap: 10px; }
/* Etykieta | pole | przycisk usuwania; na wąskich ekranach etykieta nad polem. */
.link-row { display: grid; grid-template-columns: 72px minmax(0, 1fr) var(--touch); align-items: center; gap: 12px 16px; }
.link-row label { font-size: 16px; }
.remove-link {
  width: var(--touch); height: var(--touch);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.remove-link[hidden] { display: block !important; visibility: hidden; }
.add-link {
  margin: 10px 0 0 88px;
  min-height: 44px;
  padding: 8px 16px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-strong);
  background: transparent;
  border: 1px dashed var(--accent);
  border-radius: 10px;
  cursor: pointer;
}
.add-link span { font-size: 20px; margin-right: 4px; }
@media (hover: hover) {
  .add-link:hover { background: var(--accent-soft); }
  .remove-link:hover { color: var(--bad); border-color: var(--bad); }
}
@media (max-width: 600px) {
  .link-row { grid-template-columns: minmax(0, 1fr) var(--touch); gap: 4px 12px; }
  .link-row label { grid-column: 1 / -1; }
  .add-link { margin-left: 0; }
}
}

.field-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.field-head .label { margin-bottom: 0; }
.actions { display: flex; justify-content: flex-end; margin-top: 4px; }

/* Narzędzia testowe przy zapytaniu: przykłady + model, w kolorach strefy testowej */
.test-tools {
  display: inline-flex;
  align-items: stretch;
  flex-wrap: wrap;
  border: 1px dashed var(--test-border);
  background: var(--test-bg);
  border-radius: 8px;
  overflow: hidden;
  max-width: 100%;
}
.test-tools-tag {
  display: flex;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--test-ink);
  padding: 0 12px;
}
.test-tools select, .test-tools-btn {
  width: auto;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  min-height: 44px;
  padding: 6px 12px;
  border: 0;
  border-left: 1px dashed var(--test-border);
  border-radius: 0;
  background: var(--test-surface);
  cursor: pointer;
}
.test-tools .examples-select { max-width: 280px; }
.test-tools-btn { color: var(--test-ink); font-weight: 600; }
@media (hover: hover) { .test-tools-btn:hover { background: var(--test-bg); } }
.test-tools select:focus, .test-tools-btn:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent-soft); }

.field-head { flex-wrap: wrap; }


.btn {
  font: inherit;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  font-size: 18px;
  min-height: 52px;
  padding: 12px 32px;
  cursor: pointer;
  min-width: 180px;
}
@media (hover: hover) { .btn:hover { background: var(--accent-strong); } }
.btn:active { background: var(--accent-strong); }
.btn:disabled { opacity: .6; cursor: progress; }

.error {
  margin: 16px 0 0;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--bad-soft);
  color: var(--bad);
}

.error-details { margin-top: 4px; color: var(--text); font-size: 14px; line-height: 1.45; }
/* Duży obszar dotyku dla „Szczegóły”. */
.error-details summary { cursor: pointer; color: var(--bad); font-weight: 600; font-size: 15px; width: max-content; padding: 8px 0; }
.error-details dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 3px 16px;
  margin: 0;
  padding: 10px 14px;
  background: rgba(255, 255, 255, .55);
  border-radius: 6px;
}
.error-details dt { color: var(--muted); }
.error-details dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
@media (max-width: 600px) {
  .error-details dl { grid-template-columns: 1fr; }
  .error-details dd { margin-bottom: 6px; }
}

/* Postęp */
.progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 12px; }
#progressTime { flex: none; white-space: nowrap; }
.progress-label { font-weight: 600; font-size: 17px; }

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: inherit;
  transition: width .3s ease-out;
  position: relative;
  overflow: hidden;
}
/* Delikatny połysk sygnalizujący, że praca trwa. */
.bar-fill::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}
.progress.done .bar-fill::after, .progress.failed .bar-fill::after { display: none; }
.progress.done .bar-fill { background: var(--ok); }
.progress.failed .bar-fill { background: var(--bad); }
@keyframes shimmer { to { transform: translateX(100%); } }

.steps {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  font-size: 15px;
  color: var(--muted);
}
.steps li { display: flex; align-items: center; gap: 8px; }
.step-dot {
  flex: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
}
.steps li.active { color: var(--text); font-weight: 600; }
.steps li.active .step-dot {
  border-color: var(--accent);
  background: var(--accent);
  animation: pulse 1.4s infinite;
}
.steps li.done { color: var(--text); }
.steps li.done .step-dot { border-color: var(--ok); background: var(--ok); }
.progress.failed .steps li.active .step-dot { border-color: var(--bad); background: var(--bad); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(0, 170, 227, .5); }
  70%, 100% { box-shadow: 0 0 0 6px rgba(0, 170, 227, 0); }
}

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

/* Wyniki per link */
/* minmax(0, 1fr): długie adresy skracają się wielokropkiem zamiast poszerzać kartę. */
.link-results { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.link-result {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fbfbfc;
}
.link-result .icon {
  flex: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 17px;
}
.link-result.found .icon { background: var(--ok-soft); color: var(--ok); }
.link-result.missing .icon, .link-result.invalid .icon { background: var(--bad-soft); color: var(--bad); }
.link-result .body { min-width: 0; flex: 1; }
.link-result .url { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-result .status { font-size: 15px; color: var(--muted); }
.link-result .matches { margin: 4px 0 0; padding-left: 20px; font-size: 15px; }
.link-result .matches li { padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.same-domain { margin-top: 4px; font-size: 14px; color: var(--muted); }
.same-domain summary { cursor: pointer; padding: 6px 0; width: max-content; max-width: 100%; }
.link-result .matches a { color: var(--accent-strong); }
.link-result .matches.other a { color: var(--muted); }
.hint { margin: -2px 0 12px; }
.hint code { font-size: 13px; background: var(--bg); padding: 0 4px; border-radius: 3px; }

/* Strefa testowa */
.test-zone {
  background: var(--test-bg);
  border: 1px dashed var(--test-border);
  border-radius: 14px;
  padding: 16px 16px 0;
  margin: 32px 0 40px;
}
.test-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--test-ink);
  margin: 0 4px 12px;
}
.test-card { background: var(--test-surface); border-color: var(--test-border); margin-bottom: 14px; }

.stats { display: flex; flex-wrap: wrap; gap: 8px 32px; margin: 0; }
.stats dt { font-size: 14px; color: var(--muted); }
.stats dd { margin: 0; }

.legend { color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }

.tag {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 1px 9px;
  border-radius: 999px;
  vertical-align: 1px;
}
.tag-hit { background: var(--accent); color: #fff; }
.tag-domain { background: transparent; color: var(--muted); border: 1px solid var(--border); }

.all-urls { margin: 0; padding-left: 24px; font-size: 15px; }
.all-urls li { margin-bottom: 12px; word-break: break-all; }
.all-urls li.empty { list-style: none; margin-left: -24px; }
.all-urls a { color: var(--text); }
.all-urls li.hit a { color: var(--accent-strong); font-weight: 600; }
.all-urls .url-meta { color: var(--muted); font-size: 14px; word-break: normal; }

.answer-card { margin-top: 20px; }
.answer { overflow-wrap: anywhere; }
.answer p { margin: 0 0 10px; }
.answer h4 { margin: 14px 0 6px; }
.answer a { color: var(--accent-strong); }
.answer a.target {
  background: var(--accent);
  color: #fff;
  border-radius: 3px;
  padding: 0 4px;
  text-decoration: none;
  font-weight: 600;
}

/* Podpowiedź przed pierwszym sprawdzeniem */
.placeholder { border-style: dashed; background: transparent; color: var(--text); }
.placeholder p { margin: 0 0 6px; }
.placeholder p:last-child { margin: 0; }
.credit-low { color: var(--bad); font-weight: 600; }
