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

:root {
  --navy:    #1A1A2E;
  --gold:    #D4AF37;
  --gold-dk: #B8960C;
  --cream:   #F5F0E8;
  --surface: #FFFFFF;
  --border:  #E0D9CE;
  --text:    #1A1A2E;
  --muted:   #6B7280;
  --success: #2E7D32;
  --error:   #B00020;
  --warning: #E65100;
  --radius:  8px;
  --shadow:  0 1px 4px rgba(0,0,0,.10);
  --sidebar: 220px;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--cream);
  min-height: 100vh;
}

/* ── Login page ─────────────────────────────────────────────────── */
#login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--navy);
}

.login-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
}

.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 13px;
}

/* ── App shell ──────────────────────────────────────────────────── */
#app { display: none; min-height: 100vh; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar);
  background: var(--navy);
  display: flex; flex-direction: column;
  padding: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-brand h2 {
  color: var(--gold);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .5px;
}

.sidebar-brand p {
  color: rgba(255,255,255,.45);
  font-size: 11px;
  margin-top: 2px;
}

.sidebar nav { flex: 1; padding: 12px 0; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,.65);
  cursor: pointer;
  border-left: 3px solid transparent;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  user-select: none;
}

.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }

.nav-item.active {
  color: var(--gold);
  border-left-color: var(--gold);
  background: rgba(212,175,55,.08);
}

.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.sidebar-footer small { color: rgba(255,255,255,.3); font-size: 11px; }

.main {
  flex: 1 1 auto;
  min-width: 0;
  margin-left: var(--sidebar);
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center;
  background: var(--cream);
}

.topbar { align-self: stretch; }

.menu-toggle {
  display: none;
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--navy);
  padding: 4px 8px; margin-right: 4px;
  border-radius: 6px;
}
.menu-toggle:hover { background: var(--cream); }

.sidebar-overlay { display: none; }

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }
  .sidebar.open { transform: translateX(0); }

  .main { margin-left: 0; }

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

  .sidebar-overlay.show {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 90;
  }
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 60px;
  display: flex; align-items: center;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}

.topbar-inner {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex; align-items: center; justify-content: space-between;
}

.topbar h1 { font-size: 18px; font-weight: 600; color: var(--navy); }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
  padding: 6px 12px 6px 6px;
  border-radius: 20px;
  background: var(--cream);
}

.user-chip .avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}

.content {
  padding: 28px 32px 48px;
  flex: 1;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
}

@media (max-width: 640px) {
  .content { padding: 18px 16px 32px; }
  .topbar-inner { padding: 0 16px; }
}

/* ── Panels ─────────────────────────────────────────────────────── */
.panel { display: none; }
.panel.active { display: block; }

/* ── Cards / stats ──────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}

@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 520px) {
  .stats-row { grid-template-columns: 1fr; }
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--gold);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  transition: transform .15s, box-shadow .15s;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,.12); }

.stat-card .label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.stat-card .value { font-size: 30px; font-weight: 700; color: var(--navy); margin-top: 4px; }

.stat-card .stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: rgba(212,175,55,.12);
  color: var(--gold-dk);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

/* ── Tables ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

.card-header h3 { font-size: 14px; font-weight: 600; color: var(--navy); }

.card-body { padding: 0; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  padding: 10px 20px;
  background: var(--cream);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #faf8f4; }

/* ── Forms ──────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212,175,55,.15);
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
}

.btn-primary { background: var(--gold); color: var(--navy); }
.btn-primary:hover { background: var(--gold-dk); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--gold); color: var(--gold); }

.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #8b0016; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: #e8f5e9; color: var(--success); }
.badge-warning { background: #fff3e0; color: var(--warning); }
.badge-error   { background: #fce4ec; color: var(--error); }
.badge-muted   { background: #f3f4f6; color: var(--muted); }

/* ── Alerts ─────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.alert.show { display: block; }
.alert-success { background: #e8f5e9; color: var(--success); border: 1px solid #a5d6a7; }
.alert-error   { background: #fce4ec; color: var(--error);   border: 1px solid #ef9a9a; }

/* ── Misc ───────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

.empty-state .icon { font-size: 36px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(0,0,0,.1);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

.sidebar-footer { display: flex; flex-direction: column; gap: 2px; }

.sign-out-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: none; border: none;
  color: rgba(255,255,255,.55);
  cursor: pointer; font-size: 13px;
  padding: 6px 10px; border-radius: 4px;
}
.sign-out-btn:hover { background: rgba(255,255,255,.08); color: #fff; }

.section-title {
  font-size: 18px; font-weight: 700;
  color: var(--navy); margin-bottom: 20px;
}

.row { display: flex; gap: 16px; flex-wrap: wrap; }
.col { flex: 1; min-width: 280px; }

/* ── Upload zone ────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--gold);
  background: rgba(212,175,55,.04);
}

.upload-zone p { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* ── Map card ───────────────────────────────────────────────────── */
.map-card { margin-bottom: 0; }

#scan-map {
  height: 440px;
  width: 100%;
  background: #eef1f4;
}

@media (max-width: 640px) {
  #scan-map { height: 320px; }
}

.select-sm {
  width: auto;
  padding: 6px 10px;
  font-size: 12px;
}

.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content b { color: var(--navy); }

/* ── Scan feed ──────────────────────────────────────────────────── */
.scan-row td:first-child { font-family: monospace; font-size: 12px; }

.live-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--success);
  border-radius: 50%;
  margin-right: 6px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}
