/* ============================================
   DRIVO Executive BI Dashboard
   Brand: navy/blue/yellow on near-white
   ============================================ */

:root {
  --navy: #091365;
  --blue: #0D1CA4;
  --yellow: #F3BB04;
  --white: #FBFBFB;
  --black: #121212;

  --bg: #F4F5FA;
  --surface: #FFFFFF;
  --surface-2: #F8F9FC;
  --border: #E4E7EF;
  --muted: #6B7280;
  --text: #1A1F36;
  --text-soft: #4B5266;

  --green: #10B981;
  --red: #EF4444;
  --orange: #F59E0B;

  --shadow-sm: 0 1px 2px rgba(9, 19, 101, 0.04), 0 1px 3px rgba(9, 19, 101, 0.06);
  --shadow-md: 0 4px 12px rgba(9, 19, 101, 0.06), 0 2px 6px rgba(9, 19, 101, 0.04);
  --shadow-lg: 0 12px 32px rgba(9, 19, 101, 0.10);

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;

  --font-display: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============================================
   LAYOUT
   ============================================ */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--navy);
  color: var(--white);
  padding: 24px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 0 24px 28px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 20px;
}
.brand-mark {
  width: 32px; height: 32px;
  background: var(--yellow);
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: var(--navy);
  font-weight: 800;
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: -0.02em;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.55);
  margin-top: 2px;
}

.nav { display: flex; flex-direction: column; padding: 0 12px; gap: 2px; flex: 1; }
.nav-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: rgba(255,255,255,0.4);
  padding: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, color .15s;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: var(--white); }
.nav-item.active {
  background: var(--blue);
  color: var(--white);
  font-weight: 600;
}
.nav-item .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .5;
}

.sidebar-footer {
  padding: 16px 24px;
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  border-top: 1px solid rgba(255,255,255,0.08);
}

/* MAIN */
.main {
  padding: 28px 36px 80px;
  max-width: 100%;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--navy);
}
.page-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

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

.refresh-meta {
  font-size: 11px;
  color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(16,185,129,0.18);
}
.status-dot.error { background: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,0.18); }
.status-dot.loading { background: var(--yellow); animation: pulse 1.2s infinite; }

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

/* BUTTONS */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s;
  font-family: inherit;
}
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--white);
}
.btn-primary:hover { background: var(--navy); border-color: var(--navy); color: var(--white); }
.btn-yellow {
  background: var(--yellow);
  border-color: var(--yellow);
  color: var(--navy);
  font-weight: 600;
}
.btn-yellow:hover { background: #d9a604; border-color: #d9a604; color: var(--navy); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-danger { color: var(--red); border-color: var(--border); }
.btn-danger:hover { background: var(--red); border-color: var(--red); color: white; }

/* FILTER BAR */
.filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  box-shadow: var(--shadow-sm);
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--muted);
  font-weight: 600;
}
.filter-input, .filter-select {
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  width: 100%;
}
.filter-input:focus, .filter-select:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--surface);
}

/* KPI GRID */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  min-height: 110px;
}
.kpi::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--blue);
}
.kpi.accent-yellow::before { background: var(--yellow); }
.kpi.accent-navy::before { background: var(--navy); }
.kpi.accent-green::before { background: var(--green); }
.kpi.accent-red::before { background: var(--red); }
.kpi.accent-orange::before { background: var(--orange); }

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 8px;
}
.kpi-value {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--navy);
  line-height: 1.1;
}
.kpi-sub {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.kpi-delta {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
}
.kpi-delta.up { background: rgba(16,185,129,0.12); color: var(--green); }
.kpi-delta.down { background: rgba(239,68,68,0.12); color: var(--red); }
.kpi-delta.flat { background: rgba(107,114,128,0.12); color: var(--muted); }

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.card-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--navy);
  margin: 0;
}
.card-subtitle {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.card-actions { display: flex; gap: 8px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 18px; }
@media (max-width: 1100px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* CHART CANVAS HOLDERS */
.chart-wrap { position: relative; height: 280px; }
.chart-wrap.tall { height: 360px; }
.chart-wrap.short { height: 200px; }

/* TABLES */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th, table.data td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  position: sticky; top: 0;
}
table.data tr:hover td { background: rgba(13, 28, 164, 0.025); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-soft);
  border: 1px solid var(--border);
}
.badge-yes { background: rgba(16,185,129,0.12); color: var(--green); border-color: transparent; }
.badge-no { background: rgba(239,68,68,0.10); color: var(--red); border-color: transparent; }
.badge-blue { background: rgba(13, 28, 164, 0.10); color: var(--blue); border-color: transparent; }
.badge-yellow { background: rgba(243, 187, 4, 0.20); color: #8a6900; border-color: transparent; }
.badge-navy { background: var(--navy); color: white; border-color: transparent; }

/* TABS */
.tabs {
  display: flex; gap: 4px; margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

/* SEARCH */
.search-input {
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 13px;
  width: 240px;
  max-width: 100%;
  font-family: inherit;
}
.search-input:focus { outline: none; border-color: var(--blue); background: var(--surface); }

/* PAGE VIEWS */
.view { display: none; }
.view.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* LOADING */
.loading-screen {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.92);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.25);
  color: var(--red);
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 13px;
}
.success-banner {
  background: rgba(16,185,129,0.08);
  border: 1px solid rgba(16,185,129,0.25);
  color: var(--green);
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 13px;
}

/* MODAL */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(9, 19, 101, 0.35);
  z-index: 100;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop.show { display: flex; animation: fadeIn .15s; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--navy);
  margin: 0;
}
.modal-body { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.form-row.single { grid-template-columns: 1fr; }
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 600;
}
.form-field input, .form-field select, .form-field textarea {
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}
.form-field textarea { min-height: 70px; resize: vertical; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none; border-color: var(--blue); background: var(--surface);
}

/* SECTION TITLE */
.section-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--muted);
  margin: 28px 0 12px;
  display: flex; align-items: center; gap: 10px;
}
.section-title::before {
  content: '';
  width: 18px; height: 2px;
  background: var(--yellow);
}

/* INSIGHTS LIST */
.insights {
  display: flex; flex-direction: column; gap: 10px;
}
.insight-item {
  display: flex; gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: 10px;
  border-left: 3px solid var(--blue);
  font-size: 13px;
}
.insight-item.warn { border-left-color: var(--orange); background: rgba(245,158,11,0.05); }
.insight-item.danger { border-left-color: var(--red); background: rgba(239,68,68,0.04); }
.insight-item.good { border-left-color: var(--green); background: rgba(16,185,129,0.04); }
.insight-icon {
  font-weight: 700;
  font-size: 16px;
  width: 22px;
  flex-shrink: 0;
}

/* RESPONSIVE */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; overflow-x: auto; }
  .sidebar-brand { border-bottom: none; padding: 0 16px; margin: 0; }
  .nav { flex-direction: row; padding: 0 12px; }
  .nav-section-title { display: none; }
  .nav-item { white-space: nowrap; }
  .sidebar-footer { display: none; }
  .main { padding: 18px; }
  .page-title { font-size: 22px; }
}

/* Tooltips on chart hover are handled by Chart.js */

/* Mini progress bar (for category share, etc.) */
.bar-track {
  background: var(--surface-2);
  height: 6px;
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--navy));
  border-radius: 99px;
}
.bar-fill.yellow { background: var(--yellow); }
