/* ===================================================================
   1008.GURU — Lead & Patti Management Panel
   Saffron / Sanatan Dharma theme (palette from 1008.guru)
   Light + Dark theme, fully responsive, mobile-app feel.
   =================================================================== */
:root{
  --bg:#fdf6ec; --surface:#ffffff; --surface-2:#fbf2e3; --border:#efe1cc;
  --text:#2a1c10; --text-2:#6b5840; --muted:#a08a6e;
  --primary:#e8821e; --primary-2:#c2410c; --primary-soft:#fdebd3;
  --accent:#ffc107; --green:#16a34a; --red:#dc2626; --blue:#2563eb;
  --maroon:#5a1e0c;
  --shadow:0 1px 3px rgba(120,60,10,.10),0 1px 2px rgba(120,60,10,.05);
  --shadow-lg:0 10px 30px rgba(120,60,10,.16);
  --radius:14px; --radius-sm:10px; --nav-h:64px;
  --safe-b:env(safe-area-inset-bottom,0px);
}
[data-theme="dark"]{
  --bg:#1a120a; --surface:#241a10; --surface-2:#2e2114; --border:#3d2c1a;
  --text:#f5ead9; --text-2:#c9b393; --muted:#9a8362;
  --primary:#f59e42; --primary-2:#ea7317; --primary-soft:#3a2613;
  --accent:#ffca3a; --green:#22c55e; --red:#f87171; --blue:#60a5fa;
  --maroon:#7a2d12;
  --shadow:0 1px 3px rgba(0,0,0,.45); --shadow-lg:0 12px 34px rgba(0,0,0,.55);
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;padding:0}
body{
  font-family:'Inter','Noto Sans Devanagari',system-ui,-apple-system,Segoe UI,Roboto,sans-serif;
  background:var(--bg); color:var(--text); font-size:15px; line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
a{color:var(--primary);text-decoration:none}
h1,h2,h3,h4{margin:0 0 .4em;font-weight:700;letter-spacing:-.01em}
.hi{font-family:'Noto Sans Devanagari',sans-serif}

/* ---------- Layout ---------- */
.app{display:flex;min-height:100vh}
.sidebar{
  width:248px;flex-shrink:0;background:var(--surface);border-right:1px solid var(--border);
  position:sticky;top:0;height:100vh;overflow-y:auto;padding:18px 14px;
}
.brand{display:flex;align-items:center;gap:10px;padding:6px 8px 18px;font-weight:800;font-size:17px}
.brand .logo{width:36px;height:36px;border-radius:10px;background:linear-gradient(135deg,var(--primary),var(--primary-2));display:grid;place-items:center;color:#fff;font-weight:800;box-shadow:0 2px 6px rgba(194,65,12,.3)}
.brand .logo i{font-size:18px}
.nav-group{margin-top:14px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--muted);padding:0 8px 6px}
.nav-item{display:flex;align-items:center;gap:11px;padding:10px 12px;border-radius:var(--radius-sm);color:var(--text-2);font-weight:500;margin-bottom:2px;transition:.15s}
.nav-item:hover{background:var(--surface-2);color:var(--text)}
.nav-item.active{background:var(--primary-soft);color:var(--primary-2);font-weight:600}
.nav-item .ic{width:20px;text-align:center;font-size:18px}
.nav-badge{margin-left:auto;background:var(--red);color:#fff;border-radius:20px;font-size:11px;padding:1px 7px;font-weight:700}

.main{flex:1;min-width:0;display:flex;flex-direction:column}
.topbar{
  height:60px;display:flex;align-items:center;gap:12px;padding:0 20px;
  background:var(--surface);border-bottom:1px solid var(--border);position:sticky;top:0;z-index:30;
}
.topbar h1{font-size:18px;margin:0}
.topbar .spacer{flex:1}
.content{padding:20px;max-width:1280px;width:100%;margin:0 auto}

/* ---------- Components ---------- */
.icon-btn{width:40px;height:40px;border-radius:11px;border:1px solid var(--border);background:var(--surface);
  display:grid;place-items:center;cursor:pointer;color:var(--text-2);font-size:18px;position:relative;transition:.15s}
.icon-btn:hover{background:var(--surface-2);color:var(--text)}
.dot{position:absolute;top:7px;right:8px;width:8px;height:8px;border-radius:50%;background:var(--red);border:2px solid var(--surface)}

.card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow);padding:18px}
.card-h{display:flex;align-items:center;gap:10px;margin-bottom:14px}
.card-h h3{margin:0;font-size:15px}
.grid{display:grid;gap:16px}
.grid-2{grid-template-columns:repeat(2,1fr)}
.grid-3{grid-template-columns:repeat(3,1fr)}
.grid-4{grid-template-columns:repeat(4,1fr)}

.stat{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:16px;box-shadow:var(--shadow)}
.stat .v{font-size:26px;font-weight:800;line-height:1}
.stat .l{color:var(--text-2);font-size:13px;margin-top:6px}
.stat .ic{width:42px;height:42px;border-radius:12px;display:grid;place-items:center;font-size:20px;margin-bottom:10px;background:var(--primary-soft);color:var(--primary-2)}

.btn{display:inline-flex;align-items:center;gap:8px;justify-content:center;border:none;cursor:pointer;
  font-weight:600;font-size:14px;padding:10px 16px;border-radius:11px;background:var(--primary);color:#fff;transition:.15s;font-family:inherit}
.btn:hover{background:var(--primary-2)}
.btn:active{transform:scale(.98)}
.btn-ghost{background:var(--surface-2);color:var(--text)}
.btn-ghost:hover{background:var(--border)}
.btn-outline{background:transparent;border:1px solid var(--border);color:var(--text)}
.btn-danger{background:var(--red)}
.btn-success{background:var(--green)}
.btn-sm{padding:6px 12px;font-size:13px;border-radius:9px}
.btn-block{width:100%}
.btn-wa{background:#25d366}.btn-wa:hover{background:#1eb455}

.badge{display:inline-flex;align-items:center;gap:5px;padding:3px 10px;border-radius:20px;font-size:12px;font-weight:600;color:#fff}
.tag{display:inline-block;padding:2px 9px;border-radius:7px;font-size:12px;background:var(--surface-2);color:var(--text-2);border:1px solid var(--border)}

label{display:block;font-size:13px;font-weight:600;color:var(--text-2);margin:0 0 6px}
.input,select,textarea{
  width:100%;padding:11px 13px;border:1px solid var(--border);border-radius:11px;background:var(--surface);
  color:var(--text);font-size:14px;font-family:inherit;outline:none;transition:.15s}
.input:focus,select:focus,textarea:focus{border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-soft)}
.field{margin-bottom:14px}
.row{display:flex;gap:12px;flex-wrap:wrap}
.row>*{flex:1;min-width:0}

table{width:100%;border-collapse:collapse;font-size:14px}
th{text-align:left;color:var(--text-2);font-weight:600;font-size:12px;text-transform:uppercase;letter-spacing:.04em;padding:10px 12px;border-bottom:1px solid var(--border)}
td{padding:12px;border-bottom:1px solid var(--border)}
tr:last-child td{border-bottom:none}
.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch;max-width:100%;border-radius:var(--radius);border:1px solid var(--border);background:var(--surface)}

.alert{padding:12px 16px;border-radius:11px;margin-bottom:16px;font-size:14px;font-weight:500}
.alert-success{background:rgba(22,163,74,.12);color:var(--green);border:1px solid rgba(22,163,74,.25)}
.alert-error{background:rgba(239,68,68,.12);color:var(--red);border:1px solid rgba(239,68,68,.25)}
.alert-info{background:var(--primary-soft);color:var(--primary-2)}

/* timeline */
.timeline{position:relative;padding-left:26px}
.timeline:before{content:'';position:absolute;left:9px;top:4px;bottom:4px;width:2px;background:var(--border)}
.tl-item{position:relative;padding:0 0 18px}
.tl-item:before{content:'';position:absolute;left:-21px;top:3px;width:14px;height:14px;border-radius:50%;background:var(--primary);border:3px solid var(--surface)}
.tl-meta{font-size:12px;color:var(--muted)}
.tl-body{margin-top:3px}

/* chat */
.chat-list{display:flex;flex-direction:column;gap:10px;padding:12px}
.bubble{max-width:78%;padding:9px 13px;border-radius:14px;font-size:14px;position:relative}
.bubble.in{background:var(--surface-2);border:1px solid var(--border);align-self:flex-start;border-bottom-left-radius:4px}
.bubble.out{background:var(--primary);color:#fff;align-self:flex-end;border-bottom-right-radius:4px}
.bubble .t{font-size:10px;opacity:.7;margin-top:3px;text-align:right}
.link-prev{display:block;border:1px solid var(--border);border-radius:10px;overflow:hidden;margin-top:6px;background:var(--surface)}
.link-prev img{width:100%;height:120px;object-fit:cover;display:block}
.link-prev .lp-b{padding:8px 10px}
.link-prev .lp-t{font-weight:700;font-size:13px;color:var(--text)}
.link-prev .lp-d{font-size:12px;color:var(--text-2)}

/* ---------- Mobile bottom nav + app feel ---------- */
.bottom-nav{display:none}
.mobile-top{display:none}
.fab{display:none}

@media(max-width:860px){
  .sidebar{display:none}
  .topbar{display:none}
  .mobile-top{display:flex;align-items:center;gap:10px;height:56px;padding:0 16px;
    background:var(--surface);border-bottom:1px solid var(--border);position:sticky;top:0;z-index:30}
  .mobile-top h1{font-size:17px;margin:0;flex:1}
  .content{padding:14px 14px calc(var(--nav-h) + var(--safe-b) + 16px);overflow-x:hidden}
  .grid-2,.grid-3,.grid-4{grid-template-columns:1fr}
  .stats-row{grid-template-columns:1fr 1fr}
  .bottom-nav{
    display:flex;position:fixed;bottom:0;left:0;right:0;height:calc(var(--nav-h) + var(--safe-b));
    padding-bottom:var(--safe-b);background:var(--surface);border-top:1px solid var(--border);
    z-index:50;box-shadow:0 -2px 14px rgba(0,0,0,.06)}
  .bn-item{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;
    color:var(--muted);font-size:10.5px;font-weight:600;position:relative}
  .bn-item .ic{font-size:21px}
  .bn-item.active{color:var(--primary)}
  .bn-item .nav-badge{position:absolute;top:6px;left:54%;font-size:9px;padding:0 5px}
  .fab{display:grid;place-items:center;position:fixed;right:18px;bottom:calc(var(--nav-h) + var(--safe-b) + 14px);
    width:56px;height:56px;border-radius:50%;background:var(--primary);color:#fff;font-size:26px;
    box-shadow:var(--shadow-lg);z-index:49;cursor:pointer;border:none}
  .card{padding:15px}
  .content h1{font-size:20px}
}
@media(min-width:861px){ .stats-row{display:grid;grid-template-columns:repeat(4,1fr);gap:16px} }
.stats-row{display:grid;gap:14px}

/* ---------- Bottom sheet ---------- */
.sheet-overlay{position:fixed;inset:0;background:rgba(8,12,20,.5);z-index:100;opacity:0;visibility:hidden;transition:.25s}
.sheet-overlay.open{opacity:1;visibility:visible}
.sheet{position:fixed;left:0;right:0;bottom:0;background:var(--surface);border-radius:22px 22px 0 0;z-index:101;
  transform:translateY(100%);transition:transform .3s cubic-bezier(.32,.72,0,1);max-height:92vh;overflow-y:auto;
  padding:8px 18px calc(20px + var(--safe-b));box-shadow:var(--shadow-lg)}
.sheet.open{transform:translateY(0)}
.sheet-grip{width:42px;height:5px;border-radius:3px;background:var(--border);margin:8px auto 14px}
.sheet h3{margin:0 0 14px}
@media(min-width:861px){
  .sheet{left:50%;right:auto;bottom:50%;transform:translate(-50%,60%) scale(.98);width:520px;max-width:92vw;
    border-radius:var(--radius);opacity:0}
  .sheet.open{transform:translate(-50%,50%) scale(1);opacity:1}
  .sheet-grip{display:none}
}

.muted{color:var(--muted)}
.flex{display:flex;align-items:center;gap:10px}
.between{justify-content:space-between}
.mt{margin-top:16px}.mb{margin-bottom:16px}
.pill-tabs{display:flex;gap:6px;overflow-x:auto;padding-bottom:4px;-webkit-overflow-scrolling:touch}
.pill-tabs a{white-space:nowrap;padding:7px 14px;border-radius:20px;background:var(--surface);border:1px solid var(--border);color:var(--text-2);font-size:13px;font-weight:600}
.pill-tabs a.active{background:var(--primary);color:#fff;border-color:var(--primary)}
.empty{text-align:center;padding:40px 20px;color:var(--muted)}
.empty .ic{font-size:42px;opacity:.4;margin-bottom:10px}
.avatar{width:38px;height:38px;border-radius:50%;background:var(--primary-soft);color:var(--primary-2);display:grid;place-items:center;font-weight:700;flex-shrink:0}
.topbar .avatar{cursor:pointer;border:2px solid transparent;transition:.15s}
.topbar .avatar:hover{border-color:var(--primary)}
.list-row{display:flex;align-items:center;gap:12px;padding:12px;border-bottom:1px solid var(--border)}
.list-row:last-child{border-bottom:none}

/* ===== Hierarchy tree ===== */
.hierarchy-tree{padding:6px 2px}
.hier-node{position:relative;margin-bottom:8px}
.hier-badge{display:flex;align-items:center;gap:10px;color:#fff;padding:10px 14px;border-radius:12px;box-shadow:0 2px 8px rgba(0,0,0,.12)}
.hier-badge .hn-name{font-weight:800;font-size:15px}
.hier-badge .hn-meta{font-size:12px;opacity:.85}
.hier-node .hier-line{position:absolute;left:-12px;top:0;bottom:0;width:2px;background:var(--border)}
@media(max-width:640px){.hier-node{margin-left:0 !important}.hier-badge{flex-wrap:wrap}}

/* ===== Checkbox grid (campaign assign) ===== */
.check-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:4px}
.check-grid .chk{display:flex;align-items:center;gap:8px;padding:8px 10px;border:1px solid var(--border);border-radius:10px;font-size:13px;cursor:pointer;background:var(--surface)}
.check-grid .chk input{accent-color:var(--primary)}
@media(max-width:560px){.check-grid{grid-template-columns:1fr}}

/* ===== Icon sizing (Font Awesome) ===== */
.nav-item .ic i,.bn-item .ic i{font-size:17px;line-height:1}
.icon-btn i{font-size:17px}
.stat .ic i{font-size:18px}
.empty .ic i{font-size:40px}
.card-h .ic{width:34px;height:34px;border-radius:9px;display:grid;place-items:center;background:var(--primary-soft);color:var(--primary-2);flex-shrink:0}
.card-h .ic i{font-size:15px}

/* ===== Profile dropdown menu ===== */
.profile-wrap{position:relative}
.profile-menu{position:absolute;top:48px;right:0;min-width:220px;background:var(--surface);border:1px solid var(--border);
  border-radius:14px;box-shadow:var(--shadow-lg);padding:8px;z-index:200;opacity:0;visibility:hidden;
  transform:translateY(-6px);transition:.16s}
.profile-menu.open{opacity:1;visibility:visible;transform:translateY(0)}
.profile-menu .pm-head{display:flex;align-items:center;gap:10px;padding:10px 10px 12px;border-bottom:1px solid var(--border);margin-bottom:6px}
.profile-menu .pm-head .avatar{width:42px;height:42px;font-size:16px}
.profile-menu .pm-name{font-weight:700;font-size:14px;color:var(--text)}
.profile-menu .pm-role{font-size:12px;color:var(--muted);text-transform:capitalize}
.profile-menu a{display:flex;align-items:center;gap:10px;padding:9px 11px;border-radius:9px;color:var(--text-2);font-size:14px;font-weight:500}
.profile-menu a:hover{background:var(--surface-2);color:var(--text)}
.profile-menu a i{width:18px;text-align:center;font-size:14px}
.profile-menu a.danger{color:var(--red)}
.profile-menu a.danger:hover{background:rgba(220,38,38,.1)}

/* ===== Mobile More drawer ===== */
.more-drawer-ov{position:fixed;inset:0;background:rgba(8,6,2,.5);z-index:120;opacity:0;visibility:hidden;transition:.25s}
.more-drawer-ov.open{opacity:1;visibility:visible}
.more-drawer{position:fixed;left:0;right:0;bottom:0;background:var(--surface);border-radius:22px 22px 0 0;z-index:121;
  transform:translateY(100%);transition:transform .3s cubic-bezier(.32,.72,0,1);max-height:80vh;overflow-y:auto;
  padding:8px 16px calc(20px + var(--safe-b));box-shadow:var(--shadow-lg)}
.more-drawer.open{transform:translateY(0)}
.more-grip{width:42px;height:5px;border-radius:3px;background:var(--border);margin:8px auto 14px}
.more-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;padding-bottom:8px}
.more-grid a{display:flex;flex-direction:column;align-items:center;gap:7px;padding:14px 6px;border-radius:13px;
  background:var(--surface-2);color:var(--text-2);font-size:11.5px;font-weight:600;text-align:center;border:1px solid var(--border)}
.more-grid a.active{background:var(--primary-soft);color:var(--primary-2);border-color:var(--primary)}
.more-grid a i{font-size:21px}
.more-grid a span{line-height:1.2}
@media(max-width:360px){.more-grid{grid-template-columns:repeat(3,1fr)}}

/* ===== Chat media / audio / edit-delete ===== */
.chat-input-bar{display:flex;align-items:flex-end;gap:8px;padding:10px 12px calc(10px + var(--safe-b));
  border-top:1px solid var(--border);background:var(--surface);position:sticky;bottom:0}
.chat-input-bar textarea{resize:none;max-height:120px;min-height:42px;padding:10px 13px}
.chat-tool{width:42px;height:42px;border-radius:11px;border:1px solid var(--border);background:var(--surface-2);
  display:grid;place-items:center;cursor:pointer;color:var(--text-2);font-size:17px;flex-shrink:0;transition:.15s}
.chat-tool:hover{background:var(--primary-soft);color:var(--primary-2)}
.chat-send{width:46px;height:46px;border-radius:50%;border:none;background:var(--primary);color:#fff;
  display:grid;place-items:center;cursor:pointer;font-size:18px;flex-shrink:0}
.chat-send:hover{background:var(--primary-2)}
.bubble img.chat-img{max-width:230px;width:100%;border-radius:10px;display:block;cursor:pointer;margin:2px 0}
.bubble audio{max-width:240px;width:100%;margin:2px 0;height:38px}
.bubble .b-actions{display:none;position:absolute;top:-12px;font-size:11px;gap:4px;background:var(--surface);
  border:1px solid var(--border);border-radius:8px;padding:2px;box-shadow:var(--shadow);z-index:5}
.bubble.out .b-actions{right:0}.bubble.in .b-actions{left:0}
.bubble:hover .b-actions{display:flex}
.bubble .b-actions button{border:none;background:none;cursor:pointer;color:var(--text-2);font-size:12px;padding:3px 6px;border-radius:6px}
.bubble .b-actions button:hover{background:var(--surface-2);color:var(--text)}
.bubble .b-actions button.del:hover{color:var(--red)}
.bubble.deleted{font-style:italic;opacity:.7}
.bubble .edited-tag{font-size:10px;opacity:.6;margin-left:4px}
.rec-indicator{display:none;align-items:center;gap:8px;flex:1;color:var(--red);font-weight:600;font-size:13px;padding:0 6px}
.rec-indicator.on{display:flex}
.rec-dot{width:10px;height:10px;border-radius:50%;background:var(--red);animation:recpulse 1s infinite}
@keyframes recpulse{0%,100%{opacity:1}50%{opacity:.3}}
.img-preview-strip{display:flex;gap:8px;padding:6px 12px 0;flex-wrap:wrap}
.img-preview-strip .ipv{position:relative;width:64px;height:64px;border-radius:9px;overflow:hidden;border:1px solid var(--border)}
.img-preview-strip .ipv img{width:100%;height:100%;object-fit:cover}
.img-preview-strip .ipv button{position:absolute;top:2px;right:2px;width:20px;height:20px;border-radius:50%;border:none;
  background:rgba(0,0,0,.6);color:#fff;cursor:pointer;font-size:12px;line-height:1;display:grid;place-items:center}
.lightbox{position:fixed;inset:0;background:rgba(0,0,0,.88);z-index:300;display:none;align-items:center;justify-content:center;padding:20px}
.lightbox.open{display:flex}
.lightbox img{max-width:100%;max-height:90vh;border-radius:10px}
.lightbox .lb-close{position:absolute;top:18px;right:20px;color:#fff;font-size:30px;cursor:pointer;background:none;border:none}

/* ===== Drill-down profile panel ===== */
.drill-panel{margin-top:18px;border-top:2px solid var(--primary);padding-top:16px}
.profile-head{display:flex;align-items:center;gap:14px;margin-bottom:14px}
.profile-head .avatar{width:56px;height:56px;font-size:22px}
.profile-head .ph-name{font-weight:800;font-size:18px}
.profile-head .ph-meta{font-size:13px;color:var(--text-2)}
.viewas-banner{display:flex;align-items:center;gap:10px;background:var(--maroon);color:#ffe;padding:10px 16px;border-radius:12px;margin-bottom:16px;font-size:13px;font-weight:600}
.viewas-banner i{font-size:15px}
.viewas-banner a{margin-left:auto;color:#ffd9a3;text-decoration:underline}
