/* ===== TSEP Analytics Dashboard — Brand Theme ===== */
/* Brand palette: #FF4747 / #242424 / #797979 / #f6f6f6 */

/* === LIGHT MODE (default) === */
:root {
  /* Primary brand */
  --accent: #FF4747;
  --accent-soft: rgba(255, 71, 71, 0.08);
  --accent-hover: #FF5C5C;
  --accent-deep: #E63939;

  /* Secondary = dark from palette */
  --secondary: #242424;
  --secondary-soft: rgba(36, 36, 36, 0.06);
  --secondary-hover: #3a3a3a;

  /* Brand gradient (red shades) */
  --brand-gradient: linear-gradient(135deg, #FF4747 0%, #E63939 100%);
  --brand-gradient-cool: linear-gradient(135deg, #3a3a3a 0%, #242424 100%);

  /* Surfaces */
  --bg: #f6f6f6;            /* page bg from palette */
  --bg-2: #FFFFFF;          /* card bg */
  --bg-3: #ECECEC;          /* hover */

  /* Text */
  --white: #242424;         /* primary text from palette */
  --muted: #797979;         /* secondary text from palette */
  --muted-2: #A8A8A8;       /* tertiary text */

  /* Status */
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #d97706;
  --blue: #2563eb;
  --purple: #9333ea;

  /* Misc */
  --border: rgba(36, 36, 36, 0.08);
  --grid: rgba(36, 36, 36, 0.06);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);

  --radius: 10px;
  --radius-sm: 6px;

  color-scheme: light;
}

/* === DARK MODE === */
[data-theme="dark"] {
  --accent: #FF4747;
  --accent-soft: rgba(255, 71, 71, 0.14);
  --accent-hover: #FF6666;
  --accent-deep: #E63939;

  --secondary: #f6f6f6;     /* invert in dark */
  --secondary-soft: rgba(246, 246, 246, 0.08);
  --secondary-hover: #FFFFFF;

  --brand-gradient: linear-gradient(135deg, #FF4747 0%, #E63939 100%);
  --brand-gradient-cool: linear-gradient(135deg, #f6f6f6 0%, #797979 100%);

  --bg: #1A1A1A;            /* darker than #242424 for contrast */
  --bg-2: #242424;          /* card = palette dark */
  --bg-3: #2E2E2E;          /* hover */

  --white: #f6f6f6;         /* text = palette light */
  --muted: #B8B8B8;
  --muted-2: #797979;       /* palette gray */

  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --blue: #60a5fa;
  --purple: #c084fc;

  --border: rgba(246, 246, 246, 0.10);
  --grid: rgba(246, 246, 246, 0.06);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.30);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.40);

  color-scheme: dark;
}

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

/* ===== Accessibility — Focus rings ===== */
*:focus { outline: none; }
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* Skip-to-content link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: white;
  padding: 10px 16px;
  border-radius: 0 0 6px 0;
  font-weight: 600;
  font-size: 13px;
  z-index: 9999;
  text-decoration: none;
}
.skip-link:focus {
  left: 0;
}

/* Visually hidden (for screen readers) */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Reduced motion: respect user preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .dot-live { animation: none !important; }
  .feed-item.new { animation: none !important; }
  .skeleton, .skel-chart { animation: none !important; }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --border: rgba(0, 0, 0, 0.4) !important;
    --muted: #000 !important;
    --muted-2: #444 !important;
  }
  [data-theme="dark"] {
    --border: rgba(255, 255, 255, 0.5) !important;
    --muted: #fff !important;
    --muted-2: #ccc !important;
  }
}

html, body {
  font-family: -apple-system, "Segoe UI", "Sarabun", "Noto Sans Thai", Roboto, sans-serif;
  background: var(--bg);
  color: var(--white);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

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

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

/* Hamburger toggle (mobile only) */
.menu-toggle {
  display: none;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--white);
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
}
.menu-toggle:hover { border-color: var(--accent); color: var(--accent); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
}

/* ===== MOBILE (≤ 768px) ===== */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }

  /* Sidebar becomes off-canvas drawer */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 260px;
    height: 100vh;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.3);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-backdrop.show { display: block; }

  .menu-toggle { display: inline-flex; }

  /* Topbar wrap */
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
  }
  .topbar > div:first-child {
    flex: 1; min-width: 0;
  }
  .topbar h1 { font-size: 18px; }
  .topbar .subtitle { font-size: 12px; }
  .topbar-actions {
    flex-wrap: wrap;
    width: 100%;
    gap: 6px;
  }

  /* Main padding smaller */
  .main { padding: 16px; }

  /* Card padding */
  .card, .kpi { padding: 14px; }
  .kpi .value { font-size: 22px; }

  /* All grids → 1 column or 2 */
  .grid-4 { grid-template-columns: repeat(2, 1fr) !important; }
  .grid-3 { grid-template-columns: 1fr !important; }
  .grid-2 { grid-template-columns: 1fr !important; }
  .grid-2-1 { grid-template-columns: 1fr !important; }

  /* Tables scroll horizontally */
  .card:has(.table) {
    overflow-x: auto;
  }
  .table {
    min-width: 600px;
  }

  /* Hero & home */
  .hero { padding: 20px; }
  .hero h1 { font-size: 24px; }
  .quick-kpi { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }

  /* Filter chips */
  .chip-filter .chip-btn .chip-label { display: none; }
  .filter-pill { font-size: 12px; padding: 6px 10px; }

  /* Refresh control */
  .refresh-control { font-size: 11px; padding: 3px 4px 3px 10px; }
  .refresh-control .updated b { display: none; }

  /* User 360 specific */
  .user-profile {
    flex-direction: column;
    text-align: center;
    align-items: center !important;
  }
  .user-info .meta { justify-content: center; flex-wrap: wrap; }

  /* Sidebar search dropdown */
  .search-dropdown { max-width: 90vw; min-width: 280px; }
  .search-box { min-width: 200px; }

  /* Heatmaps wider scroll */
  .heatmap-time, .cohort-matrix {
    overflow-x: auto;
    display: block;
    white-space: nowrap;
  }

  /* TOC of architecture.html hidden on mobile */
  .toc { display: none !important; }
}

/* ===== PRINT STYLESHEET ===== */
@media print {
  /* Force light theme for print */
  :root, [data-theme="dark"] {
    --bg: #FFFFFF !important;
    --bg-2: #FFFFFF !important;
    --bg-3: #F5F5F5 !important;
    --white: #000000 !important;
    --muted: #333333 !important;
    --muted-2: #666666 !important;
    --border: rgba(0, 0, 0, 0.15) !important;
    --grid: rgba(0, 0, 0, 0.10) !important;
    --shadow: none !important;
    --shadow-lg: none !important;
  }

  html, body { background: white !important; color: black !important; }

  /* Hide UI chrome */
  .sidebar,
  .menu-toggle,
  .sidebar-backdrop,
  .subnav,
  .refresh-control,
  .btn-theme,
  .filter-pill:not(.active),
  .topbar-actions button,
  .topbar-actions .btn,
  #helpFab,
  #toast,
  #tourOverlay,
  #helpOverlay,
  #welcomeOverlay,
  .chip-filter,
  .add-compare,
  .pagination,
  .fav-btn,
  .menu-toggle,
  .clear-filters,
  .step-actions,
  .actions {
    display: none !important;
  }

  /* Main full width */
  .app { grid-template-columns: 1fr !important; }
  .main { padding: 0 !important; max-width: 100% !important; }

  /* Cards: no shadow, lighter border */
  .card, .kpi, .plat-card, .cohort-card, .spot-card {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
    page-break-inside: avoid;
    background: white !important;
  }

  /* Print header for every page */
  body::before {
    content: "TSEP Analytics Report — " attr(data-print-date);
    display: block;
    text-align: center;
    font-size: 10px;
    color: #888;
    padding: 8px 0;
    border-bottom: 1px solid #ddd;
    margin-bottom: 12px;
  }

  h1 { font-size: 18pt !important; color: #000 !important; }
  h2 { font-size: 14pt !important; color: #000 !important; }
  h3 { font-size: 12pt !important; color: #000 !important; }

  /* Page breaks */
  .card { page-break-inside: avoid; }
  table { page-break-inside: auto; }
  thead { display: table-header-group; }
  tr { page-break-inside: avoid; }

  /* Gradient backgrounds → solid for print */
  .nav-item.active,
  .filter-pill.active,
  .btn,
  .btn-refresh,
  .logo-mark,
  .funnel-step .bar,
  [class*="brand-gradient"] {
    background: #FF4747 !important;
    color: white !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Chart canvases keep colors */
  canvas { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Page setup */
  @page {
    margin: 12mm 14mm;
    size: A4;
  }
  @page :first {
    margin-top: 18mm;
  }
}

/* ===== TABLET (769-1100px) ===== */
@media (min-width: 769px) and (max-width: 1100px) {
  .app { grid-template-columns: 220px 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .quick-kpi { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Sidebar ===== */
.app {
  --sidebar-w: 248px;
}
.app:has(.sidebar.mini) {
  --sidebar-w: 76px;
}
.app {
  grid-template-columns: var(--sidebar-w) 1fr;
}

.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  padding: 16px 0 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  transition: width 0.2s ease;
  display: flex;
  flex-direction: column;
}
.sidebar .nav-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 12px;
}

/* MINI: allow tooltip to overflow */
.sidebar.mini {
  overflow: visible;
}
.sidebar.mini .nav-content {
  overflow-y: auto;
  overflow-x: visible;
}

/* Logo */
.sidebar .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 16px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  position: relative;
  flex-shrink: 0;
}
.sidebar .logo-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  flex: 1;
  min-width: 0;
}

/* Sidebar footer */
.sidebar-footer {
  flex-shrink: 0;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.sidebar.mini .sidebar-footer {
  flex-direction: column;
  justify-content: center;
  padding: 10px 0 14px;
  gap: 8px;
}

/* Theme button in sidebar */
.btn-theme-sidebar {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 36px; height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s, transform 0.3s;
}
.btn-theme-sidebar:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.btn-theme-sidebar i.ph { font-size: 16px; }
.btn-theme-sidebar.theme-spin { transform: rotate(360deg); }
.sidebar.mini .btn-theme-sidebar {
  width: 44px; height: 44px;
  border-radius: 14px;
}
.sidebar.mini .btn-theme-sidebar i.ph { font-size: 20px; }

.sidebar .logo-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--brand-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #FFFFFF;
  font-size: 16px;
  position: relative;
  box-shadow:
    0 4px 10px rgba(255, 71, 71, 0.30),
    inset 0 1px 0 rgba(255, 255, 255, 0.20);
  flex-shrink: 0;
}
.sidebar .logo-mark::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(255,255,255,0.18), transparent 40%);
  pointer-events: none;
}

.sidebar .logo-text {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.2px;
  color: var(--white);
  line-height: 1.2;
  white-space: nowrap;
}
.sidebar .logo-text small {
  display: block;
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-top: 2px;
  opacity: 0.7;
}

/* Collapse button (at footer) */
.btn-collapse {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 36px; height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.btn-collapse:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.btn-collapse i.ph { font-size: 16px; }

/* show different icon depending on mini state */
.btn-collapse .ic-collapse { display: none; }
.btn-collapse .ic-expand { display: inline-flex; align-items: center; }
.sidebar.mini .btn-collapse .ic-expand { display: none; }
.sidebar.mini .btn-collapse .ic-collapse { display: inline-flex; align-items: center; }

/* === MINI MODE (สไตล์มน · spacing เยอะ) === */
.sidebar.mini .logo-link { gap: 0; pointer-events: none; }
.sidebar.mini .logo-text { display: none; }
.sidebar.mini .nav-text { display: none; }
.sidebar.mini .label { display: none; }
.sidebar.mini .nav-items { display: block !important; }
.sidebar.mini .nav-items.hidden { display: block !important; }
.sidebar.mini .nav-section { padding: 0 12px; }
.sidebar.mini .nav-section + .nav-section { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.sidebar.mini .nav-item {
  justify-content: center;
  padding: 12px 0;
  margin: 4px 0;
  border-radius: 14px;
  width: 52px;
  height: 52px;
  margin-left: auto;
  margin-right: auto;
}
.sidebar.mini .nav-item .icon svg {
  width: 24px;
  height: 24px;
  stroke-width: 1.7;
}
.sidebar.mini .nav-item .icon i.ph {
  font-size: 26px;
}
.sidebar.mini .nav-item:hover {
  background: var(--bg-3);
}
.sidebar.mini .nav-item.active {
  background: var(--brand-gradient);
  box-shadow: 0 4px 12px rgba(255, 71, 71, 0.30);
}
.sidebar.mini .nav-item.active::after {
  display: none;
}
.sidebar.mini .logo {
  justify-content: center;
  padding: 4px 0 16px;
  margin-bottom: 8px;
}
.sidebar.mini .logo-link {
  flex: 0 0 auto;
  gap: 0;
  justify-content: center;
}
.sidebar.mini .logo-mark {
  width: 44px; height: 44px;
  border-radius: 14px;
  font-size: 18px;
  margin: 0 auto;
}
.sidebar.mini .btn-collapse {
  width: 44px; height: 44px;
  border-radius: 14px;
}
.sidebar.mini .btn-collapse i.ph { font-size: 20px; }

/* === Card tooltip when mini (portaled to <body>, fixed + JS) === */
.tip-card {
  display: none;
  position: fixed;
  /* top/left set via JS */
  transform: translateY(-50%);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  width: 280px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
  z-index: 2147483647; /* max int — above Chart.js canvas / any stacking context */
  gap: 12px;
  pointer-events: none;
}
.tip-card.is-visible {
  display: flex;
  animation: tipIn 0.15s ease-out;
}
@keyframes tipIn {
  from { opacity: 0; transform: translateY(-50%) translateX(-6px); }
  to { opacity: 1; transform: translateY(-50%) translateX(0); }
}
.tip-card::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 50%;
  transform: translateY(-50%);
  border: 7px solid transparent;
  border-right-color: var(--bg-2);
  pointer-events: none;
}

.tip-card .tip-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tip-card .tip-icon i.ph { font-size: 20px; }

.tip-card .tip-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.tip-card .tip-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--white);
  line-height: 1.3;
}
.tip-card .tip-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
}
.tip-card .tip-section {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--muted-2);
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
}
.tip-card .tip-section i.ph {
  font-size: 12px;
  color: var(--accent);
}

/* Active item — icon in tip-card uses gradient */
.tip-card.is-active .tip-icon {
  background: var(--brand-gradient);
  color: white;
}

.nav-section {
  padding: 6px 10px;
}
.nav-section .label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-section .label .label-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nav-section .label .sec-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--bg-3);
  color: var(--accent);
  opacity: 0.95;
}
.nav-section .label .sec-icon i.ph {
  font-size: 12px;
  line-height: 1;
}
.nav-section .label.collapsible:hover .sec-icon {
  background: var(--accent-soft);
  color: var(--accent);
}
.nav-section .label.collapsible {
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  transition: background 0.1s;
}
.nav-section .label.collapsible:hover {
  background: var(--bg-3);
  color: var(--white);
}
.nav-section .label.collapsible .caret {
  display: inline-flex;
  align-items: center;
  transition: transform 0.15s;
  color: var(--muted-2);
}
.nav-section .label.collapsible .caret svg {
  width: 14px; height: 14px;
}
.nav-section .label.collapsible.open .caret {
  transform: rotate(180deg);
  color: var(--accent);
}
.nav-section .nav-items {
  overflow: hidden;
  transition: max-height 0.2s ease-out;
}
.nav-section .nav-items.hidden {
  display: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 1px;
  position: relative;
  transition: all 0.15s;
  text-decoration: none;
  font-weight: 500;
}
.nav-item:hover {
  background: var(--bg-3);
  color: var(--white);
}
.nav-item.active {
  background: var(--brand-gradient);
  color: #FFFFFF;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(255, 71, 71, 0.30);
}
.nav-item.active::after {
  content: "";
  position: absolute;
  right: 8px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: white;
}
.nav-item .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  flex-shrink: 0;
  opacity: 0.85;
}
.nav-item.active .icon { opacity: 1; }
.nav-item .icon svg {
  width: 19px; height: 19px;
  stroke-width: 1.7;
}
.nav-item .icon i.ph {
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-section .label.collapsible .caret i.ph {
  font-size: 14px;
}
.btn-collapse i.ph {
  font-size: 14px;
}
.nav-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}
.nav-text .nav-th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 500;
}
.nav-text .nav-en {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 10px;
  font-weight: 400;
  color: var(--muted-2);
  margin-top: 1px;
  letter-spacing: 0.2px;
}
.nav-item.active .nav-text .nav-th { font-weight: 600; }
.nav-item.active .nav-text .nav-en { color: rgba(255,255,255,0.75); }
.nav-item:hover:not(.active) .nav-text .nav-en { color: var(--muted); }

/* Section label EN subtitle */
.nav-section .label .label-stack {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.15;
}
.nav-section .label .label-th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
}
.nav-section .label .label-en {
  font-size: 9px;
  text-transform: none;
  letter-spacing: 0.3px;
  font-weight: 500;
  color: var(--muted-2);
  margin-top: 1px;
  opacity: 0.8;
}

/* Tip-card EN title */
.tip-card .tip-title-en {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.2px;
  margin-top: -2px;
}

/* ===== Main ===== */
.main {
  padding: 24px 32px;
  max-width: 1600px;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.topbar h1 {
  font-size: 22px;
  font-weight: 700;
}
.topbar .subtitle {
  color: var(--muted-2);
  font-size: 13px;
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: nowrap;
  min-width: 0;
  overflow: visible; /* allow chip dropdowns to escape */
}
.topbar-actions > * { flex-shrink: 0; white-space: nowrap; }
.topbar-actions .refresh-control { margin-left: auto; }

.filter-pill {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

/* In-card course selector (native select styled to match design) */
.course-select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 7px 30px 7px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23999'><path d='M4.7 6.3a1 1 0 0 1 1.4 0L8 8.2l1.9-1.9a1 1 0 1 1 1.4 1.4l-2.6 2.6a1 1 0 0 1-1.4 0L4.7 7.7a1 1 0 0 1 0-1.4z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px;
  max-width: 240px;
  text-overflow: ellipsis;
  transition: border-color 0.15s, background-color 0.15s;
}
.course-select:hover { border-color: var(--accent); }
.course-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,71,71,0.15);
}
.course-select option {
  background: var(--bg-2);
  color: var(--white);
  font-weight: 500;
}

/* ===== Course Detail — Course switcher strip (above course title) ===== */
.course-nav-strip {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
}
.course-nav-strip .course-nav-back {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s;
}
.course-nav-strip .course-nav-back:hover { color: var(--accent); }
.course-nav-strip .course-nav-back i.ph { font-size: 14px; }
.course-nav-strip .course-nav-right {
  display: flex;
  gap: 6px;
  align-items: center;
}
.course-nav-strip .btn {
  padding: 6px 12px;
  font-size: 12px;
}
.course-nav-strip .btn:not(.btn-ghost) {
  padding: 6px 14px;
}

/* ===== Course Detail — Right slide-in drawer (course switcher) ===== */
.cd-drawer {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.cd-drawer.open {
  pointer-events: auto;
  opacity: 1;
}
.cd-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}
.cd-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 92vw;
  height: 100vh;
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
.cd-drawer.open .cd-drawer-panel { transform: translateX(0); }

.cd-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.cd-drawer-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--white);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.cd-drawer-title i.ph { color: var(--accent); font-size: 18px; }
.cd-drawer-sub {
  font-size: 11px;
  color: var(--muted-2);
  margin-top: 2px;
}
.cd-drawer-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.cd-drawer-close:hover { background: var(--bg-2); color: var(--white); border-color: var(--accent); }
.cd-drawer-close i.ph { font-size: 16px; }

.cd-drawer-search {
  position: relative;
  padding: 14px 20px;
}
.cd-drawer-search i.ph {
  position: absolute;
  left: 32px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted-2);
  font-size: 14px;
}
.cd-drawer-search input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 8px 12px 8px 32px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
.cd-drawer-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,71,71,0.12);
}

.cd-drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 12px;
}
.cd-course-item {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}
.cd-course-item:hover { background: var(--bg-2); }
.cd-course-item.current {
  background: rgba(255,71,71,0.10);
  border: 1px solid rgba(255,71,71,0.30);
}
.cd-course-item.current::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
}
.cd-course-item .cci-mark {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--bg-3);
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.cd-course-item.current .cci-mark {
  background: var(--brand-gradient);
  color: #fff;
}
.cd-course-item .cci-info { min-width: 0; }
.cd-course-item .cci-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cd-course-item .cci-meta {
  font-size: 11px;
  color: var(--muted-2);
  margin-top: 2px;
  display: flex;
  gap: 8px;
}
.cd-course-item .cci-meta b { color: var(--white); font-weight: 600; }
.cd-course-item .cci-rate {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.cd-course-item.rate-high .cci-rate   { color: var(--green); }
.cd-course-item.rate-mid  .cci-rate   { color: var(--accent); }
.cd-course-item.rate-low  .cci-rate   { color: var(--yellow); }
.cd-course-item.rate-bad  .cci-rate   { color: var(--red); }
.cd-course-item .cci-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 700;
  margin-left: 6px;
}
.cd-course-item.current .cci-badge {
  background: var(--accent);
  color: #fff;
}

/* User drawer item variant (User 360°) */
.cd-course-item.us-user-item {
  grid-template-columns: 44px 1fr auto;
  padding: 14px 14px;
}
.us-user-item .cci-name {
  font-size: 15px !important;
  font-weight: 700 !important;
  color: var(--white) !important;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.3;
}
.us-user-item .cci-meta {
  font-size: 12px !important;
  margin-top: 4px;
}
.us-user-item .usi-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--bg-3);
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
}
.us-user-item.current .usi-avatar {
  background: var(--brand-gradient);
  color: #fff;
}
.us-user-item .usi-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: 11px;
  color: var(--muted-2);
}
.us-user-item .usi-status .status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.us-user-item .usi-status .status-dot.active   { background: var(--green); }
.us-user-item .usi-status .status-dot.idle     { background: var(--yellow); }
.us-user-item .usi-status .status-dot.inactive { background: var(--muted-2); }
.us-user-item .usi-status .usi-last {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--muted-2);
}
.us-user-item .level-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-3);
  color: var(--muted);
  font-weight: 600;
}
.us-user-item.current .level-tag { background: var(--accent-soft); color: var(--accent); }

.cd-drawer-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted-2);
  font-size: 13px;
}
.cd-drawer-empty i.ph {
  font-size: 28px;
  opacity: 0.4;
  display: block;
  margin-bottom: 8px;
}

.cd-drawer-footer {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}
.cd-drawer-footer kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
}

/* Sortable table headers */
.sortable-table thead th {
  cursor: pointer;
  user-select: none;
  position: relative;
  white-space: nowrap;
}
.sortable-table thead th:hover { color: var(--white); }
.sortable-table thead th .sort-ic {
  font-size: 11px;
  opacity: 0.4;
  margin-left: 4px;
  vertical-align: middle;
  transition: opacity 0.15s;
}
.sortable-table thead th:hover .sort-ic { opacity: 0.8; }
.sortable-table thead th.sort-active {
  color: var(--accent);
}
.sortable-table thead th.sort-active .sort-ic {
  opacity: 1;
  color: var(--accent);
}
.filter-pill:hover {
  border-color: var(--secondary);
  color: var(--secondary);
  background: var(--secondary-soft);
}
.filter-pill.active {
  background: var(--brand-gradient);
  border-color: transparent;
  color: #FFFFFF;
  box-shadow: 0 1px 3px rgba(255, 71, 71, 0.25);
}
.filter-pill.active:hover {
  color: #FFFFFF;
  background: var(--brand-gradient);
}

.btn {
  background: var(--brand-gradient);
  color: #FFFFFF;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 0;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 3px rgba(255, 71, 71, 0.25);
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
}
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(255, 71, 71, 0.35);
}
.btn:active { transform: translateY(0); }

.btn-secondary {
  background: var(--secondary);
  color: #FFFFFF;
  box-shadow: 0 1px 3px rgba(36, 36, 36, 0.25);
}
.btn-secondary:hover {
  background: var(--secondary-hover);
  box-shadow: 0 3px 8px rgba(36, 36, 36, 0.30);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--white);
  box-shadow: none;
}
.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  transform: none;
  box-shadow: none;
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  box-shadow: none;
}
.btn-outline:hover {
  background: var(--accent);
  color: #FFFFFF;
  transform: none;
}

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

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-2-1 { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
}
.card-subtitle {
  font-size: 12px;
  color: var(--muted-2);
}

/* ===== KPI Card ===== */
.kpi {                                      /* clean — no decoration, mini bars at bottom */
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px 18px;
  position: relative;
  transition: border-color .15s, transform .15s, box-shadow .15s;
  text-decoration: none;
}
.kpi:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  box-shadow: 0 8px 20px rgba(0,0,0,.05);
}
.kpi.green:hover  { border-color: color-mix(in srgb, #22c55e 40%, var(--border)); }
.kpi.yellow:hover { border-color: color-mix(in srgb, #f59e0b 40%, var(--border)); }
/* ลบ accent ออกหมด */
.kpi::before { content: none; }
.kpi .label, .kpi .value, .kpi .delta { padding-left: 0; }

/* === mini horizontal bars (แทน chip) === */
.kpi-bars {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.kpi-bar {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
}
.kpi-bar .name {
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.3px;
}
.kpi-bar .track {
  height: 5px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.kpi-bar .fill {
  height: 100%;
  border-radius: 3px;
  transition: width .35s ease-out;
}
.kpi-bar .fill.sm  { background: var(--accent); }
.kpi-bar .fill.mgr { background: #a78bfa; }
.kpi-bar .fill.trn { background: var(--green); }
.kpi-bar .val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--white);
  font-size: 12px;
}

.kpi .label {
  font-size: 12.5px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.kpi .kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  text-transform: none;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.kpi .kpi-trend.up   { background: rgba(34,197,94,0.15);  color: var(--green); }
.kpi .kpi-trend.down { background: rgba(239,68,68,0.15);  color: var(--red); }
.kpi .kpi-trend i.ph { font-size: 12px; }
.kpi .value {
  font-size: 36px;
  font-weight: 800;
  color: var(--white);
  line-height: 1;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}
.kpi .value small {
  font-size: 17px;
  color: var(--muted-2);
  font-weight: 600;
  margin-left: 4px;
}
.kpi .delta {                               /* delta แบบเรียบ — ไม่มี chip bg แค่ตัวอักษรสี */
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.kpi .delta .up, .kpi .delta .down {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.kpi .delta .up   { color: var(--green); }
.kpi .delta .down { color: var(--red); }
.kpi .delta .info { color: var(--muted); display: inline-flex; align-items: center; gap: 3px; }
.kpi .delta i.ph { font-size: 13px; }
.kpi .delta .sep { color: var(--muted-2); opacity: 0.4; }

/* ===== Drop-off Funnel — Vertical bar layout (real funnel shape) ===== */
.funnel-v {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.funnel-v .fv-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--bg-3);
  border-radius: 10px;
  border: 1px solid var(--border);
  transition: border-color 0.15s, transform 0.15s;
}
.funnel-v .fv-row:hover {
  border-color: var(--accent);
  transform: translateX(2px);
}
.funnel-v .fv-row.is-critical {
  border-color: rgba(239,68,68,0.5);
  background: linear-gradient(90deg, rgba(239,68,68,0.06) 0%, var(--bg-3) 60%);
  margin-top: 16px; /* extra space for badge */
}
.fv-row .fv-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.fv-row .fv-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.fv-row.is-critical .fv-icon { background: rgba(239,68,68,0.15); color: var(--red); }
.fv-row .fv-name { font-size: 13px; font-weight: 700; color: var(--white); line-height: 1.1; }
.fv-row .fv-sub  { font-size: 11px; color: var(--muted-2); margin-top: 2px; }
/* Dual-platform bars — CSS Grid (bulletproof layout) */
.fv-stacked {
  display: grid;
  grid-template-columns: 1fr 80px;
  align-items: center;
  column-gap: 12px;
}
.fv-bars {
  display: grid;
  row-gap: 6px;
  min-width: 0;
}
.fv-line {
  display: grid;
  grid-template-columns: 42px 1fr 120px;
  align-items: center;
  column-gap: 10px;
  min-width: 0;
}
.fv-platform {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  line-height: 1;
}
.fv-line.pf-app .fv-platform { color: var(--accent); }
.fv-line.pf-web .fv-platform { color: #60a5fa; }
.fv-track {
  width: 100%;
  height: 18px;
  background: var(--bg-2);
  border-radius: 5px;
  overflow: hidden;
  min-width: 0;
}
.fv-fill-mini {
  display: block;
  height: 100%;
  border-radius: 5px;
  transition: width 0.4s ease;
}
.fv-line.pf-app .fv-fill-mini {
  background: linear-gradient(90deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 70%, white) 100%);
}
.fv-line.pf-web .fv-fill-mini {
  background: linear-gradient(90deg, #60a5fa 0%, color-mix(in srgb, #60a5fa 70%, white) 100%);
}
.fv-val {
  font-size: 11px;
  font-weight: 700;
  color: var(--white);
  text-align: right;
  white-space: nowrap;
}
.fv-val .pct {
  font-size: 10px;
  color: var(--muted-2);
  font-weight: 500;
  margin-left: 4px;
}

/* Gap chip — shows App-Web difference */
.fv-gap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 10px;
  text-align: center;
}
.fv-gap .gap-label {
  font-size: 9px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 700;
}
.fv-gap .gap-val {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}
.fv-gap.even .gap-val { color: var(--muted); }

/* Platform legend at top of funnel */
.fv-legend {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-size: 11px;
}
.fv-legend .leg-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: var(--muted);
}
.fv-legend .leg-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}
.fv-legend .leg-swatch.pf-app {
  background: linear-gradient(90deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 70%, white) 100%);
}
.fv-legend .leg-swatch.pf-web {
  background: linear-gradient(90deg, #60a5fa 0%, color-mix(in srgb, #60a5fa 70%, white) 100%);
}

/* Critical stage glow effect */
.fv-row.is-critical {
  position: relative;
}
.fv-row.is-critical::after {
  content: "⚠ Biggest drop";
  position: absolute;
  top: -10px;
  left: 14px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 3px 9px;
  border-radius: 8px;
  background: var(--red);
  color: white;
  text-transform: uppercase;
  z-index: 2;
  box-shadow: 0 2px 4px rgba(239,68,68,0.3);
}

/* Drop connector between rows — aligned with bars (row padding 14 + meta 200 + gap 14 = 228) */
.fv-drop {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  margin-left: 228px;
  border-radius: 10px;
  align-self: flex-start;
  width: fit-content;
}
.fv-drop.sev-low    { background: rgba(34,197,94,0.12);  color: var(--green); }
.fv-drop.sev-medium { background: rgba(245,158,11,0.15); color: var(--yellow); }
.fv-drop.sev-high   { background: rgba(239,68,68,0.18);  color: var(--red); }
.fv-drop i.ph { font-size: 12px; }

/* Legacy horizontal funnel kept for backward compat */
.funnel {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-top: 8px;
  position: relative;
}
.funnel-stage {
  background: linear-gradient(180deg, var(--bg-3) 0%, color-mix(in srgb, var(--bg-3) 70%, var(--bg-2)) 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 12px 14px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  transition: transform 0.15s, border-color 0.15s;
}
.funnel-stage:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.funnel-stage.is-critical {
  border-color: rgba(239,68,68,0.4);
  background: linear-gradient(180deg, rgba(239,68,68,0.06) 0%, var(--bg-2) 100%);
}
.funnel-stage .stage-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 18px;
  margin: 0 auto 6px;
}
.funnel-stage.is-critical .stage-icon {
  background: rgba(239,68,68,0.15);
  color: var(--red);
}
.funnel-stage .stage-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.funnel-stage .stage-count {
  font-size: 24px;
  font-weight: 700;
  color: var(--white);
  line-height: 1.1;
  margin-top: 2px;
}
.funnel-stage .stage-pct {
  font-size: 11px;
  color: var(--muted-2);
  margin-top: 1px;
}
.funnel-stage .stage-drop {
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  justify-content: center;
  margin-top: 8px;
  padding: 3px 8px;
  border-radius: 10px;
  background: rgba(239,68,68,0.10);
  color: var(--red);
  align-self: center;
}
.funnel-stage .stage-drop.sev-high   { background: rgba(239,68,68,0.18); }
.funnel-stage .stage-drop.sev-medium { background: rgba(245,158,11,0.15); color: var(--yellow); }
.funnel-stage .stage-drop.sev-low    { background: rgba(34,197,94,0.12);  color: var(--green); }
.funnel-stage .stage-drop i.ph { font-size: 12px; }
.funnel-stage::after {
  content: "";
  position: absolute;
  right: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 0; height: 0;
  border: 7px solid transparent;
  border-left-color: var(--border);
  z-index: 2;
}
.funnel-stage:last-child::after { display: none; }
.funnel-stage::before {
  content: "";
  position: absolute;
  right: -11px;
  top: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 2px;
  background: var(--border);
  z-index: 1;
}
.funnel-stage:last-child::before { display: none; }

/* Re-engagement card — per-channel mini-funnel + ratio footer */
.reeng-channels {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 8px;
}
.channel-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  position: relative;
  transition: border-color 0.15s, transform 0.15s;
}
.channel-card:hover { transform: translateY(-2px); }
.channel-card.winning {
  border-color: rgba(34,197,94,0.4);
  background: linear-gradient(180deg, rgba(34,197,94,0.06) 0%, var(--bg-3) 60%);
}
.channel-card .ch-head {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.channel-card .ch-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.channel-card.winning .ch-icon {
  background: rgba(34,197,94,0.18);
  color: var(--green);
}
.channel-card .ch-name { font-size: 14px; font-weight: 700; color: var(--white); }
.channel-card .ch-tag { font-size: 11px; color: var(--muted-2); margin-top: 2px; }
.channel-card .ch-rate {
  font-size: 28px;
  font-weight: 800;
  color: var(--white);
  line-height: 1;
  letter-spacing: -0.5px;
}
.channel-card.winning .ch-rate { color: var(--green); }

.ch-funnel {
  display: grid;
  grid-template-columns: 1fr 24px 1fr 24px 1fr;
  align-items: center;
  gap: 4px;
}
.cf-step {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
}
.cf-step.win {
  background: rgba(34,197,94,0.10);
  border-color: rgba(34,197,94,0.35);
}
.cf-step .cf-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--white);
  line-height: 1.05;
}
.cf-step.win .cf-val { color: var(--green); }
.cf-step .cf-label {
  font-size: 10px;
  color: var(--muted-2);
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 600;
}
.cf-step .cf-rate {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 500;
}
.cf-arrow {
  font-size: 16px;
  color: var(--muted-2);
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Ratio footer comparing the two channels */
.reeng-ratio {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 20px;
  margin-top: 16px;
  background: linear-gradient(135deg, rgba(34,197,94,0.10) 0%, rgba(34,197,94,0.02) 100%);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 12px;
}
.reeng-ratio .rr-num {
  font-size: 44px;
  font-weight: 800;
  color: var(--green);
  line-height: 1;
  letter-spacing: -1px;
}
.reeng-ratio .rr-num small {
  font-size: 16px;
  margin-left: 2px;
  letter-spacing: 0;
}
.reeng-ratio .rr-text { flex: 1; }
.reeng-ratio .rr-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--white);
  line-height: 1.3;
}
.reeng-ratio .rr-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* Legacy hero kept for back-compat */
.reeng-hero {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 18px 20px;
  background: linear-gradient(135deg, rgba(34,197,94,0.10) 0%, rgba(34,197,94,0.02) 100%);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 12px;
  margin-top: 8px;
  margin-bottom: 14px;
}
.reeng-hero .ratio {
  font-size: 44px;
  font-weight: 800;
  color: var(--green);
  line-height: 1;
  letter-spacing: -1px;
}
.reeng-hero .ratio small {
  font-size: 16px;
  font-weight: 600;
  color: var(--green);
  margin-left: 2px;
  letter-spacing: 0;
}
.reeng-hero .ratio-caption {
  flex: 1;
  font-size: 13px;
  color: var(--white);
  line-height: 1.4;
}
.reeng-hero .ratio-caption b { color: var(--green); }

.reeng-compare-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.reeng-compare-bar .compare-row {
  display: grid;
  grid-template-columns: 140px 1fr 60px;
  align-items: center;
  gap: 12px;
}
.reeng-compare-bar .compare-label {
  font-size: 12px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}
.reeng-compare-bar .compare-label i.ph { font-size: 14px; color: var(--accent); }
.reeng-compare-bar .compare-row.win .compare-label i.ph { color: var(--green); }
.reeng-compare-bar .compare-track {
  height: 12px;
  background: var(--bg-3);
  border-radius: 6px;
  overflow: hidden;
}
.reeng-compare-bar .compare-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 6px;
  transition: width 0.4s ease;
}
.reeng-compare-bar .compare-row.win .compare-fill {
  background: linear-gradient(90deg, var(--green) 0%, color-mix(in srgb, var(--green) 70%, white) 100%);
}
.reeng-compare-bar .compare-val {
  font-size: 14px;
  font-weight: 700;
  color: var(--white);
  text-align: right;
}
.reeng-compare-bar .compare-row.win .compare-val { color: var(--green); }

.reeng-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.reeng-row {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.reeng-row .reeng-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.reeng-row .reeng-head i.ph {
  width: 24px; height: 24px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.reeng-row .reeng-metrics {
  display: flex;
  gap: 16px;
  align-items: baseline;
}
.reeng-row .reeng-val {
  font-size: 20px;
  font-weight: 700;
  color: var(--white);
  line-height: 1.1;
}
.reeng-row .reeng-val small {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 4px;
}
.reeng-row .reeng-conv {
  font-size: 11px;
  color: var(--muted-2);
  margin-top: 2px;
}
.reeng-row.winning { border-color: var(--green); background: linear-gradient(180deg, rgba(34,197,94,0.04) 0%, var(--bg-3) 100%); }
.reeng-row.winning .reeng-head i.ph { background: rgba(34,197,94,0.15); color: var(--green); }

/* Dealer segmentation rows */
.seg-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.seg-status.good   { background: rgba(34,197,94,0.15);  color: var(--green); }
.seg-status.warn   { background: rgba(245,158,11,0.15); color: var(--yellow); }
.seg-status.bad    { background: rgba(239,68,68,0.15);  color: var(--red); }
.seg-status i.ph { font-size: 12px; }

/* Row tint based on status — subtle left-border accent */
tr.row-good   { box-shadow: inset 3px 0 0 var(--green); }
tr.row-warn   { box-shadow: inset 3px 0 0 var(--yellow); }
tr.row-bad    { box-shadow: inset 3px 0 0 var(--red); background: rgba(239,68,68,0.04); }
tr.row-good td:first-child,
tr.row-warn td:first-child,
tr.row-bad  td:first-child { padding-left: 14px; }
.table tbody tr:hover { background: var(--bg-3); }
.table tbody tr.row-bad:hover { background: rgba(239,68,68,0.08); }

/* Inline pct on inactive cell */
.cell-count {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}
.cell-count .pct {
  font-size: 10px;
  color: var(--muted-2);
  font-weight: 500;
}

/* Mini bar inside table cells */
.mini-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.mini-bar .bar {
  width: 60px;
  height: 5px;
  border-radius: 3px;
  background: var(--bg-3);
  overflow: hidden;
}
.mini-bar .bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}

/* Clickable KPI card */
a.kpi {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
a.kpi:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(255,71,71,0.15);
}
a.kpi::after {
  content: "";
  position: absolute;
  top: 16px; right: 60px;
  width: 12px; height: 12px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted-2) 50%);
  opacity: 0;
  transition: opacity 0.15s;
}
a.kpi:hover::after { opacity: 0.5; }

/* Below-target badge inside KPI */
.kpi .kpi-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 7px;
  border-radius: 8px;
  margin-top: 6px;
}
.kpi .kpi-badge.below { background: rgba(245,158,11,0.15); color: var(--yellow); }
.kpi .kpi-badge.above { background: rgba(34,197,94,0.15); color: var(--green); }
.kpi .kpi-badge i.ph { font-size: 11px; }

/* Course-remaining indicator */
.course-remaining {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
}
.course-remaining .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted-2);
}
.course-remaining.has-1 .dot,
.course-remaining.has-2 .dot { background: var(--yellow); }
.course-remaining.has-3 .dot,
.course-remaining.has-many .dot { background: var(--red); }
.course-remaining.has-0 { color: var(--muted-2); }

/* Relative time below absolute date */
.cell-time {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.cell-time .rel {
  font-size: 10px;
  color: var(--muted-2);
  margin-top: 1px;
}

/* Table footer link */
.table-footer {
  padding: 12px 10px 4px;
  display: flex;
  justify-content: center;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.table-footer a {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.table-footer a:hover { color: var(--accent-hover, var(--accent)); text-decoration: underline; }

/* KPI icon — minimal: ไอคอนสีล้วน ไม่มีกล่อง ไม่มีพื้น */
.kpi-icon {
  position: absolute;
  top: 20px;
  right: 20px;
  width: auto;
  height: auto;
  background: transparent;
  border: 0;
  color: var(--accent);
  display: inline-flex;
  opacity: 0.7;
  transition: opacity .15s, transform .15s;
}
.kpi:hover .kpi-icon { opacity: 1; transform: scale(1.08); }
.kpi-icon i.ph { font-size: 24px; }
.kpi.green .kpi-icon  { color: #22c55e; }
.kpi.yellow .kpi-icon { color: #f59e0b; }
.kpi.red .kpi-icon    { color: #ef4444; }
.kpi .label, .kpi .value, .kpi .delta { padding-right: 40px; }

/* Card title icon — small badge before title text */
.card-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}
.card-icon i.ph { font-size: 14px; }

/* Filter pill Phosphor icon */
.filter-pill i.ph { font-size: 12px; }
.btn i.ph, .btn-ghost i.ph { font-size: 14px; }

/* ===== Table ===== */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-weight: 600;
  color: var(--muted-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--white);
}
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--bg-3); }

/* ===== Badge ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge i.ph { font-size: 12px; }
.badge.success { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.badge.warn { background: color-mix(in srgb, var(--yellow) 15%, transparent); color: var(--yellow); }
.badge.danger { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.muted { background: var(--bg-3); color: var(--muted); }

/* ===== Progress bar ===== */
.progress {
  width: 100%;
  height: 6px;
  background: var(--bg-3);
  border-radius: 4px;
  overflow: hidden;
}
.progress .fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}
.progress .fill.green { background: var(--green); }
.progress .fill.yellow { background: var(--yellow); }

/* ===== Chart container ===== */
.chart-wrap {
  position: relative;
  height: 280px;
}
.chart-wrap.tall { height: 360px; }
.chart-wrap.short { height: 180px; }

/* ===== Funnel ===== */
.funnel {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.funnel-step {
  background: var(--bg-3);
  border-radius: 6px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  overflow: hidden;
}
.funnel-step .bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
}
.funnel-step .text {
  position: relative;
  font-weight: 600;
  font-size: 13px;
}
.funnel-step .num {
  position: relative;
  font-weight: 700;
  font-size: 14px;
}
.funnel-step .num small {
  color: var(--muted-2);
  font-weight: 400;
  margin-left: 4px;
}

/* ===== Heatmap cell ===== */
.heatmap {
  display: grid;
  grid-template-columns: 80px repeat(7, 1fr);
  gap: 3px;
  font-size: 11px;
}
.heatmap .head {
  color: var(--muted-2);
  padding: 6px 4px;
  text-align: center;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.heatmap .label-row {
  color: var(--muted-2);
  padding: 6px 4px;
  text-align: right;
  font-weight: 600;
}
.heatmap .cell {
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #FFFFFF;
  background: var(--bg-3);
  position: relative;
}
/* Themeable heat levels — derived from --accent, intensity by opacity */
.heatmap .cell.h-100 { background: var(--accent); }
.heatmap .cell.h-80  { background: color-mix(in srgb, var(--accent) 80%, var(--bg-2)); }
.heatmap .cell.h-60  { background: color-mix(in srgb, var(--accent) 60%, var(--bg-2)); }
.heatmap .cell.h-40  { background: color-mix(in srgb, var(--accent) 40%, var(--bg-2)); }
.heatmap .cell.h-25  { background: color-mix(in srgb, var(--accent) 25%, var(--bg-2)); color: var(--muted); }
.heatmap .cell.h-na  { background: var(--bg-3); color: var(--muted-2); }

/* Heatmap legend */
.heatmap-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  font-size: 11px;
  color: var(--muted-2);
}
.heatmap-legend .legend-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.heatmap-legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.heatmap-legend .legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
}
.heatmap-legend .legend-swatch.h-100 { background: var(--accent); }
.heatmap-legend .legend-swatch.h-80  { background: color-mix(in srgb, var(--accent) 80%, var(--bg-2)); }
.heatmap-legend .legend-swatch.h-60  { background: color-mix(in srgb, var(--accent) 60%, var(--bg-2)); }
.heatmap-legend .legend-swatch.h-40  { background: color-mix(in srgb, var(--accent) 40%, var(--bg-2)); }
.heatmap-legend .legend-swatch.h-25  { background: color-mix(in srgb, var(--accent) 25%, var(--bg-2)); }
.heatmap-legend .legend-swatch.h-na  { background: var(--bg-3); border: 1px solid var(--border); }

/* ===== Shared utility classes (User 360 + Directory) ===== */

/* Status dot indicator */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.status-active   { background: var(--green); box-shadow: 0 0 0 2px rgba(34,197,94,0.15); }
.status-dot.status-idle     { background: var(--yellow); box-shadow: 0 0 0 2px rgba(245,158,11,0.15); }
.status-dot.status-inactive { background: var(--red); box-shadow: 0 0 0 2px rgba(239,68,68,0.15); }
.status-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.status-text { font-size: 12px; color: var(--muted); }

/* Search wrap with leading icon + optional kbd hint */
.search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.search-wrap > i.ph {
  position: absolute;
  left: 14px;
  color: var(--muted-2);
  font-size: 14px;
  pointer-events: none;
  z-index: 1;
}
.search-wrap input,
.search-wrap .search-box,
.search-wrap .filter-search {
  width: 100%;
  padding: 9px 50px 9px 38px !important;
}
.search-kbd {
  position: absolute;
  right: 10px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted-2);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  pointer-events: none;
}

/* Back link */
.back-link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.back-link:hover { color: var(--accent); }
.back-link i.ph { font-size: 14px; }

/* Platform mini-badge (App / Web) */
.pf-mini {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  line-height: 1.6;
}
.pf-mini.pf-app { background: var(--accent-soft); color: var(--accent); }
.pf-mini.pf-web { background: rgba(96,165,250,0.15); color: #60a5fa; }
.pf-mini i.ph { font-size: 11px; }

/* Last-access group: chip + time text grouped together */
.last-access {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
/* ===== Branch link in tables (click → directory) ===== */
.branch-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--white);
  text-decoration: none;
  transition: color .15s;
}
.branch-link:hover { color: var(--accent); }
.branch-link i { font-size: 11px; opacity: .55; transition: opacity .15s, transform .15s; }
.branch-link:hover i { opacity: 1; transform: translate(2px, -2px); }

.last-access .la-time {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}
.last-access .la-time i.ph { font-size: 12px; color: var(--muted-2); }
.last-access .la-time b {
  color: var(--white);
  font-weight: 600;
}

/* KPI platform split (User 360) */
.kpi .kpi-split {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  padding-right: 48px;
}

/* User profile contact row */
.user-info .contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  font-size: 12px;
}
.contact-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  text-decoration: none;
}
.contact-link i.ph { font-size: 13px; color: var(--accent); }
.contact-link:hover { color: var(--accent); }
.user-info .meta i.ph { color: var(--muted-2); margin-right: 2px; font-size: 13px; }

/* PII masking — phone / email with show-hide toggle */
.contact-link.masked {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 0;
}
.contact-link.masked .pii-val {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
}
.contact-link.masked.revealed {
  background: rgba(245,158,11,0.08);
  border-radius: 5px;
  padding: 2px 4px;
}
.contact-link.masked.revealed .pii-val { color: var(--white); font-weight: 600; }
.contact-link .pii-toggle {
  background: transparent;
  border: 0;
  color: var(--muted-2);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
}
.contact-link .pii-toggle i.ph { font-size: 13px; }
.contact-link .pii-toggle:hover { color: var(--accent); background: var(--accent-soft); }

/* Recommended courses list */
.recommend-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.recommend-list .rec-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 10px;
  background: var(--bg-3);
  border-radius: 6px;
  font-size: 12px;
}
.recommend-list .rec-item > i.ph {
  color: var(--accent);
  font-size: 12px;
  margin-top: 3px;
}
.recommend-list .rec-item b {
  display: block;
  color: var(--white);
  font-size: 13px;
}
.recommend-list .rec-why {
  display: block;
  color: var(--muted-2);
  font-size: 11px;
  margin-top: 2px;
}

/* Timeline event icons */
.timeline-item .time i.ph,
.timeline-item .event > i.ph:first-child {
  font-size: 14px;
}
.timeline-item .event > i.ph:first-child {
  color: var(--accent);
  margin-right: 4px;
  vertical-align: -2px;
}
.timeline-item .time {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

/* Course row hover */
.course-row { transition: background 0.1s; cursor: pointer; }
.course-row:hover { background: var(--bg-3); }

/* ===== User 360° — Profile card enhancements ===== */
.profile-card .profile-main {
  display: flex;
  align-items: flex-start;
  gap: 20px;
}
.profile-card .contact-row i.ph.ph-line-vertical {
  color: var(--border);
  font-size: 14px;
}

/* Performance tier badge in profile h2 */
.perf-tier {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}
.perf-tier.top    { background: linear-gradient(135deg, rgba(34,197,94,0.18), rgba(34,197,94,0.06)); color: var(--green); border: 1px solid rgba(34,197,94,0.35); }
.perf-tier.good   { background: rgba(96,165,250,0.15); color: #60a5fa; }
.perf-tier.avg    { background: var(--bg-3); color: var(--muted); }
.perf-tier.below  { background: rgba(245,158,11,0.15); color: var(--yellow); }
.perf-tier.risk   { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.35); }
.perf-tier i.ph { font-size: 12px; }

/* Performance snapshot bar (4 mini metrics in profile card) */
.perf-snapshot {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
@media (max-width: 800px) { .perf-snapshot { grid-template-columns: repeat(2, 1fr); } }
.snap-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 12px;
  border-right: 1px solid var(--border);
}
.snap-item:last-child { border-right: 0; padding-right: 0; }
.snap-item .snap-label {
  font-size: 11px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}
.snap-item .snap-val {
  font-size: 22px;
  font-weight: 800;
  color: var(--white);
  line-height: 1.1;
}
.snap-item .snap-val small {
  font-size: 12px;
  color: var(--muted-2);
  font-weight: 400;
  margin-left: 2px;
}
.snap-item .snap-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
}
.snap-item .snap-trend.up    { color: var(--green); }
.snap-item .snap-trend.down  { color: var(--red); }
.snap-item .snap-trend.muted { color: var(--muted-2); font-weight: 500; }

/* Snap-item per-platform split — taller card variant */
.snap-item .snap-split {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  margin-bottom: 4px;
}
.snap-item .snap-split-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.snap-item .snap-split-row .ssr-val {
  font-size: 20px;
  font-weight: 800;
  color: var(--white);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.snap-item .snap-split-row .ssr-val small {
  font-size: 12px;
  color: var(--muted-2);
  font-weight: 500;
  margin-left: 1px;
}

/* Manager attestation strip */
.mgr-attest {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-top: 14px;
  background: rgba(34,197,94,0.06);
  border: 1px solid rgba(34,197,94,0.2);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
}
.mgr-attest > i.ph {
  font-size: 18px;
  color: var(--green);
  flex-shrink: 0;
}
.mgr-attest > span { flex: 1; }
.mgr-attest b { color: var(--white); }

/* ===== Lesson Progress Detail (User 360°) ===== */
.lcg { /* lesson course group */
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--bg-3);
}
.lcg .lcg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.lcg .lcg-head b { color: var(--white); font-size: 13px; }
.lcg .lcg-meta {
  font-size: 11px;
  color: var(--muted-2);
  margin-left: 8px;
}
.ll-mini {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.ll-item {
  display: grid;
  grid-template-columns: 40px 1fr 100px 50px 24px;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 5px;
  font-size: 12px;
  background: var(--bg-2);
  transition: background 0.15s;
}
.ll-item:hover { background: color-mix(in srgb, var(--accent-soft) 30%, var(--bg-2)); }
.ll-item.stuck { background: rgba(245,158,11,0.06); border-left: 2px solid var(--yellow); padding-left: 8px; }
.ll-item.in-progress { background: rgba(255,71,71,0.06); border-left: 2px solid var(--accent); padding-left: 8px; }
.ll-item.not-started { opacity: 0.55; }
.ll-num {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted-2);
  text-transform: uppercase;
}
.ll-title { color: var(--white); }
.ll-bar {
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
}
.ll-bar .bar-fill { height: 100%; transition: width 0.3s; background: var(--accent); }
.ll-bar .bar-fill.green { background: var(--green); }
.ll-bar .bar-fill.yellow { background: var(--yellow); }
.ll-bar .bar-fill.accent { background: var(--accent); }
.ll-pct {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-align: right;
}
.ll-stat { text-align: center; }
.ll-stat i.ph { font-size: 14px; }

/* ===== Knowledge Consumption card ===== */
.kn-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.kn-card .kn-head {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}
.kn-card .kn-head i.ph { font-size: 14px; color: var(--accent); }
.kn-card .kn-val {
  font-size: 28px;
  font-weight: 800;
  color: var(--white);
  line-height: 1.1;
}
.kn-card .kn-val small {
  font-size: 12px;
  color: var(--muted-2);
  font-weight: 500;
  margin-left: 4px;
}
.kn-card .kn-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  font-size: 11px;
  color: var(--muted-2);
  margin-top: 6px;
  align-items: center;
}
.kn-card .kn-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.kn-card .kn-item {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 8px;
  align-items: start;
  font-size: 12px;
}
.kn-card .kn-icon { color: var(--accent); }
.kn-card .kn-icon i.ph { font-size: 14px; }
.kn-card .kn-info b {
  display: block;
  color: var(--white);
  font-size: 12px;
  line-height: 1.3;
}
.kn-card .kn-info span {
  display: block;
  color: var(--muted-2);
  font-size: 11px;
  margin-top: 2px;
}

/* Category bars */
.kn-cat {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 16px;
  align-items: start;
  padding: 14px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.kn-cat .kn-cat-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  line-height: 1.5;
  padding-top: 2px;
}
.kn-cat .kn-cat-bars {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.kn-cat .kn-cat-row {
  display: grid;
  grid-template-columns: 160px 1fr 44px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
.kn-cat .kn-cat-name {
  color: var(--white);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.kn-cat .kn-cat-name i.ph { font-size: 12px; color: var(--muted-2); }
.kn-cat .kn-cat-bar { height: 6px; background: var(--bg-2); border-radius: 3px; overflow: hidden; }
.kn-cat .kn-cat-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.kn-cat .kn-cat-fill.cat-vehicle    { background: #60a5fa; }
.kn-cat .kn-cat-fill.cat-tnb        { background: var(--accent); }
.kn-cat .kn-cat-fill.cat-announce   { background: var(--yellow); }
.kn-cat .kn-cat-fill.cat-survey     { background: #a78bfa; }
.kn-cat .kn-cat-pct { font-weight: 700; color: var(--white); text-align: right; font-variant-numeric: tabular-nums; }
.kn-cat .kn-cat-pct i.ph { font-size: 11px; color: var(--muted-2); margin-right: 2px; }

/* File-type row variant: name + meta (no bar) */
.kn-cat .kn-cat-row.file-row {
  grid-template-columns: 1fr auto;
  gap: 12px;
}
.kn-cat .file-row .kn-cat-name i.ph { font-size: 14px; color: inherit; }
.kn-cat .file-meta {
  font-size: 11px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.kn-cat .file-meta b { color: var(--white); font-weight: 700; font-size: 13px; }
.kn-cat .muted-soft { color: var(--muted-2); }

/* ===== KYC Verification rows ===== */
.kyc-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-3);
  border-radius: 6px;
}
.kyc-row > i.ph { font-size: 15px; }
.kyc-row .kyc-doc {
  font-size: 13px;
  font-weight: 600;
  color: var(--white);
}
.kyc-row .kyc-meta {
  font-size: 11px;
  color: var(--muted-2);
}

/* ===== Sales Activity ===== */
.sales-mini {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
}
.sales-mini .sm-val {
  font-size: 22px;
  font-weight: 800;
  color: var(--white);
  line-height: 1.1;
}
.sales-mini .sm-lbl {
  font-size: 10px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
  margin-top: 4px;
}
.deal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg-3);
  border-radius: 6px;
  border-left: 2px solid var(--accent);
  transition: background 0.15s;
  cursor: pointer;
}
.deal-row:hover { background: color-mix(in srgb, var(--accent-soft) 30%, var(--bg-3)); }

/* ===== Notes & History ===== */
.note-item {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--bg-3);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}
.note-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.note-body { min-width: 0; }
.note-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 5px;
  font-size: 13px;
}
.note-time {
  font-size: 11px;
  color: var(--muted-2);
  white-space: nowrap;
}
.note-text {
  font-size: 13px;
  color: var(--white);
  line-height: 1.5;
}
.note-tags {
  display: flex;
  gap: 5px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.note-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--bg-2);
  color: var(--muted);
}
.note-tag i.ph { font-size: 10px; }

/* Platform-colored card icons */
.card-icon.pf-app-icon { background: var(--accent-soft); color: var(--accent); }
.card-icon.pf-web-icon { background: rgba(96,165,250,0.15); color: #60a5fa; }

/* Exam cell — score + meta in 2 lines */
.exam-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.2;
}
.exam-cell .exam-score {
  font-size: 14px;
  font-weight: 800;
}
.exam-cell .exam-score.pass  { color: var(--green); }
.exam-cell .exam-score.fail  { color: var(--red); }
.exam-cell .exam-score.retry { color: var(--yellow); }
.exam-cell .exam-meta {
  font-size: 10px;
  color: var(--muted-2);
}

/* Cert link */
.cert-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.cert-link:hover { text-decoration: underline; }
.cert-link i.ph { font-size: 14px; }

/* Mini-bar target marker (vertical line at target position) */
.mini-bar .bar.with-target {
  position: relative;
}
.mini-bar .bar.with-target::after {
  content: "";
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: var(--target-pos, 50%);
  width: 2px;
  background: var(--white);
  opacity: 0.45;
  border-radius: 1px;
}

/* ===== Timeline (User 360) — Package Status style ===== */
.timeline {
  position: relative;
  padding-left: 30px;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 10px;
  bottom: 10px;
  width: 0;
  border-left: 2px solid #d1d5db;
  background: transparent;
}
.timeline-item {
  position: relative;
  margin-bottom: 18px;
  padding-bottom: 4px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "event time"
    "detail detail";
  gap: 2px 14px;
  align-items: start;
}
.timeline-item::before {
  content: "";
  position: absolute;
  left: -30px;
  top: 5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-2);
  box-shadow: 0 0 0 1px var(--accent);
}
/* แถวล่างสุด = เก่าสุด → จุดกลวง (ตามภาพ) */
.timeline-item:last-child::before {
  background: var(--bg-2);
  box-shadow: 0 0 0 2px var(--accent);
}
.timeline-item .time {
  grid-area: time;
  font-size: 11.5px;
  color: var(--muted-2);
  text-align: right;
  white-space: nowrap;
  margin: 0;
  padding-top: 2px;
}
.timeline-item .event {
  grid-area: event;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.45;
  color: var(--white);
}
.timeline-item .detail {
  grid-area: detail;
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.5;
}

/* ===== Search box (User 360) ===== */
.search-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--white);
  font-size: 14px;
  width: 100%;
  max-width: 360px;
  min-width: 320px;
}
.search-box:focus { outline: none; border-color: var(--accent); }

/* ===== Search dropdown (User 360) ===== */
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 100%;
  min-width: 380px;
  max-width: 480px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 420px;
  overflow-y: auto;
  z-index: 100;
  padding: 6px;
}

.search-dropdown .group-label {
  font-size: 10px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
  padding: 10px 12px 6px;
}

.search-dropdown .search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}
.search-dropdown .search-item:hover,
.search-dropdown .search-item.active {
  background: var(--bg-3);
}
.search-dropdown .search-item .avatar-mini {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.search-dropdown .search-item .info {
  flex: 1;
  min-width: 0;
}
.search-dropdown .search-item .name {
  font-weight: 600;
  font-size: 13px;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-dropdown .search-item .name mark {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0 2px;
  border-radius: 2px;
}
.search-dropdown .search-item .meta {
  font-size: 11px;
  color: var(--muted-2);
  margin-top: 2px;
}
.search-dropdown .search-item .badge-status {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 8px;
  font-weight: 600;
  flex-shrink: 0;
}
.search-dropdown .search-item .badge-status.active { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.search-dropdown .search-item .badge-status.idle { background: color-mix(in srgb, var(--yellow) 15%, transparent); color: var(--yellow); }
.search-dropdown .search-item .badge-status.inactive { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }

.search-dropdown .empty {
  padding: 20px;
  text-align: center;
  color: var(--muted-2);
  font-size: 13px;
}
.search-dropdown .footer-hint {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 11px;
  color: var(--muted-2);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.search-dropdown .footer-hint kbd {
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-family: monospace;
}

/* ===== User profile (User 360) ===== */
.user-profile {
  display: flex;
  gap: 16px;
  align-items: center;
}
.user-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--white);
}
.user-info h2 {
  font-size: 20px;
  margin-bottom: 4px;
}
.user-info .meta {
  display: flex;
  gap: 14px;
  color: var(--muted-2);
  font-size: 12px;
}
.user-info .meta span::before { content: "• "; color: var(--accent); }
.user-info .meta span:first-child::before { content: ""; }

/* ===== Filter chip with dropdown (Directory) ===== */
.chip-filter {
  position: relative;
  display: inline-block;
}
.chip-filter .chip-btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 5px 10px 5px 12px;
  border-radius: 18px;
  font-size: 12.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
  white-space: nowrap;
}
.chip-filter .chip-btn:hover {
  border-color: var(--secondary);
  color: var(--secondary);
  background: var(--secondary-soft);
}
.chip-filter .chip-btn .chip-label {
  color: var(--muted-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.chip-filter .chip-btn .chip-value {
  color: var(--white);
  font-weight: 500;
}
.chip-filter .chip-btn .chip-icon {
  font-size: 14px;
  color: var(--accent);
}
.chip-filter .chip-btn .chip-arrow {
  font-size: 11px;
  color: var(--muted-2);
  margin-left: 2px;
}
.chip-filter.active .chip-btn .chip-icon { color: #FFFFFF; }
.chip-filter .chip-btn .chip-clear {
  margin-left: 6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.15);
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.chip-filter .chip-btn .chip-clear:hover { background: rgba(0,0,0,0.30); }
[data-theme="dark"] .chip-filter .chip-btn .chip-clear { background: rgba(255,255,255,0.15); }
[data-theme="dark"] .chip-filter .chip-btn .chip-clear:hover { background: rgba(255,255,255,0.30); }

.chip-filter.active .chip-btn {
  background: var(--brand-gradient);
  border-color: transparent;
  color: #FFFFFF;
  box-shadow: 0 1px 3px rgba(255, 71, 71, 0.25);
}
.chip-filter.active .chip-btn .chip-label,
.chip-filter.active .chip-btn .chip-arrow {
  color: rgba(255,255,255,0.85);
}
.chip-filter.active .chip-btn .chip-value {
  color: #FFFFFF;
  font-weight: 600;
}

/* Dropdown panel */
.chip-popup {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 100;
  display: none;
}
.chip-filter.open .chip-popup { display: block; }
.chip-popup .chip-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--white);
  transition: background 0.1s;
}
.chip-popup .chip-option > span { flex: 1; }
.chip-popup .chip-option > i.ph:first-child {
  font-size: 15px;
  color: var(--muted);
  flex-shrink: 0;
}
.chip-popup .chip-option:hover { background: var(--bg-3); }
.chip-popup .chip-option.selected {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.chip-popup .chip-option.selected > i.ph:first-child { color: var(--accent); }
.chip-popup .chip-option .check {
  font-size: 14px;
  color: var(--accent);
  visibility: hidden;
}
.chip-popup .chip-option.selected .check { visibility: visible; }
.chip-popup .chip-count {
  color: var(--muted-2);
  font-size: 11px;
}
.chip-popup hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.clear-filters {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  font-weight: 600;
}
.clear-filters:hover { background: var(--accent-soft); }

/* ===== Skeleton loaders ===== */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-3) 0%,
    color-mix(in srgb, var(--bg-3) 50%, var(--bg-2)) 50%,
    var(--bg-3) 100%
  );
  background-size: 200% 100%;
  animation: skeletonShimmer 1.4s ease-in-out infinite;
  border-radius: 4px;
  color: transparent !important;
  user-select: none;
}
@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skel-line { height: 14px; margin: 6px 0; border-radius: 4px; }
.skel-line.short { width: 40%; }
.skel-line.med { width: 70%; }
.skel-line.long { width: 90%; }
.skel-circle {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-3);
  animation: skeletonShimmer 1.4s ease-in-out infinite;
}
.skel-chart {
  height: 280px;
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    var(--bg-3) 0%,
    color-mix(in srgb, var(--bg-3) 50%, var(--bg-2)) 50%,
    var(--bg-3) 100%
  );
  background-size: 200% 100%;
  animation: skeletonShimmer 1.4s ease-in-out infinite;
}

/* ===== Empty states ===== */
.empty-state {
  text-align: center;
  padding: 40px 24px;
  color: var(--muted-2);
}
.empty-state .empty-icon {
  font-size: 48px;
  opacity: 0.4;
  margin-bottom: 12px;
}
.empty-state .empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--white);
  margin-bottom: 6px;
}
.empty-state .empty-desc {
  font-size: 13px;
  margin-bottom: 16px;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

/* ===== Breadcrumb ===== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--muted-2);
}
.breadcrumb .bc-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--white);
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-right: 6px;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.breadcrumb .bc-back:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateX(-2px);
}
.breadcrumb .bc-back:active { transform: translateX(-1px); }
.breadcrumb .bc-back i.ph { font-size: 14px; }
.breadcrumb .bc-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  text-decoration: none;
  padding: 3px 8px;
  border-radius: 6px;
  transition: color 0.1s, background 0.1s;
}
.breadcrumb .bc-link:hover {
  color: var(--accent);
  background: var(--accent-soft);
}
.breadcrumb .bc-link i.ph {
  font-size: 13px;
  opacity: 0.85;
}
.breadcrumb .bc-text {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted-2);
}
.breadcrumb .bc-text i.ph { font-size: 13px; opacity: 0.85; }
.breadcrumb .bc-current {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--white);
  font-weight: 600;
  padding: 3px 8px;
}
.breadcrumb .bc-current i.ph {
  font-size: 13px;
  color: var(--accent);
}
.breadcrumb .bc-sep {
  color: var(--muted-2);
  opacity: 0.5;
}

/* ===== In-card mini tabs (Activity Timeline, etc) ===== */
.tl-tabs {
  display: inline-flex;
  gap: 3px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}
.tl-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.tl-tab i.ph { font-size: 13px; opacity: 0.85; }
.tl-tab:hover { color: var(--white); background: var(--bg-2); }
.tl-tab.active {
  background: var(--bg-2);
  color: var(--white);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.tl-tab.active i.ph { opacity: 1; }
.tl-tab .tl-count {
  font-size: 10px;
  padding: 1px 6px;
  background: var(--bg);
  border-radius: 8px;
  color: var(--muted-2);
  font-weight: 700;
  margin-left: 2px;
}
.tl-tab.active .tl-count { background: var(--accent); color: white; }
.tl-tab.tl-tab-app.active     { background: rgba(255,71,71,0.15); color: var(--accent); }
.tl-tab.tl-tab-app.active .tl-count { background: var(--accent); color: white; }
.tl-tab.tl-tab-web.active     { background: rgba(96,165,250,0.15); color: #60a5fa; }
.tl-tab.tl-tab-web.active .tl-count { background: #60a5fa; color: white; }

/* ===== Sub-navigation tabs ===== */
.subnav {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px 6px 16px;
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.subnav-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  padding-right: 12px;
  border-right: 1px solid var(--border);
}
.subnav-group i.ph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 14px;
  flex-shrink: 0;
}
.subnav-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}
.subnav-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.1s;
}
.subnav-tab i.ph {
  font-size: 14px;
  opacity: 0.85;
}
.subnav-tab:hover {
  background: var(--bg-3);
  color: var(--white);
}
.subnav-tab:hover i.ph { opacity: 1; }
.subnav-tab.active {
  background: var(--brand-gradient);
  color: white;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(255, 71, 71, 0.25);
}
.subnav-tab.active i.ph { opacity: 1; }

@media (max-width: 768px) {
  .subnav { flex-direction: column; align-items: stretch; padding: 12px; gap: 8px; }
  .subnav-group { border-right: 0; padding-right: 0; }
  .subnav-tabs { overflow-x: auto; }
}

/* ===== Onboarding / Tour / Help ===== */
.tour-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Welcome dialog */
.welcome-panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 36px;
  max-width: 440px;
  width: 90vw;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  animation: scaleIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes scaleIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.welcome-mark {
  width: 72px; height: 72px;
  border-radius: 18px;
  background: var(--brand-gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  margin: 0 auto 16px;
  box-shadow: 0 8px 20px rgba(255, 71, 71, 0.30);
}

/* Tour tooltip */
.tour-tooltip {
  position: fixed;
  background: var(--bg-2);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 18px 20px;
  width: 300px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 1001;
}
.tour-step {
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}
.tour-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.tour-body { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 14px; }
.tour-body kbd { background: var(--bg-3); border: 1px solid var(--border); padding: 1px 6px; border-radius: 4px; font-size: 11px; font-family: monospace; }
.tour-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tour-btn {
  background: var(--brand-gradient); color: white; border: 0;
  padding: 6px 14px; border-radius: 6px; cursor: pointer;
  font-size: 12px; font-weight: 600;
}
.tour-btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.tour-btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.tour-highlight {
  position: relative;
  z-index: 1001;
  box-shadow: 0 0 0 4px var(--accent), 0 0 24px rgba(255,71,71,0.45) !important;
  border-radius: 6px;
}

/* Help overlay */
.help-panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 540px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  animation: scaleIn 0.2s ease-out;
}
.help-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 20px;
}
.help-close {
  background: transparent; border: 0; color: var(--muted);
  font-size: 24px; cursor: pointer; line-height: 1;
  width: 32px; height: 32px;
  border-radius: 50%;
}
.help-close:hover { background: var(--bg-3); color: var(--accent); }

.kbd-group { margin-bottom: 16px; }
.kbd-group-name {
  font-size: 10px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.kbd-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  padding: 6px 0;
  align-items: center;
  font-size: 13px;
}
.kbd-row kbd {
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-family: 'SF Mono', Menlo, monospace;
  margin-right: 2px;
}
.kbd-desc { color: var(--muted); }
.help-tip {
  background: var(--bg-3);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

/* Help FAB */
#helpFab {
  position: fixed;
  bottom: 20px; right: 20px;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: white;
  border: 0;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255, 71, 71, 0.35);
  z-index: 90;
  transition: transform 0.15s, box-shadow 0.15s;
}
#helpFab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(255, 71, 71, 0.5);
}

/* ===== Theme toggle button ===== */
.btn-theme {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--secondary);
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.3s, box-shadow 0.15s;
}
.btn-theme:hover {
  border-color: var(--secondary);
  background: var(--secondary-soft);
  color: var(--secondary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}
.btn-theme.theme-spin {
  transform: rotate(360deg);
}

/* Smooth transition for theme switch */
html, body {
  transition: background-color 0.2s ease, color 0.2s ease;
}
.card, .kpi, .sidebar, .nav-item, .badge,
.table th, .table td, .funnel-step,
.search-box, .search-dropdown, .filter-pill,
.btn-theme, .btn, .btn-ghost, .refresh-control {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* ===== Refresh control (topbar) ===== */
.refresh-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 6px 4px 14px;
  font-size: 12px;
  color: var(--muted);
}
.refresh-control .updated {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.refresh-control .updated i.ph {
  font-size: 13px;
  color: var(--muted);
}
.refresh-control .dot-live {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 60%, transparent);
  animation: pulse 2s infinite;
}
.refresh-control .dot-live.off { background: var(--muted-2); animation: none; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 60%, transparent); }
  70%  { box-shadow: 0 0 0 8px color-mix(in srgb, var(--green) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 0%, transparent); }
}

.refresh-control .interval-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-3);
  border-radius: 12px;
  padding: 3px 4px 3px 8px;
  cursor: pointer;
}
.refresh-control .interval-wrap i.ph {
  font-size: 12px;
  color: var(--muted);
}
.refresh-control .interval-select {
  background: transparent;
  border: 0;
  color: var(--white);
  font-size: 12px;
  padding: 0 4px 0 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
}
.refresh-control .interval-select:focus { outline: 0; }
.refresh-control .interval-wrap:focus-within { outline: 1px solid var(--accent); }

.btn-refresh {
  background: var(--brand-gradient);
  color: #FFFFFF;
  border: 0;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  box-shadow: 0 1px 4px rgba(255, 71, 71, 0.30);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-refresh i.ph { font-size: 15px; }
.btn-refresh:hover {
  transform: rotate(30deg);
  box-shadow: 0 2px 8px rgba(255, 71, 71, 0.45);
}
.btn-refresh.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin {
  from { transform: rotate(0); }
  to   { transform: rotate(360deg); }
}

/* loading overlay on card */
.card.loading { position: relative; overflow: hidden; }
.card.loading::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* fade-pulse on value change */
@keyframes valueChange {
  0%   { color: var(--accent); transform: scale(1.05); }
  100% { color: var(--white); transform: scale(1); }
}
.value-changed { animation: valueChange 0.5s ease-out; }

/* ===== KPI fraction value — main + auxiliary (smaller + labeled) ===== */
.kpi .value .v-aux {
  font-size: 0.4em;
  font-weight: 600;
  margin-left: 12px;
  vertical-align: middle;
  white-space: nowrap;
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  color: var(--muted-2);
}
.kpi .value .v-aux .v-aux-sep {
  color: var(--muted-2);
  font-weight: 300;
  font-size: 1.2em;
}
.kpi .value .v-aux .v-aux-num {
  color: var(--yellow);
  font-weight: 700;
  font-size: 1.1em;
}
.kpi .value .v-aux .v-aux-lbl {
  color: var(--yellow);
  opacity: 0.78;
  font-weight: 500;
  font-size: 0.85em;
}

/* ===== Cohort card (refined) ===== */
.coh-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s, transform .15s;
}
.coh-link:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); transform: translateY(-1px); }
.coh-link i { font-size: 14px; }

.coh-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 4px 0 18px;
  padding: 14px 16px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.coh-stat { display: flex; flex-direction: column; gap: 3px; }
.coh-stat + .coh-stat { border-left: 1px solid var(--border); padding-left: 14px; }
.coh-stat .lbl { font-size: 10.5px; color: var(--muted-2); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.coh-stat .val { font-size: 22px; font-weight: 700; color: var(--white); display: flex; align-items: center; gap: 8px; line-height: 1.15; }
.coh-stat .val small { font-size: 13px; color: var(--muted); font-weight: 500; }
.coh-stat .flag { font-size: 10px; padding: 2px 7px; border-radius: 4px; font-weight: 700; line-height: 1.4; }
.coh-stat .flag.ok { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.coh-stat .flag.warn { background: color-mix(in srgb, var(--yellow) 18%, transparent); color: var(--yellow); }
.coh-stat .info { font-size: 11px; color: var(--muted-2); }

.coh-insight {
  margin-top: 14px;
  padding: 11px 14px;
  background: color-mix(in srgb, var(--yellow) 8%, transparent);
  border-left: 3px solid var(--yellow);
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}
.coh-insight i { font-size: 16px; color: var(--yellow); flex-shrink: 0; }
.coh-insight b { color: var(--white); }

/* ===== Mockup notice banner ===== */
.notice {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 18px;
}
.notice b { color: var(--accent); }
