/* ============================================================================
   CRM RESPONSIVE LAYER  (crm-responsive.css)
   Loaded AFTER style.css so these rules win on equal specificity.
   Breakpoints:
     ≥1536px  wide monitor   — wider content gutters, cap ultra-wide line length
     ≤1024px  tablet/phone   — sidebar becomes an off-canvas drawer + hamburger
     ≤768px   small tablet   — grids collapse, tables scroll, filters stack
     ≤480px   phone          — tightest paddings, full-width controls
   Pairs with crm-responsive.js (injects the hamburger button + backdrop).
   ========================================================================== */

/* ---- Hamburger button (hidden on desktop, shown by JS-driven CSS ≤1024) -- */
.crm-nav-toggle {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 70;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 11px;
  background: var(--accent, #0d47a1);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.28);
  -webkit-tap-highlight-color: transparent;
}
.crm-nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: #fff;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
body.crm-nav-open .crm-nav-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body.crm-nav-open .crm-nav-toggle span:nth-child(2) { opacity: 0; }
body.crm-nav-open .crm-nav-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.crm-nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(15, 23, 42, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  -webkit-backdrop-filter: blur(1px);
  backdrop-filter: blur(1px);
}
body.crm-nav-open .crm-nav-backdrop { opacity: 1; pointer-events: auto; }

/* Prevent body scroll behind the open drawer (phones). */
body.crm-nav-open { overflow: hidden; }

/* ============================ ≤1024px : DRAWER ============================ */
@media (max-width: 1024px) {
  .crm-nav-toggle { display: flex; }

  /* Main column takes the whole width; sidebar floats above as a drawer. */
  .crm-shell { grid-template-columns: 1fr !important; }

  .crm-sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 268px;
    max-width: 84vw;
    height: 100vh !important;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.26s ease;
    box-shadow: 0 0 44px rgba(15, 23, 42, 0.4);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.crm-nav-open .crm-sidebar { transform: translateX(0); }

  /* Reserve space so the floating hamburger doesn't cover header content. */
  .crm-main .topbar,
  .crm-top-tabs,
  .crm-main .crm-userbar { padding-left: 60px; }

  /* Touch-friendly nav rows inside the drawer. */
  .crm-side-item { padding: 0.85rem 0.8rem; font-size: 1rem; }
}

/* ===================== ≤768px : COLLAPSE + SCROLL ======================== */
@media (max-width: 768px) {
  /* Generic grid collapse — known KPI / card grids drop to a single column.
     (auto-fit grids already reflow; these are the fixed-column ones.) */
  .dashboard-layout,
  .report-op-layout,
  .hr-fresh,
  .dvcd-freshness,
  .register-actions { grid-template-columns: 1fr !important; }

  /* KPI strips look best 2-up on phones rather than 1 huge card per row. */
  .kpi-row,
  .kpis,
  .sm-kpis,
  .eval-buckets,
  .dvcd-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }

  /* Pane shells: let big tables scroll horizontally instead of overflowing. */
  .crm-main .company-stats,
  .crm-main .pane,
  .crm-main .panel,
  .crm-main .sm-panel,
  .crm-main .eval-panel,
  .crm-main .table-wrap,
  .crm-main .dvcd-table-wrap,
  .crm-main .tbl-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .crm-main table { min-width: 540px; } /* keeps columns legible while scrolling */

  /* Relax pane max-height so content isn't clipped on short mobile viewports. */
  .crm-main .company-stats { max-height: none !important; }

  /* Filters / slicers / toolbars stack vertically and go full width. */
  .report-op-slicers,
  .crm-main .filters,
  .crm-main .toolbar,
  .crm-main .actions,
  .crm-main .sm-actions,
  .crm-main .eval-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .report-op-slicers select,
  .report-op-slicers input,
  .crm-main .filters select,
  .crm-main .filters input { width: 100%; }

  /* Buttons: comfortable tap targets, full-width when stacked. */
  .crm-main .actions a,
  .crm-main .actions button,
  .crm-main .sm-actions a,
  .crm-main .eval-actions a {
    width: 100%;
    text-align: center;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Top tabs become a horizontal scroll strip rather than wrapping messily. */
  .top-tabs {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.4rem;
    padding-bottom: 0.25rem;
  }
  .top-tabs .top-tab { white-space: nowrap; flex: 0 0 auto; }

  /* Topbar brand text can shrink so it doesn't push the row too wide. */
  .brand-text { font-size: 0.82rem; line-height: 1.2; }

  /* Modals / forms fit the screen. */
  .crm-modal,
  .modal,
  .crm-dialog { width: 94vw !important; max-width: 94vw !important; }

  /* Reduce heavy outer padding so content uses the narrow width. */
  .crm-main .shell.dashboard { padding-left: 0.7rem; padding-right: 0.7rem; }
}

/* ========================= ≤480px : PHONE TIGHT ========================== */
@media (max-width: 480px) {
  .kpi-row,
  .kpis,
  .sm-kpis,
  .eval-buckets,
  .dvcd-kpis { grid-template-columns: 1fr !important; }

  .crm-main .shell.dashboard { padding-left: 0.5rem; padding-right: 0.5rem; }
  .brand-text { font-size: 0.72rem; }

  /* Avoid fixed pixel widths breaking the viewport. */
  .crm-main img,
  .crm-main canvas,
  .crm-main svg { max-width: 100%; height: auto; }
}

/* ======================= ≥1536px : WIDE MONITOR ========================== */
@media (min-width: 1536px) {
  /* Slightly wider sidebar + generous content gutter on big monitors. */
  .crm-shell { grid-template-columns: 256px minmax(0, 1fr); }
  .crm-main .shell.dashboard { padding-left: 1.6rem; padding-right: 1.6rem; }
}

/* ========================= UNIVERSAL SAFETY NETS ========================= */
/* No element may force horizontal page scroll. */
html, body { max-width: 100%; overflow-x: hidden; }
/* Long unbroken strings (IDs, emails) wrap instead of overflowing cards. */
.crm-main .company-stats td,
.crm-main .company-stats th,
.crm-main .kpi-value,
.crm-main .kpi-label { overflow-wrap: anywhere; }
/* Charts/canvas always fluid. */
.crm-main canvas { max-width: 100% !important; }

/* ============================================================================
   HIDE REDUNDANT PANE SUB-HEADER (applies to ALL panes)
   The ".executive-pane-head" row repeats the pane title + a "Main" chip + a
   "User: <name>" chip on every pane — but the top bar already shows the user +
   role, and the sidebar already shows the active pane. Per request, hide it
   everywhere. (The top bar `.topbar` with logo / role / Log out is untouched.)
   ========================================================================== */
.executive-pane-head { display: none !important; }

/* ============================================================================
   FILTER INTERACTION POLISH  (requirement #8)
   Makes selects / date inputs / search / tabs / Apply-Reset buttons feel
   interactive: clear hover, focus glow, active highlight, press animation.
   Scoped to .crm-main; uses --accent token so it matches the active theme.
   ========================================================================== */
.crm-main select,
.crm-main input[type="date"],
.crm-main input[type="search"],
.crm-main input[type="text"],
.crm-main input[type="number"] {
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, transform 0.1s ease;
  border: 1px solid var(--border, #cbd5e1);
  border-radius: 8px;
}
.crm-main select:hover,
.crm-main input[type="date"]:hover,
.crm-main input[type="search"]:hover,
.crm-main input[type="text"]:hover {
  border-color: color-mix(in srgb, var(--accent, #0d47a1) 55%, var(--border));
}
.crm-main select:focus,
.crm-main input[type="date"]:focus,
.crm-main input[type="search"]:focus,
.crm-main input[type="text"]:focus,
.crm-main input[type="number"]:focus {
  outline: none;
  border-color: var(--accent, #0d47a1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #0d47a1) 22%, transparent);
}
/* Highlight the whole filter group when any control inside is focused. */
.crm-main .report-op-filter:focus-within,
.crm-main .filter-bar__field:focus-within,
.crm-main .filter-field:focus-within {
  border-radius: 10px;
}
/* A select that holds a non-default value reads as "active" (accent ring). */
.crm-main select:valid:not([data-empty="true"]) { border-color: color-mix(in srgb, var(--accent, #0d47a1) 40%, var(--border)); }

/* Top tabs: clear active state + animated underline + hover. */
.crm-main .top-tab {
  position: relative;
  transition: color 0.16s ease, background 0.16s ease;
}
.crm-main .top-tab::after {
  content: "";
  position: absolute;
  left: 14px; right: 14px; bottom: 4px;
  height: 2.5px; border-radius: 2px;
  background: var(--accent, #0d47a1);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.2s ease;
}
.crm-main .top-tab:hover::after { transform: scaleX(0.6); }
.crm-main .top-tab.active::after { transform: scaleX(1); }
.crm-main .top-tab.active {
  color: var(--accent, #0d47a1);
  font-weight: 700;
}

/* Filter / action buttons: hover lift + press feedback + focus ring. */
.crm-main button[type="submit"],
.crm-main .btn,
.crm-main .btn-primary,
.crm-main .btn-ghost,
.crm-main .filter-apply,
.crm-main .filter-reset {
  transition: transform 0.1s ease, box-shadow 0.16s ease, filter 0.16s ease;
}
.crm-main button[type="submit"]:hover,
.crm-main .btn:hover,
.crm-main .btn-primary:hover { filter: brightness(1.06); box-shadow: 0 6px 16px rgba(13, 71, 161, 0.22); }
.crm-main button[type="submit"]:active,
.crm-main .btn:active,
.crm-main .btn-primary:active { transform: translateY(1px) scale(0.99); }
.crm-main button:focus-visible,
.crm-main .btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #0d47a1) 30%, transparent);
}

/* Tiny "applying…" affordance: when a filter form is submitted, the Apply
   button can show a pulse (added via .is-applying by inline handlers if present). */
.crm-main .is-applying { animation: filterPulse 0.9s ease-in-out infinite; }
@keyframes filterPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }

@media (prefers-reduced-motion: reduce) {
  .crm-main .top-tab::after { transition: none; }
  .crm-main .is-applying { animation: none; }
}

/* ============================================================================
   CRM UI POLISH LAYER
   Goals (from UX review): equal card heights, consistent card chrome across
   ALL panes, modern hover micro-interactions, theme-aware colors (so custom
   panes also work in dark mode), tighter consistent spacing.
   Scoped under .crm-main and uses 3-class selectors so it beats the inline
   <style> blocks that ship inside dashboard.html panes.
   Uses existing design tokens: --surface --border --shadow-sm/md --radius.
   ========================================================================== */

/* ---- 1. Unify custom-pane cards with the native surface system ---------- */
/* My Sales / Evaluation / DVCD panes hardcoded #fff + #e5e7eb. Re-point them
   at theme tokens so they match native .kpi-card and adapt to dark theme. */
.crm-main .sm-card,
.crm-main .sm-panel,
.crm-main .eval-card,
.crm-main .eval-panel,
.crm-main .dvcd-card,
.crm-main .dvcd-detail-card {
  background: color-mix(in srgb, var(--surface) 94%, #fff) !important;
  border: 1px solid color-mix(in srgb, var(--border) 82%, transparent) !important;
  border-radius: 12px !important;
  box-shadow: var(--shadow-sm);
  color: var(--text);
}
/* Card section headings + muted labels pick up theme text colors. */
.crm-main .sm-label,
.crm-main .eval-label,
.crm-main .sm-panel h3,
.crm-main .eval-panel h3 { color: var(--muted) !important; }
.crm-main .sm-value,
.crm-main .eval-value { color: var(--text) !important; }

/* ---- 2. Equal heights: cards fill their grid/flex cell uniformly -------- */
.crm-main .kpi-row > *,
.crm-main .kpis > *,
.crm-main .sm-kpis > *,
.crm-main .eval-buckets > *,
.crm-main .dvcd-kpis > * {
  height: 100%;
}
/* KPI cards become column flex so label/value/sub distribute evenly and the
   baseline of the big number lines up across a row. */
.crm-main .kpi-card,
.crm-main .sm-card,
.crm-main .eval-card {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  justify-content: flex-start;
}

/* ---- 3. Modern hover micro-interaction on all cards --------------------- */
.crm-main .kpi-card,
.crm-main .crm-card,
.crm-main .sm-card,
.crm-main .sm-panel,
.crm-main .eval-card,
.crm-main .eval-panel,
.crm-main .dvcd-card,
.crm-main .pane-section-card,
.crm-main .pane-table-card {
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  will-change: transform;
}
.crm-main .kpi-card:hover,
.crm-main .crm-card:hover,
.crm-main .sm-card:hover,
.crm-main .eval-card:hover,
.crm-main .dvcd-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

/* ---- 4. Consistent grid gaps + reduced wasted vertical space ------------ */
.crm-main .sm-kpis,
.crm-main .eval-buckets,
.crm-main .dvcd-kpis { gap: var(--pane-gap) !important; }
.crm-main .sm-grid-2,
.crm-main .eval-grid-2 { gap: var(--pane-gap) !important; }
/* Trim oversized top/bottom margins so panes feel tighter and intentional. */
.crm-main .company-stats > section + section { margin-top: var(--pane-gap); }

/* ---- 5. Tabular numerals for all KPI values (clean alignment) ----------- */
.crm-main .kpi-value,
.crm-main .sm-value,
.crm-main .eval-value,
.crm-main .dvcd-kpi-value { font-variant-numeric: tabular-nums; }

/* ---- 6. Buttons/links inside panes get a subtle consistent hover -------- */
.crm-main .sm-actions a,
.crm-main .eval-actions a,
.crm-main .toolbar a {
  transition: filter 0.15s ease, transform 0.1s ease;
}
.crm-main .sm-actions a:hover,
.crm-main .eval-actions a:hover,
.crm-main .toolbar a:hover { filter: brightness(1.06); }
.crm-main .sm-actions a:active,
.crm-main .eval-actions a:active { transform: translateY(1px); }

/* ---- 7. Section headers: clearer hierarchy, not oversized --------------- */
.crm-main .sm-panel h3,
.crm-main .eval-panel h3 {
  letter-spacing: 0.4px;
  font-size: 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  padding-bottom: 8px;
}

/* Respect reduced-motion users: disable the lift animations. */
@media (prefers-reduced-motion: reduce) {
  .crm-main .kpi-card,
  .crm-main .crm-card,
  .crm-main .sm-card,
  .crm-main .eval-card,
  .crm-main .dvcd-card { transition: none; }
  .crm-main .kpi-card:hover,
  .crm-main .crm-card:hover,
  .crm-main .sm-card:hover,
  .crm-main .eval-card:hover,
  .crm-main .dvcd-card:hover { transform: none; }
}

/* ============================================================================
   PRESENTATION MODE  (pairs with crm-present.js)
   "▶ Present" floating button → fullscreen + clean projection layout. Sidebar
   hidden for max screen real-estate; a bottom control bar drives pane nav with
   a clicker/keyboard. State persists across the app's page navigations.
   ========================================================================== */
.crm-present-launch {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 64;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(90deg, #0d47a1, #1565c0);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(13, 71, 161, 0.4);
  -webkit-tap-highlight-color: transparent;
}
.crm-present-launch:hover { filter: brightness(1.07); }
body.crm-presenting .crm-present-launch { display: none; }

/* Clean projection layout: hide chrome, give content the full width. */
body.crm-presenting .crm-appearance,
body.crm-presenting .crm-nav-toggle,
body.crm-presenting .crm-nav-backdrop { display: none !important; }
body.crm-presenting .crm-shell { grid-template-columns: 1fr !important; }
body.crm-presenting .crm-sidebar { display: none !important; }
body.crm-presenting { overflow: auto; }
/* Slightly larger base text reads better on a projector/large monitor. */
body.crm-presenting .crm-main { font-size: 1.05rem; }
body.crm-presenting .crm-main .shell.dashboard { padding-bottom: 84px; } /* clear the bar */

/* Bottom control bar. */
.crm-present-bar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 66;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(11, 30, 58, 0.94);
  box-shadow: 0 12px 34px rgba(2, 6, 23, 0.5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  max-width: 94vw;
}
.crm-present-bar button {
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.crm-present-bar button:hover { background: rgba(255, 255, 255, 0.24); }
.crm-present-bar .crm-present-exit { background: rgba(239, 68, 68, 0.85); }
.crm-present-bar .crm-present-exit:hover { background: rgba(239, 68, 68, 1); }
.crm-present-label {
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 0 10px;
  white-space: nowrap;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crm-present-sep { width: 1px; height: 24px; background: rgba(255, 255, 255, 0.22); margin: 0 2px; }

@media (max-width: 600px) {
  .crm-present-label { max-width: 30vw; }
  .crm-present-bar button { min-width: 36px; height: 36px; padding: 0 9px; }
}
