/* ═══════════════════════════════════════════════
   analytics.css  —  D-Dey PMS v3.5
   Compact · Mockup-exact · No wasted space
   DM Serif + DM Sans + JetBrains Mono
═══════════════════════════════════════════════ */

/* ── tokens ──────────────────────────────────── */
:root {
  --an-t0:#0D9488; --an-t1:#0f766e; --an-t2:#134e4a;
  --an-glow:rgba(13,148,136,0.18);
  --an-glow-xs:rgba(13,148,136,0.08);
  --an-r12:12px; --an-r8:8px; --an-r999:999px;
  --an-elev1:0 1px 3px rgba(0,0,0,0.05),0 1px 6px rgba(0,0,0,0.03);
  --an-elev2:0 3px 10px rgba(0,0,0,0.09),0 1px 3px rgba(0,0,0,0.05);
  --an-elev-teal:0 3px 14px rgba(13,148,136,0.28);
  --an-mono:'JetBrains Mono',ui-monospace,monospace;
  --an-serif:'DM Serif Display',Georgia,serif;
  --an-sans:'DM Sans',system-ui,sans-serif;
  --an-gap:8px;
  --an-card-r:10px;
}

/* ── scroll container ────────────────────────── */
.analytics-scroll-container {
  padding: 0 4px 90px; /* 90px bottom = 65px nav + 25px breathing room */
}

/* ── page header ─────────────────────────────── */
.an-page-hdr {
  padding: 4px 0 6px;
  display: flex; flex-direction: column; gap: 5px;
}
.an-page-hdr-row {
  display: flex; align-items: center; gap: 8px;
}
.an-title {
  font-family: var(--an-serif) !important;
  font-size: 1.45rem; font-weight: 700;
  letter-spacing: -0.025em; line-height: 1;
  color: var(--text-main); margin: 0;
}

/* ── live badge ──────────────────────────────── */
.an-live-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--an-r999);
  background: rgba(16,185,129,0.10);
  border: 1px solid rgba(16,185,129,0.25);
  font-family: var(--an-sans);
  font-size: 0.56rem; font-weight: 700;
  color: #10b981; letter-spacing: 0.08em;
  text-transform: uppercase;
}
.an-live-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: #10b981;
  animation: anPulse 2s ease-in-out infinite;
}
@keyframes anPulse {
  0%,100% { opacity: 1; }
  50%     { opacity: .25; }
}

/* ── search ──────────────────────────────────── */
.an-search {
  width: 100%; padding: 6px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  color: var(--text-main);
  font-family: var(--an-sans); font-size: 0.78rem;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
  -webkit-appearance: none;
}
.an-search::placeholder { color: var(--text-light); opacity: .5; }
.an-search:focus {
  border-color: var(--an-t0);
  box-shadow: 0 0 0 2.5px var(--an-glow-xs);
}

/* ── filter pills ────────────────────────────── */
.an-pills {
  display: flex; gap: 5px; padding: 0 0 var(--an-gap);
  overflow-x: auto; scrollbar-width: none;
  -ms-overflow-style: none;
}
.an-pills::-webkit-scrollbar { display: none; }

.an-filter-pill {
  flex-shrink: 0; padding: 4px 11px;
  border-radius: var(--an-r999);
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  color: var(--text-light);
  font-family: var(--an-sans);
  font-size: 0.68rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background .18s, border-color .18s, color .18s, box-shadow .18s;
  -webkit-tap-highlight-color: transparent;
}
.an-filter-pill:hover {
  border-color: rgba(13,148,136,0.35);
  color: var(--an-t0);
}
.an-filter-pill.active {
  background: linear-gradient(135deg, var(--an-t0), var(--an-t1)) !important;
  border-color: transparent !important;
  color: #fff !important;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(13,148,136,0.32);
}

/* ── KPI grid — 3 columns ────────────────────── */
.an-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
@media (max-width: 600px) {
  .an-kpi-grid { grid-template-columns: 1fr 1fr; gap: 5px; }
}
@media (max-width: 340px) {
  .an-kpi-grid { grid-template-columns: 1fr; }
}

/* ── KPI card ────────────────────────────────── */
.an-kpi-card {
  display: flex; align-items: flex-start; gap: 7px;
  padding: 8px 10px;
  border-radius: var(--an-card-r);
  background: var(--card-bg);
  border: 0.5px solid var(--border);
  position: relative; overflow: hidden;
  animation: anFadeUp .3s ease both;
}
/* left accent bar */
.an-kpi-card::before {
  content: '';
  position: absolute; left: 0; top: 14%; bottom: 14%;
  width: 2.5px; border-radius: 0 3px 3px 0;
  background: var(--an-t0);
  opacity: 0.45;
}

/* stagger entrance */
.an-kpi-card:nth-child(1) { animation-delay: .01s; }
.an-kpi-card:nth-child(2) { animation-delay: .04s; }
.an-kpi-card:nth-child(3) { animation-delay: .07s; }
.an-kpi-card:nth-child(4) { animation-delay: .10s; }
.an-kpi-card:nth-child(5) { animation-delay: .13s; }
.an-kpi-card:nth-child(6) { animation-delay: .16s; }

/* primary (revenue) card */
.an-kpi-card.an-kpi-primary {
  background: linear-gradient(145deg, var(--an-t0) 0%, var(--an-t2) 100%) !important;
  border-color: transparent !important;
  box-shadow: var(--an-elev-teal) !important;
}
.an-kpi-card.an-kpi-primary::before { display: none; }
.an-kpi-card.an-kpi-primary .an-kpi-lbl { color: rgba(255,255,255,.55); }
.an-kpi-card.an-kpi-primary .an-kpi-val { color: #fff; }
.an-kpi-card.an-kpi-primary .an-kpi-sub { color: rgba(255,255,255,.45); }
.an-kpi-card.an-kpi-primary .an-kpi-dot { background: rgba(255,255,255,.55); }
.an-kpi-card.an-kpi-primary .an-kpi-ico { color: rgba(255,255,255,.25); }

/* ── dot indicator ───────────────────────────── */
.an-kpi-dot {
  width: 6px; height: 6px; border-radius: 50%;
  flex-shrink: 0; margin-top: 4px;
}
.dot-teal   { background: #0D9488; }
.dot-green  { background: #10b981; }
.dot-indigo { background: #6366f1; }
.dot-pink   { background: #ec4899; }
.dot-amber  { background: #f59e0b; }

/* ── KPI icon (top-right) ────────────────────── */
.an-kpi-ico {
  position: absolute; top: 7px; right: 8px;
  font-size: 0.95rem !important;
  color: var(--an-t0); opacity: 0.15;
}

/* ── KPI body ────────────────────────────────── */
.an-kpi-body { display: flex; flex-direction: column; gap: 0; min-width: 0; flex: 1; }
.an-kpi-lbl {
  font-family: var(--an-sans);
  font-size: 0.54rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-light); white-space: nowrap; line-height: 1;
}
.an-kpi-val {
  font-family: var(--an-mono) !important;
  font-size: 1.05rem; font-weight: 800;
  color: var(--text-main); line-height: 1.2;
  letter-spacing: -.03em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.an-kpi-sub {
  font-family: var(--an-sans);
  font-size: 0.56rem; font-weight: 600;
  color: var(--text-light); white-space: nowrap; line-height: 1;
}
.an-kpi-sub.sub-green { color: #10b981; font-weight: 700; }
.an-kpi-sub.sub-red   { color: #ef4444; font-weight: 600; }

/* ── gradient divider ────────────────────────── */
.an-kpi-divider {
  height: 1px; margin: 2px 0 6px;
  background: linear-gradient(90deg, transparent, var(--an-glow), transparent);
  border: none;
}

/* ── insight bar ─────────────────────────────── */
.an-insight-bar {
  display: flex; gap: 5px; padding: 0 0 6px;
  overflow-x: auto; scrollbar-width: none;
}
.an-insight-bar::-webkit-scrollbar { display: none; }
.an-insight-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: var(--an-r999);
  background: var(--card-bg);
  border: 0.5px solid var(--border);
  font-family: var(--an-sans);
  font-size: 0.60rem; font-weight: 600;
  color: var(--text-main); white-space: nowrap; flex-shrink: 0;
}
.an-insight-chip .material-icons-outlined {
  font-size: 0.76rem !important; color: var(--an-t0); opacity: .6;
}
.an-insight-chip strong {
  color: var(--an-t0);
  font-family: var(--an-mono); font-size: 0.62rem;
}

/* ════════════════════════════════════════════════
   CHART CARDS
════════════════════════════════════════════════ */

/* ── card container ──────────────────────────── */
.an-chart-card-v2 {
  padding: 9px 10px;
  border-radius: var(--an-card-r);
  background: var(--card-bg);
  border: 0.5px solid var(--border);
  position: relative; overflow: hidden;
}
.an-chart-card-v2 canvas {
  display: block !important;
  width: 100% !important;
  box-sizing: border-box;
}
.an-chart-card.an-chart-card-v2 {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  transition: border-color 0.15s !important;
}
.an-chart-card.an-chart-card-v2:hover {
  transform: none !important;
  box-shadow: var(--an-elev1) !important;
}

/* ── card header (inline, replaces .an-sec-hdr) ─ */
.an-card-hdr {
  display: flex; align-items: center; gap: 5px;
  margin-bottom: 7px;
}
.an-card-hdr .material-icons-outlined {
  font-size: 0.82rem !important;
  color: var(--an-t0); opacity: .5;
}
.an-card-hdr-title {
  font-family: var(--an-sans);
  font-size: 0.60rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .10em;
  color: var(--text-light);
}
.an-card-hdr-rule { flex: 1; height: 1px; background: var(--border); }
.an-card-hdr-sub {
  font-size: 0.55rem; opacity: 0.5; font-weight: 500;
  font-family: var(--an-sans);
  text-transform: none; letter-spacing: 0;
}

/* ── chart empty state ───────────────────────── */
.an-chart-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  color: var(--text-light);
  font-family: var(--an-sans); font-size: 0.72rem; font-weight: 500;
}
.an-chart-empty .material-icons-outlined { font-size: 1.4rem; opacity: .18; }

/* ── chart legend ────────────────────────────── */
.an-chart-legend {
  display: flex; flex-wrap: wrap; gap: 6px;
  justify-content: center; margin-top: 5px;
  font-family: var(--an-sans);
  font-size: 0.62rem; color: var(--text-light);
}

/* ── centered canvas container ───────────────── */
.an-chart-centered {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}

/* ════════════════════════════════════════════════
   LAYOUT ROWS
════════════════════════════════════════════════ */

/* ── Revenue + Peak Hours — 3:2 split ───────── */
.an-row-trend {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 7px;
  margin-bottom: 7px;
}
@media (max-width: 520px) {
  .an-row-trend { grid-template-columns: 1fr; }
}

/* ── Payment Split + Staff Perf — 1:1 ──────── */
.an-row-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 7px;
}
@media (max-width: 520px) {
  .an-row-split { grid-template-columns: 1fr; gap: 6px; }
}

/* ─── also keep old an-split-row for compat ─── */
.an-split-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 7px;
}
.an-split-row .an-chart-card-v2 { margin-bottom: 0; }
@media (max-width: 520px) {
  .an-split-row { grid-template-columns: 1fr; gap: 6px; }
}

/* ════════════════════════════════════════════════
   CHART HEIGHT CONSTRAINTS
   JS canvas heights (analytics.js):
     revenue-chart       → 155px (line 292)
     peak-hours-chart    → 130px (line 397)
     payment-split-chart → 110px (line 359)
     top-meds-chart      → dynamic min 160px
   Wrapper = padding(18) + header(35) + canvas
════════════════════════════════════════════════ */

/* Revenue trend: 18+35+155 = 208 → 212px */
#revenue-chart-wrap {
  height: 212px; min-height: 212px; max-height: 212px;
  overflow: hidden;
}
#revenue-chart-wrap .an-chart-empty { height: 155px; padding: 0; }
/* Kill ghost space — JS sets display:none but not height:0 */
#revenue-chart-wrap canvas[style*="display: none"],
#revenue-chart-wrap canvas[style*="display:none"] {
  height: 0 !important; min-height: 0 !important;
}

/* Peak hours: 18+35+130 = 183 → 186px */
#peak-hours-wrapper {
  height: 186px; min-height: 186px; max-height: 186px;
  overflow: hidden;
}
#peak-hours-wrapper .an-chart-empty { height: 130px; padding: 0; }
#peak-hours-wrapper canvas[style*="display: none"],
#peak-hours-wrapper canvas[style*="display:none"] {
  height: 0 !important; min-height: 0 !important;
}

/* Payment split: 18+35+110+20(legend) = 183 → 186px */
#payment-split-wrapper {
  height: 186px; min-height: 186px; max-height: 186px;
  overflow: hidden;
}
#payment-split-wrapper .an-chart-empty { height: 110px; padding: 0; }
#payment-split-wrapper canvas[style*="display: none"],
#payment-split-wrapper canvas[style*="display:none"] {
  height: 0 !important; min-height: 0 !important;
}

/* Top medicines — hard CSS height cap kills Chart.js resize loop */
#top-meds-wrapper { overflow: hidden; }
/* CSS !important beats JS inline style → loop broken */
#top-meds-wrapper canvas {
  height: 190px !important;
  max-height: 190px !important;
  min-height: 0 !important;
}
#top-meds-wrapper .an-chart-empty { padding: 10px 0; }
/* Collapse canvas in empty state */
#top-meds-wrapper canvas[style*="display: none"],
#top-meds-wrapper canvas[style*="display:none"] {
  height: 0 !important; min-height: 0 !important; max-height: 0 !important;
  visibility: hidden; position: absolute;
}

/* ════════════════════════════════════════════════
   DATA CARDS (tables)
════════════════════════════════════════════════ */

.an-data-card {
  border-radius: var(--an-card-r);
  background: var(--card-bg);
  border: 0.5px solid var(--border);
  margin-bottom: 7px;
  overflow: hidden;
}

/* staff table */
.an-staff-table { width: 100%; border-collapse: collapse; }
.an-staff-table thead tr { border-bottom: 1px solid var(--border); }
.an-staff-table th {
  padding: 6px 10px;
  font-family: var(--an-sans);
  font-size: 0.56rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-light);
}
.an-staff-table th.al { text-align: left; }
.an-staff-table th.ar { text-align: right; }

/* ── history ─────────────────────────────────── */
.an-history-wrap { margin-bottom: 0; }

.history-table { font-size: .73rem; }
.history-table thead tr { background: var(--card-bg); }
.history-table thead th {
  font-family: var(--an-sans); font-size: .56rem;
  font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-light);
  padding: 6px 8px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
  background: var(--card-bg); z-index: 2;
}
.history-table tbody td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-main); vertical-align: middle;
  font-size: 0.73rem;
}
.history-table tbody tr:last-child td { border-bottom: none; }
.history-table tbody tr { transition: background .12s; }
.history-table tbody tr:hover { background: var(--an-glow-xs); }
.history-table tbody tr:nth-child(even) { background: rgba(13,148,136,0.015); }
.history-table tbody tr:nth-child(even):hover { background: var(--an-glow-xs); }

/* mode pill */
.mode-pill {
  display: inline-block; padding: 1px 7px;
  border-radius: var(--an-r999);
  background: var(--an-glow-xs);
  border: 1px solid rgba(13,148,136,.2);
  color: var(--an-t0); font-size: .60rem; font-weight: 700;
  font-family: var(--an-sans); letter-spacing: .02em;
}
.mode-pill.pill-green { background: rgba(22,163,74,.12); border-color: rgba(22,163,74,.3); color: #16a34a; }
.mode-pill.pill-red   { background: rgba(220,38,38,.10); border-color: rgba(220,38,38,.25); color: #dc2626; }

@media (max-width: 380px) {
  .history-table .hide-xs { display: none; }
}

/* ── action buttons ──────────────────────────── */
.hist-share-btn, .hist-wa-btn, .pdf-btn, .wp-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 6px;
  cursor: pointer; flex-shrink: 0;
  border: 1px solid var(--border); background: transparent;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s, border-color .12s, color .12s;
}
.hist-share-btn:active, .hist-wa-btn:active,
.pdf-btn:active, .wp-btn:active { transform: scale(0.88); }
.hist-share-btn, .pdf-btn { color: #64748b; }
.hist-share-btn:hover, .pdf-btn:hover {
  background: var(--an-glow-xs); color: var(--an-t0);
  border-color: rgba(13,148,136,.3);
}
.hist-wa-btn, .wp-btn { color: #16a34a; border-color: rgba(34,197,94,.25); }
.hist-wa-btn:hover, .wp-btn:hover { background: rgba(22,163,74,.08); border-color: rgba(34,197,94,.4); }
.hist-action-cell { display: flex; gap: 3px; align-items: center; }

/* ── export button ───────────────────────────── */
.an-export-btn {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: var(--an-r999);
  border: 1px solid rgba(13,148,136,0.25);
  background: rgba(13,148,136,0.06);
  color: var(--an-t0);
  font-family: var(--an-sans);
  font-size: 0.58rem; font-weight: 700;
  cursor: pointer; letter-spacing: 0.02em;
  transition: background .15s, color .15s, border-color .15s;
  text-transform: uppercase;
}
.an-export-btn:hover { background: var(--an-t0); color: #fff; border-color: transparent; }
.an-export-btn .material-icons-outlined { font-size: 0.76rem !important; }

/* ════════════════════════════════════════════════
   DESKTOP
════════════════════════════════════════════════ */
@media (min-width: 1024px) {
  .analytics-scroll-container { max-width: 100%; padding: 0 8px 4px; }
}

/* ════════════════════════════════════════════════
   ANIMATIONS
════════════════════════════════════════════════ */
@keyframes anFadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes anCountPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}
.an-kpi-val.an-counted { animation: anCountPop .25s cubic-bezier(.4,0,.2,1); }

@keyframes anShimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.an-shimmer {
  background: linear-gradient(90deg, var(--card-bg) 25%, rgba(13,148,136,0.06) 50%, var(--card-bg) 75%);
  background-size: 200% 100%;
  animation: anShimmer 1.6s ease infinite;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ════════════════════════════════════════════════
   DARK MODE
════════════════════════════════════════════════ */
body.dark-mode .an-kpi-card {
  border-color: rgba(255,255,255,0.06);
  background: rgba(30,41,59,0.7);
}
body.dark-mode .an-chart-card-v2,
body.dark-mode .an-data-card {
  border-color: rgba(255,255,255,0.06);
  background: rgba(30,41,59,0.7);
}
body.dark-mode .history-table thead th { background: rgba(30,41,59,0.95); }
body.dark-mode .history-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.015); }
body.dark-mode .an-filter-pill {
  background: rgba(30,41,59,0.8);
  border-color: rgba(255,255,255,0.08);
}
body.dark-mode .an-filter-pill:hover { border-color: rgba(45,212,191,0.3); color: #2dd4bf; }
body.dark-mode .an-filter-pill.active {
  background: linear-gradient(135deg, #0d9488, #0f766e) !important;
  box-shadow: 0 2px 8px rgba(13,148,136,0.3);
}
body.dark-mode .an-search { background: rgba(30,41,59,0.7); border-color: rgba(255,255,255,0.08); }
body.dark-mode .an-insight-chip { background: rgba(30,41,59,0.7); border-color: rgba(255,255,255,0.06); }
body.dark-mode .an-export-btn { border-color: rgba(45,212,191,0.2); background: rgba(45,212,191,0.06); color: #2dd4bf; }
body.dark-mode .mode-pill { background: rgba(45,212,191,0.08); border-color: rgba(45,212,191,0.2); color: #2dd4bf; }
