:root {
  --primary: #003087;
  --accent: #e63946;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #dde1e7;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --sidebar-w: 320px;
  --nav-h: 56px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── NAV ──────────────────────────────────────── */
.topnav {
  height: var(--nav-h);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 1000;
}
.topnav-brand { display: flex; align-items: center; gap: 10px; color: white; font-weight: 700; font-size: 18px; }
.topnav-subtitle { font-weight: 400; font-size: 13px; opacity: 0.7; margin-left: 4px; }
.topnav-actions { display: flex; gap: 8px; }

/* ── BUTTONS ──────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: none; transition: all 0.15s;
}
.btn-primary { background: #e63946; color: white; }
.btn-primary:hover { background: #c1121f; }
.btn-outline { background: rgba(255,255,255,0.1); color: white; border: 1px solid rgba(255,255,255,0.3); }
.btn-outline:hover { background: rgba(255,255,255,0.2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── LAYOUT ───────────────────────────────────── */
.layout { display: flex; flex: 1; overflow: hidden; }

/* ── SIDEBAR ──────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0;
}
.sidebar-tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab-btn {
  flex: 1; padding: 12px; background: none; border: none;
  font-size: 13px; font-weight: 500; cursor: pointer;
  color: var(--text-muted); border-bottom: 2px solid transparent; transition: all 0.15s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; flex-direction: column; overflow-y: auto; padding: 16px; flex: 1; }
.tab-content.active { display: flex; }

/* ── KPI CARDS ────────────────────────────────── */
.kpi-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.kpi-cards .kpi-card:first-child { grid-column: 1 / -1; }
.kpi-card { background: var(--bg); border-radius: var(--radius); padding: 14px; text-align: center; border: 1px solid var(--border); }
.kpi-card.warn { background: #fff8f0; border-color: #f4a261; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--primary); line-height: 1; }
.kpi-card.warn .kpi-value { color: #e07530; }
.kpi-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── ZONE BARS ────────────────────────────────── */
.section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: 10px; }
.zone-bar-item { margin-bottom: 10px; }
.zone-bar-header { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; align-items: center; }
.zone-bar-name { font-weight: 500; display: flex; align-items: center; gap: 6px; }
.zone-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.zone-bar-count { color: var(--text-muted); }
.zone-bar-track { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.zone-bar-fill { height: 100%; border-radius: 3px; transition: width 0.5s ease; }

/* ── ZONES LIST ───────────────────────────────── */
.zone-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); margin-bottom: 8px;
  cursor: pointer; transition: all 0.15s;
}
.zone-item:hover { background: var(--bg); border-color: var(--primary); }
.zone-item-color { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }
.zone-item-info { flex: 1; min-width: 0; }
.zone-item-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zone-item-count { font-size: 11px; color: var(--text-muted); }
.zone-item-arrow { color: var(--text-muted); font-size: 16px; }

/* ── MAP ──────────────────────────────────────── */
.map-wrapper { flex: 1; position: relative; overflow: hidden; }
#map { width: 100%; height: 100%; }

/* ── BACK BAR ─────────────────────────────────── */
.back-bar {
  position: absolute;
  top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 999;
  display: flex; align-items: center; gap: 12px;
  background: white;
  border-radius: 24px;
  padding: 8px 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  border: 1px solid var(--border);
}
.back-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--primary); color: white;
  border: none; border-radius: 20px;
  padding: 6px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
}
.back-btn:hover { background: #0041b8; }
.back-zone-label {
  font-size: 13px; font-weight: 600; color: var(--text);
}

/* ── MAP CONTROLS ─────────────────────────────── */
.map-controls {
  position: absolute; top: 80px; right: 12px;
  display: flex; flex-direction: column; gap: 6px; z-index: 999;
}
.map-btn {
  width: 36px; height: 36px; background: white;
  border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: var(--shadow); transition: all 0.15s; color: var(--text);
}
.map-btn:hover { background: var(--bg); }
.map-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ── ZONE LABELS (Leaflet divIcon) ────────────── */
.zone-map-label {
  background: white;
  border-radius: 6px;
  padding: 4px 8px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  border-left: 4px solid currentColor;
  cursor: pointer;
  user-select: none;
  pointer-events: auto;
}
.zone-map-label:hover { box-shadow: 0 3px 10px rgba(0,0,0,0.25); }
.zone-map-label-name { font-size: 11px; font-weight: 700; color: #1a1d23; display: block; line-height: 1.3; }
.zone-map-label-count { font-size: 10px; color: #6b7280; display: block; }

/* ── MODAL ────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 2000;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white; border-radius: 12px; width: 100%; max-width: 700px;
  max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-sm { max-width: 460px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-header h2 { font-size: 17px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; }
.input-row { display: flex; gap: 8px; }
.form-input {
  flex: 1; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; outline: none;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,48,135,0.1); }

/* ── CONTRACTS TABLE ──────────────────────────── */
.contracts-table-wrap { overflow-x: auto; }
.contracts-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.contracts-table th {
  background: var(--bg); padding: 8px 10px; text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
}
.contracts-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.contracts-table tr:hover td { background: var(--bg); }

/* ── UPLOAD ───────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 32px; text-align: center; cursor: pointer; transition: all 0.15s;
}
.upload-area:hover, .upload-area.drag-over { border-color: var(--primary); background: #f0f4ff; }
.upload-area p { margin-top: 10px; font-size: 14px; }

/* ── PROGRESS ─────────────────────────────────── */
.progress-bar-wrap { background: var(--border); border-radius: 4px; height: 8px; overflow: hidden; margin-bottom: 6px; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.3s; width: 0%; }
.progress-label { font-size: 12px; color: var(--text-muted); text-align: center; }

/* ── TOAST ────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1a1d23; color: white;
  padding: 10px 20px; border-radius: 6px; font-size: 13px;
  z-index: 3000; transition: transform 0.3s; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: #2a9d8f; }
.toast.error { background: #e63946; }

/* ── UTILITIES ────────────────────────────────── */
.text-muted { color: var(--text-muted); font-size: 13px; line-height: 1.5; }

/* ── POPUP ────────────────────────────────────── */
.leaflet-popup-content-wrapper { border-radius: var(--radius); box-shadow: var(--shadow); }
.popup-content { font-size: 13px; line-height: 1.6; min-width: 180px; }
.popup-content strong { display: block; font-size: 14px; margin-bottom: 4px; color: var(--primary); }
.popup-detail { color: var(--text-muted); font-size: 12px; }
.popup-zone-badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  color: white; font-size: 11px; font-weight: 600; margin-top: 6px;
}
