/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0a0f0d;
  --surface:     #0f1912;
  --surface2:    #162019;
  --border:      #1e3a28;
  --green:       #22c55e;
  --green-hover: #16a34a;
  --green-dim:   #166534;
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --red:         #ef4444;
  --red-dim:     #7f1d1d;
  --yellow:      #f59e0b;
  --yellow-dim:  #78350f;
  --blue:        #3b82f6;
  --blue-dim:    #1e3a8a;
  --sidebar-w:   220px;
  --topbar-h:    60px;
  --radius:      8px;
  --radius-sm:   5px;
  --shadow:      0 2px 8px rgba(0,0,0,0.4);
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ===== Utilities ===== */
.hidden { display: none !important; }
.flex-1 { flex: 1; min-width: 0; }
.text-lg { font-size: 1.1rem; font-weight: 700; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }

/* ===== Login Screen ===== */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 100;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.login-logo {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 1.3rem; font-weight: 700; color: var(--green);
  margin-bottom: 1.5rem;
}
.login-logo .logo-sub { color: var(--text-muted); font-size: 0.9rem; font-weight: 400; margin-left: 0.2rem; }
.login-card h2 { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 1.5rem; font-weight: 400; }
.login-error { color: var(--red); background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); border-radius: var(--radius-sm); padding: 0.5rem 0.75rem; margin-bottom: 1rem; font-size: 0.875rem; }

/* ===== Admin App Layout ===== */
.admin-app { display: flex; height: 100vh; overflow: hidden; }
.admin-app.hidden { display: none !important; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 1.25rem 1rem;
  font-size: 0.95rem; color: var(--green);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo .logo-icon { font-size: 1.1rem; }
.sidebar-logo strong { color: var(--text); }

.sidebar-nav { padding: 0.5rem 0; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.65rem 1rem;
  color: var(--text-muted);
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  font-size: 0.875rem;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(34,197,94,0.12); color: var(--green); border-right: 2px solid var(--green); }

.sidebar-footer { padding: 1rem; border-top: 1px solid var(--border); flex-shrink: 0; }

/* ===== Main Content ===== */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
}
.topbar h1 { font-size: 1.1rem; font-weight: 600; }
.admin-email { color: var(--text-muted); font-size: 0.875rem; }

.tab-panel {
  display: none; flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  flex-direction: column;
  gap: 1rem;
}
.tab-panel.active { display: flex; }

/* ===== Stat Cards ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  display: flex; flex-direction: column; gap: 0.35rem;
}
.stat-card.stat-green { border-color: var(--green-dim); background: rgba(34,197,94,0.05); }
.stat-card.stat-red   { border-color: var(--red-dim); background: rgba(239,68,68,0.05); }
.stat-card.stat-blue  { border-color: var(--blue-dim); background: rgba(59,130,246,0.05); }
.stat-card.stat-yellow{ border-color: var(--yellow-dim); background: rgba(245,158,11,0.05); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text); }
.stat-card.stat-green .stat-value { color: var(--green); }
.stat-card.stat-red   .stat-value { color: var(--red); }
.stat-card.stat-blue  .stat-value { color: var(--blue); }
.stat-card.stat-yellow.stat-value { color: var(--yellow); }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
}
.card-header {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 0.875rem;
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}
.card-body { padding: 1rem; flex: 1; }
.card-body.p-0 { padding: 0; }
.card-footer { padding: 0.75rem 1rem; border-top: 1px solid var(--border); }

/* ===== Info rows ===== */
.info-row { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--text-muted); font-size: 0.875rem; }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 0.2em 0.6em;
  border-radius: 9999px;
  font-size: 0.75rem; font-weight: 600;
  white-space: nowrap;
}
.badge-green  { background: rgba(34,197,94,0.15);  color: var(--green); }
.badge-red    { background: rgba(239,68,68,0.15);  color: var(--red); }
.badge-yellow { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge-blue   { background: rgba(59,130,246,0.15); color: var(--blue); }
.badge-gray   { background: rgba(148,163,184,0.15);color: var(--text-muted); }
.badge-purple { background: rgba(168,85,247,0.15); color: #a855f7; }

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

/* ===== Tables ===== */
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table thead th {
  padding: 0.6rem 1rem;
  text-align: left;
  background: var(--surface2);
  color: var(--text-muted);
  font-weight: 600; font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: var(--surface2); }
.table tbody td { padding: 0.65rem 1rem; vertical-align: middle; }
.table .empty { text-align: center; color: var(--text-muted); padding: 2rem; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: none; border-radius: var(--radius-sm);
  font-weight: 500; transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #000; }
.btn-primary:hover:not(:disabled) { background: var(--green-hover); }
.btn-danger  { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled)  { background: #dc2626; }
.btn-ghost   { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)   { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-yellow { background: var(--yellow); color: #000; }
.btn-yellow:hover:not(:disabled) { background: #d97706; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-blue:hover:not(:disabled) { background: #2563eb; }
.btn-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ===== Forms ===== */
.form-group { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.875rem; }
.form-group label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
.input:focus { border-color: var(--green); }
textarea.input { resize: vertical; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.6rem center; background-size: 1rem; padding-right: 2rem; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.25rem; }

/* ===== Toggle ===== */
.toggle { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.toggle input { display: none; }
.toggle-slider {
  width: 40px; height: 22px;
  background: var(--border);
  border-radius: 9999px;
  position: relative; transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-slider::after {
  content: ''; position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: var(--text-muted);
  border-radius: 50%; transition: left 0.2s, background 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--green-dim); }
.toggle input:checked + .toggle-slider::after { left: 21px; background: var(--green); }

/* ===== Pagination ===== */
.pagination { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.page-btn {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted);
  font-size: 0.8rem; cursor: pointer; transition: background 0.15s;
}
.page-btn:hover { background: var(--surface2); color: var(--text); }
.page-btn.active { background: var(--green); color: #000; border-color: var(--green); font-weight: 600; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow);
}
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: 0.875rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 0.5rem; }

/* ===== Toasts ===== */
.toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  z-index: 300; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: slide-in 0.2s ease;
  max-width: 320px;
}
.toast-success { background: rgba(34,197,94,0.15);  border: 1px solid var(--green-dim); color: var(--green); }
.toast-error   { background: rgba(239,68,68,0.15);  border: 1px solid var(--red-dim);  color: var(--red); }
.toast-info    { background: rgba(59,130,246,0.15); border: 1px solid var(--blue-dim); color: var(--blue); }
@keyframes slide-in { from { transform: translateX(1rem); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fade-out { to { opacity: 0; transform: translateY(0.5rem); } }
.toast.removing { animation: fade-out 0.3s ease forwards; }

/* ===== Auto-refresh badge ===== */
.auto-refresh-badge {
  margin-left: auto;
  font-size: 0.7rem; font-weight: 400;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.15rem 0.5rem;
}

/* ===== Filters ===== */
.filters { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.filters .input { width: auto; }

/* ===== Incident card ===== */
.incident-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}
.incident-title { font-weight: 600; margin-bottom: 0.25rem; }
.incident-desc  { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 0.5rem; }
.incident-meta  { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* ===== Loading spinner ===== */
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Action buttons in table ===== */
.action-btns { display: flex; gap: 0.3rem; flex-wrap: wrap; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #2d5a3d; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { width: 180px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}
