/* ── Theme variables ── */
:root, [data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-body-end: #eef3fa;
  --bg-surface: #ffffff;
  --bg-surface-2: #f2f5fb;
  --bg-surface-hover: #f1f5f9;
  --bg-topbar: rgba(255,255,255,0.9);
  --bg-input: #ffffff;
  --border: #dbe3ef;
  --border-focus: #2563eb;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-light: #fca5a5;
  --success: #059669;
  --warning: #d97706;
  --warning-light: #fde68a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.08);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.12);
  --chart-bg: linear-gradient(180deg, #fff, #f8fbff);
  --chart-grid: #e8eef8;
  --chart-line-1: #2563eb;
  --chart-line-2: #dc2626;
  --chart-line-3: #059669;
  --chart-line-4: #7c3aed;
  --chart-line-5: #ea580c;
}

[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-body-end: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-2: #283548;
  --bg-surface-hover: #334155;
  --bg-topbar: rgba(30,41,59,0.92);
  --bg-input: #1e293b;
  --border: #334155;
  --border-focus: #3b82f6;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-inverse: #0f172a;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --danger: #ef4444;
  --danger-light: #7f1d1d;
  --success: #10b981;
  --warning: #f59e0b;
  --warning-light: #78350f;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.5);
  --chart-bg: linear-gradient(180deg, #1e293b, #1a2536);
  --chart-grid: #334155;
  --chart-line-1: #3b82f6;
  --chart-line-2: #ef4444;
  --chart-line-3: #10b981;
  --chart-line-4: #a78bfa;
  --chart-line-5: #fb923c;
}

/* ── Reset ── */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, var(--bg-body) 0%, var(--bg-body-end) 100%);
  color: var(--text-primary);
}

.hidden { display: none !important; }
.view { min-height: 100vh; }

/* ── Login ── */
.login-card {
  width: min(480px, 92vw);
  margin: 10vh auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px;
  box-shadow: var(--shadow-md);
}
.login-card h1 { margin: 0 0 8px 0; }
.login-card p { margin: 0 0 16px 0; color: var(--text-muted); }

/* ── Forms ── */
label { display: block; margin-top: 10px; margin-bottom: 6px; }

input, select, button { font: inherit; color: var(--text-primary); }

input, select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
input:focus, select:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }

button {
  background: var(--accent);
  color: var(--text-inverse);
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
  transition: filter 0.15s;
}
button:hover { filter: brightness(1.08); }

button.danger { background: var(--danger); color: var(--text-inverse); }

/* ── Topbar ── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-topbar);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
  gap: 12px;
}
.topbar h1 { margin: 0; font-size: 18px; }
.topbar p { margin: 4px 0 0 0; color: var(--text-muted); font-size: 12px; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-shrink: 0;
}
.admin-badge { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.admin-badge .role {
  background: var(--bg-surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 600;
  margin-left: 4px;
}

#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  color: var(--text-muted);
  line-height: 1;
}
#theme-toggle:hover { background: var(--bg-surface-hover); }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  background: none;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}
.tab:hover:not(.active) { color: var(--text-primary); border-bottom-color: var(--border); }
.tab.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ── Main ── */
main { padding: 16px; }

/* ── Cards ── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.card .k { color: var(--text-muted); font-size: 12px; }
.card .v { margin-top: 8px; font-size: 22px; font-weight: 700; }
.card-success { border-left: 3px solid var(--success); }
.card-danger { border-left: 3px solid var(--danger); }
.card-warning { border-left: 3px solid var(--warning); }

/* ── Panel ── */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  box-shadow: var(--shadow-sm);
}
.panel h3 { margin: 0 0 8px; font-size: 14px; }

/* ── Toolbar ── */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.toolbar input, .toolbar select { max-width: 220px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { border-bottom: 1px solid var(--border); text-align: left; padding: 8px 6px; vertical-align: top; }
th { color: var(--text-muted); font-size: 11px; font-weight: 600; }
tr:hover td { background: var(--bg-surface-hover); }

/* Sortable headers */
th.sortable { cursor: pointer; user-select: none; position: relative; padding-right: 18px; }
th.sortable::after { content: '\2195'; position: absolute; right: 4px; top: 50%; transform: translateY(-50%); font-size: 10px; color: var(--text-muted); opacity: 0.5; }
th.sortable:hover::after { opacity: 1; }
th.sortable.asc::after { content: '\2191'; color: var(--accent); opacity: 1; }
th.sortable.desc::after { content: '\2193'; color: var(--accent); opacity: 1; }

/* ── Badges & Status ── */
.pill { display: inline-block; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--border); font-size: 11px; }
.ok { color: var(--success); }
.err { color: var(--danger); }
.error { color: var(--danger); margin-top: 8px; }
.subtle { color: var(--text-muted); font-size: 12px; }

/* FURS status badges */
.furs-confirmed { color: var(--success); font-weight: 600; }
.furs-failed { color: var(--danger); font-weight: 600; }
.furs-submitted { color: var(--warning); font-weight: 600; }
.furs-pending { color: var(--text-muted); }
.furs-manual { color: var(--danger); font-weight: 600; }

/* ── Actions ── */
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions button { padding: 6px 8px; font-size: 11px; }

/* ── Small button ── */
.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent);
  color: var(--text-inverse);
  border: 1px solid var(--accent);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-sm:hover { background: var(--accent-hover); }
.btn-sm-muted { background: var(--bg-surface-hover); color: var(--text-secondary); border-color: var(--border); }
.btn-sm-muted:hover { background: var(--border); }

/* ── Charts ── */
.chart {
  width: 100%;
  height: 220px;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--chart-bg);
}
.chart-grid line { stroke: var(--chart-grid); stroke-width: 1; }
.chart-line { fill: none; stroke-width: 2; }
.chart-label { font-size: 10px; fill: var(--text-muted); }
.chart-dot { r: 3; opacity: 0; transition: opacity 0.15s; }
.chart:hover .chart-dot { opacity: 1; }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-muted); margin-top: 8px; flex-wrap: wrap; }

/* ── Alerts ── */
.alert-panel { margin-bottom: 8px; }
.alert-panel.alert-high { border-color: var(--danger-light); }
.alert-panel.alert-medium { border-color: var(--warning-light); }

/* ── Toast notifications ── */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: 8px; color: #fff; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-md); animation: toastIn 0.3s ease, toastOut 0.3s ease 3.7s forwards; max-width: 400px; display: flex; align-items: center; gap: 8px; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--accent); }
.toast.warning { background: var(--warning); }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 9000; display: flex; align-items: center; justify-content: center; animation: fadeIn 0.2s ease; }
.modal { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; max-width: 480px; width: 90%; box-shadow: var(--shadow-lg); }
.modal h3 { margin: 0 0 16px; font-size: 16px; font-weight: 600; }
.modal p { margin: 0 0 16px; font-size: 13px; color: var(--text-muted); }
.modal .modal-label { font-size: 12px; font-weight: 500; display: block; margin-bottom: 4px; color: var(--text-secondary); }
.modal input, .modal textarea, .modal select { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; margin-bottom: 12px; box-sizing: border-box; background: var(--bg-input); color: var(--text-primary); }
.modal textarea { min-height: 80px; resize: vertical; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-actions button { padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); }
.modal-actions .btn-primary { background: var(--accent); color: var(--text-inverse); border-color: var(--accent); }
.modal-actions .btn-danger { background: var(--danger); color: var(--text-inverse); border-color: var(--danger); }
.modal-actions .btn-cancel { background: var(--bg-surface-hover); color: var(--text-secondary); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Loading & empty states ── */
.loading { display: flex; align-items: center; justify-content: center; padding: 60px; color: var(--text-muted); font-size: 14px; gap: 8px; }
.loading::before { content: ''; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 13px; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 16px; font-size: 13px; color: var(--text-muted); }
.pagination button { padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-surface); color: var(--text-primary); cursor: pointer; font-size: 13px; }
.pagination button:hover:not(:disabled) { background: var(--bg-surface-hover); }
.pagination button:disabled { opacity: 0.4; cursor: default; }
.pagination .page-info { min-width: 120px; text-align: center; }

/* ── Section labels ── */
.section-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); padding: 20px 0 8px; }
.section-label:first-child { padding-top: 0; }

/* ── Detail sections ── */
.detail-section { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.detail-section:first-child { border-top: none; margin-top: 0; padding-top: 0; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; font-size: 13px; }
.detail-label { color: var(--text-muted); font-size: 12px; }

/* ── Empty state icon ── */
.empty-state .es-icon { font-size: 28px; margin-bottom: 6px; opacity: 0.7; }
.empty-state .es-sub { margin-top: 4px; font-size: 12px; opacity: 0.7; }

/* ── Refresh indicator ── */
#refresh-time { cursor: pointer; font-size: 10px; }
#refresh-time:hover { color: var(--accent); }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .toolbar input, .toolbar select { max-width: none; flex: 1 1 180px; }
}

@media (max-width: 768px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar h1 { font-size: 15px; }
  .tabs { padding: 0 8px; }
  .tab { font-size: 12px; padding: 8px 10px; }
  .cards { grid-template-columns: 1fr; }
  main { padding: 10px; }
  .panel { border-radius: 8px; padding: 10px; }
  .toolbar { flex-direction: column; }
  .toolbar input, .toolbar select { max-width: none; width: 100%; }
  .modal { width: 95%; max-width: none; }
  table { font-size: 11px; }
  th, td { padding: 6px 4px; }
}

@media (max-width: 480px) {
  .topbar { flex-wrap: wrap; }
  .topbar > div:first-child { width: 100%; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
  .cards { gap: 8px; }
  .card { padding: 10px; }
  .card .v { font-size: 18px; }
}
