:root {
  --bg: #fbf7ef;
  --panel: #ffffff;
  --text: #202124;
  --muted: #5f6368;
  --line: #e6e0d8;
  --primary: #f7bb35;
  --primary-dark: #f4a51c;
  --primary-ink: #1f201d;
  --charcoal: #242520;
  --charcoal-dark: #1f201c;
  --soft: #fff4d8;
  --green: #209451;
  --amber: #b76b00;
  --red: #991b1b;
  --blue: #7a5600;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top right, rgba(247, 187, 53, .12), transparent 360px),
    var(--bg);
  color: var(--text);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  background: var(--charcoal);
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 6px;
}

.brand-logo {
  width: 50px;
  height: 50px;
  display: block;
  border-radius: 12px;
  object-fit: cover;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  color: var(--primary);
  font-size: 20px;
  letter-spacing: .01em;
}

.brand small {
  color: #d7d0c6;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #d7d0c6;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 750;
}

.nav-item:hover,
.nav-item.active {
  color: #111;
  background: var(--primary);
  border-color: var(--primary);
}

.app-shell {
  margin-left: 260px;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
}

.menu-toggle {
  display: none;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.topbar-title {
  min-width: 0;
}

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

.eyebrow,
.eyebrow-small {
  margin: 0 0 6px;
  color: #7c5b13;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.topbar-actions,
.filters,
.form-grid {
  display: flex;
  gap: 10px;
  align-items: center;
}

.manual-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) repeat(4, minmax(110px, 1fr));
  gap: 10px;
  align-items: center;
}

.token-input {
  max-width: 180px;
}

button {
  border: 0;
  background: var(--primary);
  color: var(--primary-ink);
  padding: 12px 15px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

button:hover { background: var(--primary-dark); }
button:disabled { opacity: .65; cursor: wait; }

button.secondary {
  background: #fff;
  color: var(--primary-ink);
  border: 1px solid var(--line);
}

button.secondary:hover { background: #fff4d8; }

.mini-btn {
  padding: 8px 10px;
  margin: 2px;
  font-size: 12px;
}

input,
select,
textarea {
  box-sizing: border-box;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 14px;
  outline: none;
  background: white;
  font: inherit;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(245, 182, 64, .24);
}

.hidden { display: none !important; }

.status {
  padding: 13px 15px;
  margin-bottom: 16px;
  color: var(--muted);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.status.ok {
  color: var(--green);
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.status.error {
  color: var(--red);
  background: #fef2f2;
  border-color: #fecaca;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: 0 12px 26px rgba(36, 37, 32, .06);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.stats-grid,
.run-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.run-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.stat-card {
  background: linear-gradient(180deg, #fff, #fffaf0);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.stat-card strong {
  display: block;
  font-size: 28px;
  line-height: 1;
  color: var(--charcoal);
}

.stat-card span {
  display: block;
  margin-top: 8px;
  font-weight: 850;
}

.stat-card small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, .65fr);
  gap: 16px;
}

.items {
  display: grid;
  gap: 12px;
}

.item-card {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 15px;
}

.item-card h3 {
  margin: 0 0 7px;
  font-size: 17px;
  line-height: 1.35;
}

.item-card p {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.5;
}

.card-title-row,
.report-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.report-actions,
.modal-actions,
.row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.row-actions {
  justify-content: flex-start;
  gap: 4px;
  min-width: 180px;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.badge,
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: #6d4700;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.active { background: #fff1d1; color: #6d4700; }
.status-pill.checked { background: #f1eee8; color: #5a5144; }
.status-pill.dead { background: #fee2e2; color: var(--red); }
.status-pill.duplicate { background: #fef3c7; color: var(--amber); }
.status-pill.health-ok { background: #dcfce7; color: #166534; }
.status-pill.health-warning { background: #fef3c7; color: var(--amber); }
.status-pill.health-failing { background: #fee2e2; color: var(--red); }
.status-pill.health-unknown { background: #f1eee8; color: #5a5144; }

.source-error {
  display: block;
  margin-top: 6px;
  color: var(--red);
  overflow-wrap: anywhere;
}

.source-status {
  display: grid;
  gap: 6px;
  min-width: 170px;
}

.source-status-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-status small {
  color: var(--muted);
  line-height: 1.35;
}

.source-notes {
  display: block;
  max-width: 520px;
  line-height: 1.45;
}

.anomaly-card {
  border-left: 4px solid var(--line);
}

.anomaly-card.severity-high {
  border-left-color: var(--red);
  background: #fff7f7;
}

.anomaly-card.severity-medium {
  border-left-color: var(--amber);
  background: #fffaf0;
}

.anomaly-card.severity-low {
  border-left-color: var(--primary);
}

.url-line {
  word-break: break-all;
}

a {
  color: var(--blue);
}

.source-table {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.run-details {
  margin-top: 16px;
}

.run-details h3 {
  margin: 0 0 10px;
}

.run-details table {
  min-width: 760px;
}

.source-check-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.source-check-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.source-check-row input {
  width: 16px;
  height: 16px;
}

.source-check-row strong,
.source-check-row small {
  display: block;
}

.source-check-row small {
  margin-top: 3px;
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: #fff8e8;
}

td small,
td a {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.empty,
.hint {
  color: var(--muted);
}

.mini-output {
  margin-top: 14px;
}

.api-docs code,
pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.endpoint-list {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.settings-card {
  display: grid;
  gap: 14px;
  margin: 18px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
}

.settings-card h3 {
  margin: 0 0 6px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.3fr) minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.settings-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.settings-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.schedule-grid {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  margin-bottom: 16px;
}

.admin-settings-grid {
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: end;
}

.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.settings-tab {
  background: #fff;
  color: var(--primary-ink);
  border: 1px solid var(--line);
}

.settings-tab.active {
  background: var(--primary);
  border-color: var(--primary);
}

.source-admin-grid {
  grid-template-columns: minmax(180px, 1fr) minmax(240px, 1.4fr) minmax(160px, 1fr) minmax(130px, .7fr);
  margin-bottom: 10px;
}

.endpoint {
  display: grid;
  grid-template-columns: 72px minmax(240px, .6fr) 1fr;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.endpoint p {
  margin: 0;
  color: var(--muted);
}

.method {
  display: inline-flex;
  justify-content: center;
  padding: 5px 8px;
  border-radius: 6px;
  color: white;
  font-weight: 900;
  font-size: 12px;
}

.method.get { background: var(--blue); }
.method.post { background: var(--primary); }

pre {
  overflow: auto;
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
  padding: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(31, 32, 28, .62);
}

.modal-panel {
  width: min(860px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 24px 80px rgba(31, 32, 28, .28);
}

.compact-modal {
  width: min(560px, 100%);
}

.source-modal-panel {
  width: min(780px, 100%);
  overflow-x: hidden;
}

.source-modal-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
  margin-bottom: 14px;
}

.source-modal-form label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.source-modal-panel textarea {
  min-height: 120px;
  resize: vertical;
}

.source-modal-panel .hint {
  max-width: 620px;
}

.source-modal-panel .modal-actions {
  justify-content: flex-end;
}

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

@media (max-width: 980px) {
  .sidebar {
    position: fixed;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 18px 0 50px rgba(31, 32, 28, .22);
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .nav {
    display: grid;
    overflow: visible;
    padding-bottom: 0;
  }

  .nav-item {
    width: 100%;
    padding: 12px 14px;
  }

  .app-shell {
    margin-left: 0;
    padding: 18px;
  }

  .panel-head,
  .topbar-actions,
  .filters,
  .manual-controls,
  .form-grid,
  .card-title-row,
  .report-card,
  .report-actions,
  .modal-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar {
    align-items: center;
  }

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

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

  .manual-controls {
    grid-template-columns: 1fr;
  }

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

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

  .admin-settings-grid {
    grid-template-columns: 1fr;
  }

  .source-admin-grid {
    grid-template-columns: 1fr;
  }

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

  .source-check-row {
    grid-template-columns: 20px minmax(0, 1fr);
  }
}

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

  .topbar h1 {
    font-size: 26px;
    line-height: 1.15;
  }

  .panel {
    padding: 14px;
  }

  button,
  .token-input {
    width: 100%;
  }

  .stats-grid,
  .run-grid,
  .run-grid.compact {
    grid-template-columns: 1fr 1fr;
  }

  .stat-card {
    padding: 12px;
  }

  .stat-card strong {
    font-size: 22px;
  }

  .item-card {
    padding: 13px;
  }

  .badge,
  .status-pill {
    max-width: 100%;
    overflow-wrap: anywhere;
    text-align: left;
  }

  .source-check-list {
    max-height: none;
  }

  .modal-backdrop {
    padding: 10px;
    place-items: stretch;
  }

  .modal-panel {
    max-height: calc(100vh - 20px);
    border-radius: 8px;
  }
}
