/* ─── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #22222f;
  --surface3: #2a2a3a;
  --border: #2e2e40;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --teal: #22d3ee;
  --teal-hover: #67e8f9;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --sans: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --gray: #475569;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 150ms ease;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --surface3: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

/* ─── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ─── Layout ──────────────────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .sidebar-subtitle { display: none; }

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
}
.sidebar-logo {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--teal));
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.sidebar-title {
  font-size: 14px; font-weight: 700; color: var(--text);
  white-space: nowrap;
}
.sidebar-subtitle {
  font-size: 10px; color: var(--text-dim);
  font-family: var(--mono);
  white-space: nowrap;
}

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-section-label {
  font-size: 10px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.1em;
  padding: 8px 8px 4px;
  white-space: nowrap;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 8px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(99,102,241,0.15); color: var(--accent); }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.nav-label { white-space: nowrap; }
.nav-badge {
  margin-left: auto; background: var(--red);
  color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 10px;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}
.sidebar-toggle {
  width: 100%; background: transparent; border: none;
  color: var(--text-dim); font-size: 18px;
  padding: 8px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.sidebar-toggle:hover { color: var(--text); background: var(--surface2); }

/* ─── Main Content ─────────────────────────────────────────────────────────── */
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-spacer { flex: 1; }

.search-global {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 16px;
  display: flex; align-items: center; gap: 8px;
  width: 280px;
}
.search-global input {
  background: transparent; border: none; outline: none;
  color: var(--text); font-size: 13px; width: 100%;
}
.search-global input::placeholder { color: var(--text-dim); }
.search-icon { color: var(--text-dim); font-size: 14px; }

.page-content { padding: 24px; flex: 1; }
.page-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 24px;
}
.page-title { font-size: 22px; font-weight: 700; }
.page-actions { margin-left: auto; display: flex; gap: 8px; }

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-title {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  cursor: default;
  transition: border-color var(--transition);
}
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover { border-color: var(--accent); }
.stat-label {
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.stat-value {
  font-size: 32px; font-weight: 800; font-family: var(--mono);
  line-height: 1.2; margin: 4px 0;
}
.stat-value.green { color: var(--green); }
.stat-value.amber { color: var(--amber); }
.stat-value.red { color: var(--red); }
.stat-value.teal { color: var(--teal); }
.stat-value.accent { color: var(--accent); }
.stat-sub { font-size: 12px; color: var(--text-muted); }

/* ─── Tables ───────────────────────────────────────────────────────────────── */
.table-container { overflow-x: auto; }
table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: var(--surface2); color: var(--text-muted);
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 10px 12px;
  text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--text); }
thead th.sorted { color: var(--accent); }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:nth-child(even) { background: rgba(255,255,255,0.015); }
tbody tr:hover { background: var(--surface2); }
td { padding: 10px 12px; vertical-align: middle; }
td.mono { font-family: var(--mono); font-size: 12px; }

.th-sort::after { content: ' ⇅'; opacity: 0.4; }
.th-sort.asc::after { content: ' ↑'; opacity: 1; }
.th-sort.desc::after { content: ' ↓'; opacity: 1; }

/* ─── Badges / Pills ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
  font-family: var(--mono); white-space: nowrap;
}
.badge-green { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-amber { background: rgba(245,158,11,0.15); color: var(--amber); }
.badge-red { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-gray { background: rgba(71,85,105,0.2); color: var(--gray); }
.badge-accent { background: rgba(99,102,241,0.15); color: var(--accent); }
.badge-teal { background: rgba(34,211,238,0.15); color: var(--teal); }

/* Days remaining hero badge */
.days-badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 4px 12px; border-radius: 20px;
  font-family: var(--mono); font-weight: 800; font-size: 13px;
  min-width: 72px;
}
.days-badge.good { background: rgba(34,197,94,0.15); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.days-badge.warn { background: rgba(245,158,11,0.15); color: var(--amber); border: 1px solid rgba(245,158,11,0.3); }
.days-badge.crit { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.days-badge.dead { background: rgba(71,85,105,0.15); color: var(--gray); border: 1px solid rgba(71,85,105,0.3); }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; border: none;
  transition: all var(--transition);
  text-decoration: none;
}
.btn-primary {
  background: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-secondary {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface3); }
.btn-teal { background: var(--teal); color: #0f0f13; }
.btn-teal:hover { background: var(--teal-hover); color: #0f0f13; }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

.btn-group { display: flex; gap: 4px; }

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
label {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.form-control {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.form-control:focus { border-color: var(--accent); }
.form-control::placeholder { color: var(--text-dim); }
.form-control:disabled { opacity: 0.5; cursor: not-allowed; }

.input-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.input-group .form-control { border: none; border-radius: 0; }
.input-group .btn { border-radius: 0; border-left: 1px solid var(--border); }

.form-hint { font-size: 11px; color: var(--text-dim); }
.form-error { font-size: 11px; color: var(--red); }
.form-section-title {
  font-size: 13px; font-weight: 700; color: var(--text-muted);
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
  grid-column: 1 / -1;
  margin-top: 8px;
}

/* ─── Filters Bar ──────────────────────────────────────────────────────────── */
.filters-bar {
  display: flex; gap: 8px; flex-wrap: wrap;
  align-items: center; margin-bottom: 16px;
}
.filter-input {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  padding: 7px 12px; font-size: 13px; outline: none;
}
.filter-input:focus { border-color: var(--accent); }

/* ─── Pagination ───────────────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 4px;
  margin-top: 16px;
}
.page-btn {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 5px 10px; font-size: 13px;
  transition: all var(--transition);
}
.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ─── Checkbox ────────────────────────────────────────────────────────────── */
.checkbox-cell { width: 40px; text-align: center; }
input[type="checkbox"] {
  width: 16px; height: 16px; cursor: pointer;
  accent-color: var(--accent);
}

/* ─── Toast Notifications ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  min-width: 280px;
  animation: slideIn 0.2s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }
.toast.warning { border-left: 3px solid var(--amber); }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-lg { max-width: 720px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 20px; line-height: 1;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 20px;
}

/* ─── Loading ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
  position: absolute; inset: 0; z-index: 5;
  background: rgba(15,15,19,0.7);
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
}

/* ─── FAB ──────────────────────────────────────────────────────────────────── */
.fab {
  position: fixed; bottom: 28px; right: 28px; z-index: 50;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); border: none; color: #fff;
  font-size: 24px; box-shadow: 0 4px 20px rgba(99,102,241,0.5);
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.fab:hover { transform: scale(1.08); background: var(--accent-hover); }

/* ─── Login Page ───────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow);
}
.login-logo {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--accent), var(--teal));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin: 0 auto 20px;
}
.login-title {
  text-align: center; font-size: 22px; font-weight: 800; margin-bottom: 4px;
}
.login-subtitle {
  text-align: center; font-size: 13px; color: var(--text-muted); margin-bottom: 28px;
}

/* ─── Timeline ─────────────────────────────────────────────────────────────── */
.timeline-bar {
  height: 8px; background: var(--surface3); border-radius: 4px;
  overflow: hidden; position: relative; margin: 8px 0;
}
.timeline-fill {
  height: 100%; border-radius: 4px;
  transition: width 0.3s ease;
}
.timeline-fill.good { background: linear-gradient(90deg, var(--green), #4ade80); }
.timeline-fill.warn { background: linear-gradient(90deg, var(--amber), #fbbf24); }
.timeline-fill.crit { background: linear-gradient(90deg, var(--red), #f87171); }
.timeline-fill.dead { background: var(--gray); }

/* ─── Audit Changes ────────────────────────────────────────────────────────── */
.change-diff { font-family: var(--mono); font-size: 12px; }
.change-before { color: var(--red); }
.change-after { color: var(--green); }
.change-arrow { color: var(--text-dim); margin: 0 4px; }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -240px; z-index: 100; transition: left 0.2s ease; }
  .sidebar.mobile-open { left: 0; }
  .main-content { margin-left: 0; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .search-global { width: 200px; }
  .page-content { padding: 16px; }
}

/* ─── Misc Utils ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-family: var(--mono); }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.w-full { width: 100%; }

.divider {
  height: 1px; background: var(--border);
  margin: 16px 0;
}

/* ─── Activity Feed ────────────────────────────────────────────────────────── */
.activity-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; flex-shrink: 0;
  background: var(--surface2);
}
.activity-text { font-size: 13px; }
.activity-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* ─── Quick-Add Panel ──────────────────────────────────────────────────────── */
.quick-add-panel {
  position: fixed; bottom: 96px; right: 28px; z-index: 49;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  width: 340px; box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
}
.quick-add-panel.hidden { display: none; }

/* ─── Import/Export Dropdown ───────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); min-width: 160px;
  box-shadow: var(--shadow); z-index: 50;
  padding: 4px 0;
}
.dropdown-menu.hidden { display: none; }
.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; font-size: 13px;
  color: var(--text); transition: background var(--transition);
  cursor: pointer; border: none; background: none; width: 100%; text-align: left;
}
.dropdown-item:hover { background: var(--surface2); }

/* ─── Settings Sections ────────────────────────────────────────────────────── */
.settings-grid {
  display: grid; grid-template-columns: 240px 1fr; gap: 24px;
}
@media (max-width: 768px) { .settings-grid { grid-template-columns: 1fr; } }
.settings-nav { display: flex; flex-direction: column; gap: 2px; }
.settings-nav-item {
  padding: 8px 12px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text-muted); cursor: pointer;
  transition: all var(--transition);
}
.settings-nav-item:hover { background: var(--surface2); color: var(--text); }
.settings-nav-item.active { background: rgba(99,102,241,0.15); color: var(--accent); }
.settings-panel { display: none; }
.settings-panel.active { display: block; }
