/* ─── Reset & base ─────────────────────────────────────────────── */
:root {
  --sidebar-w: 260px;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #2563eb;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #fff;
  --topbar-h: 64px;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #0ea5e9;
  --body-bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.08);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--body-bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ─── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: transform .3s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  text-decoration: none !important;
}

.sidebar-brand-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--primary), #1d4ed8);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(37,99,235,.4);
}

.sidebar-brand-text { flex: 1; }
.sidebar-brand-title { color: #fff; font-size: 15px; font-weight: 700; line-height: 1.2; }
.sidebar-brand-sub { color: var(--sidebar-text); font-size: 11px; }

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

.sidebar-section {
  padding: 16px 16px 4px;
  color: #475569;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 0;
  transition: all .18s;
  text-decoration: none !important;
  cursor: pointer;
  position: relative;
}

.sidebar-item:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.sidebar-item.active {
  background: rgba(37,99,235,.15);
  color: #fff;
}
.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.sidebar-item i { font-size: 18px; flex-shrink: 0; }

.sidebar-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

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

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255,255,255,.04);
}

.sidebar-avatar {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-name { color: #e2e8f0; font-size: 13px; font-weight: 600; }
.sidebar-user-role { color: var(--sidebar-text); font-size: 11px; }

/* ─── Main content ──────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Topbar ────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

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

.topbar-btn {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: 8px;
  background: var(--body-bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all .18s;
  position: relative;
}
.topbar-btn:hover { background: #e2e8f0; color: var(--text); }

.topbar-dot {
  position: absolute;
  top: 5px; right: 5px;
  width: 8px; height: 8px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid #fff;
}

/* ─── Page content ──────────────────────────────────────────────── */
.page-content {
  padding: 24px;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header-left h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.page-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.page-breadcrumb a { color: var(--text-muted); }
.page-breadcrumb a:hover { color: var(--primary); }

/* ─── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

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

.card-header h5 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header h5 i { color: var(--primary); }

.card-body { padding: 20px; }

.card-footer {
  padding: 12px 20px;
  background: #fafafa;
  border-top: 1px solid var(--border);
}

/* ─── KPI Cards ─────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.kpi-card.blue::before   { background: var(--primary); }
.kpi-card.green::before  { background: var(--success); }
.kpi-card.yellow::before { background: var(--warning); }
.kpi-card.red::before    { background: var(--danger); }
.kpi-card.cyan::before   { background: var(--info); }
.kpi-card.purple::before { background: #8b5cf6; }

.kpi-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin-bottom: 12px;
}
.kpi-card.blue   .kpi-icon { background: rgba(37,99,235,.1);  color: var(--primary); }
.kpi-card.green  .kpi-icon { background: rgba(16,185,129,.1); color: var(--success); }
.kpi-card.yellow .kpi-icon { background: rgba(245,158,11,.1); color: var(--warning); }
.kpi-card.red    .kpi-icon { background: rgba(239,68,68,.1);  color: var(--danger); }
.kpi-card.cyan   .kpi-icon { background: rgba(14,165,233,.1); color: var(--info); }
.kpi-card.purple .kpi-icon { background: rgba(139,92,246,.1); color: #8b5cf6; }

.kpi-value { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1; }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi-sub   { font-size: 11px; color: var(--text-muted); margin-top: 8px; display: flex; align-items: center; gap: 4px; }

/* ─── Tables ────────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  background: #f8fafc;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: 0; }

/* ─── Forms ─────────────────────────────────────────────────────── */
.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 5px;
  display: block;
}

.form-control, .form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .18s, box-shadow .18s;
  outline: none;
  font-family: inherit;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

textarea.form-control { resize: vertical; min-height: 100px; }

.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check-input {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.input-group {
  display: flex;
  gap: 0;
}
.input-group .form-control { border-radius: 7px 0 0 7px; }
.input-group .btn { border-radius: 0 7px 7px 0; }

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .18s;
  text-decoration: none !important;
  line-height: 1.4;
  white-space: nowrap;
}

.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success   { background: var(--success);   color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger    { background: var(--danger);    color: #fff; }
.btn-danger:hover  { background: #dc2626; }
.btn-warning   { background: var(--warning);   color: #fff; }
.btn-secondary { background: var(--border);    color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; border-radius: 7px; }

.btn-outline-primary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline-primary:hover { background: var(--primary); color: #fff; }

.btn-outline-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-outline-danger:hover { background: var(--danger); color: #fff; }

/* ─── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-blue    { background: rgba(37,99,235,.12);  color: var(--primary); }
.badge-green   { background: rgba(16,185,129,.12); color: #059669; }
.badge-yellow  { background: rgba(245,158,11,.12); color: #d97706; }
.badge-red     { background: rgba(239,68,68,.12);  color: #dc2626; }
.badge-gray    { background: rgba(100,116,139,.12);color: var(--text-muted); }

/* ─── Alerts ────────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 13.5px;
}
.alert i { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: rgba(16,185,129,.1);  color: #065f46; border-left: 3px solid var(--success); }
.alert-error   { background: rgba(239,68,68,.1);   color: #991b1b; border-left: 3px solid var(--danger); }
.alert-warning { background: rgba(245,158,11,.1);  color: #92400e; border-left: 3px solid var(--warning); }
.alert-info    { background: rgba(14,165,233,.1);  color: #0c4a6e; border-left: 3px solid var(--info); }

/* ─── Progress bar ──────────────────────────────────────────────── */
.progress {
  height: 6px;
  background: var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: 10px;
  background: var(--primary);
  transition: width .5s ease;
}
.progress-bar.green { background: var(--success); }
.progress-bar.yellow{ background: var(--warning); }
.progress-bar.red   { background: var(--danger); }

/* ─── Filter bar ────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.filter-bar .form-control,
.filter-bar .form-select { max-width: 200px; }

/* ─── Totals row ────────────────────────────────────────────────── */
.totals-bar {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: rgba(37,99,235,.05);
  border-radius: var(--radius);
  border: 1px solid rgba(37,99,235,.15);
  margin-bottom: 20px;
}
.totals-item { text-align: center; }
.totals-value { font-size: 18px; font-weight: 700; color: var(--primary); }
.totals-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* ─── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 25px 50px rgba(0,0,0,.25);
  animation: fadeUp .25s ease;
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }
.modal-text  { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Auth pages ────────────────────────────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo-icon {
  width: 60px; height: 60px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 28px;
  margin-bottom: 12px;
  box-shadow: 0 8px 24px rgba(37,99,235,.4);
}

.auth-logo h1 { font-size: 22px; font-weight: 800; color: var(--text); }
.auth-logo p  { color: var(--text-muted); font-size: 13px; }

.auth-form .form-label { font-size: 13px; }
.auth-form .form-control { padding: 11px 14px; font-size: 15px; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Tabs ──────────────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab-item {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  text-decoration: none !important;
  white-space: nowrap;
  transition: all .18s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab-item:hover { color: var(--primary); }
.tab-item.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── Status indicators ─────────────────────────────────────────── */
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
}
.status-dot.green  { background: var(--success); }
.status-dot.yellow { background: var(--warning); }
.status-dot.red    { background: var(--danger); }
.status-dot.gray   { background: var(--text-muted); }

/* ─── Utilities ─────────────────────────────────────────────────── */
.flex   { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.gap-4  { gap: 16px; }
.mt-1   { margin-top: 4px; }
.mt-2   { margin-top: 8px; }
.mt-3   { margin-top: 12px; }
.mt-4   { margin-top: 16px; }
.mt-6   { margin-top: 24px; }
.mb-2   { margin-bottom: 8px; }
.mb-3   { margin-bottom: 12px; }
.mb-4   { margin-bottom: 16px; }
.mb-6   { margin-bottom: 24px; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.hidden { display: none !important; }

.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ─── Responsive ────────────────────────────────────────────────── */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  font-size: 22px;
  padding: 4px;
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .page-content { padding: 16px; }
  .filter-bar .form-control,
  .filter-bar .form-select { max-width: 100%; }
}

@media (max-width: 540px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 24px; }
  .topbar { padding: 0 14px; }
  .page-header { flex-direction: column; }
}

/* ─── Overlay backdrop (mobile sidebar) ─────────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}
.sidebar-backdrop.show { display: block; }

/* ─── Empty state ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state i { font-size: 52px; opacity: .3; margin-bottom: 12px; display: block; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; margin-bottom: 20px; }

/* ─── Pagination ────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  padding: 16px 0 0;
}
.page-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none !important;
  border: 1px solid var(--border);
  background: #fff;
  transition: all .18s;
}
.page-item:hover { background: var(--body-bg); color: var(--primary); border-color: var(--primary); }
.page-item.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-item.disabled { opacity: .4; pointer-events: none; }

/* ─── Floating label for forms ──────────────────────────────────── */
.form-row { display: grid; gap: 16px; }
.form-row.col-2 { grid-template-columns: 1fr 1fr; }
.form-row.col-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 640px) {
  .form-row.col-2,
  .form-row.col-3 { grid-template-columns: 1fr; }
}

/* ─── Map indicator ─────────────────────────────────────────────── */
.coord-pair {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
}

/* ─── Print ─────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .filter-bar, .btn, .page-header .btn { display: none !important; }
  .main-content { margin-left: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
