:root {
  --bg: #0f1419;
  --bg-elevated: #1a2129;
  --bg-card: #1e2730;
  --border: #2d3844;
  --text: #e8edf2;
  --muted: #8b9aab;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --sidebar-w: 280px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.875rem; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(59, 130, 246, 0.12), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(34, 197, 94, 0.08), transparent 50%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login-brand { text-align: center; margin-bottom: 1.75rem; }
.login-brand h1 { margin: 0.75rem 0 0.25rem; font-size: 1.5rem; }

.logo-dot {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #06b6d4);
}

.login-foot { margin-top: 1.25rem; text-align: center; font-size: 0.8rem; }

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.sidebar-brand .logo-dot { width: 36px; height: 36px; margin: 0; border-radius: 10px; }
.sidebar-brand strong { display: block; font-size: 0.95rem; }

.nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 0.75rem;
  overflow-y: auto;
}

.nav-section {
  margin: 0.85rem 0.5rem 0.3rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-section:first-child {
  margin-top: 0.15rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.nav-link.active { background: rgba(59, 130, 246, 0.15); color: var(--text); }

.nav-icon { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.nav-icon-blue { background: #3b82f6; }
.nav-icon-green { background: #22c55e; }
.nav-icon-purple { background: #a855f7; }
.nav-icon-cyan { background: #06b6d4; }
.nav-icon-amber { background: #f59e0b; }
.nav-icon-red { background: #ef4444; }
.nav-icon-slate { background: #94a3b8; }
.nav-icon-orange { background: #f97316; }
.nav-icon-indigo { background: #6366f1; }
.nav-icon-teal { background: #14b8a6; }
.nav-icon-pink { background: #ec4899; }

.sidebar-foot {
  padding: 1rem 1.25rem 0;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.sidebar-foot .btn {
  font-weight: 600;
}

.session-meta { margin: 0.5rem 0 0; font-size: 0.75rem; text-align: center; }

#logout-btn-top {
  color: var(--muted);
  border-color: var(--border);
}

#logout-btn-top:hover {
  color: var(--text);
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(239, 68, 68, 0.08);
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.topbar h2 { margin: 0; font-size: 1.35rem; }
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; justify-content: flex-end; }
.page-content { flex: 1; padding: 1.5rem 2rem 2.5rem; overflow-y: auto; }

.refresh-meta {
  font-size: 0.75rem;
  white-space: nowrap;
  min-width: 7.5rem;
  text-align: right;
}

.autorefresh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.autorefresh-toggle input {
  width: auto;
  margin: 0;
  accent-color: var(--primary);
}

.page-hint {
  margin: 0 0 1rem;
  font-size: 0.875rem;
}

.toolbar label {
  margin-bottom: 0;
}

.toolbar input[type="text"] {
  width: auto;
  min-width: 280px;
  margin-bottom: 0;
}

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 0.4rem;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
  animation: live-pulse 2s ease-out infinite;
}

@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.section-title {
  margin: 1.5rem 0 0.85rem;
  font-size: 1rem;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 1.5rem 1rem !important;
}

.time-rel { cursor: help; border-bottom: 1px dotted var(--border); }

.page-refreshing .table-wrap,
.page-refreshing .log-viewer,
.page-refreshing .grid {
  opacity: 0.92;
  transition: opacity 0.15s;
}

.page-error {
  margin: 1rem 2rem 0;
  padding: 0.85rem 1rem;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 0.9rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-card); border-color: var(--border); color: var(--text); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }

label { display: block; margin-bottom: 0.4rem; font-size: 0.85rem; color: var(--muted); }

input, select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

.form-error { color: #fca5a5; font-size: 0.85rem; margin: -0.5rem 0 0; }

.status-pill {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-ok { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.status-warn { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.status-bad { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.status-unknown { background: rgba(139, 154, 171, 0.15); color: var(--muted); }

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

@media (max-width: 1100px) {
  .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar, .page-content { padding-left: 1rem; padding-right: 1rem; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card h3 { margin: 0 0 0.75rem; font-size: 0.95rem; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }

.card-ok { border-left: 3px solid var(--success); }
.card-warn { border-left: 3px solid var(--warning); }
.card-bad { border-left: 3px solid var(--danger); }
.card-info { border-left: 3px solid var(--primary); }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 0.65rem 0.85rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg-elevated); color: var(--muted); font-weight: 500; white-space: nowrap; }
tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-ok { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.badge-warn { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-bad { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.badge-neutral { background: rgba(139, 154, 171, 0.15); color: var(--muted); }

.kpi {
  font-size: 1.75rem;
  font-weight: 650;
  margin: 0.35rem 0;
  letter-spacing: -0.02em;
}

.log-viewer {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.55;
  background: #0a0e12;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.15rem;
  max-height: 70vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 2;
}

.toolbar-check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0;
}

.toolbar-check input {
  width: auto;
  margin: 0;
}

.toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-bottom: 1rem; }
.toolbar select { width: auto; min-width: 160px; margin-bottom: 0; }

.ops-list { list-style: none; padding: 0; margin: 0; }
.ops-list li { padding: 0.85rem 0; border-bottom: 1px solid var(--border); }
.ops-list code {
  display: block;
  margin-top: 0.35rem;
  padding: 0.5rem 0.65rem;
  background: #0a0e12;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: #93c5fd;
}

.a { color: #93c5fd; }
.job-link { color: #93c5fd; text-decoration: none; font-family: var(--mono); font-size: 0.8rem; }
.mono { font-family: var(--mono); font-size: 0.85rem; }
.job-link:hover { text-decoration: underline; }

.trace-step { padding: 1rem; }

.trace-summary {
  margin-bottom: 1rem;
}

.trace-summary-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.trace-subject {
  margin: 0.15rem 0 0;
  font-size: 1.15rem;
  line-height: 1.35;
  word-break: break-word;
}

.trace-summary-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.trace-summary-actions .btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.detail-cell {
  min-width: 180px;
  max-width: 420px;
  vertical-align: top;
}

.api-resp {
  margin-top: 0.45rem;
  font-size: 0.78rem;
}

.api-resp summary {
  cursor: pointer;
  color: #93c5fd;
  user-select: none;
}

.api-resp summary:hover {
  text-decoration: underline;
}

.api-resp-pre {
  margin: 0.45rem 0 0;
  padding: 0.65rem 0.75rem;
  max-height: 280px;
  overflow: auto;
  background: #0a0e12;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: #e2e8f0;
}

.trace-api-response {
  margin-top: 0.75rem;
}

.job-cell { white-space: nowrap; }
.btn-link {
  margin-left: 0.5rem;
  padding: 0;
  border: none;
  background: none;
  color: #a5b4fc;
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: underline;
}
.btn-link:hover { color: #c7d2fe; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(2px);
}
.modal-panel {
  position: relative;
  width: min(1180px, 96vw);
  height: min(92vh, 1100px);
  max-height: 92vh;
  overflow: hidden;
  margin: 0;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.35rem 1rem;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
  flex-shrink: 0;
}
.modal-head-text { min-width: 0; }
.modal-eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.modal-head h3 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.35;
  word-break: break-word;
}
.preview-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem 1rem;
  margin-bottom: 0.85rem;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.preview-meta-item { min-width: 0; }
.preview-meta-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.15rem;
}
.preview-meta-value {
  display: block;
  font-size: 0.85rem;
  line-height: 1.35;
  word-break: break-word;
}
.preview-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}
.preview-tab {
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
}
.preview-tab.active {
  background: rgba(59, 130, 246, 0.15);
  color: var(--text);
  border-color: rgba(59, 130, 246, 0.4);
}
.preview-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.preview-pane-html {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  min-height: 420px;
}
.preview-frame {
  width: 100%;
  height: 100%;
  min-height: 420px;
  border: 0;
  background: #fff;
  display: block;
  flex: 1;
}
.preview-loader {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  background: rgba(248, 250, 252, 0.92);
  color: #334155;
}
.preview-loader.hidden { display: none; }
.preview-loader-spin {
  width: 36px;
  height: 36px;
  border: 3px solid #cbd5e1;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: preview-spin 0.7s linear infinite;
}
.preview-loader-text {
  margin: 0;
  font-size: 0.9rem;
  color: #64748b;
}
@keyframes preview-spin {
  to { transform: rotate(360deg); }
}
.preview-pane-text {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.preview-text {
  margin: 0;
  padding: 1rem 1.1rem;
  min-height: 420px;
  background: #0a0e12;
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.preview-foot {
  margin: 0.75rem 0 0;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.mini-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.alert-banner { border-color: rgba(245, 158, 11, 0.45); }

.heat-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
  min-width: 80px;
}

.heat-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #06b6d4);
  border-radius: 999px;
}

.heat-bar-warn > span {
  background: linear-gradient(90deg, var(--warning), var(--danger));
}

.queue-layout { align-items: start; }

.queue-job-row { cursor: pointer; }
.queue-job-row:hover { background: rgba(255, 255, 255, 0.03); }
.queue-job-row.selected { background: rgba(59, 130, 246, 0.12); }

.queue-job-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.queue-job-edit-label {
  display: block;
  margin: 0.75rem 0;
}

.queue-job-edit-label input {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.btn-danger {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.35);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.12);
}

.queue-job-payload summary {
  cursor: pointer;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.queue-job-payload pre {
  max-height: 280px;
  overflow: auto;
  font-size: 0.78rem;
}

.toolbar-wrap {
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
}

.toolbar-wrap label input[type="search"] {
  min-width: 9rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.sparkline-wrap { margin-top: 0.5rem; }

.sparkline {
  display: grid;
  grid-template-columns: repeat(24, minmax(0, 1fr));
  gap: 4px;
  align-items: end;
  height: 120px;
  padding: 0.5rem 0;
}

.spark-bar {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
}

.spark-stack {
  display: flex;
  flex-direction: column-reverse;
  width: 100%;
  min-height: 6px;
  border-radius: 4px 4px 0 0;
  overflow: hidden;
}

.spark-ok { background: var(--success); width: 100%; }
.spark-fail { background: var(--danger); width: 100%; }

.sparkline-legend {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.35rem;
}

.spark-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.25rem;
}

.spark-dot-ok { background: var(--success); }
.spark-dot-fail { background: var(--danger); }

.tls-renew-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1rem;
  align-items: start;
}

.tls-countdown-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background:
    conic-gradient(var(--primary) calc(var(--pct) * 1%), rgba(255,255,255,0.08) 0);
  display: grid;
  place-items: center;
  padding: 8px;
}

.tls-countdown-warn .tls-countdown-ring {
  background:
    conic-gradient(var(--warning) calc(var(--pct) * 1%), rgba(255,255,255,0.08) 0);
}

.tls-countdown-bad .tls-countdown-ring {
  background:
    conic-gradient(var(--danger) calc(var(--pct) * 1%), rgba(255,255,255,0.08) 0);
}

.tls-countdown-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.tls-countdown-days {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.tls-countdown-label {
  font-size: 0.75rem;
  color: var(--muted);
}

@media (max-width: 900px) {
  .tls-renew-grid { grid-template-columns: 1fr; }
  .sparkline { grid-template-columns: repeat(12, minmax(0, 1fr)); }
}
