/* ============================================================
   PropFlow CRM — Custom Styles (v2 — Responsive + PWA)
   Free to use, modify, and distribute. No license restrictions.
   Bootstrap 5.3 (MIT) | Bootstrap Icons (MIT) | Fontsource (OFL)
   ============================================================ */

/* ── Local Fonts ── */
@font-face{font-family:'Outfit';font-style:normal;font-weight:300;font-display:swap;src:url('/fonts/outfit-latin-300-normal.woff2') format('woff2');}
@font-face{font-family:'Outfit';font-style:normal;font-weight:400;font-display:swap;src:url('/fonts/outfit-latin-400-normal.woff2') format('woff2');}
@font-face{font-family:'Outfit';font-style:normal;font-weight:500;font-display:swap;src:url('/fonts/outfit-latin-500-normal.woff2') format('woff2');}
@font-face{font-family:'Outfit';font-style:normal;font-weight:600;font-display:swap;src:url('/fonts/outfit-latin-600-normal.woff2') format('woff2');}
@font-face{font-family:'Outfit';font-style:normal;font-weight:700;font-display:swap;src:url('/fonts/outfit-latin-700-normal.woff2') format('woff2');}
@font-face{font-family:'JetBrains Mono';font-style:normal;font-weight:400;font-display:swap;src:url('/fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2');}
@font-face{font-family:'JetBrains Mono';font-style:normal;font-weight:500;font-display:swap;src:url('/fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2');}

/* ── Theme Variables ── */
[data-theme="dark"]{
  --bg-base:#0e1117;--bg-surface:#151820;--bg-card:#1a1e2a;
  --bg-hover:#1f2435;--bg-input:#12151e;
  --border:#252b3b;--border-light:#2e3550;
  --text-primary:#e8eaf0;--text-secondary:#8892a4;--text-muted:#4e5a6e;
  --shadow:0 2px 12px rgba(0,0,0,.4);--shadow-card:0 4px 24px rgba(0,0,0,.35);
  --overlay:rgba(10,12,18,.7);
}
[data-theme="light"]{
  --bg-base:#f0f2f7;--bg-surface:#ffffff;--bg-card:#ffffff;
  --bg-hover:#f5f7fc;--bg-input:#f8f9fc;
  --border:#e2e6f0;--border-light:#d0d6e8;
  --text-primary:#1a2035;--text-secondary:#4a5568;--text-muted:#9aa3b5;
  --shadow:0 2px 8px rgba(0,0,0,.07);--shadow-card:0 4px 20px rgba(0,0,0,.08);
  --overlay:rgba(240,242,247,.7);
}
:root{
  --accent:#2d7dd2;--accent-light:#4a9ee8;
  --gold:#c9973a;--gold-light:#e0b05a;
  --success:#28a970;--warning:#e5a225;--danger:#d94f4f;--info:#3892c8;
  --hot:#d94f4f;--warm:#e5a225;--cold:#3892c8;
  --sidebar-w:240px;--topbar-h:58px;--transition:0.18s ease;
  /* PWA safe-area insets */
  --safe-top:env(safe-area-inset-top,0px);
  --safe-bottom:env(safe-area-inset-bottom,0px);
  --safe-left:env(safe-area-inset-left,0px);
  --safe-right:env(safe-area-inset-right,0px);
}

/* ── Base ── */
*,*::before,*::after{box-sizing:border-box;}
html,body{height:100%;}
body{
  font-family:'Outfit',sans-serif;
  background:var(--bg-base);color:var(--text-primary);
  font-size:14px;line-height:1.5;overflow-x:hidden;
  transition:background var(--transition),color var(--transition);
  /* PWA: prevent text resize on orientation change */
  -webkit-text-size-adjust:100%;text-size-adjust:100%;
  /* PWA: prevent callouts and selection highlight */
  -webkit-tap-highlight-color:transparent;
}
::-webkit-scrollbar{width:5px;height:5px;}
::-webkit-scrollbar-track{background:transparent;}
::-webkit-scrollbar-thumb{background:var(--border-light);border-radius:3px;}
a{color:var(--accent-light);text-decoration:none;}
code,.mono{font-family:'JetBrains Mono',monospace;font-size:12px;}
img,svg{max-width:100%;}

/* ── TOPBAR ── */
#topbar{
  position:fixed;top:0;left:0;right:0;
  height:calc(var(--topbar-h) + var(--safe-top));
  padding-top:var(--safe-top);
  background:var(--bg-surface);border-bottom:1px solid var(--border);
  display:flex;align-items:center;
  padding-right:max(20px, var(--safe-right));
  z-index:1000;box-shadow:var(--shadow);
  transition:background var(--transition),border-color var(--transition);
}
.topbar-brand{
  width:var(--sidebar-w);display:flex;align-items:center;gap:10px;
  padding:0 20px;flex-shrink:0;
  border-right:1px solid var(--border);height:100%;
}
.brand-logo{
  width:32px;height:32px;border-radius:8px;
  background:linear-gradient(135deg,var(--accent) 0%,var(--gold) 100%);
  display:flex;align-items:center;justify-content:center;
  font-size:15px;font-weight:700;color:#fff;flex-shrink:0;
}
.brand-name{font-size:15px;font-weight:700;color:var(--text-primary);letter-spacing:-.3px;}
.brand-sub{font-size:10px;color:var(--text-muted);letter-spacing:.5px;margin-top:-2px;}
/* hamburger — mobile only */
#sidebar-toggle{
  display:none;width:38px;height:38px;border-radius:8px;
  background:none;border:1px solid var(--border);
  align-items:center;justify-content:center;
  color:var(--text-secondary);cursor:pointer;
  transition:all var(--transition);margin-left:12px;flex-shrink:0;
}
#sidebar-toggle:hover{background:var(--bg-hover);color:var(--text-primary);}
.topbar-center{flex:1;display:flex;align-items:center;padding:0 16px;gap:12px;min-width:0;}
.topbar-search{
  display:flex;align-items:center;gap:8px;
  background:var(--bg-input);border:1px solid var(--border);
  border-radius:8px;padding:7px 14px;flex:1;max-width:360px;
  transition:border-color var(--transition);
}
.topbar-search:focus-within{border-color:var(--accent);}
.topbar-search input{background:none;border:none;outline:none;color:var(--text-primary);font-size:13px;font-family:inherit;width:100%;min-width:0;}
.topbar-search input::placeholder{color:var(--text-muted);}
.topbar-search .search-kbd{font-size:10px;color:var(--text-muted);background:var(--border);padding:1px 6px;border-radius:4px;flex-shrink:0;}
.topbar-right{display:flex;align-items:center;gap:6px;margin-left:auto;flex-shrink:0;}
.topbar-btn{
  width:36px;height:36px;border-radius:8px;background:none;border:1px solid var(--border);
  display:flex;align-items:center;justify-content:center;
  color:var(--text-secondary);cursor:pointer;transition:all var(--transition);position:relative;
}
.topbar-btn:hover{background:var(--bg-hover);color:var(--text-primary);border-color:var(--border-light);}
.notif-badge{position:absolute;top:4px;right:4px;width:7px;height:7px;border-radius:50%;background:var(--danger);border:1.5px solid var(--bg-surface);}
.theme-toggle{
  width:36px;height:36px;border-radius:8px;background:var(--bg-input);
  border:1px solid var(--border);display:flex;align-items:center;justify-content:center;
  color:var(--text-secondary);cursor:pointer;font-size:16px;transition:all var(--transition);
}
.theme-toggle:hover{background:var(--bg-hover);color:var(--text-primary);}
.user-avatar{
  width:34px;height:34px;border-radius:8px;
  background:linear-gradient(135deg,var(--accent),var(--gold));
  display:flex;align-items:center;justify-content:center;
  font-size:12px;font-weight:700;color:#fff;cursor:pointer;flex-shrink:0;
  border:2px solid var(--border);
}

/* ── SIDEBAR OVERLAY (mobile) ── */
#sidebar-overlay{
  display:none;position:fixed;inset:0;background:var(--overlay);
  z-index:1010;backdrop-filter:blur(2px);-webkit-backdrop-filter:blur(2px);
  opacity:0;transition:opacity .25s ease;
}
#sidebar-overlay.active{display:block;opacity:1;}

/* ── SIDEBAR ── */
#sidebar{
  position:fixed;
  top:calc(var(--topbar-h) + var(--safe-top));
  left:0;bottom:0;
  width:var(--sidebar-w);
  background:var(--bg-surface);border-right:1px solid var(--border);
  overflow-y:auto;overflow-x:hidden;
  z-index:1020;
  transition:background var(--transition),border-color var(--transition),transform .25s ease;
  display:flex;flex-direction:column;
  /* PWA bottom safe area */
  padding-bottom:var(--safe-bottom);
}
.sidebar-section-label{
  font-size:10px;font-weight:600;letter-spacing:1.2px;
  text-transform:uppercase;color:var(--text-muted);
  padding:18px 20px 6px;
}
.nav-item{
  display:flex;align-items:center;gap:11px;
  padding:9px 20px;cursor:pointer;
  color:var(--text-secondary);font-size:13.5px;font-weight:500;
  border-left:3px solid transparent;
  transition:all var(--transition);position:relative;
  white-space:nowrap;text-decoration:none;
  /* PWA: minimum touch target */
  min-height:44px;
}
.nav-item:hover{background:var(--bg-hover);color:var(--text-primary);}
.nav-item.active{color:var(--accent-light);background:var(--bg-hover);border-left-color:var(--accent);}
.nav-item .nav-icon{font-size:16px;width:20px;text-align:center;flex-shrink:0;}
.nav-item .nav-badge{margin-left:auto;font-size:10px;font-weight:600;padding:1px 6px;border-radius:10px;background:var(--danger);color:#fff;}
.nav-item .nav-count{margin-left:auto;font-size:11px;color:var(--text-muted);}
.sidebar-divider{border-top:1px solid var(--border);margin:8px 0;}

/* ── EXPANDABLE NAV GROUP ── */
.nav-group{}

/* Parent row — same look as .nav-item but never navigates */
.nav-group-header{
  display:flex;align-items:center;gap:11px;
  padding:9px 20px;cursor:pointer;
  color:var(--text-secondary);font-size:13.5px;font-weight:500;
  border-left:3px solid transparent;
  transition:all var(--transition);
  white-space:nowrap;user-select:none;
  min-height:44px;
}
.nav-group-header:hover{background:var(--bg-hover);color:var(--text-primary);}
/* parent row highlighted when any child is active */
.nav-group.has-active .nav-group-header{
  color:var(--accent-light);
  background:var(--bg-hover);
  border-left-color:var(--accent);
}
.nav-group-header .nav-icon{font-size:16px;width:20px;text-align:center;flex-shrink:0;}
.nav-group-header .nav-group-label{flex:1;min-width:0;}
/* chevron arrow */
.nav-group-chevron{
  font-size:12px;color:var(--text-muted);
  transition:transform .22s ease;
  flex-shrink:0;margin-left:auto;
}
.nav-group.open .nav-group-chevron{transform:rotate(180deg);}

/* Submenu container — collapses with max-height animation */
.nav-sub{
  max-height:0;overflow:hidden;
  transition:max-height .28s ease;
  background:var(--bg-base); /* slightly different shade to visually nest */
}
.nav-group.open .nav-sub{max-height:400px;}/* tall enough for many items */

/* Sub-item rows */
.nav-sub-item{
  display:flex;align-items:center;gap:9px;
  padding:8px 20px 8px 48px; /* 48px left-indent: icon space (20) + gap (8) + extra (20) */
  color:var(--text-muted);font-size:13px;font-weight:400;
  text-decoration:none;cursor:pointer;
  border-left:3px solid transparent;
  transition:all var(--transition);
  white-space:nowrap;min-height:40px;
  position:relative;
}
/* vertical connector line on the left of sub-items */
.nav-sub-item::before{
  content:'';position:absolute;
  left:31px;top:0;bottom:0;width:1px;
  background:var(--border);
}
.nav-sub-item:last-child::before{height:50%;} /* cut line at last item */
/* dot connector */
.nav-sub-item::after{
  content:'';position:absolute;
  left:28px;top:50%;transform:translateY(-50%);
  width:6px;height:6px;border-radius:50%;
  background:var(--border);
  transition:background var(--transition);
}
.nav-sub-item:hover{background:var(--bg-hover);color:var(--text-secondary);}
.nav-sub-item:hover::after{background:var(--border-light);}
/* active sub-item */
.nav-sub-item.active{
  color:var(--accent-light);
  background:color-mix(in srgb, var(--accent) 8%, transparent);
  border-left-color:var(--accent);
  font-weight:500;
}
.nav-sub-item.active::after{background:var(--accent-light);}
.nav-sub-item .sub-icon{font-size:13px;flex-shrink:0;}
.nav-sub-item .nav-badge{margin-left:auto;font-size:10px;font-weight:600;padding:1px 6px;border-radius:10px;background:var(--danger);color:#fff;}

/* ── Fallback for browsers without color-mix ── */
@supports not (color:color-mix(in srgb,red,blue)){
  .nav-sub-item.active{background:rgba(45,125,210,.08);}
}

.sidebar-footer{
  margin-top:auto;padding:14px 20px;border-top:1px solid var(--border);
}
.agent-card-mini{
  display:flex;align-items:center;gap:10px;padding:10px 12px;
  border-radius:10px;background:var(--bg-hover);cursor:pointer;
  transition:background var(--transition);
}
.agent-card-mini:hover{background:var(--bg-card);}
.agent-mini-name{font-size:13px;font-weight:600;color:var(--text-primary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.agent-mini-role{font-size:11px;color:var(--text-muted);}
.online-dot{width:8px;height:8px;border-radius:50%;background:var(--success);flex-shrink:0;}

/* ── MAIN CONTENT (sidebar layout uses #main-content, topnav uses #tn-main) ── */
#main-content{
  margin-left:var(--sidebar-w);
  margin-top:calc(var(--topbar-h) + var(--safe-top));
  min-height:calc(100vh - var(--topbar-h) - var(--safe-top));
  padding:24px;
  padding-bottom:calc(24px + var(--safe-bottom));
  transition:background var(--transition);
}
/* #tn-main is defined in propflow-topnav.css — shared component styles apply to both via .pf-page */

/* ── PAGE ANIMATION ── */
.pf-page{animation:fadeUp .22s ease;}
@keyframes fadeUp{from{opacity:0;transform:translateY(8px);}to{opacity:1;transform:translateY(0);}}

/* ── CARDS ── */
.card-surface{
  background:var(--bg-card);border:1px solid var(--border);
  border-radius:12px;box-shadow:var(--shadow-card);
  transition:background var(--transition),border-color var(--transition);
}
.card-surface:hover{border-color:var(--border-light);}

/* ── STAT CARDS ── */
.stat-card{
  background:var(--bg-card);border:1px solid var(--border);
  border-radius:12px;padding:20px;
  transition:all var(--transition);position:relative;overflow:hidden;
}
.stat-card::before{content:'';position:absolute;top:0;left:0;right:0;height:3px;}
.stat-card.accent::before{background:var(--accent);}
.stat-card.gold::before{background:var(--gold);}
.stat-card.success::before{background:var(--success);}
.stat-card.warning::before{background:var(--warning);}
.stat-card.danger::before{background:var(--danger);}
.stat-card:hover{transform:translateY(-2px);box-shadow:var(--shadow-card);border-color:var(--border-light);}
.stat-label{font-size:11px;font-weight:600;letter-spacing:.8px;text-transform:uppercase;color:var(--text-muted);margin-bottom:8px;}
.stat-value{font-size:28px;font-weight:700;color:var(--text-primary);line-height:1;letter-spacing:-1px;}
.stat-sub{font-size:12px;color:var(--text-muted);margin-top:6px;display:flex;align-items:center;gap:4px;}
.stat-change.up{color:var(--success);}
.stat-change.down{color:var(--danger);}
.stat-icon{position:absolute;right:18px;top:18px;font-size:28px;opacity:.07;color:var(--text-primary);}

/* ── RESPONSIVE TABLE WRAPPER ──
   Wrap every crm-table in .table-responsive-crm for mobile */
.table-responsive-crm{
  width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;
  border-radius:12px;
}
/* On mobile, card-surface that wraps a table gets no border-radius clipping issue */
.card-surface .table-responsive-crm{border-radius:0;}

.crm-table{width:100%;border-collapse:separate;border-spacing:0;min-width:200px;}
.crm-table thead th{
  padding:10px 14px;font-size:11px;font-weight:600;
  letter-spacing:.8px;text-transform:uppercase;color:var(--text-muted);
  background:var(--bg-hover);border-bottom:1px solid var(--border);white-space:nowrap;
}
.crm-table thead th:first-child{border-radius:8px 0 0 0;}
.crm-table thead th:last-child{border-radius:0 8px 0 0;}
.crm-table tbody tr{transition:background var(--transition);cursor:pointer;}
.crm-table tbody tr:hover td{background:var(--bg-hover);}
.crm-table tbody td{
  padding:11px 14px;border-bottom:1px solid var(--border);
  color:var(--text-secondary);font-size:13px;vertical-align:middle;
}
.crm-table tbody tr:last-child td{border-bottom:none;}
.cell-primary{color:var(--text-primary)!important;font-weight:500;}

/* ── MOBILE CARD LIST (replaces table rows on very small screens) ── */
.mobile-lead-card{
  background:var(--bg-card);border:1px solid var(--border);
  border-radius:10px;padding:14px;margin-bottom:10px;
  display:none;/* shown via media query */
  flex-direction:column;gap:8px;cursor:pointer;
  transition:all var(--transition);
}
.mobile-lead-card:hover{border-color:var(--border-light);box-shadow:var(--shadow);}
.mlc-top{display:flex;justify-content:space-between;align-items:flex-start;}
.mlc-name{font-size:14px;font-weight:600;color:var(--text-primary);}
.mlc-phone{font-size:11px;color:var(--text-muted);font-family:'JetBrains Mono',monospace;}
.mlc-row{display:flex;justify-content:space-between;align-items:center;font-size:12px;color:var(--text-secondary);}

/* ── BADGES ── */
.badge-custom{display:inline-flex;align-items:center;gap:4px;padding:3px 9px;border-radius:6px;font-size:11px;font-weight:600;}
.badge-hot{background:rgba(217,79,79,.15);color:var(--hot);}
.badge-warm{background:rgba(229,162,37,.15);color:var(--warm);}
.badge-cold{background:rgba(56,146,200,.15);color:var(--cold);}
.badge-new{background:rgba(45,125,210,.15);color:var(--accent-light);}
.badge-qualified{background:rgba(40,169,112,.15);color:var(--success);}
.badge-viewing{background:rgba(201,151,58,.15);color:var(--gold-light);}
.badge-reserved{background:rgba(229,162,37,.15);color:var(--warning);}
.badge-closed{background:rgba(40,169,112,.15);color:var(--success);}
.badge-lost{background:rgba(78,90,110,.15);color:var(--text-muted);}
.badge-offplan{background:rgba(201,151,58,.15);color:var(--gold-light);}
.badge-ready{background:rgba(56,146,200,.15);color:var(--cold);}
.badge-secondary{background:rgba(78,90,110,.15);color:var(--text-muted);}
.badge-success{background:rgba(40,169,112,.15);color:var(--success);}
.badge-danger{background:rgba(217,79,79,.15);color:var(--danger);}
.badge-warning{background:rgba(229,162,37,.15);color:var(--warning);}
.badge-info{background:rgba(56,146,200,.15);color:var(--info);}

/* ── STAGE FLOW ── */
.stage-flow{display:flex;align-items:center;gap:0;overflow-x:auto;padding-bottom:4px;-webkit-overflow-scrolling:touch;}
.stage-pill{
  display:flex;align-items:center;gap:6px;padding:6px 14px;
  font-size:12px;font-weight:500;background:var(--bg-hover);
  border:1px solid var(--border);color:var(--text-secondary);
  cursor:pointer;transition:all var(--transition);white-space:nowrap;flex-shrink:0;
  min-height:36px;/* PWA touch target */
}
.stage-pill:first-child{border-radius:8px 0 0 8px;}
.stage-pill:last-child{border-radius:0 8px 8px 0;}
.stage-pill+.stage-pill{border-left:none;}
.stage-pill.active{background:var(--accent);border-color:var(--accent);color:#fff;}
.stage-pill:hover:not(.active){background:var(--bg-card);color:var(--text-primary);}
.stage-pill .s-count{background:rgba(255,255,255,.2);border-radius:10px;padding:0 6px;font-size:10px;}
.stage-pill:not(.active) .s-count{background:var(--border);color:var(--text-muted);}

/* ── KANBAN ── */
.kanban-board{display:flex;gap:16px;overflow-x:auto;padding-bottom:8px;align-items:flex-start;-webkit-overflow-scrolling:touch;}
.kanban-col{min-width:260px;max-width:260px;background:var(--bg-hover);border:1px solid var(--border);border-radius:12px;padding:12px;flex-shrink:0;}
.kanban-col-header{display:flex;justify-content:space-between;align-items:center;padding:4px 4px 10px;border-bottom:1px solid var(--border);margin-bottom:10px;}
.kanban-col-title{font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:.6px;color:var(--text-muted);}
.kanban-col-meta{font-size:11px;color:var(--text-muted);}
.kanban-card{background:var(--bg-card);border:1px solid var(--border);border-radius:10px;padding:12px;margin-bottom:8px;cursor:pointer;transition:all var(--transition);border-left:3px solid transparent;}
.kanban-card:hover{border-color:var(--border-light);transform:translateY(-1px);box-shadow:var(--shadow);}
.kanban-card.hot{border-left-color:var(--hot);}
.kanban-card.warm{border-left-color:var(--warm);}
.kanban-card.cold{border-left-color:var(--cold);}
.kc-name{font-size:13px;font-weight:600;color:var(--text-primary);margin-bottom:4px;}
.kc-prop{font-size:11px;color:var(--text-muted);margin-bottom:8px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.kc-footer{display:flex;justify-content:space-between;align-items:center;}
.kc-val{font-size:12px;font-weight:600;color:var(--gold-light);font-family:'JetBrains Mono',monospace;}
.kc-days{font-size:10px;color:var(--text-muted);}
.kc-agent{width:22px;height:22px;border-radius:6px;background:var(--accent);display:flex;align-items:center;justify-content:center;font-size:9px;font-weight:700;color:#fff;}

/* ── TIMELINE ── */
.timeline-item{display:flex;gap:14px;position:relative;padding-bottom:18px;}
.timeline-item::before{content:'';position:absolute;left:15px;top:30px;bottom:0;width:1px;background:var(--border);}
.timeline-item:last-child::before{display:none;}
.timeline-icon{width:30px;height:30px;border-radius:8px;flex-shrink:0;display:flex;align-items:center;justify-content:center;font-size:13px;border:1px solid var(--border);}
.tl-call{background:rgba(45,125,210,.15);color:var(--accent-light);}
.tl-whatsapp{background:rgba(40,169,112,.15);color:var(--success);}
.tl-email{background:rgba(201,151,58,.15);color:var(--gold-light);}
.tl-visit{background:rgba(229,162,37,.15);color:var(--warning);}
.tl-note{background:rgba(78,90,110,.15);color:var(--text-muted);}
.timeline-body{flex:1;min-width:0;}
.tl-title{font-size:13px;font-weight:500;color:var(--text-primary);}
.tl-meta{font-size:11px;color:var(--text-muted);margin-top:2px;}
.tl-note-text{font-size:12px;color:var(--text-secondary);margin-top:4px;background:var(--bg-hover);border-radius:6px;padding:6px 10px;}

/* ── BANT ── */
.bant-bar{height:6px;border-radius:3px;background:var(--border);overflow:hidden;}
.bant-fill{height:100%;border-radius:3px;transition:width .6s ease;}
.score-high{background:linear-gradient(90deg,var(--success),#5ddba0);}
.score-mid{background:linear-gradient(90deg,var(--warning),#f5c84a);}
.score-low{background:linear-gradient(90deg,var(--danger),#f07070);}

/* ── FUNNEL ── */
.funnel-row{display:flex;align-items:center;gap:12px;margin-bottom:12px;}
.funnel-label{font-size:12px;color:var(--text-secondary);width:120px;flex-shrink:0;}
.funnel-track{flex:1;height:8px;background:var(--border);border-radius:4px;overflow:hidden;}
.funnel-fill{height:100%;border-radius:4px;}
.funnel-count{font-size:12px;color:var(--text-muted);font-family:'JetBrains Mono',monospace;width:40px;text-align:right;flex-shrink:0;}
.funnel-pct{font-size:11px;color:var(--text-muted);width:36px;text-align:right;flex-shrink:0;}

/* ── FORM CONTROLS ── */
.form-control-crm,.form-select-crm{
  background:var(--bg-input);border:1px solid var(--border);
  color:var(--text-primary);border-radius:8px;
  padding:10px 14px;font-size:14px;font-family:'Outfit',sans-serif;
  width:100%;outline:none;transition:border-color var(--transition),box-shadow var(--transition);
  -webkit-appearance:none;appearance:none;
  /* PWA: minimum touch target height */
  min-height:44px;
}
.form-control-crm:focus,.form-select-crm:focus{
  border-color:var(--accent);
  box-shadow:0 0 0 3px rgba(45,125,210,.15);
}
.form-control-crm::placeholder{color:var(--text-muted);}
.form-label-crm{font-size:11px;font-weight:600;letter-spacing:.6px;text-transform:uppercase;color:var(--text-muted);margin-bottom:6px;display:block;}
/* Textarea */
textarea.form-control-crm{min-height:90px;resize:vertical;}
/* Checkbox + Radio */
.pf-check{display:flex;align-items:flex-start;gap:10px;cursor:pointer;min-height:44px;padding:8px 0;}
.pf-check input[type="checkbox"],.pf-check input[type="radio"]{
  width:18px;height:18px;flex-shrink:0;margin-top:1px;
  accent-color:var(--accent);cursor:pointer;
}
.pf-check-label{font-size:13px;color:var(--text-secondary);line-height:1.4;}
.pf-check-label small{display:block;font-size:11px;color:var(--text-muted);margin-top:2px;}
/* Select arrow */
.form-select-crm{
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%234e5a6e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat:no-repeat;background-position:right 12px center;
  padding-right:36px;
}
/* Form group spacing */
.form-group-crm{margin-bottom:18px;}
/* Input with icon */
.input-icon-wrap{position:relative;}
.input-icon-wrap .form-control-crm{padding-left:38px;}
.input-icon-wrap .input-icon{position:absolute;left:12px;top:50%;transform:translateY(-50%);color:var(--text-muted);font-size:15px;pointer-events:none;}
/* Toggle switch */
.pf-toggle{display:flex;align-items:center;gap:10px;cursor:pointer;min-height:44px;}
.pf-toggle input{display:none;}
.pf-toggle-track{
  width:42px;height:24px;border-radius:12px;background:var(--border);
  position:relative;transition:background .2s;flex-shrink:0;
}
.pf-toggle input:checked+.pf-toggle-track{background:var(--accent);}
.pf-toggle-thumb{
  width:18px;height:18px;border-radius:50%;background:#fff;
  position:absolute;top:3px;left:3px;transition:transform .2s;
  box-shadow:0 1px 4px rgba(0,0,0,.3);
}
.pf-toggle input:checked~.pf-toggle-track .pf-toggle-thumb{transform:translateX(18px);}
/* actually nested */
.pf-toggle .pf-toggle-track .pf-toggle-thumb{transform:translateX(0);}
.pf-toggle input:checked+.pf-toggle-track .pf-toggle-thumb{transform:translateX(18px);}
/* Form section card */
.form-section{background:var(--bg-card);border:1px solid var(--border);border-radius:12px;padding:24px;margin-bottom:20px;}
.form-section-title{font-size:13px;font-weight:700;text-transform:uppercase;letter-spacing:.6px;color:var(--text-primary);margin-bottom:18px;padding-bottom:12px;border-bottom:1px solid var(--border);}

/* ── BUTTONS ── */
.btn-crm{
  display:inline-flex;align-items:center;gap:6px;
  padding:10px 18px;border-radius:8px;font-size:13px;font-weight:600;
  border:none;cursor:pointer;transition:all var(--transition);
  font-family:'Outfit',sans-serif;white-space:nowrap;
  /* PWA: minimum touch target */
  min-height:44px;
}
.btn-crm-primary{background:var(--accent);color:#fff;}
.btn-crm-primary:hover{background:var(--accent-light);transform:translateY(-1px);}
.btn-crm-outline{background:transparent;border:1px solid var(--border);color:var(--text-secondary);}
.btn-crm-outline:hover{background:var(--bg-hover);color:var(--text-primary);border-color:var(--border-light);}
.btn-crm-ghost{background:transparent;border:none;color:var(--text-muted);padding:6px 10px;}
.btn-crm-ghost:hover{color:var(--text-primary);background:var(--bg-hover);border-radius:6px;}
.btn-crm-gold{background:var(--gold);color:#fff;}
.btn-crm-gold:hover{background:var(--gold-light);}
.btn-crm-success{background:var(--success);color:#fff;}
.btn-crm-success:hover{filter:brightness(1.1);}
.btn-crm-danger{background:var(--danger);color:#fff;}
.btn-crm-danger:hover{filter:brightness(1.1);}
.btn-crm-sm{padding:6px 12px;font-size:12px;min-height:36px;}
.btn-crm-icon{width:36px;height:36px;padding:0;justify-content:center;border-radius:8px;min-height:36px;}
.btn-crm-lg{padding:12px 24px;font-size:15px;min-height:50px;}
.btn-crm-full{width:100%;justify-content:center;}

/* ── PAGE HEADER ── */
.page-header{display:flex;align-items:flex-start;justify-content:space-between;margin-bottom:22px;flex-wrap:wrap;gap:12px;}
.page-title{font-size:20px;font-weight:700;color:var(--text-primary);letter-spacing:-.4px;margin:0;}
.page-subtitle{font-size:13px;color:var(--text-muted);margin-top:2px;}

/* ── DOC CHECKLIST ── */
.doc-row{display:flex;align-items:center;gap:10px;padding:8px 0;border-bottom:1px solid var(--border);}
.doc-row:last-child{border-bottom:none;}
.doc-check{width:18px;height:18px;border-radius:4px;display:flex;align-items:center;justify-content:center;font-size:10px;flex-shrink:0;}
.doc-check.done{background:rgba(40,169,112,.2);color:var(--success);}
.doc-check.pend{background:rgba(229,162,37,.2);color:var(--warning);}
.doc-check.miss{background:rgba(217,79,79,.2);color:var(--danger);}
.doc-name{font-size:12px;color:var(--text-secondary);flex:1;}
.doc-date{font-size:11px;color:var(--text-muted);}

/* ── PAYMENT MILESTONES ── */
.milestone-row{display:flex;align-items:center;gap:10px;padding:9px 0;border-bottom:1px solid var(--border);}
.milestone-row:last-child{border-bottom:none;}
.ms-dot{width:10px;height:10px;border-radius:50%;flex-shrink:0;}
.ms-dot.paid{background:var(--success);}
.ms-dot.upcoming{background:transparent;border:2px solid var(--warning);}
.ms-dot.due{background:var(--danger);}
.ms-label{font-size:12px;color:var(--text-secondary);flex:1;}
.ms-amount{font-size:12px;font-weight:600;color:var(--text-primary);font-family:'JetBrains Mono',monospace;}
.ms-pct{font-size:11px;color:var(--text-muted);width:32px;text-align:right;}

/* ── UTILITIES ── */
.divider{border-top:1px solid var(--border);margin:16px 0;}
.text-gold{color:var(--gold-light);}
.text-accent{color:var(--accent-light);}
.text-muted-crm{color:var(--text-muted);}
.fw-600{font-weight:600;}
.section-title{font-size:13px;font-weight:700;color:var(--text-primary);text-transform:uppercase;letter-spacing:.6px;margin-bottom:14px;}
.flag{font-size:16px;}
.avatar-sm{width:30px;height:30px;border-radius:8px;display:inline-flex;align-items:center;justify-content:center;font-size:11px;font-weight:700;color:#fff;flex-shrink:0;}

/* ── BOTTOM NAV BAR (PWA/Mobile) ── */
#bottom-nav{
  display:none;
  position:fixed;bottom:0;left:0;right:0;
  height:calc(56px + var(--safe-bottom));
  padding-bottom:var(--safe-bottom);
  background:var(--bg-surface);border-top:1px solid var(--border);
  z-index:950;align-items:stretch;
}
.bnav-item{
  flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;
  gap:3px;text-decoration:none;color:var(--text-muted);
  font-size:10px;font-weight:500;cursor:pointer;
  transition:color var(--transition);min-height:44px;
}
.bnav-item:hover,.bnav-item.active{color:var(--accent-light);}
.bnav-item .bnav-icon{font-size:20px;line-height:1;}
.bnav-badge{
  position:absolute;top:-4px;right:-6px;
  width:16px;height:16px;border-radius:50%;
  background:var(--danger);color:#fff;font-size:9px;
  display:flex;align-items:center;justify-content:center;
  border:2px solid var(--bg-surface);font-weight:700;
}
.bnav-icon-wrap{position:relative;}

/* ── LOGIN PAGE ── */
.login-page{
  min-height:100vh;display:flex;align-items:center;justify-content:center;
  background:var(--bg-base);padding:20px;
  padding-top:max(20px, var(--safe-top));
  padding-bottom:max(20px, var(--safe-bottom));
}
.login-card{
  background:var(--bg-card);border:1px solid var(--border);
  border-radius:16px;padding:40px;
  width:100%;max-width:420px;
  box-shadow:var(--shadow-card);
}
.login-logo{
  width:52px;height:52px;border-radius:14px;
  background:linear-gradient(135deg,var(--accent),var(--gold));
  display:flex;align-items:center;justify-content:center;
  font-size:22px;font-weight:700;color:#fff;margin:0 auto 18px;
}
.login-title{font-size:22px;font-weight:700;color:var(--text-primary);text-align:center;letter-spacing:-.4px;}
.login-subtitle{font-size:13px;color:var(--text-muted);text-align:center;margin-top:4px;margin-bottom:28px;}
.login-divider{display:flex;align-items:center;gap:12px;margin:20px 0;}
.login-divider::before,.login-divider::after{content:'';flex:1;height:1px;background:var(--border);}
.login-divider span{font-size:11px;color:var(--text-muted);white-space:nowrap;}
.login-footer{text-align:center;font-size:12px;color:var(--text-muted);margin-top:20px;}
.login-footer a{color:var(--accent-light);}
/* alert banner */
.pf-alert{padding:10px 14px;border-radius:8px;font-size:13px;display:flex;align-items:flex-start;gap:10px;margin-bottom:16px;}
.pf-alert-danger{background:rgba(217,79,79,.1);border:1px solid rgba(217,79,79,.3);color:var(--danger);}
.pf-alert-success{background:rgba(40,169,112,.1);border:1px solid rgba(40,169,112,.3);color:var(--success);}
.pf-alert-warning{background:rgba(229,162,37,.1);border:1px solid rgba(229,162,37,.3);color:var(--warning);}

/* ── PWA INSTALL PROMPT ── */
#pwa-install-banner{
  display:none;position:fixed;bottom:calc(60px + var(--safe-bottom));left:16px;right:16px;
  background:var(--bg-card);border:1px solid var(--border);border-radius:12px;
  padding:14px 16px;z-index:940;box-shadow:var(--shadow-card);
  align-items:center;gap:12px;
}
#pwa-install-banner.show{display:flex;}
.pwa-banner-text{flex:1;font-size:13px;color:var(--text-secondary);}
.pwa-banner-text strong{color:var(--text-primary);}

/* ── OFFLINE INDICATOR (PWA) ── */
#offline-bar{
  display:none;position:fixed;top:calc(var(--topbar-h) + var(--safe-top));
  left:0;right:0;z-index:990;
  background:var(--danger);color:#fff;
  text-align:center;font-size:12px;font-weight:600;
  padding:6px;letter-spacing:.5px;
}
body.offline #offline-bar{display:block;}
body.offline #main-content{margin-top:calc(var(--topbar-h) + var(--safe-top) + 32px);}

/* ================================================================
   RESPONSIVE BREAKPOINTS
   ================================================================ */

/* ── Tablet (≤ 991px) ── */
@media(max-width:991px){
  :root{--sidebar-w:220px;}
  .topbar-search .search-kbd{display:none;}
  .stat-value{font-size:22px;}
  #main-content{padding:18px;}
}

/* ── Mobile (≤ 767px) ── */
@media(max-width:767px){
  /* show hamburger, hide sidebar brand */
  #sidebar-toggle{display:flex;}
  .topbar-brand .brand-sub{display:none;}

  /* sidebar slides off-screen */
  #sidebar{transform:translateX(-100%);box-shadow:none;}
  #sidebar.open{transform:translateX(0);box-shadow:4px 0 24px rgba(0,0,0,.3);}

  /* main takes full width */
  #main-content{
    margin-left:0;
    padding:14px 12px;
    padding-bottom:calc(72px + var(--safe-bottom));/* room for bottom nav */
  }

  /* show bottom nav */
  #bottom-nav{display:flex;}

  /* hide topbar search on very small */
  .topbar-search{display:none;}
  .topbar-btn.hide-mobile{display:none;}

  /* page header stacks */
  .page-header{flex-direction:column;align-items:flex-start;gap:10px;}
  .page-header>div:last-child{width:100%;display:flex;flex-wrap:wrap;gap:8px;}

  /* stat cards: 2 per row */
  .stat-value{font-size:20px;}
  .stat-icon{display:none;}

  /* tables: show mobile cards, hide table */
  .crm-table-desktop{display:none!important;}
  .mobile-lead-card{display:flex;}

  /* form sections full-width */
  .form-section{padding:16px;}
  .login-card{padding:24px 20px;}

  /* funnel labels shorten */
  .funnel-label{width:80px;font-size:11px;}

  /* kanban board stays scrollable */
  .kanban-board{padding-bottom:4px;}

  /* stage flow stays scrollable */
  .stage-flow{gap:0;}
}

/* ── Small Mobile (≤ 480px) ── */
@media(max-width:480px){
  .page-title{font-size:17px;}
  .btn-crm:not(.btn-crm-icon):not(.btn-crm-sm){font-size:12px;padding:9px 14px;}
  #topbar .topbar-right .user-avatar{display:none;}
}

/* ── Landscape mobile / small tablet (height-limited) ── */
@media(max-height:500px) and (orientation:landscape){
  #sidebar{overflow-y:auto;}
  .login-card{padding:20px;max-height:90vh;overflow-y:auto;}
}

/* ── PWA standalone mode adjustments ── */
@media(display-mode:standalone){
  /* extra top padding for status bar already handled by safe-area-inset */
  #topbar{background:var(--bg-surface);}
  /* prevent bounce scroll on iOS */
  body{position:fixed;width:100%;overflow:hidden;}
  #main-content{overflow-y:auto;height:calc(100vh - var(--topbar-h) - var(--safe-top));}
}

/* ================================================================
   TABS — Horizontal & Vertical  (v3 addition)
   ================================================================ */

/* ── Shared wrapper ── */
.pf-tabs { display: flex; }

/* ─────────────────────────────────
   HORIZONTAL TABS
   Usage:
     <div class="pf-tabs-h">
       <button class="pf-tab active" data-tab="tab1">Label</button>
       …
     </div>
     <div class="pf-tab-panel active" id="tab1">…</div>
   ───────────────────────────────── */
.pf-tabs-h {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}
.pf-tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 18px;
  background: none; border: none;
  color: var(--text-muted);
  font-size: 13px; font-weight: 500; font-family: 'Outfit', sans-serif;
  cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;          /* sit on top of wrapper border */
  transition: color var(--transition), border-color var(--transition);
  min-height: 44px;             /* PWA touch target */
}
.pf-tab:hover { color: var(--text-primary); }
.pf-tab.active {
  color: var(--accent-light);
  border-bottom-color: var(--accent);
  background: none;
}
.pf-tab .tab-badge {
  font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 10px;
  background: var(--danger); color: #fff;
}
.pf-tab .tab-icon { font-size: 14px; }

/* ─────────────────────────────────
   VERTICAL TABS
   Usage:
     <div class="pf-tabs pf-tabs-v-wrap">
       <div class="pf-tabs-v">
         <button class="pf-tab-v active" data-tab="t1">Label</button>
         …
       </div>
       <div class="pf-tab-panels">
         <div class="pf-tab-panel active" id="t1">…</div>
         …
       </div>
     </div>
   ───────────────────────────────── */
.pf-tabs-v-wrap {
  display: flex;
  gap: 0;
  align-items: flex-start;
}
.pf-tabs-v {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 8px 0;
  background: var(--bg-hover);
  border-radius: 12px 0 0 12px;
}
.pf-tab-v {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 16px;
  background: none; border: none;
  border-left: 3px solid transparent;
  color: var(--text-muted);
  font-size: 13px; font-weight: 500; font-family: 'Outfit', sans-serif;
  text-align: left; cursor: pointer; white-space: nowrap;
  transition: all var(--transition);
  min-height: 44px;
}
.pf-tab-v:hover { background: var(--bg-card); color: var(--text-primary); }
.pf-tab-v.active {
  color: var(--accent-light);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-left-color: var(--accent);
}
@supports not (color: color-mix(in srgb, red, blue)) {
  .pf-tab-v.active { background: rgba(45,125,210,.08); }
}
.pf-tab-v .tab-icon { font-size: 15px; flex-shrink: 0; }
.pf-tab-v .tab-badge {
  margin-left: auto; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 10px;
  background: var(--danger); color: #fff;
}
.pf-tab-v-section {
  font-size: 9px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text-muted);
  padding: 14px 16px 4px; pointer-events: none;
}

/* ── Shared panel ── */
.pf-tab-panels { flex: 1; min-width: 0; }
.pf-tab-panel { display: none; }
.pf-tab-panel.active { display: block; animation: fadeUp .18s ease; }

/* Vertical panel gets left padding + border-radius on right side */
.pf-tabs-v-wrap .pf-tab-panels {
  padding: 20px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 12px 12px 0;
}

/* ── Responsive: vertical tabs stack on mobile ── */
@media (max-width: 600px) {
  .pf-tabs-v-wrap { flex-direction: column; }
  .pf-tabs-v {
    flex-direction: row; overflow-x: auto; min-width: 0; width: 100%;
    border-right: none; border-bottom: 1px solid var(--border);
    border-radius: 12px 12px 0 0; padding: 4px 8px;
    -webkit-overflow-scrolling: touch;
  }
  .pf-tab-v {
    border-left: none;
    border-bottom: 2px solid transparent;
    border-radius: 0; flex-shrink: 0;
    padding: 8px 14px;
  }
  .pf-tab-v.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
    background: none;
  }
  .pf-tabs-v-wrap .pf-tab-panels {
    border-left: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 12px 12px;
  }
  .pf-tab-v-section { display: none; }
}

/* ================================================================
   MODALS — Centre + Right Drawer  (v5 addition)
   ================================================================ */

/* ── Shared backdrop ── */
.pf-backdrop {
  position: fixed; inset: 0; z-index: 2000;
  background: var(--overlay);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden;
  transition: opacity .22s ease, visibility .22s;
  padding: 16px;
}
.pf-backdrop.open { opacity: 1; visibility: visible; }

/* ── Centre modal ── */
.pf-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0,0,0,.45);
  width: 100%; max-width: 520px;
  max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  transform: translateY(16px) scale(.97);
  transition: transform .22s ease;
  overflow: hidden;
}
.pf-backdrop.open .pf-modal { transform: translateY(0) scale(1); }

/* size variants */
.pf-modal.sm { max-width: 380px; }
.pf-modal.lg { max-width: 720px; }
.pf-modal.xl { max-width: 960px; }

.pf-modal-header {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pf-modal-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0;
}
.pf-modal-title   { font-size: 15px; font-weight: 700; color: var(--text-primary); flex: 1; }
.pf-modal-subtitle{ font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.pf-modal-close {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  background: var(--bg-hover); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); cursor: pointer; font-size: 15px;
  transition: all var(--transition);
}
.pf-modal-close:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

.pf-modal-body {
  padding: 20px 22px;
  overflow-y: auto; flex: 1;
  -webkit-overflow-scrolling: touch;
}

.pf-modal-footer {
  display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-hover);
}

/* Danger/confirm variant */
.pf-modal.danger .pf-modal-header { border-bottom-color: rgba(217,79,79,.3); }
.pf-modal.danger .pf-modal-icon { background: rgba(217,79,79,.15); color: var(--danger); }

/* Success variant */
.pf-modal.success .pf-modal-icon { background: rgba(40,169,112,.15); color: var(--success); }

/* ── Right Drawer (side panel) ── */
.pf-drawer-backdrop {
  position: fixed; inset: 0; z-index: 2000;
  background: var(--overlay);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden;
  transition: opacity .25s ease, visibility .25s;
}
.pf-drawer-backdrop.open { opacity: 1; visibility: visible; }

.pf-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 2010;
  width: 440px; max-width: calc(100vw - 40px);
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 40px rgba(0,0,0,.35);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
.pf-drawer-backdrop.open .pf-drawer { transform: translateX(0); }

/* size variants */
.pf-drawer.sm { width: 340px; }
.pf-drawer.lg { width: 600px; }

.pf-drawer-header {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pf-drawer-title   { font-size: 15px; font-weight: 700; color: var(--text-primary); flex: 1; }
.pf-drawer-subtitle{ font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.pf-drawer-close {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  background: var(--bg-hover); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); cursor: pointer; font-size: 15px;
  transition: all var(--transition);
}
.pf-drawer-close:hover { background: var(--bg-hover); border-color: var(--border-light); color: var(--text-primary); }

.pf-drawer-body {
  padding: 20px 22px;
  overflow-y: auto; flex: 1;
  -webkit-overflow-scrolling: touch;
}

.pf-drawer-footer {
  display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-hover);
}

/* ── Safe area for mobile ── */
@media (max-width: 767px) {
  .pf-drawer {
    width: 100%;
    max-width: 100%;
    padding-bottom: var(--safe-bottom);
  }
  .pf-modal { border-radius: 14px; }
}

/* ================================================================
   TOAST / SNACKBAR NOTIFICATIONS  (v5 addition)
   ================================================================ */

/* Container — toasts stack from bottom-right */
#pf-toast-container {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column-reverse;
  gap: 10px;
  pointer-events: none;
  max-width: 360px; width: calc(100vw - 48px);
}

/* Individual toast */
.pf-toast {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 13px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.35);
  pointer-events: all;
  cursor: default;
  opacity: 0; transform: translateX(24px);
  transition: opacity .22s ease, transform .22s ease;
  position: relative; overflow: hidden;
}
.pf-toast.show { opacity: 1; transform: translateX(0); }
.pf-toast.hide { opacity: 0; transform: translateX(24px); }

/* Coloured left accent */
.pf-toast::before {
  content: ''; position: absolute;
  left: 0; top: 0; bottom: 0; width: 3px;
}
.pf-toast.success::before { background: var(--success); }
.pf-toast.danger::before  { background: var(--danger); }
.pf-toast.warning::before { background: var(--warning); }
.pf-toast.info::before    { background: var(--accent); }

/* Icon */
.pf-toast-icon {
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0; margin-top: 1px;
}
.pf-toast.success .pf-toast-icon { background: rgba(40,169,112,.15); color: var(--success); }
.pf-toast.danger  .pf-toast-icon { background: rgba(217,79,79,.15);  color: var(--danger); }
.pf-toast.warning .pf-toast-icon { background: rgba(229,162,37,.15); color: var(--warning); }
.pf-toast.info    .pf-toast-icon { background: rgba(45,125,210,.15); color: var(--accent-light); }

.pf-toast-body    { flex: 1; min-width: 0; }
.pf-toast-title   { font-size: 13px; font-weight: 600; color: var(--text-primary); line-height: 1.3; }
.pf-toast-msg     { font-size: 12px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.pf-toast-action  {
  font-size: 12px; font-weight: 600; color: var(--accent-light);
  background: none; border: none; cursor: pointer;
  padding: 0; margin-top: 6px; display: inline-block;
  font-family: 'Outfit', sans-serif;
  transition: color var(--transition);
}
.pf-toast-action:hover { color: var(--accent); }
.pf-toast-dismiss {
  width: 22px; height: 22px; border-radius: 6px; flex-shrink: 0;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); margin-top: 1px;
}
.pf-toast-dismiss:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Progress bar auto-dismiss timer */
.pf-toast-progress {
  position: absolute; bottom: 0; left: 0;
  height: 2px; border-radius: 0 0 0 10px;
  animation: toastProgress linear forwards;
}
.pf-toast.success .pf-toast-progress { background: var(--success); }
.pf-toast.danger  .pf-toast-progress { background: var(--danger); }
.pf-toast.warning .pf-toast-progress { background: var(--warning); }
.pf-toast.info    .pf-toast-progress { background: var(--accent); }
@keyframes toastProgress { from { width: 100%; } to { width: 0%; } }

/* Snackbar (bottom-center, single line) */
#pf-snackbar {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%) translateY(80px);
  z-index: 9999;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: #1e2535;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  font-size: 13px; color: var(--text-primary);
  white-space: nowrap; max-width: calc(100vw - 48px);
  transition: transform .25s cubic-bezier(.4,0,.2,1), opacity .25s ease;
  opacity: 0; pointer-events: none;
}
[data-theme="light"] #pf-snackbar { background: #1a2035; color: #e8eaf0; }
#pf-snackbar.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1; pointer-events: all;
}
.pf-snackbar-action {
  font-size: 12px; font-weight: 700; color: var(--accent-light);
  background: none; border: none; cursor: pointer;
  padding: 0; font-family: 'Outfit', sans-serif;
  text-transform: uppercase; letter-spacing: .5px;
  transition: color var(--transition);
}
.pf-snackbar-action:hover { color: var(--gold-light); }

@media (max-width: 767px) {
  #pf-toast-container { right: 12px; bottom: calc(70px + var(--safe-bottom)); max-width: calc(100vw - 24px); width: auto; }
  #pf-snackbar        { bottom: calc(70px + var(--safe-bottom)); }
}

/* ================================================================
   VIEW / EDIT MODE TOGGLE  (v6 addition)
   ================================================================ */

/* A read-only "display field" — used in view mode */
.pf-field-view {
  display: flex; flex-direction: column; gap: 3px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.pf-field-view:last-child { border-bottom: none; }
.pf-field-label {
  font-size: 10px; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; color: var(--text-muted);
}
.pf-field-value {
  font-size: 14px; color: var(--text-primary);
  font-weight: 400; line-height: 1.4;
  min-height: 20px;
}
.pf-field-value.empty { color: var(--text-muted); font-style: italic; font-size: 13px; }
.pf-field-value .pf-inline-badge { display: inline-flex; align-items: center; gap: 6px; }

/* Section card in view mode */
.pf-view-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
  transition: border-color var(--transition);
}
.pf-view-section:hover { border-color: var(--border-light); }
.pf-view-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
}
.pf-view-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .7px; color: var(--text-muted);
  display: flex; align-items: center; gap: 8px;
}
.pf-view-section-body { padding: 4px 20px 12px; }

/* Profile hero in view mode */
.pf-profile-hero {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
  position: relative;
}
.pf-profile-avatar-lg {
  width: 64px; height: 64px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.pf-edit-fab {
  position: absolute; top: 20px; right: 20px;
  display: flex; gap: 8px;
}

/* Mode toggle (view ↔ edit) — JS driven, no re-render needed */
[data-mode="view"]  .pf-edit-only  { display: none; }
[data-mode="edit"]  .pf-view-only  { display: none; }
[data-mode="view"]  .pf-view-only  { display: block; }
[data-mode="edit"]  .pf-edit-only  { display: block; }

/* unsaved badge */
.pf-unsaved-badge {
  display: none;
  font-size: 10px; font-weight: 700; padding: 2px 8px;
  border-radius: 10px; background: var(--warning); color: #fff;
  animation: pulse 1.5s infinite;
}
[data-mode="edit"] .pf-unsaved-badge { display: inline-flex; }

/* ================================================================
   CONTACT INBOX — master/detail split  (v6 addition)
   ================================================================ */

.ci-layout {
  display: flex;
  height: calc(100vh - var(--topbar-h) - var(--safe-top) - 48px);
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

/* ── Left master panel ── */
.ci-master {
  width: 320px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
  transition: width var(--transition);
}
.ci-master-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
  flex-shrink: 0;
}
.ci-master-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px;
  transition: border-color var(--transition);
}
.ci-master-search:focus-within { border-color: var(--accent); }
.ci-master-search input {
  background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 13px;
  font-family: 'Outfit', sans-serif; width: 100%;
}
.ci-master-search input::placeholder { color: var(--text-muted); }
.ci-filter-tabs {
  display: flex; gap: 4px; margin-top: 10px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.ci-filter-tab {
  padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 600;
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  cursor: pointer; white-space: nowrap; transition: all var(--transition);
  font-family: 'Outfit', sans-serif;
}
.ci-filter-tab:hover { background: var(--bg-card); color: var(--text-primary); }
.ci-filter-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* List of contact rows */
.ci-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.ci-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  position: relative; min-height: 72px;
}
.ci-row:hover { background: var(--bg-hover); }
.ci-row.active {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-left: 3px solid var(--accent);
}
@supports not (color: color-mix(in srgb,red,blue)) { .ci-row.active { background: rgba(45,125,210,.08); } }
.ci-row-avatar {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.ci-row-info { flex: 1; min-width: 0; }
.ci-row-name {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ci-row-meta {
  font-size: 11px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.ci-row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.ci-row-tag {
  font-size: 10px; font-weight: 600; padding: 1px 7px;
  border-radius: 6px; white-space: nowrap;
}
.ci-row-time { font-size: 10px; color: var(--text-muted); }
.ci-unread-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
  margin-top: 2px;
}

/* ── Right detail panel ── */
.ci-detail {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.ci-detail-header {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
  flex-shrink: 0; flex-wrap: wrap; gap: 10px;
}
.ci-detail-body { flex: 1; overflow-y: auto; padding: 24px; -webkit-overflow-scrolling: touch; }
.ci-detail-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

/* Empty state */
.ci-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-muted); text-align: center; padding: 40px;
}

/* Responsive — stack on mobile */
@media (max-width: 767px) {
  .ci-layout { flex-direction: column; height: auto; min-height: calc(100vh - 140px); }
  .ci-master { width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 320px; }
  .ci-detail { min-height: 400px; }
  .pf-edit-fab { position: static; margin-top: 12px; }
  .pf-profile-hero { padding: 16px; }
}

@media (max-width: 991px) {
  .ci-master { width: 260px; }
}

/* ================================================================
   CALENDAR COMPONENT  (v7 addition)
   ================================================================ */

/* ── Toolbar ── */
.cal-toolbar {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.cal-nav-btn {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); cursor: pointer; font-size: 16px;
  transition: all var(--transition);
}
.cal-nav-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-light); }
.cal-title {
  font-size: 18px; font-weight: 700; color: var(--text-primary);
  letter-spacing: -.3px; min-width: 200px;
}
.cal-today-btn {
  padding: 6px 16px; border-radius: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer; font-size: 13px;
  font-family: 'Outfit', sans-serif; font-weight: 500;
  transition: all var(--transition);
}
.cal-today-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.cal-view-btns {
  display: flex; margin-left: auto; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.cal-view-btn {
  padding: 6px 14px; background: var(--bg-card); border: none;
  color: var(--text-muted); cursor: pointer; font-size: 12px; font-weight: 600;
  font-family: 'Outfit', sans-serif; transition: all var(--transition);
  border-right: 1px solid var(--border);
}
.cal-view-btn:last-child { border-right: none; }
.cal-view-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.cal-view-btn.active { background: var(--accent); color: #fff; }

/* ── Month grid ── */
.cal-grid { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.cal-header-row {
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: var(--bg-hover); border-bottom: 1px solid var(--border);
}
.cal-header-cell {
  padding: 10px 0; text-align: center;
  font-size: 11px; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; color: var(--text-muted);
}
.cal-body { display: grid; grid-template-rows: repeat(6, 1fr); }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--border); }
.cal-week:last-child { border-bottom: none; }
.cal-cell {
  min-height: 110px; padding: 6px; border-right: 1px solid var(--border);
  transition: background var(--transition); cursor: pointer; position: relative;
  vertical-align: top;
}
.cal-cell:last-child { border-right: none; }
.cal-cell:hover { background: var(--bg-hover); }
.cal-cell.other-month { opacity: .45; }
.cal-cell.today { background: color-mix(in srgb, var(--accent) 6%, transparent); }
@supports not (color: color-mix(in srgb,red,blue)) { .cal-cell.today { background: rgba(45,125,210,.06); } }
.cal-cell.selected { background: color-mix(in srgb, var(--accent) 10%, transparent); }
@supports not (color: color-mix(in srgb,red,blue)) { .cal-cell.selected { background: rgba(45,125,210,.10); } }
.cal-day-num {
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; margin-bottom: 4px; transition: all var(--transition);
}
.cal-cell.today .cal-day-num {
  background: var(--accent); color: #fff; font-weight: 700;
}
.cal-cell.selected .cal-day-num { color: var(--accent-light); font-weight: 700; }

/* ── Calendar events (chips inside cells) ── */
.cal-event {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 7px; border-radius: 5px; margin-bottom: 3px;
  font-size: 11px; font-weight: 500; cursor: pointer;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  transition: filter var(--transition);
}
.cal-event:hover { filter: brightness(1.15); }
.cal-event.call    { background: rgba(45,125,210,.2);  color: var(--accent-light); }
.cal-event.visit   { background: rgba(229,162,37,.2);  color: var(--warning); }
.cal-event.meeting { background: rgba(40,169,112,.2);  color: var(--success); }
.cal-event.task    { background: rgba(155,114,207,.2); color: #9b72cf; }
.cal-event.deadline{ background: rgba(217,79,79,.2);   color: var(--danger); }
.cal-event-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.cal-more {
  font-size: 10px; color: var(--text-muted); padding: 2px 6px;
  cursor: pointer; font-weight: 600;
}
.cal-more:hover { color: var(--accent-light); }

/* ── Week view ── */
.cal-week-grid {
  display: grid; grid-template-columns: 52px repeat(7, 1fr);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
.cal-week-header {
  grid-column: 1 / -1; display: grid;
  grid-template-columns: 52px repeat(7, 1fr);
  background: var(--bg-hover); border-bottom: 1px solid var(--border);
}
.cal-week-time-label { /* empty top-left corner */ }
.cal-week-day-hdr {
  padding: 10px 4px; text-align: center; border-left: 1px solid var(--border);
}
.cal-week-day-name { font-size: 10px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--text-muted); }
.cal-week-day-num {
  font-size: 20px; font-weight: 700; color: var(--text-muted); line-height: 1.2;
  display: inline-flex; width: 36px; height: 36px; align-items: center;
  justify-content: center; border-radius: 50%; margin: 2px auto 0; transition: all var(--transition);
}
.cal-week-day-hdr.today .cal-week-day-num { background: var(--accent); color: #fff; }
.cal-week-body {
  grid-column: 1 / -1; display: grid;
  grid-template-columns: 52px repeat(7, 1fr);
  grid-template-rows: repeat(24, 48px);
  overflow-y: auto; max-height: 576px; position: relative;
}
.cal-time-col {
  grid-column: 1; display: contents;
}
.cal-time-slot {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 2px 6px 0;
  font-size: 10px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace;
}
.cal-day-col, .cal-day-col-wrap {
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: relative; cursor: pointer; transition: background var(--transition);
}
.cal-day-col:hover, .cal-day-col-wrap:hover { background: var(--bg-hover); }
.cal-day-col.today-col, .cal-day-col-wrap.today-col { background: color-mix(in srgb, var(--accent) 4%, transparent); }
@supports not (color: color-mix(in srgb,red,blue)) { .cal-day-col.today-col, .cal-day-col-wrap.today-col { background: rgba(45,125,210,.04); } }
/* Week-view event blocks */
.cal-block {
  position: absolute; left: 3px; right: 3px;
  border-radius: 6px; padding: 4px 7px; overflow: hidden;
  cursor: pointer; z-index: 2; transition: filter var(--transition);
}
.cal-block:hover { filter: brightness(1.12); z-index: 3; }
.cal-block.call    { background: rgba(45,125,210,.25);  border-left: 3px solid var(--accent-light); }
.cal-block.visit   { background: rgba(229,162,37,.25);  border-left: 3px solid var(--warning); }
.cal-block.meeting { background: rgba(40,169,112,.25);  border-left: 3px solid var(--success); }
.cal-block.task    { background: rgba(155,114,207,.25); border-left: 3px solid #9b72cf; }
.cal-block-title { font-size: 11px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-block-time  { font-size: 10px; color: var(--text-muted); }
/* Current time indicator */
.cal-now-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: var(--danger); z-index: 10; pointer-events: none;
}
.cal-now-line::before {
  content: ''; position: absolute; left: -4px; top: -4px;
  width: 10px; height: 10px; border-radius: 50%; background: var(--danger);
}

/* ── Day view panel ── */
.cal-day-panel {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
.cal-day-panel-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg-hover); display: flex; align-items: center; justify-content: space-between;
}
.cal-day-events { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.cal-day-event-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 14px; border-radius: 10px;
  background: var(--bg-hover); border: 1px solid var(--border);
  cursor: pointer; transition: all var(--transition);
}
.cal-day-event-row:hover { border-color: var(--border-light); transform: translateX(2px); }
.cal-day-event-time { font-size: 11px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; width: 80px; flex-shrink: 0; padding-top: 1px; }
.cal-day-event-bar { width: 3px; border-radius: 2px; align-self: stretch; flex-shrink: 0; min-height: 20px; }
.cal-day-event-body { flex: 1; min-width: 0; }
.cal-day-event-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.cal-day-event-meta  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Legend ── */
.cal-legend { display: flex; flex-wrap: wrap; gap: 12px; }
.cal-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.cal-legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* ── Responsive ── */
@media (max-width: 767px) {
  .cal-cell { min-height: 60px; padding: 3px; }
  .cal-event .cal-event-label { display: none; }
  .cal-title { font-size: 15px; min-width: 0; }
  .cal-week-body { max-height: 420px; }
  .cal-view-btns { display: none; }
}

/* ================================================================
   CALENDAR COMPONENT  (v7 addition)
   ================================================================ */

/* ── Layout wrapper ── */
.cal-wrap {
  display: flex; gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 600px;
}

/* ── Left sidebar: mini-calendar + task list ── */
.cal-sidebar {
  width: 280px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--bg-hover);
}
.cal-sidebar-section { padding: 16px 18px; border-bottom: 1px solid var(--border); }

/* ── Mini calendar ── */
.mini-cal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.mini-cal-title { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.mini-cal-nav {
  width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--border);
  background: none; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-muted); font-size: 12px;
  transition: all var(--transition);
}
.mini-cal-nav:hover { background: var(--bg-card); color: var(--text-primary); }
.mini-cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
  text-align: center;
}
.mini-cal-dow {
  font-size: 9px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-muted);
  padding: 4px 0;
}
.mini-cal-day {
  width: 30px; height: 30px; border-radius: 8px; margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-secondary);
  cursor: pointer; transition: all var(--transition);
  position: relative;
}
.mini-cal-day:hover { background: var(--bg-card); color: var(--text-primary); }
.mini-cal-day.other-month { color: var(--text-muted); opacity: .4; }
.mini-cal-day.today {
  background: var(--accent); color: #fff; font-weight: 700;
}
.mini-cal-day.selected { background: var(--bg-card); color: var(--accent-light); font-weight: 700; box-shadow: 0 0 0 2px var(--accent); }
.mini-cal-day.has-event::after {
  content: ''; position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--gold);
}
.mini-cal-day.today.has-event::after { background: rgba(255,255,255,.7); }

/* Upcoming tasks in sidebar */
.cal-task-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.cal-task-item:last-child { border-bottom: none; }
.cal-task-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 5px;
}
.cal-task-title { font-size: 12px; color: var(--text-primary); font-weight: 500; line-height: 1.3; }
.cal-task-meta  { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

/* ── Main calendar area ── */
.cal-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.cal-main-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap; gap: 10px;
  background: var(--bg-hover);
}
.cal-main-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.cal-view-btns { display: flex; gap: 0; }
.cal-view-btn {
  padding: 6px 14px; font-size: 12px; font-weight: 600;
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; transition: all var(--transition);
  font-family: 'Outfit', sans-serif;
}
.cal-view-btn:first-child { border-radius: 8px 0 0 8px; }
.cal-view-btn:last-child  { border-radius: 0 8px 8px 0; }
.cal-view-btn + .cal-view-btn { border-left: none; }
.cal-view-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.cal-view-btn:hover:not(.active) { background: var(--bg-card); color: var(--text-primary); }

/* ── Month grid ── */
.cal-grid-header {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
}
.cal-grid-dow {
  padding: 10px 8px; text-align: center;
  font-size: 10px; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; color: var(--text-muted);
}
.cal-grid-dow.weekend { color: var(--danger); opacity: .7; }

.cal-grid-body {
  flex: 1; display: grid; grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 1fr; overflow: hidden;
}
.cal-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 8px; min-height: 100px;
  cursor: pointer; transition: background var(--transition);
  display: flex; flex-direction: column; gap: 3px;
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell:hover { background: var(--bg-hover); }
.cal-cell.today { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.cal-cell.other-month { background: var(--bg-base); opacity: .6; }
.cal-cell.selected { background: color-mix(in srgb, var(--accent) 10%, transparent); }
@supports not (color: color-mix(in srgb,red,blue)) {
  .cal-cell.today   { background: rgba(45,125,210,.06); }
  .cal-cell.selected{ background: rgba(45,125,210,.10); }
}
.cal-date-num {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.cal-cell.today .cal-date-num {
  background: var(--accent); color: #fff; font-weight: 700;
}

/* ── Calendar event chips ── */
.cal-event {
  font-size: 10px; font-weight: 600; padding: 2px 6px;
  border-radius: 4px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; cursor: pointer;
  transition: filter var(--transition); line-height: 1.4;
}
.cal-event:hover { filter: brightness(1.15); }
.cal-event.call     { background: rgba(45,125,210,.2);  color: var(--accent-light); }
.cal-event.visit    { background: rgba(229,162,37,.2);  color: var(--warning); }
.cal-event.meeting  { background: rgba(40,169,112,.2);  color: var(--success); }
.cal-event.deadline { background: rgba(217,79,79,.2);   color: var(--danger); }
.cal-event.personal { background: rgba(155,114,207,.2); color: #c49ef0; }
.cal-event.more {
  color: var(--text-muted); background: none; font-style: italic; font-weight: 400;
}

/* ── Week / Day view ── */
.cal-week-grid {
  flex: 1; display: flex; overflow: hidden;
}
.cal-time-col {
  width: 56px; flex-shrink: 0; border-right: 1px solid var(--border);
  padding-top: 48px; /* align with all-day row */
}
.cal-time-slot {
  height: 60px; display: flex; align-items: flex-start;
  padding: 4px 8px 0;
  font-size: 10px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace;
  border-bottom: 1px solid var(--border);
}
.cal-week-cols {
  flex: 1; display: grid; overflow-y: auto; -webkit-overflow-scrolling: touch;
  position: relative;
}
.cal-week-col { border-right: 1px solid var(--border); position: relative; }
.cal-week-col:last-child { border-right: none; }
.cal-week-col-header {
  height: 48px; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-hover);
  z-index: 1; gap: 1px;
}
.cal-week-col-dow  { font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--text-muted); }
.cal-week-col-date { font-size: 18px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.cal-week-col.today .cal-week-col-date { color: var(--accent-light); }
.cal-week-slot {
  height: 60px; border-bottom: 1px solid var(--border);
  position: relative; cursor: pointer;
  transition: background var(--transition);
}
.cal-week-slot:hover { background: var(--bg-hover); }
/* Positioned event block inside week view */
.cal-week-event {
  position: absolute; left: 2px; right: 2px;
  border-radius: 6px; padding: 4px 6px;
  font-size: 11px; font-weight: 600; cursor: pointer;
  overflow: hidden; z-index: 2;
  transition: filter var(--transition);
}
.cal-week-event:hover { filter: brightness(1.15); z-index: 3; }
.cal-week-event.call     { background: rgba(45,125,210,.25);  color: var(--accent-light);  border-left: 3px solid var(--accent); }
.cal-week-event.visit    { background: rgba(229,162,37,.25);  color: var(--warning);       border-left: 3px solid var(--warning); }
.cal-week-event.meeting  { background: rgba(40,169,112,.25);  color: var(--success);       border-left: 3px solid var(--success); }
.cal-week-event.deadline { background: rgba(217,79,79,.25);   color: var(--danger);        border-left: 3px solid var(--danger); }
.cal-week-event.personal { background: rgba(155,114,207,.25); color: #c49ef0;              border-left: 3px solid #9b72cf; }
/* Current time indicator */
.cal-now-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: var(--danger); z-index: 5; pointer-events: none;
}
.cal-now-line::before {
  content: ''; position: absolute; left: -5px; top: -4px;
  width: 10px; height: 10px; border-radius: 50%; background: var(--danger);
}

/* ── Responsive ── */
@media (max-width: 991px) {
  .cal-sidebar { width: 240px; }
}
@media (max-width: 767px) {
  .cal-wrap { flex-direction: column; min-height: auto; }
  .cal-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .cal-cell { min-height: 64px; padding: 4px; }
  .cal-event { display: none; } /* hide chips on mobile month view — tap cell to see events */
  .cal-cell .cal-event:first-of-type { display: block; } /* show just the first */
}

/*progress indicator added custom: 260512*/
.htmx-indicator {
    display: none;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}
