/* ==========================================================================
   NAM A BANK - KPI SYSTEM - THEME
   Enterprise / Power BI style - Navy / Gold / White + Dark mode
   ========================================================================== */

:root {
  --navy: #0b2545;
  --navy-light: #163a63;
  --navy-lighter: #1f4e8c;
  --gold: #c9a227;
  --gold-light: #e6c862;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-alt: #f0f2f7;
  --text: #1b2430;
  --text-muted: #64748b;
  --border: #e2e8f0;

  --red: #e5484d;
  --yellow: #f5a623;
  --blue: #2e90fa;
  --green: #12b76a;

  --red-bg: #fde8e8;
  --yellow-bg: #fef3d9;
  --blue-bg: #e3f2ff;
  --green-bg: #e2f8ec;

  --sidebar-width: 250px;
  --topbar-height: 64px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.1);
}

:root[data-theme='dark'] {
  --bg: #0f172a;
  --surface: #16213b;
  --surface-alt: #1c2b4a;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #263a5c;
  --red-bg: #3a1518;
  --yellow-bg: #3a2c0f;
  --blue-bg: #0f2540;
  --green-bg: #0d2f22;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f172a;
    --surface: #16213b;
    --surface-alt: #1c2b4a;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #263a5c;
    --red-bg: #3a1518;
    --yellow-bg: #3a2c0f;
    --blue-bg: #0f2540;
    --green-bg: #0d2f22;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  transition: background 0.2s ease, color 0.2s ease;
}

a { text-decoration: none; }

/* ---------------- Auth pages ---------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 55%, #0a1a33 100%);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
}

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}

.auth-logo img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--gold);
  margin-bottom: 10px;
}

.auth-logo h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
  margin: 0;
}
:root[data-theme='dark'] .auth-logo h1 { color: var(--gold-light); }

.auth-logo p {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 2px 0 0;
}

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

.sidebar {
  width: var(--sidebar-width);
  background: var(--navy);
  color: #fff;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 1030;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand img { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--gold); }
.sidebar-brand .name { font-weight: 700; font-size: 14px; line-height: 1.2; }
.sidebar-brand .sub { font-size: 10.5px; color: var(--gold-light); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.sidebar-nav .nav-section-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: rgba(255,255,255,0.45); padding: 14px 18px 6px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; color: rgba(255,255,255,0.82); font-size: 13.5px;
  border-left: 3px solid transparent;
}
.sidebar-nav a i { width: 18px; text-align: center; font-size: 15px; }
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active {
  background: rgba(201,162,39,0.14);
  border-left-color: var(--gold);
  color: var(--gold-light);
  font-weight: 600;
}

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

.main-wrap { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 1020;
}
.topbar .page-title { font-size: 17px; font-weight: 700; color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); cursor: pointer; position: relative;
}
.icon-btn:hover { background: var(--surface-alt); }
.icon-btn .dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }

.user-chip { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.user-chip .avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--navy); color: var(--gold-light);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.user-chip .meta { line-height: 1.15; }
.user-chip .meta .name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-chip .meta .role { font-size: 11px; color: var(--text-muted); }

.content { padding: 22px; flex: 1; }

#sidebarBackdrop { display: none; }

@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  #sidebarBackdrop.show {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 1025;
  }
}

/* ---------------- Cards / KPI tiles ---------------- */
.card-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
}
.stat-tile .icon {
  width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.stat-tile .label { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.stat-tile .value { font-size: 21px; font-weight: 700; color: var(--text); }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.kpi-card.status-red { border-left-color: var(--red); }
.kpi-card.status-yellow { border-left-color: var(--yellow); }
.kpi-card.status-blue { border-left-color: var(--blue); }
.kpi-card.status-green { border-left-color: var(--green); }

.kpi-card .kpi-name { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.kpi-card .kpi-figures { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-muted); margin-bottom: 8px; }
.kpi-card .kpi-figures b { color: var(--text); font-weight: 600; }

.progress-track {
  height: 8px; border-radius: 6px; background: var(--surface-alt); overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 6px; transition: width 0.4s ease; }
.progress-fill.status-red { background: var(--red); }
.progress-fill.status-yellow { background: var(--yellow); }
.progress-fill.status-blue { background: var(--blue); }
.progress-fill.status-green { background: var(--green); }

.badge-status { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; display: inline-block; }
.badge-status.status-red { background: var(--red-bg); color: var(--red); }
.badge-status.status-yellow { background: var(--yellow-bg); color: #a06400; }
.badge-status.status-blue { background: var(--blue-bg); color: var(--blue); }
.badge-status.status-green { background: var(--green-bg); color: var(--green); }

/* ---------------- Section header ---------------- */
.section-title {
  font-size: 15px; font-weight: 700; margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.section-title i { color: var(--gold); }

/* ---------------- Insight box ---------------- */
.insight-box {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: #fff; border-radius: var(--radius); padding: 16px 18px;
}
.insight-box .title { font-weight: 700; font-size: 13px; color: var(--gold-light); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.insight-box ul { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.7; }

/* ---------------- Heatmap ---------------- */
.heatmap-wrap { overflow-x: auto; }
.heatmap-table { border-collapse: collapse; font-size: 11px; width: 100%; }
.heatmap-table th, .heatmap-table td { padding: 3px; text-align: center; border: 1px solid var(--border); }
.heatmap-table th { color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.heatmap-cell { width: 26px; height: 22px; border-radius: 4px; margin: 0 auto; }

/* ---------------- Ranking ---------------- */
.rank-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; }
.rank-row:hover { background: var(--surface-alt); }
.rank-number { width: 30px; text-align: center; font-weight: 700; color: var(--text-muted); }
.rank-medal { font-size: 20px; }
.rank-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--navy); color: var(--gold-light);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.rank-name { font-weight: 600; font-size: 13.5px; }
.rank-sub { font-size: 11.5px; color: var(--text-muted); }
.rank-score { font-weight: 700; font-size: 14px; margin-left: auto; }

/* ---------------- Tables ---------------- */
.table thead th {
  background: var(--surface-alt); color: var(--text-muted); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700;
  border-bottom: 2px solid var(--border);
}
.table td, .table th { vertical-align: middle; color: var(--text); border-color: var(--border); }
.table-hover tbody tr:hover { background: var(--surface-alt); }

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
}
.dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { color: var(--text) !important; }
.page-link { background: var(--surface); color: var(--text); border-color: var(--border); }
.page-item.active .page-link { background: var(--navy); border-color: var(--navy); }

/* ---------------- Forms / buttons ---------------- */
.form-control, .form-select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.form-control:focus, .form-select:focus {
  border-color: var(--navy-lighter); box-shadow: 0 0 0 3px rgba(31,78,140,0.15);
  background: var(--surface); color: var(--text);
}
.btn-navy { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-light); border-color: var(--navy-light); color: #fff; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #1b2430; font-weight: 600; }
.btn-gold:hover { background: var(--gold-light); border-color: var(--gold-light); color: #1b2430; }

.modal-content { background: var(--surface); color: var(--text); }

/* ---------------- Toast ---------------- */
.toast-stack { position: fixed; top: 78px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }

/* ---------------- Misc ---------------- */
.text-muted-2 { color: var(--text-muted); }
.badge-team { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); font-weight: 600; }
.loading-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.35); z-index: 2500;
  display: flex; align-items: center; justify-content: center;
}
.spinner-gold { width: 3rem; height: 3rem; color: var(--gold); }

.filter-bar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
