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

:root {
  --surface-0: #f9fafb;
  --surface-1: #ffffff;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-tertiary: #9ca3af;
  --border: #e5e7eb;
  --border-hover: #d1d5db;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #22c55e;
  --success-bg: #f0fdf4;
  --success-text: #15803d;
  --warning: #f59e0b;
  --warning-bg: #fefce8;
  --warning-text: #a16207;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-text: #b91c1c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--surface-0);
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Header & Nav */
header { border-bottom: 2px solid var(--accent); padding: 1rem 0; margin-bottom: 1.5rem; }
header h1 { font-size: 1.4rem; color: var(--accent); }

nav { margin-top: 0.5rem; }
nav a {
  display: inline-block;
  margin-right: 1rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.25rem 0;
  font-size: 0.9rem;
}
nav a:hover { text-decoration: underline; }

main { min-height: 60vh; }

/* Typography */
h2 { margin-bottom: 1rem; color: var(--text-primary); }
h3 { margin: 1.5rem 0 0.75rem; color: #333; }

section { margin-bottom: 2rem; }

/* Section Headers */
.section-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.section-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}
.section-subtitle {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}

/* Status Bar */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  margin-bottom: 2rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.status-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.status-label {
  color: var(--text-tertiary);
}
.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot--success { background: var(--success); }
.status-dot--danger { background: var(--danger); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.5;
  border-radius: 9999px;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: currentColor;
}
.badge--success { color: var(--success-text); background: var(--success-bg); }
.badge--warning { color: var(--warning-text); background: var(--warning-bg); }
.badge--danger  { color: var(--danger-text); background: var(--danger-bg); }
.badge--neutral { color: var(--text-tertiary); background: #f3f4f6; }

/* Card Grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

/* Cards */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.card--clickable {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.card--clickable:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.card-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}
.card-metric {
  margin-bottom: 0.5rem;
}
.metric-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.metric-label {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-left: 0.25rem;
}
.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-tertiary);
}
.card-arrow {
  color: var(--accent);
  font-weight: 500;
}
.card-detail {
  text-transform: capitalize;
}

/* Progress Bar */
.progress-bar {
  height: 0.375rem;
  background: #f3f4f6;
  border-radius: 9999px;
  overflow: hidden;
  margin: 0.5rem 0;
}
.progress-fill {
  height: 100%;
  border-radius: inherit;
  transition: width 0.3s ease;
}
.progress-bar[data-severity="normal"] .progress-fill { background: var(--success); }
.progress-bar[data-severity="warning"] .progress-fill { background: var(--warning); }
.progress-bar[data-severity="danger"] .progress-fill { background: var(--danger); }

/* Metric Row (performance cards) */
.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 0.5rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.metric-item { text-align: center; }
.metric-mini-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.metric-mini-value {
  display: block;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.metric--success { color: var(--success-text); }
.metric--warning { color: var(--warning-text); }
.metric--danger { color: var(--danger-text); }

/* Sparklines */
.sparkline-container {
  height: 2rem;
  margin-top: 0.5rem;
}
.sparkline {
  width: 100%;
  height: 100%;
}

/* Empty State */
.empty-state {
  color: var(--text-tertiary);
  padding: 2rem;
  text-align: center;
  background: var(--surface-1);
  border: 1px dashed var(--border);
  border-radius: 0.75rem;
}
.empty-state a { color: var(--accent); }

/* Welcome */
.welcome-section {
  text-align: center;
  padding: 4rem 2rem;
}
.welcome-section h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}
.welcome-section p {
  color: var(--text-secondary);
}

/* Tables */
table { border-collapse: collapse; width: 100%; margin-bottom: 1rem; }
th, td { border: 1px solid var(--border); padding: 0.5rem 0.75rem; text-align: left; }
th { background: #e5e7eb; font-weight: 600; }
tr:nth-child(even) { background: #f3f4f6; }

/* Forms */
form { margin-bottom: 1rem; }
label { display: block; margin-bottom: 0.5rem; font-weight: 500; }
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
select,
textarea {
  display: block;
  width: 100%;
  max-width: 500px;
  padding: 0.5rem;
  border: 1px solid #9ca3af;
  border-radius: 4px;
  font-size: 0.95rem;
  margin-top: 0.25rem;
}
textarea { min-height: 100px; }

button, input[type="submit"] {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1.25rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  margin-top: 0.5rem;
}
button:hover, input[type="submit"]:hover { background: var(--accent-hover); }
button.danger { background: #dc2626; }
button.danger:hover { background: #b91c1c; }

/* Flash Messages */
.flash-success {
  background: var(--success-bg);
  border: 1px solid #6ee7b7;
  color: #065f46;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}
.flash-error {
  background: var(--danger-bg);
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}

/* Key Display */
.key-display {
  background: #fef3c7;
  border: 2px solid #f59e0b;
  padding: 1rem;
  border-radius: 4px;
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 1.1rem;
  word-break: break-all;
}

/* Info Tables */
.info-table { max-width: 600px; }
.info-table td:first-child { font-weight: 600; width: 180px; background: #e5e7eb; }

/* Code Blocks */
pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 0.5rem 0 1rem;
}

/* Links */
a { color: var(--accent); }
a:hover { text-decoration: underline; }

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 1rem 0;
  margin-top: 2rem;
  color: #6b7280;
  font-size: 0.85rem;
}

/* Loading States */
button[data-loading="true"], input[type="submit"][data-loading="true"] {
  opacity: 0.6;
  cursor: wait;
}
.loading-indicator {
  display: inline-block;
  margin-left: 0.5rem;
  color: #6b7280;
  font-size: 0.9rem;
}

/* Filter Forms */
.inline-form { display: inline; }
.filter-form { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; margin-bottom: 1rem; }
.filter-form label { margin-bottom: 0; }
.filter-form input, .filter-form select { max-width: 200px; }

/* Range Selector */
.range-selector { display: flex; gap: 0.25rem; }
.range-btn { padding: 0.25rem 0.75rem; border-radius: 0.375rem; font-size: 0.8125rem; color: var(--text-secondary); text-decoration: none; border: 1px solid var(--border); background: var(--surface-0); transition: all 0.15s; }
.range-btn:hover { background: var(--surface-1); color: var(--text-primary); }
.range-btn--active { background: var(--accent); color: #fff; border-color: var(--accent); }
.range-btn--active:hover { background: var(--accent); color: #fff; }

/* Tab bar (same visual style as range selector) */
.tab-bar { display: flex; gap: 0.25rem; margin-bottom: 1.25rem; }
.tab-btn { padding: 0.375rem 1rem; border-radius: 0.375rem; font-size: 0.875rem; font-weight: 500; color: var(--text-secondary); border: 1px solid var(--border); background: var(--surface-0); cursor: pointer; transition: all 0.15s; }
.tab-btn:hover { background: var(--surface-1); color: var(--text-primary); }
.tab-btn--active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tab-btn--active:hover { background: var(--accent); color: #fff; }
.tab-panel { display: none; }
.tab-panel--active { display: block; }

/* =====================================================
   DATA TABLES — styled, sortable, with hover
   ===================================================== */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table { border-collapse: collapse; width: 100%; font-size: 0.875rem; border: none; }
.data-table thead th {
  background: var(--surface-0);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  padding: 0.625rem 0.75rem;
  border: none;
  border-bottom: 2px solid var(--border);
  cursor: default;
  user-select: none;
  white-space: nowrap;
}
.data-table thead th.sortable { cursor: pointer; }
.data-table thead th.sortable::after { content: ' \2195'; opacity: 0.3; font-size: 0.75rem; }
.data-table thead th.sort-asc::after { content: ' \2191'; opacity: 1; }
.data-table thead th.sort-desc::after { content: ' \2193'; opacity: 1; }
.data-table thead th.sortable:hover { color: var(--text-secondary); }
.data-table tbody td {
  padding: 0.5rem 0.75rem;
  border: none;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr[style*="display: none"] + tr:hover { background: #f8fafc; }
.data-table--compact th, .data-table--compact td { padding: 0.375rem 0.5rem; }

/* Table Toolbar (search + meta) */
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.table-search {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  min-width: 240px;
  max-width: 100%;
  background: var(--surface-1);
}
.table-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15); }
.table-meta { font-size: 0.8125rem; color: var(--text-tertiary); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
  gap: 0.5rem;
}
.pagination-buttons { display: flex; gap: 0.25rem; align-items: center; }
.pagination-btn {
  padding: 0.25rem 0.625rem;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface-1);
  cursor: pointer;
  transition: all 0.15s;
}
.pagination-btn:hover { background: var(--surface-0); color: var(--text-primary); }
.pagination-btn--active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination-btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }
.page-size-select {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  background: var(--surface-1);
  max-width: 80px;
}

/* =====================================================
   FORM GRID — two-column responsive layout
   ===================================================== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.5rem;
  max-width: 700px;
}
.form-grid--single { grid-template-columns: 1fr; }
.form-grid--wide { max-width: 100%; }
.form-group { display: flex; flex-direction: column; }
.form-group--full { grid-column: 1 / -1; }
.form-group label { margin-bottom: 0.25rem; font-size: 0.875rem; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea { max-width: 100%; margin-top: 0; }
.form-help { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 0.25rem; line-height: 1.4; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 0.5rem; grid-column: 1 / -1; }

/* =====================================================
   DETAIL GRID — replaces .info-table
   ===================================================== */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.detail-item { min-width: 0; }
.detail-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  font-weight: 600;
  margin-bottom: 0.125rem;
}
.detail-value {
  font-size: 0.9375rem;
  color: var(--text-primary);
  word-break: break-word;
}

/* =====================================================
   BUTTON VARIANTS
   ===================================================== */
.btn-secondary {
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-0); border-color: var(--border-hover); }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8125rem; margin-top: 0; }
.btn-icon { background: none; border: none; padding: 0.25rem; cursor: pointer; color: var(--text-tertiary); margin-top: 0; }
.btn-icon:hover { color: var(--text-primary); }

/* Badge as toggle button */
.badge-btn {
  cursor: pointer;
  border: none;
  font: inherit;
  transition: opacity 0.15s;
}
.badge-btn:hover { opacity: 0.8; }

/* =====================================================
   NAV ACTIVE STATE
   ===================================================== */
nav a[aria-current="page"] {
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0.125rem;
}
