/* ============================================================
   Payment CRM — Alpine theme
   Cool blues, snow whites, soft animations.
   ============================================================ */

:root {
  /* ----------------------------------------------------------
     Typography — self-contained system stack (no web fonts).
     "Inter" / "Segoe UI Variable" are used when locally present;
     otherwise we fall back through the OS UI faces.
     Emoji families are pinned last so the heavy emoji usage in
     the UI renders in colour on every platform.
     ---------------------------------------------------------- */
  --font-sans:
      "Inter", "Inter var", "Segoe UI Variable Text", "Segoe UI",
      -apple-system, BlinkMacSystemFont, system-ui, Roboto,
      "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif,
      "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --font-display:
      "Inter", "Inter var", "Segoe UI Variable Display", "Segoe UI",
      -apple-system, BlinkMacSystemFont, system-ui, Roboto,
      "Helvetica Neue", Arial, sans-serif,
      "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --font-mono:
      ui-monospace, "Cascadia Mono", "Cascadia Code", "SF Mono",
      "Segoe UI Mono", Consolas, "Liberation Mono", Menlo, monospace;

  /* Type scale — 1rem = 16px. Dense-data friendly, still legible. */
  --fs-3xs:  0.6875rem;  /* 11px — eyebrow / uppercase labels */
  --fs-2xs:  0.75rem;    /* 12px — meta, counts, chips        */
  --fs-xs:   0.8125rem;  /* 13px — secondary text, small btns */
  --fs-sm:   0.875rem;   /* 14px — table cells, body-small    */
  --fs-md:   0.9375rem;  /* 15px — base body                  */
  --fs-base: 1rem;       /* 16px — inputs, lead text          */
  --fs-lg:   1.0625rem;  /* 17px — panel / card titles        */
  --fs-xl:   1.25rem;    /* 20px — section headings           */
  --fs-2xl:  1.5rem;     /* 24px — page titles                */
  --fs-3xl:  1.875rem;   /* 30px — stat values                */

  /* Line heights */
  --lh-none:    1;
  --lh-tight:   1.25;
  --lh-snug:    1.4;
  --lh-normal:  1.55;
  --lh-relaxed: 1.7;

  /* Weights */
  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semi:   600;
  --fw-bold:   700;
  --fw-black:  800;

  /* Tracking */
  --ls-tight:  -0.014em;
  --ls-snug:   -0.008em;
  --ls-normal: 0;
  --ls-caps:   0.06em;
  --ls-caps-wide: 0.08em;

  /* ----------------------------------------------------------
     Spacing — strict 4px rhythm
     ---------------------------------------------------------- */
  --sp-0:  0;
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-7:  28px;
  --sp-8:  32px;
  --sp-10: 40px;
  --sp-12: 48px;
  /* Half-steps, used sparingly for optical alignment */
  --sp-05: 2px;
  --sp-15: 6px;
  --sp-25: 10px;
  --sp-35: 14px;

  /* --- Alpine palette --- */
  --bg-top:      #e6f0fb;   /* high alpine sky */
  --bg-bot:      #f7fbff;   /* fresh snow */
  --card:        #ffffff;
  --card-soft:   #f4f9ff;
  --text:        #0b1e3f;   /* deep navy */
  --text-soft:   #1c3557;
  --muted:       #536880;   /* AA on white (~5.7:1) even at 11px */
  --muted-soft:  #7189a6;   /* decorative only — never body copy */

  --primary:        #1d4ed8;
  --primary-hover:  #1e3a8a;
  --primary-bright: #3b82f6;
  --primary-soft:   #dbeafe;
  --primary-glow:   rgba(59, 130, 246, 0.22);

  --ice:           #e0f2fe;
  --frost:         #f2f8ff;
  --border:        #dbe6f4;
  --border-strong: #b6cbe6;

  --error-bg:   #fee2e2; --error-text:   #b3161c; --error:   #ef4444;
  --success-bg: #d1fae5; --success-text: #05614a; --success: #10b981;
  --warn-bg:    #fef3c7; --warn-text:    #874100; --warn:    #f59e0b;
  --info-bg:    #dbeafe; --info-text:    #1e3a8a; --info:    #3b82f6;

  /* ----------------------------------------------------------
     Elevation — soft, layered, low-contrast
     ---------------------------------------------------------- */
  --shadow-xs: 0 1px 2px rgba(16, 42, 90, 0.05);
  --shadow-sm: 0 1px 2px rgba(16, 42, 90, 0.04), 0 2px 6px rgba(16, 42, 90, 0.05);
  --shadow:    0 2px 4px rgba(16, 42, 90, 0.04), 0 10px 24px rgba(16, 42, 90, 0.07);
  --shadow-lg: 0 4px 10px rgba(16, 42, 90, 0.05), 0 20px 44px rgba(16, 42, 90, 0.11);
  --shadow-pop: 0 24px 64px rgba(11, 30, 63, 0.30);

  /* Radii */
  --radius-xs:   6px;
  --radius-sm:   8px;
  --radius:      12px;
  --radius-lg:   16px;
  --radius-pill: 999px;

  /* Focus ring — used by :focus-visible everywhere */
  --ring: 0 0 0 3px rgba(59, 130, 246, 0.40);

  /* Motion */
  --ease: cubic-bezier(.32, .72, .35, 1);
  --t-fast: .12s;
  --t-med:  .18s;
  --t-slow: .28s;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  font-weight: var(--fw-normal);
  color: var(--text);
  line-height: var(--lh-normal);
  letter-spacing: var(--ls-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* NOTE: deliberately no `text-rendering: optimizeLegibility` — it costs
     real layout time on the 200+ row customer tables on cheap Android phones. */
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(59,130,246,0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(14,165,233,0.10), transparent 60%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bot) 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

/* Headings share one display face and a tight, consistent rhythm */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-snug);
  color: var(--text);
}
h1 { font-size: var(--fs-2xl); letter-spacing: var(--ls-tight); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }

p { line-height: var(--lh-normal); }

strong, b { font-weight: var(--fw-semi); }

code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.9375em; }

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--sp-5) 0;
}

::selection { background: var(--primary-soft); color: var(--primary-hover); }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--t-fast) var(--ease);
}
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* ------------------------------------------------------------
   Focus-visible: one consistent, high-contrast keyboard ring.
   Mouse users never see it; keyboard users always do.
   ------------------------------------------------------------ */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
a:focus-visible,
button:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
.btn:focus-visible,
.page-tab:focus-visible,
.stage-chip:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
/* Fields keep their own ring (see the Forms section) — a square outline
   would clash with their rounded border. */
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

.muted { color: var(--muted); }
.small { font-size: var(--fs-2xs); line-height: var(--lh-snug); }
.num   { text-align: right; font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* Figures line up: money, dates, counts, phone numbers */
.stat-value, .stat-foot, .hero-stat-value, .pipeline-total-value,
.stage-chip-count, .stage-board-count, .stage-check-count,
.badge, .timeline-date, .journey-time, .activity-day-num, .activity-day-count,
.customer-code, .customer-code-small, .last-remark-date,
.table td, .kv dd, .master-count {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  50%      { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.animate-in { animation: slideUp .4s ease-out both; }
.delay-1 { animation-delay: .05s; }
.delay-2 { animation-delay: .10s; }
.delay-3 { animation-delay: .15s; }
.delay-4 { animation-delay: .20s; }

/* ============================================================
   Auth pages (login / install)
   ============================================================ */
.auth-body {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-5);
}
.auth-card {
  width: 100%; max-width: 440px;
  background: linear-gradient(180deg, #ffffff 0%, var(--frost) 100%);
  padding: var(--sp-10) var(--sp-8);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  position: relative;
  animation: slideUp .5s ease-out both;
  overflow: hidden;
}
.auth-card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--primary-bright), var(--accent, #0ea5e9), var(--primary));
}
.auth-brand {
  display: flex; align-items: center; gap: var(--sp-25);
  font-family: var(--font-display);
  font-size: var(--fs-2xl); font-weight: var(--fw-bold);
  letter-spacing: var(--ls-tight);
  line-height: var(--lh-tight);
  color: var(--text);
  margin-bottom: var(--sp-1);
}
.auth-brand .emoji { font-size: 32px; display: inline-block; animation: float 3s ease-in-out infinite; }
.auth-card h1 { margin: 0 0 var(--sp-1); font-size: var(--fs-xl); }
.auth-card form { margin-top: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-4); }
.auth-foot { margin-top: var(--sp-5); text-align: center; font-size: var(--fs-2xs); color: var(--muted); }

/* ============================================================
   Forms
   ============================================================ */
label {
  display: flex; flex-direction: column;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  line-height: var(--lh-snug);
  letter-spacing: 0.005em;
  gap: var(--sp-15);
  color: var(--text-soft);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="datetime-local"],
input[type="search"], select, textarea {
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  line-height: 1.45;
  padding: 10px var(--sp-3);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease);
  width: 100%;
  font-weight: var(--fw-normal);
  font-variant-numeric: tabular-nums;
}
select {
  cursor: pointer;
  /* room for the native arrow so the label never collides with it */
  padding-right: var(--sp-7);
}
textarea {
  resize: vertical;
  min-height: 76px;
  line-height: var(--lh-normal);
  font-variant-numeric: normal;
}
input:hover:not(:focus), select:hover:not(:focus), textarea:hover:not(:focus) {
  border-color: #9dbadd;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-bright);
  box-shadow: 0 0 0 4px var(--primary-glow);
  background: #fff;
}
/* Keyboard focus gets a noticeably stronger ring than pointer focus. */
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--primary);
  box-shadow: var(--ring);
}
input::placeholder, textarea::placeholder { color: #8fa3bd; opacity: 1; }
input:disabled, select:disabled, textarea:disabled {
  background: var(--frost);
  color: var(--muted);
  cursor: not-allowed;
}
input[type="checkbox"], input[type="radio"] {
  width: auto;
  accent-color: var(--primary);
  cursor: pointer;
}

.form-card {
  background: #fff;
  padding: var(--sp-6);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.form-tight { padding: var(--sp-5); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4) var(--sp-5); }
.span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.form-actions {
  margin-top: var(--sp-6);
  display: flex; gap: var(--sp-25); align-items: center;
  flex-wrap: wrap;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--sp-15);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  letter-spacing: 0.005em;
  padding: 9px var(--sp-4);
  min-height: 38px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer; text-decoration: none;
  line-height: 1.2;
  transition: background var(--t-med) var(--ease),
              border-color var(--t-med) var(--ease),
              color var(--t-med) var(--ease),
              transform var(--t-fast) var(--ease),
              box-shadow var(--t-med) var(--ease),
              filter var(--t-med) var(--ease);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.995); }
.btn[disabled], .btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-sm {
  padding: 5px var(--sp-25);
  font-size: var(--fs-xs);
  min-height: 30px;
  border-radius: var(--radius-xs);
  gap: var(--sp-1);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-bright), var(--primary));
  color: #fff;
  box-shadow: 0 2px 4px rgba(29, 78, 216, 0.16), 0 6px 16px rgba(59, 130, 246, 0.26);
}
.btn-primary:hover { box-shadow: 0 4px 8px rgba(29, 78, 216, 0.18), 0 10px 22px rgba(59, 130, 246, 0.34); filter: brightness(1.05); }

.btn-secondary {
  background: #fff; color: var(--text-soft); border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { border-color: var(--primary-bright); color: var(--primary); background: var(--frost); }

.btn-danger {
  background: #fff; color: var(--error-text); border-color: var(--error);
}
.btn-danger:hover { background: var(--error-bg); }

.btn-link {
  background: transparent; color: var(--primary);
  padding: 9px var(--sp-1);
  min-height: 0;
  font-weight: var(--fw-semi);
}
.btn-link:hover { text-decoration: underline; transform: none; }

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  display: flex; align-items: center;
  padding: var(--sp-25) var(--sp-5);
  background: linear-gradient(180deg, rgba(255,255,255,0.96) 0%, rgba(242,248,255,0.94) 100%);
  border-bottom: 1px solid var(--border);
  gap: var(--sp-35);
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: saturate(150%) blur(8px);
  -webkit-backdrop-filter: saturate(150%) blur(8px);
}
.topbar-brand a {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--frost);
  border: 1px solid var(--border);
  transition: background .15s, border-color .15s;
}
.topbar-brand a:hover { text-decoration: none; background: var(--ice); border-color: var(--primary-bright); }
.topbar-brand .emoji { font-size: 22px; transition: transform .4s; display: inline-block; line-height: 1; }
.topbar-brand a:hover .emoji { transform: rotate(-8deg) scale(1.1); }

.topbar-links { display: flex; gap: var(--sp-05); flex: 1; flex-wrap: wrap; }
.topbar-links a {
  color: var(--muted);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  font-weight: var(--fw-semi);
  font-size: var(--fs-xs);
  letter-spacing: 0.005em;
  line-height: 1.3;
  display: inline-flex; align-items: center; gap: var(--sp-15);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  white-space: nowrap;
}
.topbar-links a:hover { background: var(--ice); color: var(--primary); text-decoration: none; }
.topbar-links a.active {
  color: var(--primary-hover);
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px rgba(59,130,246,0.18);
}

.topbar-user {
  display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-xs);
}
.topbar-user .muted { display: inline-flex; align-items: center; gap: var(--sp-15); }

.container {
  max-width: 1240px; margin: 0 auto; padding: var(--sp-7) var(--sp-6) var(--sp-12);
  animation: fadeIn .4s ease-out;
}

/* ============================================================
   Page head
   ============================================================ */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: var(--sp-6); gap: var(--sp-4);
}
.page-head h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-2xl); font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
  display: inline-flex; align-items: center; gap: var(--sp-25);
  flex-wrap: wrap;
}
.page-head h1 .muted { font-weight: var(--fw-medium); font-size: var(--fs-lg); }
.page-head .actions { display: flex; gap: var(--sp-2); }

/* ============================================================
   Alerts
   ============================================================ */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  margin-bottom: var(--sp-35);
  font-weight: var(--fw-medium);
  border: 1px solid transparent;
  animation: slideUp .35s ease-out;
}
.alert-error   { background: var(--error-bg);   color: var(--error-text);   border-color: #fecaca; }
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: #a7f3d0; }
.alert-info    { background: var(--info-bg);    color: var(--info-text);    border-color: #bfdbfe; }
.alert-warn    { background: var(--warn-bg);    color: var(--warn-text);    border-color: #fde68a; }

/* ============================================================
   Stat cards
   ============================================================ */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(216px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.stat {
  background: linear-gradient(180deg, #ffffff, var(--card-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5) var(--sp-5) var(--sp-5) var(--sp-6);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: transform var(--t-med) var(--ease), box-shadow var(--t-med) var(--ease);
  animation: slideUp .4s ease-out both;
}
.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat-link {
  text-decoration: none; color: inherit; display: block;
}
.stat-link:hover { text-decoration: none; }
.stat-link:hover .stat-value { color: var(--primary); }
.stat::before {
  content: ""; position: absolute; top: 0; left: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--primary-bright), var(--primary));
}
.stat-error::before { background: linear-gradient(180deg, #fca5a5, var(--error)); }
.stat-warn::before  { background: linear-gradient(180deg, #fcd34d, var(--warn)); }

.stat-label {
  font-size: var(--fs-3xs); color: var(--muted);
  text-transform: uppercase; letter-spacing: var(--ls-caps-wide);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  display: inline-flex; align-items: center; gap: var(--sp-15);
}
.stat-value {
  font-family: var(--font-display);
  font-size: var(--fs-3xl); font-weight: var(--fw-bold);
  margin-top: var(--sp-15);
  line-height: 1.1;
  color: var(--text); letter-spacing: var(--ls-tight);
  transition: color var(--t-fast) var(--ease);
}
.stat-foot  {
  font-size: var(--fs-2xs); color: var(--muted);
  margin-top: var(--sp-15); line-height: var(--lh-snug);
}

/* ============================================================
   Panels
   ============================================================ */
.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--sp-5);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  animation: slideUp .4s ease-out both;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-35) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--frost), #fff);
}
.panel-head h2 {
  margin: 0;
  font-size: var(--fs-lg); font-weight: var(--fw-bold);
  letter-spacing: var(--ls-snug);
  line-height: var(--lh-tight);
  color: var(--text);
  display: inline-flex; align-items: center; gap: var(--sp-2);
}
.panel .empty { padding: var(--sp-8) var(--sp-6); text-align: center; color: var(--muted); }
.empty-success { color: var(--success-text); }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-5);
  margin-bottom: var(--sp-5);
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.kv {
  display: grid; grid-template-columns: 152px 1fr;
  gap: var(--sp-25) var(--sp-4);
  margin: 0;
  padding: var(--sp-5);
}
.kv dt {
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semi);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  line-height: 1.6;
  padding-top: 1px;
}
.kv dd {
  margin: 0;
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--text);
}

.notes-block { padding: 0 var(--sp-5) var(--sp-5); }
.notes-block p { margin: var(--sp-15) 0 0; white-space: pre-wrap; font-size: var(--fs-sm); line-height: var(--lh-normal); }

/* ============================================================
   Tables
   ============================================================ */
.table { width: 100%; border-collapse: collapse; background: #fff; }
.table th, .table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  border-top: 1px solid var(--border);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  vertical-align: top;
}
.table thead th {
  background: var(--frost); border-top: 0;
  padding-top: var(--sp-25); padding-bottom: var(--sp-25);
  font-size: var(--fs-3xs);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  line-height: var(--lh-tight);
  color: var(--muted); font-weight: var(--fw-bold);
  position: relative;
}
.table tbody tr {
  transition: background var(--t-fast) var(--ease);
  animation: fadeIn .3s ease-out both;
}
.table tbody tr:hover { background: var(--frost); }
.table tbody td strong { font-weight: var(--fw-semi); }
.table td .muted.small,
.table td .small { line-height: var(--lh-snug); }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn + .btn { margin-left: var(--sp-1); }

/* "Add new outcome" inline input + button */
.outcome-new-wrap {
  display: flex; gap: 6px; align-items: stretch;
}
.outcome-new-wrap input[name="outcome_new"] {
  flex: 1; min-width: 0;
}
.outcome-new-wrap .btn {
  flex-shrink: 0;
  white-space: nowrap;
}
[data-outcome-add-status] {
  display: inline-block;
  margin-top: 4px;
}

/* ============================================================
   Last call + remark combined column (followup pages, on screen)
   ============================================================ */
.col-last-remark {
  font-size: var(--fs-2xs);
  line-height: var(--lh-snug);
  max-width: 280px;
  vertical-align: top;
}
.col-last-remark .last-remark-date {
  display: inline-block;
  font-weight: var(--fw-bold);
  color: var(--primary-hover);
  background: var(--ice);
  padding: 0 var(--sp-15);
  border-radius: var(--radius-xs);
  font-size: var(--fs-3xs);
  line-height: 1.6;
  white-space: nowrap;
  margin-right: var(--sp-1);
  font-family: var(--font-mono);
}
.col-last-remark .last-remark-text {
  color: var(--text);
  word-break: break-word;
}

@media (max-width: 768px) {
  .col-last-remark { font-size: 11px; max-width: 180px; padding: 6px 8px !important; }
  .col-last-remark .last-remark-date { font-size: 10px; padding: 1px 5px; }
}

/* ============================================================
   Page tabs (used on stages.php to switch By Stage / By Last Payment)
   ============================================================ */
.page-tabs {
  display: flex; gap: var(--sp-1);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-15);
  margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.page-tab {
  flex: 1 1 0;
  text-align: center;
  padding: var(--sp-25) var(--sp-35);
  border-radius: var(--radius-sm);
  font-weight: var(--fw-semi);
  font-size: var(--fs-sm);
  letter-spacing: 0.005em;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.page-tab:hover {
  background: var(--frost);
  color: var(--text);
  text-decoration: none;
}
.page-tab.active {
  background: linear-gradient(135deg, var(--primary-bright), var(--primary));
  color: #fff;
  box-shadow: 0 3px 10px rgba(59, 130, 246, 0.30);
}

@media (max-width: 480px) {
  .page-tab { padding: 8px 10px; font-size: 13px; }
}

/* ============================================================
   🧠 Smart Suggestions panel (customer_report.php)
   ============================================================ */
.insights-panel { border-left: 4px solid #6366f1; }
.insights-list { padding: 4px 0; }
.insight {
  display: flex; gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
  transition: background .12s;
}
.insight:last-child { border-bottom: 0; }
.insight:hover { background: rgba(99, 102, 241, 0.03); }
.insight-icon {
  font-size: 22px;
  flex-shrink: 0;
  width: 32px;
  text-align: center;
  margin-top: 1px;
}
.insight-body { flex: 1; min-width: 0; }
.insight-title { font-weight: var(--fw-bold); font-size: var(--fs-sm); color: var(--text); line-height: var(--lh-tight); letter-spacing: var(--ls-snug); }
.insight-detail { font-size: var(--fs-2xs); color: var(--muted); margin-top: var(--sp-1); line-height: var(--lh-snug); }
.insight-action {
  font-size: var(--fs-2xs); color: var(--primary); font-weight: var(--fw-semi);
  margin-top: var(--sp-15); padding: var(--sp-1) 0;
  border-top: 1px dashed rgba(99, 102, 241, 0.25);
}

/* Priority colors via subtle left strip */
.insight-high   { background: linear-gradient(90deg, rgba(239,68,68,0.06), transparent 60%); }
.insight-medium { background: linear-gradient(90deg, rgba(245,158,11,0.06), transparent 60%); }
.insight-low    { background: linear-gradient(90deg, rgba(59,130,246,0.05), transparent 60%); }
.insight-info   { background: linear-gradient(90deg, rgba(16,185,129,0.05), transparent 60%); }
.insight-high   .insight-icon { filter: drop-shadow(0 0 4px rgba(239,68,68,0.35)); }

.insights-foot {
  padding: 12px 18px;
  background: var(--frost);
  border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
  .insight { padding: 10px 14px; gap: 8px; }
  .insight-icon { font-size: 18px; width: 24px; }
  .insight-title { font-size: 13px; }
  .insight-detail { font-size: 11px; }
}

/* Center-align Stage and Next-Followup columns (both TH and TD) */
.table .cell-stage,
.table .cell-followup,
.table th.cell-stage,
.table th.cell-followup {
  text-align: center;
}

/* ============================================================
   Filters bar
   ============================================================ */
.filters {
  display: flex; gap: var(--sp-2) var(--sp-25); flex-wrap: wrap; align-items: center;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--sp-35); margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-sm);
}
.filters input[type="search"] { flex: 1; min-width: 240px; }
.filters select { width: auto; min-width: 150px; }
.filters label { flex-direction: row; align-items: center; gap: var(--sp-15); }

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  font-size: var(--fs-2xs); font-weight: var(--fw-bold);
  letter-spacing: 0.005em;
  padding: 2px var(--sp-25);
  border-radius: var(--radius-pill);
  background: #eaf2fb; color: #3d5875;
  line-height: 1.55;
  transition: transform var(--t-fast) var(--ease);
}
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-error   { background: var(--error-bg);   color: var(--error-text); animation: pulseGlow 2s ease-in-out infinite; }
.badge-warn    { background: var(--warn-bg);    color: var(--warn-text); }
.badge-info    { background: var(--info-bg);    color: var(--info-text); }
.badge-muted   { background: #eaf2fb;           color: #4a6280; }
.badge-agent   { background: #ede9fe;           color: #5b21b6; }

/* ============================================================
   Stage breakdown grid (dashboard)
   ============================================================ */
.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  padding: 16px 20px 20px;
}
.stage-group-title {
  font-size: var(--fs-3xs);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps-wide);
  color: var(--muted);
  font-weight: var(--fw-bold);
  margin-bottom: var(--sp-2);
}
.stage-chip {
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  background: #fff;
  border: 1px solid var(--border);
  margin-bottom: var(--sp-15);
  font-size: var(--fs-xs); font-weight: var(--fw-semi);
  line-height: var(--lh-snug);
  color: var(--text);
  transition: transform var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.stage-chip:hover {
  text-decoration: none;
  transform: translateX(2px);
  border-color: var(--primary-bright);
  box-shadow: var(--shadow-sm);
}
.stage-chip-count {
  display: inline-block;
  min-width: 26px; text-align: center;
  padding: 1px var(--sp-2); border-radius: var(--radius-pill);
  background: var(--frost); color: var(--muted);
  border: 1px solid var(--border);
  font-weight: var(--fw-bold); font-size: var(--fs-2xs);
  line-height: 1.5;
  flex-shrink: 0;
}
.stage-chip.stage-tone-info    { border-left: 3px solid var(--info); }
.stage-chip.stage-tone-warn    { border-left: 3px solid var(--warn); }
.stage-chip.stage-tone-error   { border-left: 3px solid var(--error); }
.stage-chip.stage-tone-success { border-left: 3px solid var(--success); }
.stage-chip.stage-tone-agent   { border-left: 3px solid #8b5cf6; }
.stage-chip.stage-tone-muted   { border-left: 3px solid #94a3b8; }

/* ============================================================
   Stages page — redesigned board view
   ============================================================ */
.pipeline-card {
  background: linear-gradient(180deg, #fff, var(--card-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
  animation: slideUp .35s ease-out;
}
.pipeline-totals {
  display: flex; gap: 32px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.pipeline-total-label {
  font-size: var(--fs-3xs); color: var(--muted);
  text-transform: uppercase; letter-spacing: var(--ls-caps-wide);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
}
.pipeline-total-value {
  font-family: var(--font-display);
  font-size: var(--fs-3xl); font-weight: var(--fw-bold);
  letter-spacing: var(--ls-tight);
  line-height: 1.1;
  margin-top: var(--sp-1);
}
.pipeline-bar {
  display: flex;
  height: 32px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--frost);
  box-shadow: inset 0 1px 2px rgba(11,30,63,0.05);
  cursor: pointer;
}
.pipeline-seg {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 11px;
  transition: filter .15s, transform .15s, box-shadow .15s;
  min-width: 0;
  white-space: nowrap;
  text-decoration: none;
  position: relative;
}
.pipeline-seg:hover {
  filter: brightness(1.12);
  text-decoration: none;
  z-index: 2;
  box-shadow: 0 0 0 2px rgba(11, 30, 63, 0.15) inset, 0 4px 12px rgba(0,0,0,0.15);
}
.pipeline-seg::after {
  /* tiny click affordance — a chevron on hover */
  content: "›";
  position: absolute; right: 6px;
  opacity: 0; transition: opacity .15s;
  font-size: 14px; font-weight: 900;
}
.pipeline-seg:hover::after { opacity: 0.85; }
.pipeline-seg-label { padding: 0 8px; text-shadow: 0 1px 2px rgba(0,0,0,0.15); }

.pipeline-legend {
  display: flex; flex-wrap: wrap; gap: var(--sp-15);
  margin-top: var(--sp-35);
  font-size: var(--fs-2xs);
}
.pipeline-legend-item {
  display: inline-flex; align-items: center; gap: var(--sp-15);
  color: var(--muted);
  padding: var(--sp-1) var(--sp-25);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-weight: var(--fw-medium);
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  text-decoration: none;
}
.pipeline-legend-item:hover {
  color: var(--text);
  border-color: var(--primary-bright);
  background: var(--ice);
  text-decoration: none;
}
.pipeline-legend-item strong { color: var(--text); }
.pipeline-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%;
}

/* Clear-filter link inside the filter summary */
.filter-clear {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--error-text);
  background: var(--error-bg);
  padding: 2px 10px;
  border-radius: 999px;
  text-decoration: none;
}
.filter-clear:hover { filter: brightness(1.05); text-decoration: none; }

.board-title {
  font-size: var(--fs-2xs); font-weight: var(--fw-bold);
  text-transform: uppercase; letter-spacing: var(--ls-caps-wide);
  color: var(--muted);
  margin: var(--sp-6) 0 var(--sp-3);
}

.stage-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stage-board-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: transform .18s, box-shadow .18s;
  animation: slideUp .35s ease-out both;
}
.stage-board-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}
.stage-board-card .stage-board-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fff, var(--frost));
}
.stage-board-name {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-weight: var(--fw-bold); font-size: var(--fs-md);
  letter-spacing: var(--ls-snug);
  line-height: var(--lh-tight);
  color: var(--text);
}
.stage-board-name .stage-emoji { font-size: 18px; line-height: 1; }
.stage-board-count {
  background: var(--primary-soft);
  color: var(--primary-hover);
  font-weight: var(--fw-bold); font-size: var(--fs-2xs);
  padding: 2px var(--sp-25);
  border-radius: var(--radius-pill);
  min-width: 30px; text-align: center;
  line-height: 1.6;
}

/* Color-coded top border by tone */
.stage-board-card.stage-tone-info    { border-top: 4px solid var(--info); }
.stage-board-card.stage-tone-success { border-top: 4px solid var(--success); }
.stage-board-card.stage-tone-warn    { border-top: 4px solid var(--warn); }
.stage-board-card.stage-tone-error   { border-top: 4px solid var(--error); }
.stage-board-card.stage-tone-agent   { border-top: 4px solid #8b5cf6; }
.stage-board-card.stage-tone-muted   { border-top: 4px solid #94a3b8; }

.stage-board-card.stage-tone-info    .stage-board-count { background: var(--info-bg);    color: var(--info-text); }
.stage-board-card.stage-tone-success .stage-board-count { background: var(--success-bg); color: var(--success-text); }
.stage-board-card.stage-tone-warn    .stage-board-count { background: var(--warn-bg);    color: var(--warn-text); }
.stage-board-card.stage-tone-error   .stage-board-count { background: var(--error-bg);   color: var(--error-text); }
.stage-board-card.stage-tone-agent   .stage-board-count { background: #ede9fe;           color: #5b21b6; }

.stage-customer-list {
  list-style: none; margin: 0; padding: var(--sp-2) var(--sp-4);
  flex: 1;
}
.stage-customer-list li {
  padding: var(--sp-2) 0;
  border-bottom: 1px dashed var(--border);
}
.stage-customer-list li:last-child { border-bottom: 0; }
.stage-customer-link {
  display: block;
  color: var(--text);
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
}
.stage-customer-link:hover { text-decoration: none; color: var(--primary); }
.stage-customer-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.stage-customer-sub { margin-top: 2px; }
.stage-more { font-style: italic; }
.stage-board-foot {
  display: block;
  padding: var(--sp-25) var(--sp-4);
  border-top: 1px solid var(--border);
  background: var(--frost);
  text-align: right;
  font-size: var(--fs-2xs); font-weight: var(--fw-semi);
  color: var(--muted);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.stage-board-foot:hover { color: var(--primary); background: var(--ice); text-decoration: none; }

.empty-stages-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}
.empty-stages-panel summary {
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex; align-items: center; justify-content: space-between;
}
.empty-stages-panel summary::after {
  content: '▾';
  color: var(--muted);
  transition: transform .2s;
}
.empty-stages-panel[open] summary::after { transform: rotate(180deg); }
.empty-stages-panel summary::-webkit-details-marker { display: none; }
.empty-stage-chips {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 4px 18px 18px;
}
.empty-stage-chip {
  display: inline-flex; align-items: center; gap: var(--sp-15);
  padding: var(--sp-1) var(--sp-3);
  background: var(--frost);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: var(--fs-2xs); font-weight: var(--fw-semi);
  color: var(--muted);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.empty-stage-chip:hover {
  background: var(--ice); color: var(--primary);
  text-decoration: none; border-color: var(--primary-bright);
}

/* ============================================================
   Stage filter panel (stages.php)
   ============================================================ */
.stage-filter {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.stage-filter > summary {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  background: linear-gradient(180deg, var(--frost), #fff);
}
.stage-filter > summary::-webkit-details-marker { display: none; }
.stage-filter[open] > summary { border-bottom: 1px solid var(--border); }
.stage-filter .filter-badge {
  margin-left: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--frost);
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.stage-filter .filter-badge strong { color: var(--primary); }
.stage-filter > summary .collapsible-chevron { margin-left: auto; color: var(--muted); transition: transform .2s; }
.stage-filter[open] > summary .collapsible-chevron { transform: rotate(180deg); }

.stage-filter-toolbar {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 12px 16px;
  background: var(--frost);
  border-bottom: 1px solid var(--border);
}

.stage-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
  padding: 10px 12px;
}
.stage-filter-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px 6px;
  margin: 0;
  background: #fff;
}
.stage-filter-group legend {
  padding: 0 var(--sp-1);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  color: var(--muted);
}
/* Override base `label { flex-direction: column }` so checkbox + name are on one line */
.group-toggle,
.stage-check {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.group-toggle {
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  font-size: 12px;
  padding: 2px 0;
}
.group-toggle input { width: auto; flex-shrink: 0; margin: 0; }

.stage-check {
  padding: var(--sp-1) var(--sp-15);
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  margin: 1px 0;
  transition: background var(--t-fast) var(--ease);
  line-height: 1.45;
}
.stage-check:hover { background: var(--frost); }
.stage-check input {
  width: auto;
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
}
.stage-check-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stage-check-count {
  font-size: 10.5px;
  font-weight: 700;
  background: var(--frost);
  color: var(--muted);
  padding: 0 7px;
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
  flex-shrink: 0;
}
.stage-check.has-data .stage-check-count {
  background: var(--primary-soft);
  color: var(--primary);
}
.stage-check.has-data { font-weight: 600; }
.stage-check.has-data .stage-check-name { color: var(--text); }

/* ============================================================
   Reports page — chart cards
   ============================================================ */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.chart-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  animation: slideUp .35s ease-out both;
}
.chart-card h3 {
  margin: 0 0 var(--sp-35);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps-wide);
  line-height: var(--lh-snug);
  color: var(--muted);
}
.chart-card.span-2 { grid-column: span 2; }
@media (max-width: 900px) { .chart-card.span-2 { grid-column: auto; } }
.chart-canvas-wrap {
  position: relative;
  height: 260px;
}
.chart-empty {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  font-size: 14px;
  background: linear-gradient(180deg, #fff, var(--frost));
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}

/* Make charts print cleanly: keep canvases visible, hide animation, white bg. */
@media print {
  .chart-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .chart-card {
    box-shadow: none !important;
    border-color: #999 !important;
    page-break-inside: avoid;
  }
  .chart-canvas-wrap { height: 220px; }
}

/* ============================================================
   Quick stage-change bar on customer view
   ============================================================ */
.stage-bar {
  display: flex; align-items: center; gap: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.stage-bar select { width: auto; min-width: 240px; }

/* ============================================================
   Global customer search overlay (open with "+")
   ============================================================ */
.search-trigger {
  display: inline-flex; align-items: center; gap: var(--sp-15);
  background: var(--frost);
  border: 1.5px solid var(--border-strong);
  color: var(--muted);
  padding: var(--sp-15) var(--sp-3);
  min-height: 34px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans); font-size: var(--fs-xs); font-weight: var(--fw-semi);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.search-trigger:hover {
  border-color: var(--primary-bright);
  color: var(--primary);
  background: #fff;
}
.search-trigger kbd {
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  padding: 0 var(--sp-15);
  font-family: var(--font-mono); font-size: var(--fs-3xs); font-weight: var(--fw-bold);
  color: var(--text);
  box-shadow: 0 1px 0 var(--border-strong);
}

.search-overlay {
  position: fixed; inset: 0;
  background: rgba(11, 30, 63, 0.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-start; justify-content: center;
  padding: 80px 20px 20px;
  z-index: 200;
  animation: fadeIn .15s ease-out;
}
.search-overlay.open { display: flex; }
body.search-open { overflow: hidden; }

.search-panel {
  width: 100%; max-width: 600px;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  border: 1px solid var(--border);
  overflow: hidden;
  animation: slideUp .2s ease-out;
}
.search-bar {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-35) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fff, var(--frost));
}
.search-icon { font-size: 18px; line-height: 1; }
.search-bar input[type="search"] {
  border: none !important;
  padding: var(--sp-1) 0 !important;
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  background: transparent;
  box-shadow: none !important;
  flex: 1;
}
.search-bar input[type="search"]:focus { outline: none; }
.search-close {
  background: var(--frost);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.search-close:hover { color: var(--error-text); border-color: var(--error); }

.search-results {
  max-height: 50vh;
  overflow-y: auto;
}
.search-result {
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  transition: background var(--t-fast) var(--ease);
}
.search-result:last-child { border-bottom: 0; }
.search-result:hover,
.search-result.active {
  background: var(--ice);
}
.search-result-main strong { color: var(--text); font-weight: var(--fw-semi); }
.search-result-meta { display: flex; gap: var(--sp-25); align-items: center; }

.search-hint {
  padding: var(--sp-6);
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-sm);
}
.search-foot {
  display: flex; gap: var(--sp-5);
  padding: var(--sp-25) var(--sp-5);
  background: var(--frost);
  border-top: 1px solid var(--border);
  font-size: var(--fs-2xs);
  color: var(--muted);
}
.search-foot kbd {
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  padding: 1px var(--sp-15);
  font-family: var(--font-mono);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-bold);
  margin-right: var(--sp-1);
  color: var(--text);
}

/* Brief highlight when JS auto-fills a field */
@keyframes fieldFlash {
  0%   { background: #fff9c4; box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.25); }
  100% { background: #fff;    box-shadow: 0 0 0 0  rgba(245, 158, 11, 0); }
}
.field-flash { animation: fieldFlash .9s ease-out; }

/* ============================================================
   Call + WhatsApp icon buttons
   ============================================================ */
.contact-buttons {
  display: inline-flex; gap: 4px; flex-wrap: nowrap;
  margin-top: 4px;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  text-decoration: none;
  font-size: 14px; line-height: 1;
  border: 1px solid transparent;
  transition: transform .12s, box-shadow .15s, filter .15s;
}
.icon-btn:hover { transform: translateY(-1px); text-decoration: none; filter: brightness(1.08); }
.icon-btn-lg { width: 38px; height: 38px; font-size: 18px; }

.icon-btn-call {
  background: linear-gradient(135deg, #34d399, #059669);
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.28);
}
.icon-btn-call:hover { box-shadow: 0 3px 10px rgba(16, 185, 129, 0.42); }

.icon-btn-whatsapp {
  background: linear-gradient(135deg, #22c55e, #15803d);
  box-shadow: 0 2px 6px rgba(34, 197, 94, 0.28);
}
.icon-btn-whatsapp:hover { box-shadow: 0 3px 10px rgba(34, 197, 94, 0.42); }

/* Comfortable on touch */
@media (max-width: 640px) {
  .icon-btn { width: 34px; height: 34px; font-size: 16px; }
  .icon-btn-lg { width: 44px; height: 44px; font-size: 20px; }
}

/* ============================================================
   Print styles
   ============================================================ */
@media print {
  @page { size: A4; margin: 0.5cm 0.6cm; }
  body {
    background: #fff !important;
    color: #000;
    font-size: 9pt;
    line-height: 1.25;
  }
  .topbar,
  .search-overlay,
  .search-trigger,
  .filters,
  .row-actions,
  .actions,
  .stage-bar,
  .form-actions,
  .timeline-actions,
  .btn,
  .page-head a.btn-primary,
  .topbar-user,
  .contact-buttons,
  .icon-btn,
  .icon-btn-call,
  .icon-btn-whatsapp { display: none !important; }

  /* Force phone number text to show in print (mobile breakpoint hides it on narrow widths) */
  .phone-number { display: block !important; font-weight: 600; }

  .container { max-width: 100%; padding: 0; margin: 0; }
  .panel, .stat, .form-card {
    box-shadow: none !important;
    border-color: #999 !important;
    page-break-inside: avoid;
  }

  .table {
    font-size: 9pt;
    border-collapse: collapse;
    width: 100%;
  }
  .table th, .table td {
    padding: 3px 6px !important;
    vertical-align: top;
    border-top: 1px solid #999 !important;
  }
  .table thead th {
    background: #eee !important; color: #000 !important;
    font-size: 8pt;
    border-bottom: 1.5px solid #000 !important;
  }
  /* Repeat headers on every printed page when a table spans multiple pages */
  .table thead { display: table-header-group; }
  .table tr    { page-break-inside: avoid; }

  /* Hide contact-person sub-line in print to keep one row per record */
  td .contact-sub { display: none !important; }

  .badge {
    background: transparent !important;
    color: #000 !important;
    border: 0 !important;
    border-radius: 0 !important;
    padding: 0 !important;
    font-weight: normal !important;
    box-shadow: none !important;
    animation: none !important;
    display: inline !important;
  }
  a { color: #000 !important; text-decoration: none !important; }
  .print-only { display: revert !important; }
  .no-print   { display: none !important; }
  .print-header {
    display: block !important;
    margin: 0 0 6px;
    padding-bottom: 4px;
    border-bottom: 2px solid #000;
  }
  .print-header h1 { font-size: 12pt !important; margin: 0 !important; }

  /* Print: last call + remark combined column — wraps tight to free up paper space */
  th.col-last-remark, td.col-last-remark {
    width: 120px;
    min-width: 110px;
    max-width: 130px;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-size: 8pt;
    line-height: 1.2;
    vertical-align: top;
  }
  td.col-last-remark .last-remark-date {
    display: block;
    font-weight: 700;
    white-space: nowrap;
    font-size: 8pt;
    margin-bottom: 1px;
  }
  td.col-last-remark .last-remark-text {
    display: block;
    font-size: 7.5pt;
    color: #444;
  }

  /* Print: today's blank Remarks column — wide handwriting area with ruled line.
     .col-remarks is the same column on the customer list printout. */
  th.col-today-remark, td.col-today-remark,
  th.col-remarks,      td.col-remarks {
    min-width: 200px;
    height: 28px;
    border-bottom: 1px solid #333 !important;
  }

  /* Last conversation column on followup printouts */
  td.col-last-talk { min-width: 130px; max-width: 220px; }
  td.col-last-talk .last-talk-date { font-weight: 600; white-space: nowrap; }
  td.col-last-talk .last-talk-note {
    font-size: 8pt;
    color: #333 !important;
    white-space: normal;
    word-break: break-word;
  }

  /* Code column tighter */
  td.col-code, th:first-child { white-space: nowrap; }
  .customer-code, .customer-code-small {
    background: transparent !important;
    color: #000 !important;
    border: 0 !important;
    padding: 0 !important;
    font-family: ui-monospace, Consolas, monospace;
    font-weight: 600;
  }
  /* Drop big stat tiles when present on print */
  .stats { display: none !important; }
  .chart-grid { display: none !important; }
}
.print-only, .print-header { display: none; }

/* Customer code styling for screen */
.customer-code {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--fs-xs); font-weight: var(--fw-bold);
  letter-spacing: 0.02em;
  line-height: 1.6;
  background: var(--ice);
  color: var(--primary-hover);
  padding: 1px var(--sp-25);
  border-radius: var(--radius-xs);
  margin-right: var(--sp-15);
  border: 1px solid var(--border);
}
.customer-code-small {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs); font-weight: var(--fw-bold);
  line-height: 1.6;
  background: var(--frost);
  color: var(--text-soft);
  padding: 1px var(--sp-2);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ============================================================
   Tags
   ============================================================ */
.tag-row, .tag-row-inline {
  display: inline-flex; flex-wrap: wrap; gap: 4px;
  margin-top: 4px;
}
.tag-chip, .tag-chip-sm {
  display: inline-block;
  background: #f0f9ff;
  color: #075985;
  border: 1px solid #bae6fd;
  padding: 1px var(--sp-2);
  border-radius: var(--radius-pill);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-semi);
  line-height: 1.6;
  transition: background var(--t-fast) var(--ease);
}
.tag-chip-sm { font-size: var(--fs-3xs); padding: 0 var(--sp-15); }
.tag-chip:hover, .tag-chip-sm:hover {
  text-decoration: none;
  background: #e0f2fe;
}

/* ============================================================
   Inline stage select on lists
   ============================================================ */
select.inline-stage {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  padding: var(--sp-1) var(--sp-15) !important;
  border-radius: var(--radius-xs);
  border-color: var(--border) !important;
  background: #fff;
  min-width: 130px;
  cursor: pointer;
}
select.inline-stage:hover { border-color: var(--primary-bright) !important; }

/* ============================================================
   Snooze buttons
   ============================================================ */
.snooze-row {
  display: inline-flex; gap: var(--sp-1);
  margin-top: var(--sp-15);
}
.btn-snooze {
  background: var(--frost);
  border: 1px solid var(--border-strong);
  color: var(--muted);
  padding: 2px var(--sp-2);
  border-radius: var(--radius-xs);
  font-family: var(--font-sans);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.btn-snooze:hover {
  background: var(--ice);
  color: var(--primary);
  border-color: var(--primary-bright);
}

/* ============================================================
   Modal overlay (quick-log, cheatsheet)
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(11, 30, 63, 0.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-start; justify-content: center;
  padding: 80px 20px 20px;
  z-index: 220;
  animation: fadeIn .15s ease-out;
}
.modal-overlay.open { display: flex; }
.modal-panel {
  width: 100%; max-width: 520px;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  border: 1px solid var(--border);
  overflow: hidden;
  animation: slideUp .2s ease-out;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-35) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fff, var(--frost));
}
.modal-head h2 { margin: 0; font-size: var(--fs-lg); font-weight: var(--fw-bold); letter-spacing: var(--ls-snug); }
.modal-close {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--frost);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px; height: 32px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-xs);
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.modal-close:hover { color: var(--error-text); border-color: var(--error); background: var(--error-bg); }
/* the "Cancel" text button in .form-actions also carries .modal-close — keep it a link */
.btn.modal-close {
  width: auto; height: auto;
  background: transparent;
  border-color: transparent;
}
.btn.modal-close:hover { background: transparent; border-color: transparent; color: var(--error-text); }
#quick-log-form { padding: var(--sp-5); }
.kbd-table { width: 100%; font-size: var(--fs-sm); }
.kbd-table td { padding: var(--sp-15) var(--sp-2); }
.kbd-table kbd {
  background: var(--frost);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  padding: 2px var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--text);
  font-weight: var(--fw-bold);
  display: inline-block;
  min-width: 24px;
  text-align: center;
}

/* Recent customers strip */
.recent-strip {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.recent-strip a {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: var(--sp-15) var(--sp-35);
  font-size: var(--fs-2xs);
  color: var(--text-soft);
  font-weight: var(--fw-semi);
  display: inline-flex; align-items: center; gap: var(--sp-15);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.recent-strip a:hover {
  border-color: var(--primary-bright); color: var(--primary);
  text-decoration: none;
}

/* Activity strip */
.activity-strip {
  display: grid; grid-template-columns: repeat(14, 1fr);
  gap: 4px; margin: 14px 0 18px;
}
.activity-day {
  display: block; padding: var(--sp-2) var(--sp-1);
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-sm); text-align: center;
  color: var(--text); font-weight: var(--fw-semi);
  transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.activity-day:hover { border-color: var(--primary-bright); text-decoration: none; color: var(--primary); }
.activity-day.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-hover); }
.activity-day-label { font-size: var(--fs-3xs); color: var(--muted); text-transform: uppercase; letter-spacing: var(--ls-caps); }
.activity-day-num   { font-size: var(--fs-base); font-weight: var(--fw-bold); line-height: 1.25; }
.activity-day-count { font-size: var(--fs-3xs); color: var(--muted); }
.activity-day.active .activity-day-label,
.activity-day.active .activity-day-count { color: var(--primary); }

/* WhatsApp template menu (details/summary dropdown) */
.wa-tpl-menu { position: relative; display: inline-block; }
.wa-tpl-menu summary { list-style: none; cursor: pointer; user-select: none; }
.wa-tpl-menu summary::-webkit-details-marker { display: none; }
.wa-tpl-list {
  position: absolute;
  top: calc(100% + 6px); right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 320px; max-width: 420px;
  z-index: 50;
  padding: 6px;
}
.wa-tpl-item {
  display: flex; flex-direction: column;
  padding: var(--sp-25) var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
}
.wa-tpl-item:hover { background: var(--frost); text-decoration: none; }
.wa-tpl-item strong { display: block; margin-bottom: var(--sp-05); font-weight: var(--fw-semi); font-size: var(--fs-sm); }
.wa-tpl-manage { border-top: 1px solid var(--border); margin-top: 4px; }

/* ============================================================
   Timeline
   ============================================================ */
.timeline { list-style: none; margin: 0; padding: var(--sp-25) var(--sp-5) var(--sp-5); }
.timeline li {
  padding: var(--sp-35) 0 var(--sp-35) var(--sp-7);
  border-bottom: 1px dashed var(--border);
  position: relative;
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
  animation: slideInLeft .4s ease-out both;
}
.timeline li::before {
  content: "🔵";
  position: absolute; left: 0; top: var(--sp-35);
  font-size: 10px;
  line-height: 1.6;
}
.timeline li:last-child { border-bottom: 0; }
.timeline-head { margin-bottom: var(--sp-1); }
.timeline-meta { display: flex; gap: var(--sp-15); margin-top: var(--sp-15); flex-wrap: wrap; align-items: center; }
.timeline p { margin: var(--sp-1) 0; white-space: pre-wrap; }
.timeline-row { display: flex; gap: var(--sp-3); align-items: flex-start; }
.timeline-body { flex: 1; min-width: 0; }
.timeline-actions {
  display: flex; gap: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.timeline li:hover .timeline-actions { opacity: 1; }
@media (max-width: 640px) {
  .timeline-actions { opacity: 1; }
}

/* Rich timeline (followup history with date / outcome / stage / next) */
.timeline-rich li::before { top: 18px; }
.timeline-rich .timeline-head {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 6px;
}
.timeline-date {
  font-size: var(--fs-2xs);
  color: var(--muted);
  font-weight: var(--fw-semi);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.timeline-outcome { font-size: var(--fs-sm); font-weight: var(--fw-semi); color: var(--text); }
.timeline-tags {
  display: flex; gap: 5px; flex-wrap: wrap;
  margin-bottom: 8px;
}
.timeline-note {
  background: var(--frost);
  border-left: 3px solid var(--primary-bright);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-xs);
  margin-top: var(--sp-15);
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
}
.timeline-note p { margin: var(--sp-1) 0 0; white-space: pre-wrap; }

/* Collapsible <details> sections (Details + Followup history) */
.collapsible-section { padding: 0; }
.collapsible-section > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-35) var(--sp-5);
  background: linear-gradient(180deg, var(--frost), #fff);
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast) var(--ease);
}
.collapsible-section > summary:hover { background: linear-gradient(180deg, var(--ice), var(--frost)); }
.collapsible-section > summary::-webkit-details-marker { display: none; }
.collapsible-section > summary h2 {
  margin: 0; font-size: var(--fs-lg); font-weight: var(--fw-bold);
  letter-spacing: var(--ls-snug); line-height: var(--lh-tight);
  color: var(--text);
  display: inline-flex; align-items: center; gap: var(--sp-2);
}
.collapsible-actions { display: inline-flex; align-items: center; gap: 10px; }
.collapsible-chevron {
  color: var(--muted);
  transition: transform .2s;
  font-size: 14px;
}
.collapsible-section[open] .collapsible-chevron { transform: rotate(180deg); }
.collapsible-section[open] > summary { border-bottom: 1px solid var(--border); }
.collapsible-section:not([open]) > summary { border-bottom: 0; }

/* ============================================================
   Empty state
   ============================================================ */
.empty {
  padding: var(--sp-10) var(--sp-6);
  text-align: center; color: var(--muted);
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
  background: linear-gradient(180deg, #fff, var(--frost));
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty-icon { font-size: 36px; display: block; margin-bottom: var(--sp-2); line-height: 1; }

/* Hamburger menu button (mobile only) */
.hamburger-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 40px; height: 40px;
  background: var(--frost);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 20px; line-height: 1;
  cursor: pointer;
  color: var(--text);
  margin-left: auto;
}
.hamburger-btn:hover { background: var(--ice); border-color: var(--primary-bright); }

/* Back button (visible on every page, both mobile and desktop) */
.topbar-back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: var(--frost);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 20px; line-height: 1;
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
  transition: background .15s, border-color .15s, color .15s, transform .12s;
}
.topbar-back:hover {
  background: var(--ice);
  border-color: var(--primary-bright);
  color: var(--primary);
  transform: translateX(-2px);
}
.topbar-back:active { transform: translateX(-3px); }

/* ============================================================
   Decorative — alpine mountain silhouette in topbar (optional)
   ============================================================ */
.brand-tag {
  font-size: var(--fs-3xs);
  color: var(--muted);
  background: var(--ice);
  padding: 1px var(--sp-2);
  border-radius: var(--radius-pill);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  line-height: 1.6;
}

/* ============================================================
   Personal dashboard — hero card + achievements + journey
   ============================================================ */
.hero-card {
  background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 50%, #0ea5e9 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 26px 30px;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 32px rgba(30, 64, 175, 0.25);
}
.hero-card::before,
.hero-card::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.18), transparent 70%);
  pointer-events: none;
}
.hero-card::before { top: -80px; right: -60px;  width: 240px; height: 240px; }
.hero-card::after  { bottom: -100px; left: -40px; width: 220px; height: 220px; }
.hero-card > * { position: relative; z-index: 1; }

.hero-quote {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: var(--fw-semi);
  line-height: var(--lh-snug);
  letter-spacing: var(--ls-snug);
  margin-bottom: var(--sp-5);
  text-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
.hero-stats-row {
  display: flex; flex-wrap: wrap; gap: var(--sp-8);
  margin-bottom: var(--sp-35);
}
.hero-stat-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: var(--fw-black);
  line-height: 1;
  letter-spacing: var(--ls-tight);
  font-variant-numeric: tabular-nums;
}
.hero-stat-label {
  font-size: var(--fs-3xs);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps-wide);
  font-weight: var(--fw-semi);
  opacity: 0.9;
  margin-top: var(--sp-15);
}
.hero-compare {
  display: inline-block;
  background: rgba(255,255,255,0.20);
  padding: var(--sp-15) var(--sp-35);
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* Achievements section */
.achievements-section { margin-bottom: 22px; }
.section-title {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps-wide);
  color: var(--muted);
  margin: var(--sp-6) 0 var(--sp-25);
}
.achievement-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.achievement-card {
  background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
  border: 1px solid #fde68a;
  border-left: 4px solid #f59e0b;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.15);
  animation: slideUp .4s ease-out both;
}
.achievement-icon {
  font-size: 26px; line-height: 1; flex-shrink: 0;
}
.achievement-title {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: #6b2f0c;
  line-height: var(--lh-tight);
}
.achievement-sub {
  font-size: var(--fs-3xs);
  color: #874100;
  margin-top: var(--sp-05);
  line-height: var(--lh-snug);
}

/* Stat unit (e.g. "days") */
.stat-unit { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--muted); }
.stat.stat-streak::before { background: linear-gradient(180deg, #fb923c, #ea580c); }

/* Today's journey list */
.journey-list {
  list-style: none;
  margin: 0;
  padding: 8px 18px 8px;
  counter-reset: jnum;
}
.journey-list li {
  display: flex; gap: var(--sp-25); align-items: baseline;
  padding: var(--sp-25) 0;
  border-bottom: 1px dashed var(--border);
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
  position: relative;
  padding-left: var(--sp-7);
  counter-increment: jnum;
}
.journey-list li::before {
  content: counter(jnum);
  position: absolute; left: 0; top: 9px;
  width: 22px; height: 22px;
  background: var(--frost);
  color: var(--muted);
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700;
}
.journey-list li:last-child { border-bottom: 0; }
.journey-time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-bold);
  letter-spacing: 0.01em;
  min-width: 70px;
  flex-shrink: 0;
}
.journey-outcome {
  font-weight: var(--fw-semi);
  min-width: 150px;
  flex-shrink: 0;
}
.journey-customer { color: var(--text); }
.journey-customer:hover { color: var(--primary); text-decoration: none; }
.journey-note { flex: 1; min-width: 0; }

@media (max-width: 768px) {
  .hero-card { padding: 20px 18px; }
  .hero-quote { font-size: 16px; }
  .hero-stats-row { gap: 16px; }
  .hero-stat-value { font-size: 24px; }
  .achievement-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .achievement-card { padding: 8px 10px; }
  .achievement-icon { font-size: 20px; }
  .achievement-title { font-size: 12px; }
  .achievement-sub { display: none; }

  .journey-list li {
    flex-wrap: wrap;
    padding-left: 26px;
    font-size: 12px;
  }
  .journey-time { min-width: 0; font-size: 10px; }
  .journey-outcome { min-width: 0; font-size: 12px; }
  .journey-customer { width: 100%; margin-top: 2px; }
  .journey-note { width: 100%; }
}

/* ============================================================
   Show/hide responsive utility classes
   ============================================================ */
.show-mobile { display: none !important; }
@media (max-width: 768px) {
  .show-desktop { display: none !important; }
  .show-mobile  { display: revert !important; }
  th.show-mobile, td.show-mobile { display: table-cell !important; }
}

/* ============================================================
   📱 MOBILE OVERHAUL (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: var(--fs-md); }
  .container { padding: var(--sp-35) var(--sp-35) var(--sp-8); }

  /* ---- Topbar ---- */
  .topbar {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 10px;
    align-items: center;
  }
  .topbar-brand { order: 1; }
  .hamburger-btn { display: inline-flex; order: 2; }

  .topbar-links {
    order: 4;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 4px 0 8px;
    border-top: 1px solid var(--border);
    display: none;
  }
  body.nav-open .topbar-links { display: flex; }
  .topbar-links a {
    padding: var(--sp-3) var(--sp-35);
    font-size: var(--fs-md);
    border-radius: var(--radius-sm);
    width: 100%;
    min-height: 44px;
  }

  .topbar-user {
    order: 3;
    gap: 8px;
    margin-left: 0;
  }
  /* Hide the "Hi {name} [role]" text on mobile to save space — keep just the search + logout */
  .topbar-user .muted { display: none; }
  .search-trigger { padding: 6px 10px; font-size: 12px; }
  .search-trigger kbd { display: none; }
  .topbar-user .btn { padding: 8px 10px; font-size: 12px; }

  /* ---- Page head ---- */
  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 16px;
  }
  .page-head h1 { font-size: var(--fs-xl); }
  .page-head h1 .muted { font-size: var(--fs-md); }
  .page-head .actions {
    flex-wrap: wrap;
    gap: var(--sp-15);
  }
  .page-head .actions .btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    font-size: var(--fs-xs);
    padding: var(--sp-25) var(--sp-25);
  }

  /* ---- Tables: horizontal scroll inside panel ---- */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table th, .table td {
    padding: var(--sp-25) var(--sp-25);
    font-size: var(--fs-xs);
  }
  .table thead th { font-size: var(--fs-3xs); }
  /* Keep cells from wrapping into useless multi-lines; the panel scrolls horizontally instead */
  .table td > div, .table td .snooze-row { white-space: nowrap; }

  /* Inline stage select narrower so column doesn't blow up */
  select.inline-stage { min-width: 110px; max-width: 140px; }

  /* ---- Filters bar ---- */
  .filters {
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
  }
  .filters input, .filters select, .filters .btn, .filters .btn-link {
    width: 100%;
  }
  .filters input[type="search"] { min-width: 0; }

  /* ---- Stats tiles ---- */
  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .stat { padding: var(--sp-35) var(--sp-35) var(--sp-35) var(--sp-4); }
  .stat-value { font-size: var(--fs-xl); margin-top: var(--sp-1); }
  .stat-label { font-size: var(--fs-3xs); letter-spacing: var(--ls-caps); }
  .stat-foot  { font-size: var(--fs-3xs); }

  /* ---- Forms ---- */
  /* Larger inputs prevent iOS zoom-on-focus + touch-friendly */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="date"], input[type="datetime-local"],
  input[type="search"], select, textarea {
    font-size: var(--fs-base);
    padding: var(--sp-3);
  }
  label { font-size: var(--fs-sm); }
  .form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .form-actions .btn { width: 100%; justify-content: center; padding: var(--sp-3) var(--sp-35); min-height: 44px; }

  /* ---- Buttons: 40px+ hit targets on touch ---- */
  .btn { min-height: 40px; }
  .btn-sm { min-height: 32px; padding: var(--sp-15) var(--sp-25); }

  /* ---- KV details: stack label above value ---- */
  .kv {
    grid-template-columns: 1fr;
    gap: var(--sp-05);
    padding: var(--sp-35);
  }
  .kv dt {
    color: var(--muted);
    font-size: var(--fs-3xs);
    text-transform: uppercase;
    letter-spacing: var(--ls-caps);
    margin-top: var(--sp-2);
  }
  .kv dd { font-size: var(--fs-sm); margin-bottom: var(--sp-1); }

  /* ---- Two-col already stacks at 900px ---- */

  /* ---- Stage board → single column ---- */
  .stage-board { grid-template-columns: 1fr; }
  .stage-grid  { grid-template-columns: 1fr; padding: 14px; }

  /* ---- Pipeline ---- */
  .pipeline-card { padding: 16px; }
  .pipeline-totals { gap: 16px; }
  .pipeline-total-value { font-size: 22px; }
  .pipeline-seg-label { font-size: 10px; }

  /* ---- Reports charts: single column ---- */
  .chart-grid { grid-template-columns: 1fr; gap: 12px; }
  .chart-card { padding: 14px; }
  .chart-card.span-2 { grid-column: auto; }
  .chart-canvas-wrap { height: 240px; }

  /* ---- Activity strip: scroll horizontally ---- */
  .activity-strip {
    grid-template-columns: repeat(14, 58px);
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }

  /* ---- Customer detail header ---- */
  .actions { flex-wrap: wrap; gap: 6px; }
  .actions .btn { font-size: 13px; padding: 8px 10px; }

  /* ---- Modals ---- */
  .modal-overlay { padding: 16px 12px 12px; align-items: stretch; }
  .modal-panel { max-width: 100%; }
  #quick-log-form { padding: 14px; }

  /* ---- Search overlay ---- */
  .search-overlay { padding: 16px 12px 12px; }
  .search-panel { max-width: 100%; }

  /* ---- Timeline ---- */
  .timeline { padding: 8px 14px 14px; }
  .timeline li { padding-left: 20px; }
  .timeline-row { flex-direction: column; }
  .timeline-actions { opacity: 1; align-self: flex-end; }

  /* ---- Trash + Users tables similar ---- */
  .panel-head { padding: var(--sp-3) var(--sp-35); }
  .panel-head h2 { font-size: var(--fs-md); }
  .collapsible-section > summary { padding: var(--sp-3) var(--sp-35); }
  .collapsible-section > summary h2 { font-size: var(--fs-md); }

  /* ---- WhatsApp template menu drops below button ---- */
  .wa-tpl-list { position: static; min-width: 0; max-width: none; box-shadow: var(--shadow-sm); }
  .wa-tpl-menu summary { width: 100%; }

  /* ---- Recent strip ---- */
  .recent-strip { gap: 6px; }
  .recent-strip a { font-size: 11px; padding: 5px 10px; }
}

/* ============================================================
   📱 EXTRA SMALL (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
  body { font-size: var(--fs-sm); }
  .container { padding: var(--sp-25) var(--sp-25) var(--sp-7); }
  .stats { grid-template-columns: 1fr; }
  .topbar { padding: var(--sp-2) var(--sp-25); gap: var(--sp-15); }
  .topbar-brand a { width: 34px; height: 34px; }
  .topbar-brand .emoji { font-size: 18px; }
  .hamburger-btn { width: 36px; height: 36px; }
  .page-head h1 { font-size: var(--fs-lg); }
  .page-head h1 .muted { font-size: var(--fs-sm); }
  .page-head .actions { gap: var(--sp-1); }
  .table th, .table td { padding: var(--sp-2); font-size: var(--fs-2xs); }
  .table thead th { letter-spacing: .04em; }
  .stat-value { font-size: var(--fs-xl); }
  .pipeline-total-value { font-size: var(--fs-xl); }
  .activity-strip { grid-template-columns: repeat(14, 52px); }
  .badge { font-size: var(--fs-3xs); padding: 1px var(--sp-2); }
}

/* ============================================================
   Followup table — single-render structure with viewport switching
   (overdue / due_today / upcoming)
   ============================================================ */

/* --- Default (DESKTOP, >768px): show code chip, hide action button ---
       Customer cell: firm (line 1), contact (line 2 if different), code-line hidden (code is in its own col) */
.col-action-cell .cell-action-btn { display: none; }

.customer-cell .customer-firm    { display: inline-block; font-weight: var(--fw-semi); letter-spacing: var(--ls-snug); }
.customer-cell .customer-contact {
  display: block;
  font-size: var(--fs-2xs);
  color: var(--muted);
  margin-top: var(--sp-05);
  line-height: var(--lh-snug);
}
.customer-cell .customer-contact::before { content: '👤 '; }
.customer-cell .customer-code-line { display: none; } /* code shown in its own column on desktop */

/* The Quick-Log button styling for desktop is hidden anyway */
.cell-action-btn {
  width: 36px; height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 14px;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary-bright), var(--primary));
  color: #fff;
  border: none;
  box-shadow: 0 3px 10px rgba(59, 130, 246, 0.30);
  cursor: pointer;
  line-height: 1;
  transition: filter .15s, transform .12s;
}
.cell-action-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* --- MOBILE (≤768px) overrides --- */
@media (max-width: 768px) {
  /* Hide desktop-only columns */
  .hide-on-mobile { display: none !important; }

  /* Wide tables scroll inside themselves rather than dragging the whole page
     sideways. Tables sitting in a .panel already get this from the panel; this
     covers the bare ones (customer list, category report, masters). */
  .table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Followup table doesn't need horizontal scroll on mobile */
  .table-followup { min-width: 0; }
  .table-followup th, .table-followup td {
    padding: 8px 6px !important;
    vertical-align: top;
  }

  /* Leftmost cell: swap code chip for action button */
  .col-action-cell {
    width: 46px;
    text-align: center;
    padding: 6px 4px !important;
  }
  .col-action-cell .cell-code        { display: none !important; }
  .col-action-cell .cell-action-btn  { display: inline-flex !important; }

  /* Customer cell on mobile: 3 lines stacked — firm / contact / code */
  .customer-cell-th, .customer-cell { width: 140px; max-width: 160px; }
  .customer-cell .customer-firm,
  .customer-cell .customer-contact {
    display: block;
    max-width: 15ch;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.2;
  }
  .customer-cell .customer-firm    { font-size: 13px; }
  .customer-cell .customer-contact { font-size: 12px; color: var(--muted); margin-top: 1px; }
  .customer-cell .customer-contact::before { content: ''; }  /* drop the 👤 emoji on mobile to save horizontal space */

  /* Show the code as a third line on mobile (it was hidden on desktop) */
  .customer-cell .customer-code-line {
    display: inline-block;
    font-size: var(--fs-3xs);
    color: var(--primary-hover);
    font-family: var(--font-mono);
    font-weight: var(--fw-semi);
    margin-top: var(--sp-05);
    background: var(--frost);
    padding: 0 var(--sp-15);
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
  }

  /* Hide the desktop phone-number text line (call/wa icons remain) */
  .phone-number { display: none; }
}

/* ============================================================
   Components that live in page-level markup but had no global
   styling yet. Added here so they inherit the same type scale
   and spacing rhythm as everything else.
   ============================================================ */

/* stages.php — each figure block inside .pipeline-totals */
.pipeline-total-block { min-width: 0; }

/* dashboard.php — one figure inside .hero-stats-row */
.hero-stat { min-width: 0; }

/* customer_report.php — the "pick a customer" form */
.report-picker {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: var(--sp-2) var(--sp-25);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-35);
  margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-sm);
}
.report-picker select { width: auto; min-width: 240px; max-width: 100%; }

.report-customer-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-sm);
}

/* masters.php — bulk actions toolbar + row selection */
.bulk-form { margin: 0; }
.sel-count {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.row-check, .check-all, .group-check { accent-color: var(--primary); cursor: pointer; }

/* customers_import.php — column mapping dropdowns */
.map-choice { font-size: var(--fs-xs); padding: var(--sp-15) var(--sp-2); }

/* wa_send.php — customer picker cards (page supplies its own layout) */
.wa-cust-result, .wa-cust-card { font-size: var(--fs-sm); line-height: var(--lh-snug); }
.wa-cust-result { transition: background var(--t-fast) var(--ease); }
.wa-cust-selected { font-weight: var(--fw-semi); }

/* masters.php inline <style> owns .master-* layout; these only align
   its typography with the global scale (no --accent is declared here,
   so the per-section --accent custom property keeps working). */
.master-title { font-family: var(--font-display); font-weight: var(--fw-bold); letter-spacing: var(--ls-snug); }
.master-count { font-variant-numeric: tabular-nums; line-height: 1.6; }
.master-hint  { font-size: var(--fs-xs); line-height: var(--lh-normal); }

/* ============================================================
   Utility helpers (opt-in, nothing here changes existing markup)
   ============================================================ */
.text-tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.text-mono    { font-family: var(--font-mono); }
.text-balance { text-wrap: balance; }
.truncate     { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Skip-to-content style target for any future accessibility link */
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ============================================================
   Motion preferences — respects OS "reduce motion" setting.
   Content must never depend on an animation to become visible,
   so `both`-filled entrance animations are reset, not just paused.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .btn:hover, .stat:hover, .stage-board-card:hover,
  .icon-btn:hover, .stage-chip:hover, .topbar-back:hover {
    transform: none !important;
  }
  .timeline-actions { opacity: 1; }
}

/* ============================================================
   Print — typography hardening.
   Kept last so it wins over the screen rules above without
   touching any of the existing @media print declarations.
   ============================================================ */
@media print {
  body {
    font-family: var(--font-sans);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .table th, .table td {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
  }
  .table thead th { letter-spacing: .02em; }
  /* Headings should not float away from the rows they introduce */
  h1, h2, h3, .panel-head, .print-header { break-after: avoid-page; }

  /* The ≤768px block carries no media type, so it also matches print on narrow
     paper. Undo the mobile scroll-container here — a printed table must be a
     real table or repeating headers and page breaks stop working. */
  .table {
    display: table !important;
    overflow: visible !important;
    max-width: none !important;
  }
}
