:root {
  --bg: #0f1419;
  --bg-card: #1a2332;
  --bg-hover: #243044;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --text-muted: #8b9bb4;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.5rem 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
  letter-spacing: -0.02em;
}

.brand span {
  color: var(--accent);
}

.nav-link {
  display: block;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  transition: 0.15s ease;
}

.nav-link:hover,
.nav-link.active {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}

.nav-link.active {
  color: #fff;
  background: rgba(59, 130, 246, 0.18);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.main {
  padding: 1.75rem 2rem 3rem;
  max-width: 1200px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.page-header .sub {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.2rem;
}

/* Cards */
.grid {
  display: grid;
  gap: 1rem;
}

.grid-4 {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

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

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    height: auto;
    position: relative;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

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

.card h2,
.card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.85rem;
  color: var(--text);
}

.stat-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.stat-value.sm {
  font-size: 1.15rem;
}

.stat-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Progress */
.progress {
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.75rem;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #60a5fa);
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: 0.15s ease;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: #2c3b52;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.35);
}

.btn-success {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.35);
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-success {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
}

.badge-failed,
.badge-danger {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
}

.badge-pending,
.badge-warning {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
}

.badge-skipped {
  background: rgba(139, 155, 180, 0.2);
  color: #cbd5e1;
}

.badge-on {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
}

.badge-off {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

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

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.truncate {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.url-cell {
  max-width: 360px;
  word-break: break-all;
  font-size: 0.8rem;
}

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

/* Forms */
.form-grid {
  display: grid;
  gap: 1.1rem;
  max-width: 640px;
}

.form-row {
  display: grid;
  gap: 0.35rem;
}

.form-row.inline {
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

select {
  cursor: pointer;
  appearance: auto;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.checkbox-row label {
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
}

.help {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-success {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #86efac;
}

.alert-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.alert-info {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #93c5fd;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(59, 130, 246, 0.12), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(99, 102, 241, 0.1), transparent 45%),
    var(--bg);
}

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

.login-card h1 {
  font-size: 1.4rem;
  margin-bottom: 0.35rem;
}

.login-card .sub {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.login-card .form-grid {
  max-width: none;
}

.login-card .btn {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.75rem;
}

.section-gap {
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 1rem;
}

.pagination-ellipsis {
  padding: 0 0.25rem;
  font-size: 0.9rem;
}

/* Expandable card sections (closed by default via <details>) */
.collapsible-card {
  padding: 0;
  overflow: hidden;
}

.collapsible-summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  padding: 1.1rem 1.25rem;
  margin: 0;
}

.collapsible-summary::-webkit-details-marker {
  display: none;
}

.collapsible-summary::before {
  content: "▸";
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1;
  margin-right: 0.15rem;
  transition: transform 0.15s ease;
}

.collapsible-card[open] > .collapsible-summary::before {
  content: "▾";
}

.collapsible-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.collapsible-hint {
  font-size: 0.85rem;
  margin-left: auto;
}

.collapsible-body {
  padding: 0 1.25rem 1.25rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.collapsible-summary:hover {
  background: var(--bg-hover);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
}

/* Visit Logs — keep ERROR column from blowing up the table */
.error-cell {
  max-width: 180px;
  font-size: 0.8rem;
  vertical-align: top;
}

.error-preview {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
  line-height: 1.35;
}

.error-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.75rem;
  margin-top: 0.25rem;
  user-select: none;
  list-style: none;
}

.error-details summary::-webkit-details-marker {
  display: none;
}

.error-details summary::before {
  content: "▸ ";
  font-size: 0.7rem;
}

.error-details[open] summary::before {
  content: "▾ ";
}

.error-full {
  margin-top: 0.4rem;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-width: 360px;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.72rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text-muted);
}

/* Name catalog admin */
.name-toc-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

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

.name-section-head h3 {
  margin-bottom: 0.25rem;
  font-size: 1.05rem;
}

.name-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-height: 320px;
  overflow-y: auto;
  padding: 0.15rem;
}

.name-chip {
  display: inline-block;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text);
  white-space: nowrap;
}

.name-chip:hover {
  border-color: var(--accent);
  color: #fff;
}

.name-sample-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.name-sample-list {
  list-style: none;
  margin-top: 0.4rem;
  padding: 0;
}

.name-sample-list li {
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.name-sample-list li:last-child {
  border-bottom: none;
}
