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

:root {
  /* --- Alpine palette --- */
  --bg-top:      #e6f0fb;   /* high alpine sky */
  --bg-bot:      #f7fbff;   /* fresh snow */
  --card:        #ffffff;
  --card-soft:   #f4f9ff;
  --text:        #0b1e3f;   /* deep navy */
  --text-soft:   #1e3a5f;
  --muted:       #5d738f;

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

  --ice:           #e0f2fe;
  --frost:         #f0f8ff;
  --border:        #d6e4f5;
  --border-strong: #b8cce8;

  --error-bg:   #fee2e2; --error-text:   #b91c1c; --error:   #ef4444;
  --success-bg: #d1fae5; --success-text: #065f46; --success: #10b981;
  --warn-bg:    #fef3c7; --warn-text:    #92400e; --warn:    #f59e0b;
  --info-bg:    #dbeafe; --info-text:    #1e3a8a; --info:    #3b82f6;

  --shadow-sm: 0 1px 3px  rgba(30, 64, 175, 0.06);
  --shadow:    0 4px 14px rgba(30, 64, 175, 0.08);
  --shadow-lg: 0 12px 32px rgba(30, 64, 175, 0.12);
  --radius:    12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  color: var(--text);
  line-height: 1.55;
  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;
}

a { color: var(--primary); text-decoration: none; transition: color .15s; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.num   { text-align: right; font-variant-numeric: tabular-nums; }

/* ============================================================
   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: 20px;
}
.auth-card {
  width: 100%; max-width: 440px;
  background: linear-gradient(180deg, #ffffff 0%, var(--frost) 100%);
  padding: 40px 36px;
  border-radius: 16px;
  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: 10px;
  font-size: 26px; font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.auth-brand .emoji { font-size: 32px; display: inline-block; animation: float 3s ease-in-out infinite; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card form { margin-top: 22px; display: flex; flex-direction: column; gap: 16px; }
.auth-foot { margin-top: 18px; text-align: center; font-size: 12px; color: var(--muted); }

/* ============================================================
   Forms
   ============================================================ */
label { display: flex; flex-direction: column; font-size: 13px; font-weight: 600; gap: 6px; 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: inherit;
  padding: 10px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
  width: 100%;
  font-weight: 400;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-bright);
  box-shadow: 0 0 0 4px var(--primary-glow);
  background: #fff;
}
input::placeholder, textarea::placeholder { color: #94a3b8; }

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

.form-actions { margin-top: 20px; display: flex; gap: 10px; align-items: center; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer; text-decoration: none;
  line-height: 1.2;
  transition: background .18s, border-color .18s, color .18s, transform .12s, box-shadow .18s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-sm { padding: 6px 11px; font-size: 13px; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary-bright), var(--primary));
  color: #fff;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.30);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(59, 130, 246, 0.40); filter: brightness(1.05); }

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

.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: 10px 4px;
}
.btn-link:hover { text-decoration: underline; }

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  display: flex; align-items: center;
  padding: 10px 20px;
  background: linear-gradient(180deg, #ffffff 0%, var(--frost) 100%);
  border-bottom: 1px solid var(--border);
  gap: 14px;
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(6px);
}
.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: 2px; flex: 1; flex-wrap: wrap; }
.topbar-links a {
  color: var(--muted);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  display: inline-flex; align-items: center; gap: 5px;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.topbar-links a:hover { background: var(--ice); color: var(--primary); text-decoration: none; }
.topbar-links a.active {
  color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px rgba(59,130,246,0.15);
}

.topbar-user {
  display: flex; align-items: center; gap: 14px; font-size: 13px;
}

.container {
  max-width: 1200px; margin: 0 auto; padding: 28px;
  animation: fadeIn .4s ease-out;
}

/* ============================================================
   Page head
   ============================================================ */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 22px; gap: 16px;
}
.page-head h1 {
  margin: 0; font-size: 26px; font-weight: 700;
  letter-spacing: -0.01em;
  display: inline-flex; align-items: center; gap: 10px;
}
.page-head .actions { display: flex; gap: 8px; }

/* ============================================================
   Alerts
   ============================================================ */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px;
  margin-bottom: 14px; font-weight: 500;
  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(220px, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}
.stat {
  background: linear-gradient(180deg, #ffffff, var(--card-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
  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: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px;
}
.stat-value {
  font-size: 30px; font-weight: 700; margin-top: 6px;
  color: var(--text); letter-spacing: -0.02em;
}
.stat-foot  { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ============================================================
   Panels
   ============================================================ */
.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  animation: slideUp .4s ease-out both;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--frost), #fff);
}
.panel-head h2 {
  margin: 0; font-size: 15px; font-weight: 700; color: var(--text);
  display: inline-flex; align-items: center; gap: 8px;
}
.panel .empty { padding: 28px; text-align: center; color: var(--muted); }
.empty-success { color: var(--success-text); }

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

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; padding: 18px 20px; }
.kv dt { color: var(--muted); font-size: 13px; font-weight: 600; }
.kv dd { margin: 0; font-size: 14px; }

.notes-block { padding: 0 20px 18px; }
.notes-block p { margin: 6px 0 0; white-space: pre-wrap; }

/* ============================================================
   Tables
   ============================================================ */
.table { width: 100%; border-collapse: collapse; background: #fff; }
.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  border-top: 1px solid var(--border);
  font-size: 14px;
  vertical-align: top;
}
.table thead th {
  background: var(--frost); border-top: 0;
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700;
}
.table tbody tr {
  transition: background .15s;
  animation: fadeIn .3s ease-out both;
}
.table tbody tr:hover { background: var(--frost); }
.row-actions { text-align: right; white-space: nowrap; }

/* "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: 12px;
  line-height: 1.35;
  max-width: 280px;
  vertical-align: top;
}
.col-last-remark .last-remark-date {
  display: inline-block;
  font-weight: 700;
  color: var(--primary);
  background: var(--ice);
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 11px;
  white-space: nowrap;
  margin-right: 4px;
  font-family: ui-monospace, Consolas, monospace;
}
.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: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.page-tab {
  flex: 1 1 0;
  text-align: center;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.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: 700; font-size: 14px; color: var(--text); line-height: 1.3; }
.insight-detail { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.45; }
.insight-action {
  font-size: 12px; color: var(--primary); font-weight: 600;
  margin-top: 6px; padding: 4px 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: 10px; flex-wrap: wrap; align-items: center;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.filters input[type="search"] { flex: 1; min-width: 240px; }
.filters select { width: auto; min-width: 150px; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 700;
  padding: 3px 10px; border-radius: 999px;
  background: #eef4fb; color: #475569;
  line-height: 1.5;
  transition: transform .15s;
}
.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: #eef4fb;           color: #5d738f; }
.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: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 8px;
}
.stage-chip {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: #fff;
  border: 1px solid var(--border);
  margin-bottom: 6px;
  font-size: 13px; font-weight: 600;
  color: var(--text);
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.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: 24px; text-align: center;
  padding: 1px 8px; border-radius: 999px;
  background: var(--frost); color: var(--muted);
  font-weight: 700; font-size: 12px;
}
.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: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
}
.pipeline-total-value {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em;
  margin-top: 4px;
}
.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: 6px;
  margin-top: 14px;
  font-size: 12px;
}
.pipeline-legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  transition: all .12s;
  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: 14px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
  margin: 18px 0 12px;
}

.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: 8px;
  font-weight: 700; font-size: 15px; color: var(--text);
}
.stage-board-name .stage-emoji { font-size: 18px; }
.stage-board-count {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700; font-size: 13px;
  padding: 3px 12px;
  border-radius: 999px;
  min-width: 30px; text-align: center;
}

/* 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: 8px 16px;
  flex: 1;
}
.stage-customer-list li {
  padding: 8px 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: 13px;
}
.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: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--frost);
  text-align: right;
  font-size: 12px; font-weight: 600;
  color: var(--muted);
}
.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: 6px;
  padding: 5px 12px;
  background: var(--frost);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  color: var(--muted);
}
.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 4px;
  font-size: 11px;
  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: 3px 6px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
  margin: 1px 0;
  transition: background .12s;
  line-height: 1.3;
}
.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 14px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  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: 6px;
  background: var(--frost);
  border: 1.5px solid var(--border-strong);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.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: 4px;
  padding: 0 6px;
  font-family: inherit; font-size: 12px;
  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: 14px;
  box-shadow: 0 24px 64px rgba(11, 30, 63, 0.35);
  border: 1px solid var(--border);
  overflow: hidden;
  animation: slideUp .2s ease-out;
}
.search-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fff, var(--frost));
}
.search-icon { font-size: 18px; }
.search-bar input[type="search"] {
  border: none !important;
  padding: 4px 0 !important;
  font-size: 16px;
  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;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.search-result:last-child { border-bottom: 0; }
.search-result:hover,
.search-result.active {
  background: var(--ice);
}
.search-result-main strong { color: var(--text); }
.search-result-meta { display: flex; gap: 10px; align-items: center; }

.search-hint {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.search-foot {
  display: flex; gap: 18px;
  padding: 10px 18px;
  background: var(--frost);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.search-foot kbd {
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
  margin-right: 4px;
  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 */
  th.col-today-remark, td.col-today-remark {
    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: ui-monospace, Consolas, monospace;
  font-size: 13px; font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--ice);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: 6px;
  margin-right: 6px;
  border: 1px solid var(--border);
}
.customer-code-small {
  display: inline-block;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px; font-weight: 700;
  background: var(--frost);
  color: var(--text);
  padding: 1px 8px;
  border-radius: 5px;
  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: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.tag-chip-sm { font-size: 10px; padding: 1px 7px; }
.tag-chip:hover, .tag-chip-sm:hover {
  text-decoration: none;
  background: #e0f2fe;
}

/* ============================================================
   Inline stage select on lists
   ============================================================ */
select.inline-stage {
  font-size: 12px;
  padding: 4px 6px !important;
  border-radius: 6px;
  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: 4px;
  margin-top: 6px;
}
.btn-snooze {
  background: var(--frost);
  border: 1px solid var(--border-strong);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all .12s;
}
.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: 14px;
  box-shadow: 0 24px 64px rgba(11, 30, 63, 0.35);
  border: 1px solid var(--border);
  overflow: hidden;
  animation: slideUp .2s ease-out;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fff, var(--frost));
}
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-close {
  background: var(--frost);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.modal-close:hover { color: var(--error-text); border-color: var(--error); }
#quick-log-form { padding: 18px; }
.kbd-table { width: 100%; }
.kbd-table td { padding: 6px 8px; }
.kbd-table kbd {
  background: var(--frost);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 2px 8px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  color: var(--text);
  font-weight: 700;
  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: 999px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text);
  font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.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: 8px 4px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; text-align: center;
  color: var(--text); font-weight: 600;
}
.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); }
.activity-day-label { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.activity-day-num   { font-size: 16px; font-weight: 700; line-height: 1.1; }
.activity-day-count { font-size: 11px; 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: 9px 12px;
  border-radius: 8px;
  color: var(--text);
}
.wa-tpl-item:hover { background: var(--frost); text-decoration: none; }
.wa-tpl-item strong { display: block; margin-bottom: 2px; }
.wa-tpl-manage { border-top: 1px solid var(--border); margin-top: 4px; }

/* ============================================================
   Timeline
   ============================================================ */
.timeline { list-style: none; margin: 0; padding: 10px 20px 18px; }
.timeline li {
  padding: 14px 0 14px 26px;
  border-bottom: 1px dashed var(--border);
  position: relative;
  animation: slideInLeft .4s ease-out both;
}
.timeline li::before {
  content: "🔵";
  position: absolute; left: 0; top: 14px;
  font-size: 10px;
}
.timeline li:last-child { border-bottom: 0; }
.timeline-head { margin-bottom: 4px; }
.timeline-meta { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.timeline p { margin: 4px 0; white-space: pre-wrap; }
.timeline-row { display: flex; gap: 12px; 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: 12px;
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.timeline-outcome { font-size: 14px; 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: 8px 12px;
  border-radius: 6px;
  margin-top: 6px;
}
.timeline-note p { margin: 4px 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;
  padding: 14px 20px;
  background: linear-gradient(180deg, var(--frost), #fff);
  border-bottom: 1px solid var(--border);
}
.collapsible-section > summary::-webkit-details-marker { display: none; }
.collapsible-section > summary h2 {
  margin: 0; font-size: 15px; font-weight: 700; color: var(--text);
  display: inline-flex; align-items: center; gap: 8px;
}
.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: 32px; text-align: center; color: var(--muted);
  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: 8px; }

/* 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: 10px;
  color: var(--muted);
  background: var(--ice);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* ============================================================
   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-size: 19px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 18px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.hero-stats-row {
  display: flex; flex-wrap: wrap; gap: 28px;
  margin-bottom: 14px;
}
.hero-stat-value {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}
.hero-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
  opacity: 0.85;
  margin-top: 4px;
}
.hero-compare {
  display: inline-block;
  background: rgba(255,255,255,0.20);
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(4px);
}

/* Achievements section */
.achievements-section { margin-bottom: 22px; }
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 14px 0 10px;
}
.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: 13px;
  font-weight: 700;
  color: #78350f;
  line-height: 1.2;
}
.achievement-sub {
  font-size: 11px;
  color: #92400e;
  opacity: 0.85;
  margin-top: 2px;
  line-height: 1.3;
}

/* Stat unit (e.g. "days") */
.stat-unit { font-size: 14px; font-weight: 500; 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: 10px; align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
  position: relative;
  padding-left: 28px;
  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: 11px;
  font-weight: 700;
  min-width: 70px;
  flex-shrink: 0;
}
.journey-outcome {
  font-weight: 600;
  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: 15px; }
  .container { padding: 14px; }

  /* ---- 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: 12px 14px;
    font-size: 15px;
    border-radius: 8px;
    width: 100%;
  }

  .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: 19px; }
  .page-head .actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  .page-head .actions .btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    font-size: 13px;
    padding: 9px 10px;
  }

  /* ---- Tables: horizontal scroll inside panel ---- */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table th, .table td {
    padding: 9px 10px;
    font-size: 13px;
  }
  .table thead th { font-size: 11px; }
  /* 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: 12px 14px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 10px; }

  /* ---- 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: 16px;
    padding: 11px 12px;
  }
  .form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .form-actions .btn { width: 100%; justify-content: center; padding: 12px 14px; }

  /* ---- Buttons ---- */
  .btn { min-height: 38px; }
  .btn-sm { min-height: 32px; padding: 6px 10px; }

  /* ---- KV details: stack label above value ---- */
  .kv {
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 14px;
  }
  .kv dt {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-top: 8px;
  }
  .kv dd { font-size: 14px; margin-bottom: 4px; }

  /* ---- 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: 12px 14px; }
  .panel-head h2 { font-size: 14px; }

  /* ---- 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: 14px; }
  .container { padding: 10px; }
  .stats { grid-template-columns: 1fr; }
  .topbar { padding: 8px 10px; gap: 6px; }
  .topbar-brand a { width: 34px; height: 34px; }
  .topbar-brand .emoji { font-size: 18px; }
  .hamburger-btn { width: 36px; height: 36px; }
  .page-head h1 { font-size: 17px; }
  .page-head .actions { gap: 4px; }
  .table th, .table td { padding: 8px; font-size: 12.5px; }
  .stat-value { font-size: 20px; }
  .pipeline-total-value { font-size: 18px; }
  .activity-strip { grid-template-columns: repeat(14, 52px); }
}

/* ============================================================
   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: 700; }
.customer-cell .customer-contact {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.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; }

  /* 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: 11px;
    color: var(--primary);
    font-family: ui-monospace, Consolas, monospace;
    font-weight: 600;
    margin-top: 2px;
    background: var(--frost);
    padding: 1px 7px;
    border-radius: 5px;
    border: 1px solid var(--border);
  }

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