:root {
  color-scheme: dark;
  --bg: #0c0e12;
  --bg-elevated: #141820;
  --bg-card: #181d27;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #e8eaed;
  --text-muted: #8b939e;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(59, 130, 246, 0.15), transparent),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

.hidden {
  display: none !important;
}

.app {
  min-height: 100vh;
}

.view {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* Login */
.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

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

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.login-sub {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.login-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.logo-mark.sm {
  width: 36px;
  height: 36px;
  font-size: 0.75rem;
  border-radius: 10px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

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

.btn-secondary {
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
  background: #1f2633;
}

.btn-ghost {
  color: var(--text-muted);
  background: transparent;
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

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

.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

.btn-icon {
  min-width: 38px;
  padding: 0;
  font-size: 1.1rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.btn-icon:hover {
  color: var(--text);
  background: #1f2633;
}

.btn-link {
  min-height: auto;
  padding: 4px 8px;
  color: var(--accent);
  background: transparent;
  font-size: 0.8rem;
}

.btn-link:hover {
  text-decoration: underline;
}

/* Inputs */
input,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--bg-elevated);
  color: var(--text);
}

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

input.table-input {
  padding: 6px 8px;
  font-size: 0.85rem;
}

textarea.table-input {
  min-height: 52px;
  padding: 6px 8px;
  font-size: 0.8rem;
  resize: vertical;
}

/* Header */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.brand h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.brand.with-back {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.detail-url {
  margin: 4px 0 0;
  font-size: 0.8rem;
  word-break: break-all;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.stat-card span {
  display: block;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card.success strong {
  color: var(--success);
}

.stat-card.danger strong {
  color: var(--danger);
}

/* Cards */
.card {
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.card-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.card-head .muted {
  margin: 4px 0 0;
  font-size: 0.82rem;
}

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

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

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(0, 0, 0, 0.2);
}

.data-table tbody tr {
  transition: background 0.12s;
}

.data-table tbody tr.clickable {
  cursor: pointer;
}

.data-table tbody tr.clickable:hover {
  background: rgba(59, 130, 246, 0.08);
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.col-check {
  width: 52px;
}

.data-table .mono {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge.ok {
  color: #86efac;
  background: rgba(34, 197, 94, 0.15);
}

.badge.fail {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.15);
}

.badge.neutral {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
}

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.tab {
  flex: 1;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: transparent;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  background: var(--bg-card);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.tab-panel {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Form grid */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 20px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.danger-zone {
  padding: 0 0 8px;
}

.danger-zone .btn {
  width: 100%;
}

/* History */
.history-list {
  padding: 12px 16px 16px;
}

.history-list.compact .history-item {
  margin-top: 8px;
}

.history-item {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  overflow: hidden;
}

.history-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--success);
  font-size: 0.75rem;
  font-weight: 700;
}

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

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

.forward-list {
  padding: 10px 16px 12px;
}

.forward-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.forward-row:last-child {
  border-bottom: 0;
}

.body-preview {
  max-height: 120px;
  margin: 0;
  padding: 12px 16px;
  overflow: auto;
  background: #0a0c10;
  color: #a1a8b3;
  font-size: 0.78rem;
  white-space: pre-wrap;
}

.message,
.error {
  margin: 0 0 12px;
  font-size: 0.85rem;
}

.message {
  color: var(--success);
  font-weight: 600;
}

.error {
  min-height: 18px;
  color: var(--danger);
  font-weight: 600;
}

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

.toggle-inline input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

@media (max-width: 768px) {
  .view {
    padding: 16px 14px 32px;
  }

  .app-header {
    flex-direction: column;
  }

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

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

  .card-head {
    flex-direction: column;
  }

  .history-summary,
  .forward-row {
    grid-template-columns: 1fr;
  }

  .data-table th:nth-child(4),
  .data-table td:nth-child(4) {
    display: none;
  }
}
