/* ==========================================================================
   platform.css — consistent look & feel on Windows, macOS, iOS and Android
   Loaded last on both index.html and login.html.
   ========================================================================== */

/* ---------- One font everywhere (Inter is loaded in <head>; system fonts are only fallbacks) ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv11', 'ss01';
}
button, input, select, textarea { font-family: inherit; }
table, .lc-table, .branch-summary-table { font-variant-numeric: tabular-nums; }
* { -webkit-tap-highlight-color: transparent; }
::selection { background: rgba(2, 132, 199, 0.22); }

/* ---------- Scrollbars: slim and themed (Windows shows thick grey bars by default) ---------- */
* { scrollbar-width: thin; scrollbar-color: rgba(100, 116, 139, 0.45) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, 0.38); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(100, 116, 139, 0.62); background-clip: padding-box; border: 3px solid transparent; }
::-webkit-scrollbar-corner { background: transparent; }
[data-theme="dark"] * { scrollbar-color: rgba(148, 163, 184, 0.35) transparent; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.3); background-clip: padding-box; border: 3px solid transparent; }
.app-sidebar .sidebar-nav { scrollbar-gutter: stable; }

/* ---------- Keyboard focus: one clear ring on every platform ---------- */
:focus-visible { outline: 2px solid #0284c7; outline-offset: 2px; }
[data-theme="dark"] :focus-visible { outline-color: #38bdf8; }

/* ---------- Charts never wider than their panel ---------- */
.chart-panel, .charts-row > *, .panel-card { min-width: 0; }
.chart-panel canvas, .panel-card canvas, .outcomes-canvas-wrap canvas, .stacked-canvas-wrap canvas { max-width: 100% !important; }
.outcomes-canvas-wrap, .stacked-canvas-wrap, .chart-canvas-md, .chart-canvas-lg, .chart-canvas-xl { min-width: 0; overflow: hidden; }

/* ---------- Layout height on mobile browsers with dynamic toolbars ---------- */
.app-layout { min-height: 100vh; min-height: 100dvh; }
@media (max-width: 1024px) {
  .app-sidebar { height: 100vh; height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
  .mobile-topbar { padding-top: calc(8px + env(safe-area-inset-top)); padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .dashboard-wrapper { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
}

/* ---------- Touch screens (phones, tablets, touch laptops) ---------- */
@media (pointer: coarse) {
  /* comfortable tap targets (Apple / Google guidance ≈ 44 px) */
  .export-btn, .cmp-reset, .seg-btn, .lc-chip, .lc-mode-btn, .lc-icon-btn, .lc-cf-step, .lc-cf-gran button,
  .lc-mini-toggle button, .md-types button, .md-more, .ms-btn, .btn-date-cancel, .btn-date-apply, .btn-date-reset,
  .mv-size button, .sidebar-logout-btn, .nav-group-toggle, .lcw-leg { min-height: 40px; }
  .lc-icon-btn, .lc-cf-step, .sidebar-logout-btn { min-width: 40px; }
  .seg-btn { padding-top: 9px; padding-bottom: 9px; }
  .lc-chip { padding: 9px 14px; }
  .filter-pill { min-height: 44px; }
  .nav-link { padding-top: 12px; padding-bottom: 12px; }
  .lc-range label, .cmp-date, .md-filters label { min-height: 42px; }
  .lc-range input, .cmp-date input, .md-filters input, .lc-dom select, .lc-cf-period select, .md-month select { min-height: 32px; }
  /* iOS zooms the page when a field under 16 px gets focus — keep fields at 16 px */
  input, select, textarea, .pill-menu-search input { font-size: 16px !important; }
  /* no hover "stuck" states after a tap */
  .filter-pill:hover, .export-btn:hover, .cmp-reset:hover, .ms-btn:hover, .lc-chip:hover, .lc-mode-btn:hover,
  .lc-icon-btn:hover, .btn-date-cancel:hover, .btn-all-branches:hover, .lc-cf-step:hover,
  .ui-kpi-card:hover, .spend-kpi:hover, .lc-kpi:hover, .channel-box:hover, .al-ch:hover, .md-card:hover {
    transform: none !important;
  }
}

/* ---------- Very wide screens: keep content readable and centred ---------- */
@media (min-width: 1800px) {
  .dashboard-wrapper { max-width: 1560px; }
}

/* ---------- Printing / PDF from any OS ---------- */
@media print {
  .app-sidebar, .mobile-topbar, .sidebar-overlay, .filter-group, .theme-toggle, .lc-tip, .mv { display: none !important; }
  html.cine body::before, html.cine body::after { display: none !important; }
  .app-main-content { overflow: visible !important; }
  .panel-card, .chart-panel, .lc-kpi, .spend-kpi, .ui-kpi-card { break-inside: avoid; box-shadow: none !important; }
  .cine-reveal { opacity: 1 !important; transform: none !important; }
}

/* ---------- KPI rows (Lead Comparison, Spend Allocation, TP - SEO / Meta): every row filled, no empty slots ---------- */
.lc-kpis { display: flex !important; flex-wrap: wrap; }
.lc-kpis > .lc-kpi { flex: 1 1 180px; min-width: 0; }
@media (max-width: 767.98px) { .lc-kpis > .lc-kpi { flex-basis: 150px; } }

/* ---------- Windows laptops & small MacBooks (1025–1366 px wide, sidebar open) ---------- */
@media (min-width: 1025px) and (max-width: 1366px) {
  /* 7 channel boxes: icon on top, text below — nothing touches the card edge */
  .channels-cards-grid { gap: 10px; }
  .channel-box { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; }
  .channel-box-title { white-space: normal; line-height: 1.25; min-height: 2.5em; display: block; }
  /* KPI cards: trend line moves under the number instead of squeezing the label */
  .ui-kpi-card { flex-wrap: wrap; gap: 10px 12px; align-items: flex-start; padding: 14px 16px; }
  .ui-kpi-card .kpi-sub-trend { flex-direction: row; align-items: baseline; gap: 6px; text-align: left; width: 100%; padding-left: 62px; }
  .ui-kpi-card .kpi-title-txt { white-space: nowrap; }
  .kpi-big-num { font-size: 1.7rem; }
  /* header filters wrap neatly under the title */
  .header-row { align-items: flex-start; }
}
/* collapsed sidebar gives the content room again */
@media (min-width: 1025px) and (max-width: 1366px) {
  body.sb-collapsed .channel-box { flex-direction: row; align-items: center; }
  body.sb-collapsed .channel-box-title { min-height: 0; }
}

/* ==========================================================================
   Light mode — hover never hides button text
   Every hoverable control keeps dark, opaque text on its light hover surface
   (guards against white text inherited from dark-mode or 3D button rules).
   ========================================================================== */
[data-theme="light"] .filter-pill:not(.go-pill):hover,
[data-theme="light"] .export-btn:hover,
[data-theme="light"] .cmp-reset:hover,
[data-theme="light"] .ms-btn:hover,
[data-theme="light"] .ms-item:hover,
[data-theme="light"] .seg-btn:not(.active):not(.is-active):hover,
[data-theme="light"] .lc-chip:not(.is-active):hover,
[data-theme="light"] .lc-mode-btn:not(.is-active):hover,
[data-theme="light"] .lc-icon-btn:hover,
[data-theme="light"] .lc-cf-step:hover,
[data-theme="light"] .btn-date-cancel:hover,
[data-theme="light"] .btn-date-reset:hover,
[data-theme="light"] .btn-all-branches:hover,
[data-theme="light"] .branch-table-btn:hover,
[data-theme="light"] .pill-menu-item:hover,
[data-theme="light"] .al-plan-toggle:hover,
[data-theme="light"] .nav-link:not(.active):hover,
[data-theme="light"] .nav-sublink:hover {
  color: #0f172a !important;
  -webkit-text-fill-color: currentColor;
  opacity: 1;
}
[data-theme="light"] .lc-chip:not(.is-active):hover { color: #0369a1 !important; }
[data-theme="light"] .filter-pill:hover span,
[data-theme="light"] .export-btn:hover span,
[data-theme="light"] .pill-menu-item:hover .pmi-text { color: inherit !important; -webkit-text-fill-color: currentColor; }
[data-theme="light"] .nav-link.active:hover { color: #ffffff !important; -webkit-text-fill-color: #ffffff; }
