/* ============================================
   SF VDU Dashboard — styles
   ============================================ */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-alt: #fafbfd;
  --border: #e6e9ef;
  --border-strong: #d8dde6;

  --text: #0f172a;
  --text-soft: #475569;
  --text-mute: #94a3b8;

  --primary: #0f172a;
  --primary-2: #1e293b;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --accent-soft: #eef2ff;

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;

  --c1: #6366f1;
  --c2: #06b6d4;
  --c3: #10b981;
  --c4: #f59e0b;
  --c5: #ef4444;
  --c6: #8b5cf6;
  --c7: #ec4899;
  --c8: #14b8a6;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 24px -10px rgba(15, 23, 42, 0.18), 0 4px 8px -4px rgba(15, 23, 42, 0.08);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

/* ============ Sidebar ============ */
.sidebar {
  background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
  color: #cbd5e1;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 20px;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  font-size: 13px;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}
.brand-title { color: #fff; font-weight: 700; font-size: 15px; }
.brand-subtitle { font-size: 11px; color: #64748b; letter-spacing: 0.3px; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  color: #94a3b8;
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: all 0.15s ease;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: #e2e8f0; }
.nav-item.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(99, 102, 241, 0.08));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.2);
}
.nav-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-size: 14px;
  color: var(--accent-2);
}
.nav-item.active .nav-icon { color: var(--accent-2); }

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 11px;
  color: #64748b;
}
.meta-line { padding: 2px 0; }
.meta-line em { color: #94a3b8; font-style: normal; }

/* ============ Main area ============ */
.main { padding: 32px 40px 60px; min-width: 0; }

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}
.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.2px;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.topbar h1 { font-size: 28px; font-weight: 700; margin: 0; letter-spacing: -0.5px; color: var(--text); }
.lead { color: var(--text-soft); margin: 6px 0 0; font-size: 14px; }

.topbar-actions { display: flex; gap: 10px; align-items: center; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface);
  color: var(--text-soft);
  border: 1px solid var(--border);
}
.badge-soft { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ============ KPIs ============ */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
}
.kpi.kpi-amber::before { background: var(--c4); }
.kpi.kpi-cyan::before { background: var(--c2); }
.kpi.kpi-emerald::before { background: var(--c3); }
.kpi.kpi-rose::before { background: var(--c7); }
.kpi.kpi-violet::before { background: var(--c6); }
.kpi.kpi-teal::before { background: var(--c8); }
.kpi-label { font-size: 11.5px; color: var(--text-soft); font-weight: 500; text-transform: uppercase; letter-spacing: 0.6px; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--text); margin-top: 6px; letter-spacing: -0.5px; }
.kpi-hint { font-size: 11px; color: var(--text-mute); margin-top: 2px; }

/* ============ Grid & cards ============ */
.grid { display: grid; gap: 20px; margin-bottom: 24px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 1100px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .app { grid-template-columns: 64px 1fr; }
  .brand-text, .nav-item span:last-child, .sidebar-footer { display: none; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.card-chart { display: flex; flex-direction: column; }
.card-head { margin-bottom: 14px; }
.card-head h3 {
  font-size: 14.5px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
  letter-spacing: -0.2px;
}
.card-head .sub { font-size: 12px; color: var(--text-mute); display: block; margin-top: 2px; }

.canvas-wrap { position: relative; height: 280px; }
.canvas-wrap.tall { height: 360px; }
.canvas-wrap.xtall { height: 460px; }
canvas { max-width: 100%; }

/* ============ Tables ============ */
.table-wrap { overflow: auto; max-height: 440px; border: 1px solid var(--border); border-radius: var(--r-md); }
.table-wrap-tall { max-height: 600px; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-alt);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-soft);
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table th.num { text-align: right; }
.data-table tbody tr { transition: background 0.1s; }
.data-table tbody tr:hover { background: var(--accent-soft); }
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }

/* ============ Category tiles ============ */
.cat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.cat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.cat-tile::after {
  content: '';
  position: absolute;
  right: -30px; top: -30px;
  width: 110px; height: 110px;
  border-radius: 50%;
  background: var(--cat-color, var(--accent));
  opacity: 0.08;
}
.cat-tile-label { font-size: 12px; color: var(--text-soft); font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase; }
.cat-tile-count { font-size: 30px; font-weight: 800; margin-top: 6px; color: var(--cat-color, var(--accent)); letter-spacing: -0.6px; }
.cat-tile-pct { font-size: 12px; color: var(--text-mute); margin-top: 2px; }

/* ============ Search / filters ============ */
.search, .filter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  transition: all 0.15s;
  min-width: 220px;
}
.search:focus, .filter:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.filter { min-width: 160px; }
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  align-items: center;
}
.result-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 500;
}

.pager {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
  align-items: center;
  font-size: 12.5px;
  color: var(--text-soft);
}
.pager button {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: all 0.1s;
}
.pager button:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pager button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ Tabs ============ */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: transparent;
  border: none;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-soft);
  cursor: pointer;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.25s ease; }

/* ============ Timing summary ============ */
.timing-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}
.timing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.timing-card.month-mai { border-top: 3px solid var(--c1); }
.timing-card.month-juin { border-top: 3px solid var(--c2); }
.timing-card.month-juillet { border-top: 3px solid var(--c4); }
.timing-card-label { font-size: 11px; color: var(--text-soft); font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase; }
.timing-card-count { font-size: 22px; font-weight: 700; color: var(--text); margin-top: 4px; }

/* ============ Heatmaps ============ */
.heatmap-wrap {
  overflow: auto;
  padding-top: 6px;
  border-radius: var(--r-md);
}
.heatmap-large { max-height: 700px; }

.heatmap {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  table-layout: auto;
}

/* Column cells: fixed-ish width so timing month columns line up nicely */
.heatmap th, .heatmap td {
  padding: 9px 10px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background-clip: padding-box;
  min-width: 70px;
  white-space: nowrap;
}
.heatmap thead th:first-child,
.heatmap tbody th:first-child,
.heatmap tfoot td:first-child {
  border-left: 1px solid var(--border);
}
.heatmap thead th { border-top: 1px solid var(--border); }

/* Header row: month / timing labels */
.heatmap thead th {
  background: var(--surface-alt);
  font-weight: 600;
  color: var(--text-soft);
  font-size: 11px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 2;
}

/* First column header (corner cell) */
.heatmap thead th.row-label {
  left: 0;
  z-index: 3;
  text-align: left;
  background: var(--surface-alt);
}

/* Row labels (first column of each body row): sticky on horizontal scroll */
.heatmap th.row-label {
  text-align: left;
  font-weight: 500;
  color: var(--text);
  background: #fff;
  text-transform: none;
  letter-spacing: 0;
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 180px;
  max-width: 280px;
  white-space: normal;
}

/* Body cells */
.heatmap td.cell {
  color: var(--text);
  font-weight: 500;
}
.heatmap td.cell-empty {
  color: var(--text-mute);
  font-weight: 400;
}

/* Footer totals row */
.heatmap tfoot td {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text);
  border-top: 2px solid var(--border-strong);
  position: sticky;
  bottom: 0;
  z-index: 2;
}
.heatmap tfoot td.row-label {
  text-align: left;
  position: sticky;
  left: 0;
  bottom: 0;
  z-index: 3;
}

/* Total column (rightmost) */
.heatmap th.total-col,
.heatmap td.total-col {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text);
  border-left: 2px solid var(--border-strong);
}

/* Zebra-stripe body rows for readability */
.heatmap tbody tr:nth-child(odd) th.row-label { background: #fbfcfe; }

.scroll-shadow { box-shadow: var(--shadow-sm); border-radius: var(--r-md); }

/* ============ Auth overlay ============ */
.auth-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 25% 20%, rgba(99, 102, 241, 0.25), transparent 55%),
    radial-gradient(circle at 80% 80%, rgba(6, 182, 212, 0.18), transparent 55%),
    linear-gradient(135deg, #0f172a 0%, #111827 100%);
  z-index: 9999;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}
.auth-overlay.hidden {
  display: none;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 20px;
  padding: 36px 36px 28px;
  box-shadow:
    0 25px 60px -15px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}
.auth-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.5px;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.4);
}
.auth-title-block h2 { margin: 0; font-size: 19px; font-weight: 700; color: #0f172a; letter-spacing: -0.3px; }
.auth-title-block p { margin: 1px 0 0; font-size: 11px; color: #64748b; letter-spacing: 0.4px; text-transform: uppercase; }

.auth-desc {
  font-size: 13px;
  color: #475569;
  line-height: 1.5;
  margin: 0 0 22px;
}

.auth-field {
  margin-bottom: 16px;
}
.auth-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #475569;
  margin-bottom: 7px;
}
.auth-field input[type=password] {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  color: #0f172a;
  background: #fff;
  border: 1px solid #d8dde6;
  border-radius: 10px;
  transition: all 0.15s;
  letter-spacing: 0.05em;
}
.auth-field input[type=password]:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

.auth-btn {
  width: 100%;
  padding: 12px 16px;
  background: linear-gradient(135deg, #6366f1, #818cf8);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
  margin-top: 4px;
}
.auth-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(99, 102, 241, 0.45);
}
.auth-btn:disabled { opacity: 0.7; cursor: not-allowed; }

.auth-btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.auth-btn.loading .auth-btn-spinner { display: inline-block; }
.auth-btn.loading .auth-btn-label { opacity: 0.8; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-error {
  margin-top: 12px;
  padding: 9px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 12.5px;
  border-radius: 8px;
  font-weight: 500;
  text-align: center;
  animation: shake 0.35s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.auth-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 12.5px;
  color: #64748b;
  user-select: none;
  cursor: pointer;
}
.auth-remember input { accent-color: #6366f1; cursor: pointer; }

.logout-btn {
  margin-top: 10px;
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #94a3b8;
  padding: 7px 10px;
  font-size: 11.5px;
  font-family: inherit;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.logout-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}
