/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: #050D18; color: #E2E8F0; font-family: 'Inter', sans-serif; font-size: 14px; }
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ── Login ─────────────────────────────────────────────────────────────────── */
.login-bg {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: #050D18;
  background-image: radial-gradient(ellipse at 30% 40%, #0B2545 0%, transparent 55%),
                    radial-gradient(ellipse at 75% 70%, #08192E 0%, transparent 50%);
}
.login-card {
  width: 420px; background: linear-gradient(160deg, #0A1929 0%, #070F1C 100%);
  border: 1px solid #1E3A5F55; border-radius: 16px; padding: 48px 44px;
  box-shadow: 0 24px 80px #00000088;
}
.login-logo { text-align: center; margin-bottom: 40px; }
.logo-icon {
  width: 52px; height: 52px; margin: 0 auto 14px;
  background: linear-gradient(135deg, #00D4B4, #5B6AE8);
  border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; color: #fff;
}
.logo-icon.sm { width: 34px; height: 34px; font-size: 16px; border-radius: 9px; flex-shrink: 0; }
.logo-text { color: #E2E8F0; font-size: 20px; font-weight: 700; font-family: 'Playfair Display', serif; }
.logo-sub { color: #334155; font-size: 10px; letter-spacing: 2px; margin-top: 4px; }
.login-title { text-align: center; font-size: 22px; font-weight: 600; margin-bottom: 6px; }
.login-sub { text-align: center; color: #475569; font-size: 13px; margin-bottom: 32px; }
.field { margin-bottom: 16px; }
.field label { display: block; color: #64748B; font-size: 11px; letter-spacing: 0.8px; text-transform: uppercase; margin-bottom: 7px; }
.field input {
  width: 100%; padding: 13px 16px; background: #0A1929;
  border: 1px solid #1E3A5F; border-radius: 8px;
  color: #E2E8F0; font-size: 14px; outline: none; transition: all 0.2s;
}
.field input:focus { background: #0F2236; border-color: #00D4B466; }
.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 44px; }
.toggle-pass {
  position: absolute; right: 13px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: #334155; font-size: 15px; padding: 0; line-height: 1;
}
.btn-login {
  width: 100%; padding: 14px; margin-top: 12px;
  background: linear-gradient(135deg, #00C4A7 0%, #4F5FD8 100%);
  border: none; border-radius: 8px; color: #fff;
  font-size: 15px; font-weight: 600; letter-spacing: 0.3px; transition: opacity 0.2s;
  position: relative;
}
.btn-login:hover { opacity: 0.9; }
.btn-label {}
.error-box {
  background: #FF6B6B0D; border: 1px solid #FF6B6B33;
  border-radius: 8px; padding: 10px 14px; margin-bottom: 16px;
  color: #FF6B6B; font-size: 13px; text-align: center;
}
.login-footer { color: #1E3A5F; font-size: 12px; text-align: center; margin-top: 28px; }

/* HTMX indicator on login */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request .btn-label { display: none; }
.htmx-request.btn-login { background: #0F2236; border: 1px solid #1E3A5F; color: #475569; cursor: not-allowed; }

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

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: linear-gradient(180deg, #0A1929 0%, #050D18 100%);
  border-right: 1px solid #1E3A5F44;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-logo {
  padding: 22px 18px 18px;
  border-bottom: 1px solid #1E3A5F33;
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand { color: #E2E8F0; font-size: 15px; font-weight: 700; }
.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-btn {
  width: 100%; padding: 10px 12px; background: transparent;
  border: 1px solid transparent; border-radius: 8px;
  color: #64748B; font-size: 13px; text-align: left;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 4px; transition: all 0.15s;
}
.nav-btn:hover { color: #94A3B8; background: #0D1B2A; }
.nav-btn.active { color: #00D4B4; background: #00D4B411; border-color: #00D4B444; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }
.sidebar-user {
  padding: 14px 12px; border-top: 1px solid #1E3A5F33;
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #00D4B4, #5B6AE8);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
}
.user-name { color: #E2E8F0; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: #475569; font-size: 10px; }
.logout-btn {
  margin-left: auto; color: #475569; font-size: 16px;
  background: none; border: none; cursor: pointer; padding: 4px;
  flex-shrink: 0; transition: color 0.2s;
}
.logout-btn:hover { color: #FF6B6B; }

/* ── Main ──────────────────────────────────────────────────────────────────── */
.main { flex: 1; padding: 28px 32px; overflow-y: auto; min-width: 0; }

/* ── Topbar ────────────────────────────────────────────────────────────────── */
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; }
.page-title { font-size: 24px; font-weight: 700; font-family: 'Playfair Display', serif; }
.page-sub { color: #475569; font-size: 13px; margin-top: 4px; }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.badge-date { background: #0D1B2A; border: 1px solid #1E3A5F; border-radius: 8px; padding: 7px 14px; color: #94A3B8; font-size: 12px; }
.badge-live { background: #00D4B411; border: 1px solid #00D4B444; border-radius: 8px; padding: 7px 14px; color: #00D4B4; font-size: 12px; }

/* ── Tab loader ────────────────────────────────────────────────────────────── */
.tab-loader { display: none; margin-bottom: 8px; }
.tab-loader.htmx-request { display: block; }
.loader-bar {
  height: 2px; background: linear-gradient(90deg, #00D4B4, #5B6AE8);
  border-radius: 2px; animation: loadBar 1s ease infinite;
}
@keyframes loadBar { 0%{width:0%} 50%{width:70%} 100%{width:100%} }
.loading-placeholder { color: #334155; padding: 40px; text-align: center; }

/* ── KPI Grid ──────────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi-grid.three { grid-template-columns: repeat(3, 1fr); }
.kpi-grid.four  { grid-template-columns: repeat(4, 1fr); }
.kpi-card {
  background: linear-gradient(135deg, #0D1B2A 0%, #132030 100%);
  border: 1px solid #1E3A5F; border-radius: 12px;
  padding: 18px 20px; position: relative; overflow: hidden;
}
.kpi-glow { position: absolute; top: -20px; right: -20px; width: 80px; height: 80px; border-radius: 50%; }
.kpi-body { display: flex; justify-content: space-between; align-items: flex-start; position: relative; }
.kpi-label { color: #64748B; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; }
.kpi-value { color: #E2E8F0; font-size: 22px; font-weight: 700; margin: 6px 0 4px; font-family: 'IBM Plex Mono', monospace; }
.kpi-sub { font-size: 11px; }
.kpi-trend { font-size: 11px; margin-top: 2px; }
.kpi-trend.up { color: #00D4B4; }
.kpi-trend.down { color: #FF6B6B; }
.kpi-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }

/* ── Charts ────────────────────────────────────────────────────────────────── */
.charts-row { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; margin-bottom: 20px; }
.chart-card {
  background: #0D1B2A; border: 1px solid #1E3A5F44;
  border-radius: 12px; padding: 20px 24px;
}
.chart-card.wide { /* taken by 2fr grid */ }
.chart-card.full { margin-bottom: 20px; }
.chart-title { color: #E2E8F0; font-size: 14px; font-weight: 600; margin-bottom: 18px; }
.chart-wrap { position: relative; height: 220px; }
.chart-wrap.sm { height: 160px; }
.chart-wrap.tall { height: 280px; }

/* ── Legend ────────────────────────────────────────────────────────────────── */
.legend { margin-top: 12px; }
.legend-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.legend-name { color: #94A3B8; font-size: 11px; flex: 1; }
.legend-val { font-size: 11px; font-family: 'IBM Plex Mono', monospace; }

/* ── Progress bars ─────────────────────────────────────────────────────────── */
.progress-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.progress-label { color: #94A3B8; font-size: 12px; width: 90px; flex-shrink: 0; }
.progress-bar-bg { flex: 1; height: 6px; background: #0A1929; border-radius: 4px; }
.progress-bar-fill { height: 6px; border-radius: 4px; transition: width 0.6s ease; }
.progress-val { font-size: 11px; width: 36px; text-align: right; flex-shrink: 0; }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.mini-table, .data-table { width: 100%; border-collapse: collapse; }
.mini-table th, .data-table th { color: #475569; font-size: 11px; letter-spacing: 0.5px; padding: 8px 10px; text-align: left; border-bottom: 1px solid #1E3A5F; text-transform: uppercase; }
.mini-table td, .data-table td { color: #E2E8F0; font-size: 12px; padding: 10px 10px; border-bottom: 1px solid #1E3A5F22; }
.mini-table tr:last-child td, .data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #0A192988; }

/* ── Tags & Badges ─────────────────────────────────────────────────────────── */
.tag { background: #1E3A5F44; border-radius: 4px; padding: 2px 8px; color: #64748B; font-size: 11px; }
.badge-active { border: 1px solid; border-radius: 20px; padding: 3px 10px; font-size: 10px; }
.aging-badge { border-radius: 4px; padding: 2px 8px; font-size: 10px; }
.aging-badge.green  { background: #00D4B422; color: #00D4B4; }
.aging-badge.yellow { background: #FFD70022; color: #FFD700; }
.aging-badge.red    { background: #FF6B6B22; color: #FF6B6B; }

/* ── Utility ───────────────────────────────────────────────────────────────── */
.mono   { font-family: 'IBM Plex Mono', monospace; }
.muted  { color: #475569; }
.teal   { color: #00D4B4; }
.red    { color: #FF6B6B; }
.yellow { color: #FFD700; }

/* ── Routes ────────────────────────────────────────────────────────────────── */
.route-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.route-card { background: #0D1B2A; border: 1px solid; border-radius: 12px; padding: 20px 24px; }
.route-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.route-header h3 { font-size: 16px; font-weight: 700; }
.route-revenue { font-size: 24px; font-weight: 700; font-family: 'IBM Plex Mono', monospace; margin-bottom: 16px; color: #E2E8F0; }
.route-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat-box { background: #0A1929; border-radius: 8px; padding: 10px 12px; }
.stat-label { color: #475569; font-size: 10px; letter-spacing: 0.5px; margin-bottom: 4px; text-transform: uppercase; }
.stat-val { font-size: 14px; font-weight: 600; font-family: 'IBM Plex Mono', monospace; color: #E2E8F0; }
.stat-val.lg { font-size: 18px; }
.route-sp { background: #0A1929; border-radius: 8px; padding: 8px 12px; color: #475569; font-size: 11px; }
.route-sp span { color: #E2E8F0; }

/* ── Debtors ───────────────────────────────────────────────────────────────── */
.aging-row { margin-bottom: 16px; }
.aging-header { display: flex; justify-content: space-between; margin-bottom: 6px; color: #94A3B8; font-size: 12px; }
.alert-box { background: #FF6B6B11; border: 1px solid #FF6B6B22; border-radius: 8px; padding: 12px; color: #FF6B6B; font-size: 12px; margin-top: 20px; }

/* ── Team ──────────────────────────────────────────────────────────────────── */
.sp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-bottom: 24px; }
.sp-card { background: #0D1B2A; border: 1px solid #1E3A5F44; border-radius: 12px; padding: 20px 24px; }
.sp-header { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.sp-avatar {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #00D4B4, #5B6AE8);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: #fff;
}
.sp-header h3 { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.sp-route { color: #5B6AE8; font-size: 12px; }
.sp-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* ── Group View ────────────────────────────────────────────────────────────── */
.group-banner {
  background: linear-gradient(135deg, #0D1B2A, #132030);
  border: 1px solid #FFD70033; border-radius: 12px;
  padding: 20px 24px; margin-bottom: 24px;
  display: flex; gap: 16px; align-items: center;
}
.group-icon { font-size: 32px; }
.group-banner h2 { color: #FFD700; font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.group-banner p { color: #64748B; font-size: 12px; }
.company-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.company-card { background: #0D1B2A; border: 1px solid; border-radius: 12px; padding: 24px; }
.company-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.company-header h3 { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.company-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Mobile Navigation Bottom Bar ─────────────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: #0A1929; border-top: 1px solid #1E3A5F44;
  padding: 8px 4px 12px;
  overflow-x: auto; gap: 4px;
}
.mobile-nav-btn {
  flex: 1; min-width: 56px; padding: 6px 4px;
  background: transparent; border: none;
  color: #475569; font-size: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  cursor: pointer; border-radius: 8px; transition: all 0.15s;
  white-space: nowrap;
}
.mobile-nav-btn.active { color: #00D4B4; background: #00D4B411; }
.mobile-nav-icon { font-size: 18px; line-height: 1; }

/* ── Tablet & Mobile ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Login */
  .login-card { width: 100%; max-width: 100%; border-radius: 0; padding: 40px 24px; min-height: 100vh; border: none; display: flex; flex-direction: column; justify-content: center; }

  /* App layout — hide sidebar, show bottom nav */
  .sidebar { display: none; }
  .mobile-nav { display: flex; }
  .app { flex-direction: column; }
  .main { padding: 16px; padding-bottom: 80px; }

  /* Topbar */
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 18px; }
  .page-title { font-size: 20px; }
  .topbar-right { width: 100%; justify-content: flex-start; }
  .badge-date { font-size: 11px; padding: 5px 10px; }
  .badge-live { font-size: 11px; padding: 5px 10px; }

  /* KPI grids — 2 columns on mobile */
  .kpi-grid        { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .kpi-grid.three  { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid.four   { grid-template-columns: repeat(2, 1fr); }
  .kpi-value       { font-size: 16px; }
  .kpi-card        { padding: 14px 14px; }
  .kpi-icon        { display: none; }

  /* Charts — stack vertically */
  .charts-row { grid-template-columns: 1fr; gap: 14px; margin-bottom: 14px; }
  .chart-wrap { height: 180px; }
  .chart-wrap.sm { height: 160px; }
  .chart-wrap.tall { height: 220px; }
  .chart-card { padding: 16px; }
  .chart-card.full { margin-bottom: 14px; }

  /* Routes — single column */
  .route-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Team — single column */
  .sp-grid { grid-template-columns: 1fr; gap: 14px; }
  .sp-stats { grid-template-columns: repeat(3, 1fr); }

  /* Company grid — single column */
  .company-grid { grid-template-columns: 1fr; }
  .company-stats { grid-template-columns: repeat(2, 1fr); }

  /* Tables — scrollable */
  .chart-card { overflow-x: auto; }
  .data-table, .mini-table { min-width: 500px; }

  /* Group banner */
  .group-banner { flex-direction: column; align-items: flex-start; gap: 10px; padding: 16px; }
  .group-banner h2 { font-size: 15px; }
}

@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-grid.three { grid-template-columns: 1fr; }
  .sp-stats { grid-template-columns: repeat(2, 1fr); }
  .main { padding: 12px; padding-bottom: 80px; }
}
