:root {
  --bg: #0b0c10;
  --panel: #111318;
  --header: rgba(13, 16, 23, 0.85);
  --border: #1f2227;
  --border-soft: #242832;
  --text: #e6e6e6;
  --muted: #9aa3ad;
  --accent: #61ce70;
  --danger: #ef4444;
  --pill-ok: #10b981;
  --pill-baseline: #fa7e60;
  --pill-neutral: #6b7280;
  --diff-low: #facc15;
  --diff-medium: #fb923c;
  --diff-high: #ef4444;
  --diff-critical: #991b1b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: #90caf9;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

main {
  flex: 1 0 auto;
}

.container {
  padding: 24px;
  max-width: 1500px;
  margin: 0 auto;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.app-header__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.nav {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 18px 24px rgba(0, 0, 0, 0.25);
}

.system-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 1.5rem;
  margin: 0 auto;
  padding: 1rem;
}

.system-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 18px 24px rgba(0, 0, 0, 0.25);
  height: fit-content;
  margin-bottom: 0;
}

@media (max-width: 768px) {
  .system-grid {
    grid-template-columns: 1fr;
    padding: 0.5rem;
  }
}

.card h2,
.card h3,
.card h4 {
  margin-top: 0;
  margin-bottom: 12px;
  font-weight: 600;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(36, 43, 56, 0.65);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.btn:hover {
  background: rgba(61, 128, 248, 0.15);
  border-color: rgba(96, 165, 250, 0.6);
  text-decoration: none;
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

button.btn {
  border-width: 1px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-heading {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field__label {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.form-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

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

.header-actions__content {
  flex: 1;
}

.header-actions__content h2 {
  margin: 0 0 6px 0;
}

.header-actions__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.schedule-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  width: 100%;
  margin: 0;
}

.schedule-toggle {
  grid-column: 1 / -1;
  position: relative;
}

.schedule-toggle__control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch__slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  transition: background 0.2s ease;
}

.switch__slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 4px;
  bottom: 3px;
  background: #0f172a;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.switch input:checked + .switch__slider {
  background: rgba(97, 206, 112, 0.45);
}

.switch input:checked + .switch__slider::before {
  transform: translateX(20px);
}

[data-schedule-section].is-disabled {
  opacity: 0.6;
}

[data-smtp-section].is-disabled {
  opacity: 0.65;
}

[data-smtp-section].is-disabled input,
[data-smtp-section].is-disabled select,
[data-smtp-section].is-disabled textarea {
  pointer-events: none;
}

input,
select,
textarea,
button {
  font-family: inherit;
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(19, 23, 30, 0.9);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(96, 165, 250, 0.75);
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.25);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
}

.stack-table {
  width: 100%;
}

.stack-table--kv .stack-table__key {
  font-weight: 600;
  width: 38%;
}

.stack-table--kv .stack-table__value {
  width: 62%;
}

thead th {
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  color: #cbd5e1;
  padding: 6px 10px;
}

tbody tr {
  background: rgba(17, 20, 27, 0.9);
  border: 1px solid var(--border);
}

tbody td {
  padding: 10px;
  vertical-align: top;
  font-size: 14px;
}

.stack-table--kv .stack-table__key,
.stack-table--kv .stack-table__value {
  display: table-cell;
}

.nowrap {
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.pill.ok {
  background: var(--pill-ok);
}

.pill.baseline {
  background: #60a5fa; /* Blue for real baselines */
}

.pill.placeholder-warning {
  background: #f97316; /* Orange for placeholder baselines */
}

.pill.alert,
.pill.fail,
.pill.error {
  background: var(--danger);
}

.pill.neutral {
  background: var(--pill-neutral);
}

.pill.diff-low {
  background: var(--diff-low);
  color: #1f2937;
}

.pill.diff-medium {
  background: var(--diff-medium);
  color: #1f2937;
}

.pill.diff-high {
  background: var(--diff-high);
  color: #fee2e2;
}

.pill.diff-critical {
  background: var(--diff-critical);
  color: #fee2e2;
}

.status-card {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-top: 10px;
}

.status-card__tile {
  background: rgba(15, 19, 26, 0.9);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.status-card__tile h4 {
  margin: 0 0 8px 0;
  font-size: 15px;
}

.status-card__metric {
  display: block;
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 6px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: rgba(8, 10, 15, 0.95);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  z-index: 10000;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.toast a {
  color: #10b981;
  text-decoration: underline;
  font-weight: 500;
}

.capture-overlay.show {
  display: flex;
}

.capture-overlay__content {
  background: rgba(15, 19, 26, 0.95);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 22px 40px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  position: relative;
  z-index: 1;
}

.capture-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 17, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 32px;
  z-index: 2000;
  pointer-events: none;
}

.capture-overlay__content p {
  margin: 18px 0 0 0;
  font-size: 15px;
  line-height: 1.5;
}

.capture-overlay .spinner {
  width: 52px;
  height: 52px;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: vw-spin 1s linear infinite;
  margin: 0 auto;
}

body.overlay-active {
  overflow: hidden;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.status-badge--red {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.status-badge--green {
  background: rgba(16, 185, 129, 0.18);
  color: #86efac;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.status-badge--amber {
  background: rgba(251, 191, 36, 0.2);
  color: #fcd34d;
  border: 1px solid rgba(251, 191, 36, 0.4);
}

.status-badge--grey {
  background: rgba(148, 163, 184, 0.16);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.status-badge--diff-low {
  background: rgba(250, 204, 21, 0.2);
  color: #facc15;
  border: 1px solid rgba(250, 204, 21, 0.45);
}

.status-badge--diff-medium {
  background: rgba(251, 146, 60, 0.2);
  color: #fb923c;
  border: 1px solid rgba(251, 146, 60, 0.45);
}

.status-badge--diff-high {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.status-badge--diff-critical {
  background: rgba(153, 27, 27, 0.23);
  color: #fecaca;
  border: 1px solid rgba(153, 27, 27, 0.5);
}

.app-footer {
  flex-shrink: 0;
  padding: 16px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  background: rgba(15, 18, 24, 0.9);
  border-top: 1px solid var(--border);
}

.pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}

.pair > .tile {
  min-width: 0;
}

.pair .shot {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 0 12px 18px rgba(0, 0, 0, 0.22);
}

.shot-scroll {
  max-height: 70vh;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 0 12px 18px rgba(0, 0, 0, 0.22);
  background: rgba(8, 11, 17, 0.9);
}

.shot-scroll--current {
  max-height: 70vh;
}

.shot-scroll--history {
  max-height: 300px;
}

.shot-scroll .shot {
  border-radius: 0;
  border: none;
  box-shadow: none;
  display: block;
  width: 100%;
}

.shot--flush {
  border-radius: 0;
  border: none;
  box-shadow: none;
}

.tile {
  background: rgba(16, 20, 26, 0.96);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  transition: border-color 0.4s ease, background-color 0.4s ease;
}

.tile h4 {
  margin: 0 0 10px 0;
  font-size: 15px;
}

.tile.curr-neutral {
  background: rgba(16, 21, 29, 0.95);
}

.tile.curr-diff {
  border-color: rgba(239, 68, 68, 0.45);
}

.tile.curr-ok {
  border-color: rgba(16, 185, 129, 0.45);
}

.tile.curr-changed {
  border-color: rgba(239, 68, 68, 0.6);
}

.tile.curr-unchanged {
  border-color: rgba(16, 185, 129, 0.6);
}

.tile.curr-diff-low {
  border-color: rgba(250, 204, 21, 0.55);
  background: rgba(250, 204, 21, 0.08);
}

.tile.curr-diff-medium {
  border-color: rgba(251, 146, 60, 0.6);
  background: rgba(251, 146, 60, 0.1);
}

.tile.curr-diff-high {
  border-color: rgba(239, 68, 68, 0.7);
  background: rgba(239, 68, 68, 0.12);
}

.tile.curr-diff-critical {
  border-color: rgba(153, 27, 27, 0.75);
  background: rgba(153, 27, 27, 0.15);
}

.tile.curr-failed {
  border-color: rgba(239, 68, 68, 0.75);
  background: rgba(239, 68, 68, 0.08);
}

.tile.curr-missing {
  border-color: rgba(148, 163, 184, 0.5);
}

.tile.curr-placeholder {
  border-color: rgba(249, 115, 22, 0.45);
  background: rgba(249, 115, 22, 0.08);
}

code {
  font-family: "Fira Code", "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  padding: 2px 5px;
}

iframe.hidden-iframe {
    display: none;
}

@media (max-width: 768px) {
  .app-header__inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .container {
    padding: 18px;
  }

  .row {
    flex-direction: column;
  }

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

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

  table {
    font-size: 13px;
  }

  .stack-table thead {
    display: none;
  }

  .stack-table tbody tr {
    display: block;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
  }

  .stack-table tbody tr:last-child {
    margin-bottom: 0;
  }

  .stack-table tbody tr td {
    display: block;
    padding: 6px 0;
    border: none;
  }

  .stack-table tbody tr td + td {
    border-top: 1px solid var(--border-soft);
    margin-top: 6px;
    padding-top: 8px;
  }

  .stack-table tbody tr td[data-label] {
    display: block;
  }

  .stack-table tbody tr td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
  }

  .stack-table--sites tbody tr td:first-child {
    padding-bottom: 10px;
    margin-bottom: 6px;
  }

  .stack-table--sites tbody tr td:first-child + td {
    border-top: 1px solid var(--border-soft);
  }

  .stack-table--kv tbody tr {
    padding: 12px 14px;
  }

  .stack-table--kv .stack-table__key {
    display: block;
    width: 100%;
    font-size: 12px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
  }

  .stack-table--kv .stack-table__value {
    display: block;
    width: 100%;
    padding-top: 0;
  }

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

  /* Make all buttons full width on mobile */
  .card .row {
    width: 100%;
  }

  .card .row .btn,
  .card .row form,
  .card .row button {
    width: 100%;
  }

  .card .row form {
    display: block;
  }

  .card .row .btn,
  .card .row form button {
    display: block;
    width: 100%;
    text-align: center;
  }

  /* Left align all headings in cards */
  .card h1,
  .card h2,
  .card h3,
  .card h4 {
    text-align: left;
  }

  /* Header actions responsive */
  .header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions__buttons {
    flex-direction: column;
    width: 100%;
  }

  .header-actions__buttons .btn,
  .header-actions__buttons form {
    width: 100%;
  }

  .header-actions__buttons form button {
    width: 100%;
  }
}

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

.run-preview-row {
  transition: opacity 0.2s ease-in-out;
}

.run-preview-row td {
  padding: 16px !important;
  background: rgba(0, 0, 0, 0.2);
}

.run-preview-row .preview {
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

[data-schedule-section].is-disabled [data-schedule-setting] input,
[data-schedule-section].is-disabled [data-schedule-setting] select,
[data-schedule-section].is-disabled [data-schedule-setting] textarea {
  pointer-events: none;
}

/* Capture loader in current tile */
.capture-loader {
  text-align: center;
  padding: 2rem 1rem;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.capture-loader .spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: vw-spin 1s linear infinite;
}

.capture-loader .muted {
  margin-top: 1rem;
  font-size: 14px;
}

/* Smooth transitions for all tile content */
.tile img,
.tile .muted,
.tile h4 {
  transition: opacity 0.2s ease;
}

/* Zone overlays should also transition smoothly */
.zone-overlay {
  transition: opacity 0.3s ease;
}

/* Additional mobile enhancements */
@media (max-width: 768px) {
  /* Ensure container has proper padding on mobile */
  .container {
    padding: 16px;
  }

  /* Make cards more compact on mobile */
  .card {
    padding: 14px 16px;
    margin-bottom: 14px;
  }

  /* Better font sizes for mobile */
  body {
    font-size: 14px;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 20px;
  }

  h3 {
    font-size: 18px;
  }

  h4 {
    font-size: 16px;
  }

  /* Improve form layout on mobile */
  .form-grid {
    grid-template-columns: 1fr;
  }

  /* Better button sizing on mobile */
  .btn {
    padding: 12px 18px;
    font-size: 15px;
    min-height: 44px; /* iOS touch target recommendation */
  }

  /* Make inputs larger for mobile */
  input,
  select,
  textarea {
    font-size: 16px; /* Prevents iOS zoom on focus */
    min-height: 44px;
    padding: 10px 14px;
  }

  /* Quality metrics grid - stack on mobile */
  div[style*="grid-template-columns:repeat(auto-fit,minmax(200px,1fr))"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  /* Better image display on mobile */
  .tile img,
  .shot {
    max-width: 100%;
    height: auto;
  }

  /* Improve table actions on mobile */
  .nowrap {
    white-space: normal !important;
    word-break: break-word;
  }

  /* Better status pills on mobile */
  .pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 6px 12px;
  }

  /* Scrollable tables on mobile if needed */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Better navigation spacing on mobile */
  .nav {
    gap: 8px;
    flex-wrap: wrap;
  }

  /* Improve app header on mobile */
  .app-header__inner {
    padding: 12px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .brand {
    font-size: 18px;
  }

  /* Better zone display on mobile */
  .zone-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  /* Improve modal/overlay on mobile */
  .modal,
  .overlay {
    padding: 16px;
  }

  /* Better spacing for muted text on mobile */
  .muted {
    font-size: 13px;
  }

  /* Fix long URLs on mobile */
  a {
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* Better toast notifications on mobile */
  #toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    max-width: calc(100% - 32px);
  }
}

/* Small mobile devices (<480px) */
@media (max-width: 480px) {
  .container {
    padding: 12px;
  }

  .card {
    padding: 12px;
    border-radius: 10px;
  }

  /* Even smaller text on very small screens */
  body {
    font-size: 13px;
  }

  h1 {
    font-size: 20px;
  }

  h2 {
    font-size: 18px;
  }

  h3 {
    font-size: 16px;
  }

  /* Compact buttons on small screens */
  .btn {
    padding: 10px 14px;
    font-size: 14px;
  }

  /* Single column for everything */
  .row {
    flex-direction: column;
  }

  /* Override inline flex styles on mobile */
  .card[style*="display:flex"] {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  /* Make flex items full width on mobile */
  [style*="flex:2"],
  [style*="flex:1"] {
    flex: 1 1 100% !important;
    min-width: 100% !important;
  }
}

/* Touch-friendly improvements for all screen sizes */
@media (hover: none) and (pointer: coarse) {
  /* Increase touch targets on touch devices */
  .btn,
  button,
  a.btn,
  input[type="button"],
  input[type="submit"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Better spacing for touch on interactive elements */
  .stack-table tbody tr {
    padding: 16px;
  }

  /* Larger click areas for status cells */
  td[data-status-cell] {
    padding: 14px !important;
  }
}
