:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --card-muted: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-hover: #334155;
  --sidebar-active: #2563eb;
  --sidebar-width: 264px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body.ui-booting { display: block; }
body.ui-booting .admin-shell,
body.ui-booting .v2-shell,
body.ui-booting .auth-screen { display: none; }
body.ui-booting .boot-screen { display: flex; }

body.auth-locked { display: block; }
body.auth-locked .admin-shell,
body.auth-locked .v2-shell,
body.auth-locked .boot-screen { display: none; }
body.auth-locked .auth-screen { display: flex; }

.auth-screen {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #e2e8f0 0%, #f8fafc 100%);
}

.boot-screen {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #e2e8f0 0%, #f8fafc 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
  padding: 28px;
}

.boot-card {
  width: 100%;
  max-width: 420px;
  background: rgba(255,255,255,.84);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.08);
  padding: 28px;
  text-align: center;
}

.auth-card h1 { margin: 0 0 6px; font-size: 28px; }
.auth-card p { margin: 0 0 20px; color: var(--text-muted); }
.boot-card h1 { margin: 0 0 6px; font-size: 26px; }
.boot-card p { margin: 0; color: var(--text-muted); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-error { min-height: 20px; color: var(--danger); font-size: 13px; }

.boot-spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 14px;
  border-radius: 999px;
  border: 3px solid #cbd5e1;
  border-top-color: var(--primary);
  animation: boot-spin .8s linear infinite;
}

@keyframes boot-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.admin-shell,
.v2-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand h1 { margin: 0; font-size: 18px; color: #fff; }
.sidebar-brand p { margin: 4px 0 0; font-size: 11px; opacity: .75; }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-group { margin-bottom: 10px; }
.nav-label {
  padding: 8px 20px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  opacity: .8;
}

.nav-link, .nav-text {
  display: block;
  padding: 8px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
}

.nav-link:hover, .nav-subtext:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active, .nav-subtext.active {
  background: rgba(37,99,235,.15);
  color: #fff;
  font-weight: 600;
  border-right: 3px solid var(--sidebar-active);
}

.nav-text { font-size: 12px; padding-left: 36px; opacity: .8; }
.nav-subtext {
  display: block;
  padding: 7px 20px 7px 52px;
  font-size: 13px;
  color: var(--sidebar-text);
  text-decoration: none;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.header h2 { margin: 0; font-size: 22px; }
.header p { margin: 4px 0 0; color: var(--text-muted); }
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
}

.page {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.page-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
}

.section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15,23,42,.05);
}

.section-card-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.section-card-header h3 { margin: 0; font-size: 16px; }
.section-card-body { padding: 16px 18px 18px; }
.section-note, .helper-text { margin-top: 8px; color: var(--text-muted); font-size: 12px; }
.controls, .section-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.controls .sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { background: #f8fafc; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #059669; color: #fff; border-color: #059669; }
.btn-secondary:hover { background: #047857; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.pill.healthy { background: #dcfce7; color: #166534; }
.pill.unhealthy { background: #fee2e2; color: #991b1b; }
.pill.loading { background: #e2e8f0; color: #334155; }
.pill.pending_review { background: #fef3c7; color: #92400e; }
.pill.enabled { background: #dcfce7; color: #166534; }
.pill.ignored { background: #e2e8f0; color: #334155; }
.pill.idle { background: #e2e8f0; color: #334155; }
.pill.queued { background: #dbeafe; color: #1d4ed8; }
.pill.running { background: #fef3c7; color: #92400e; }
.pill.completed { background: #dcfce7; color: #166534; }
.pill.error { background: #fee2e2; color: #991b1b; }

.grid-2, .grid-3, .grid-4 { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat-card {
  background: var(--card-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.stat-card .label {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.field-label,
.label-with-help {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.help-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #dbeafe;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  flex-shrink: 0;
}

.help-tip::before,
.help-tip::after {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
  z-index: 30;
}

.help-tip::before {
  content: "";
  left: 50%;
  bottom: calc(100% + 2px);
  transform: translateX(-50%);
  border-width: 6px 5px 0 5px;
  border-style: solid;
  border-color: rgba(15, 23, 42, 0.94) transparent transparent transparent;
}

.help-tip::after {
  content: attr(data-tooltip);
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: max-content;
  max-width: min(320px, calc(100vw - 48px));
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.94);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
}

.help-tip:hover::before,
.help-tip:hover::after,
.help-tip:focus-visible::before,
.help-tip:focus-visible::after {
  opacity: 1;
}

.stat-card .value { margin-top: 6px; font-size: 24px; font-weight: 700; }
.key-value { display: grid; gap: 10px; }

.key-value-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.key-value-row:last-child { border-bottom: 0; padding-bottom: 0; }
.key-value-row .label { color: var(--text-muted); }
.key-value-row .value { text-align: right; word-break: break-word; }

label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}

input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}

textarea { min-height: 110px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-actions { margin-top: 14px; display: flex; gap: 10px; }
.form-row { display: grid; gap: 12px; }
.form-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

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

tr:last-child td { border-bottom: 0; }
.offer-row { cursor: pointer; transition: background .12s ease; }
.offer-row:hover { background: #f6f8fa; }
.offer-row.active-row { background: #eef2ff; }
.empty-state { padding: 28px 0; color: var(--text-muted); text-align: center; }
.status-line { min-height: 20px; color: var(--text-muted); font-size: 13px; }
.status-line.error { color: var(--danger); }
.status-line.success { color: var(--success); }
.muted { color: var(--text-muted); }
.table-actions { display: flex; gap: 8px; align-items: center; }
.table-actions .btn { padding: 6px 10px; }
.table-pagination {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.table-pagination-summary,
.table-pagination-page {
  color: var(--text-muted);
  font-size: 12px;
}

.table-pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-calendar-shell {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.search-calendar-controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.search-calendar-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card-muted);
}

.search-calendar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.search-calendar-title {
  font-size: 15px;
  font-weight: 700;
  text-transform: capitalize;
}

.search-calendar-subtitle {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.search-calendar-weekdays,
.search-calendar-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.search-calendar-weekday {
  padding: 10px 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.search-calendar-days {
  gap: 8px;
  padding: 0 14px 14px;
}

.search-calendar-day {
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-calendar-day.available {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 700;
  cursor: pointer;
}

.search-calendar-day.available:hover {
  background: #dbeafe;
}

.search-calendar-day.selected {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.search-calendar-day.muted {
  opacity: 0;
  pointer-events: none;
}

.run-expander {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.run-expander:hover { color: var(--primary-hover); }

.run-expander-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  color: var(--text-muted);
  transition: transform .16s ease;
}

.run-expander[aria-expanded="true"] .run-expander-icon {
  transform: rotate(90deg);
}

.run-details-row td {
  background: #f8fafc;
  white-space: normal;
  padding-top: 0;
}

.run-details-card {
  padding: 16px 6px 6px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.run-details-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.run-detail-field {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.run-detail-label {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.run-detail-value {
  margin-top: 6px;
  color: var(--text);
  font-weight: 600;
  word-break: break-word;
}

.run-detail-block {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.run-detail-title {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.run-detail-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.run-detail-list-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-muted);
}

.run-detail-code {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
}

.run-detail-meta {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.run-detail-empty {
  color: var(--text-muted);
  font-size: 13px;
}

.run-detail-error {
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
}

.summary-bar { display: flex; gap: 16px; padding: 0; flex-wrap: wrap; }
.summary-card {
  background: var(--card);
  border-radius: 8px;
  padding: 12px 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  min-width: 130px;
}
.summary-card .label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: .03em;
}
.summary-card .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.sort-arrow { margin-left: 4px; font-size: 10px; }
.pagination { display:flex; align-items:center; gap:6px; padding:12px 0; justify-content:center; flex-wrap:wrap; }
.pagination button { background:var(--card); border:1px solid var(--border); border-radius:6px; padding:4px 10px; cursor:pointer; font-size:13px; }
.pagination button:hover { background:var(--bg); }
.pagination button.active { background:var(--primary); color:#fff; border-color:var(--primary); }
.pagination button:disabled { opacity:.4; cursor:default; }
.pagination .page-info { font-size:12px; color:var(--text-muted); margin-left:8px; }

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop.open { display: flex; }

.modal {
  width: 100%;
  max-width: 720px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15,23,42,.22);
  overflow: hidden;
}

.modal-header,
.modal-footer {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-footer {
  border-bottom: 0;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-header h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px; }
.modal-close {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
}

.link-list { display: flex; flex-direction: column; gap: 8px; }
.link-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

@media (max-width: 1080px) {
  .page-grid, .grid-4, .grid-3, .run-details-grid { grid-template-columns: 1fr; }
}

@media (max-width: 840px) {
  .sidebar { position: static; width: 100%; }
  .admin-shell, .v2-shell { flex-direction: column; }
  .main { margin-left: 0; }
  .header { flex-direction: column; align-items: stretch; }
  .grid-2, .form-row.two, .form-row.three { grid-template-columns: 1fr; }
  .run-detail-list-row { grid-template-columns: 1fr; }
  .run-detail-meta { white-space: normal; }
  .table-pagination { flex-direction: column; align-items: stretch; }
}
