/* ============ TOKENS ============ */
:root{
  --bg:#f1f5f9; --surface:#ffffff; --surface-2:#f8fafc; --text:#0f172a; --muted:#64748b;
  --border:#e2e8f0; --primary:#4f46e5; --primary-600:#4338ca; --primary-soft:#eef2ff;
  --success:#10b981; --warning:#f59e0b; --danger:#ef4444; --info:#3b82f6;
  --radius:12px; --radius-sm:8px;
  --shadow:0 1px 2px rgba(15,23,42,.06), 0 8px 24px -14px rgba(15,23,42,.22);
  --sidebar-w:252px;
}
[data-theme="dark"]{
  --bg:#0b1220; --surface:#111a2e; --surface-2:#0f172a; --text:#e2e8f0; --muted:#94a3b8;
  --border:#1e293b; --primary-soft:#1e1b4b;
  --shadow:0 1px 2px rgba(0,0,0,.4), 0 8px 24px -14px rgba(0,0,0,.6);
}

/* ============ BASE ============ */
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  background:var(--bg); color:var(--text); font-size:14px; line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
a{color:inherit;text-decoration:none}
button,input,select,textarea{font:inherit;color:inherit}
.ico{flex-shrink:0}

/* ============ LAYOUT ============ */
.app{display:flex;min-height:100vh}

.sidebar{
  width:var(--sidebar-w);background:var(--surface);border-right:1px solid var(--border);
  position:fixed;inset:0 auto 0 0;display:flex;flex-direction:column;z-index:60;
  transition:transform .25s ease;
}
.main{
  flex:1;margin-left:var(--sidebar-w);display:flex;flex-direction:column;min-width:0;
}
.content{padding:24px;flex:1;max-width:1500px;width:100%;margin:0 auto}

/* ============ SIDEBAR ============ */
.sidebar-brand{
  display:flex;align-items:center;gap:11px;padding:20px 18px;border-bottom:1px solid var(--border);
}
.brand-mark{
  width:38px;height:38px;border-radius:10px;display:grid;place-items:center;font-weight:800;
  color:#fff;background:linear-gradient(135deg,var(--primary),#7c3aed);letter-spacing:-.5px;
}
.brand-text{display:flex;flex-direction:column;line-height:1.25}
.brand-text strong{font-size:14px}
.brand-text span{font-size:11px;color:var(--muted)}
.sidebar-close{display:none;margin-left:auto;background:none;border:none;cursor:pointer;color:var(--muted)}

.sidebar-nav{padding:14px 12px;flex:1;overflow-y:auto}
.nav-label{
  font-size:10.5px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;
  color:var(--muted);padding:14px 12px 7px;
}
.nav-item{
  display:flex;align-items:center;gap:11px;padding:10px 12px;border-radius:var(--radius-sm);
  font-size:13.5px;font-weight:500;color:var(--muted);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);font-weight:600}

.sidebar-foot{padding:14px;border-top:1px solid var(--border);display:flex;flex-direction:column;gap:10px}
.user-chip{display:flex;align-items:center;gap:10px}
.avatar{
  width:36px;height:36px;border-radius:50%;background:linear-gradient(135deg,var(--primary),#7c3aed);
  color:#fff;display:grid;place-items:center;font-weight:700;font-size:14px;flex-shrink:0;
}
.user-meta{display:flex;flex-direction:column;line-height:1.3;min-width:0}
.user-meta strong{font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.user-meta span{font-size:11px;color:var(--muted)}

/* ============ TOPBAR ============ */
.topbar{
  display:flex;align-items:center;gap:14px;padding:16px 24px;background:var(--surface);
  border-bottom:1px solid var(--border);position:sticky;top:0;z-index:40;
}
.topbar-title h1{font-size:18px;font-weight:700}
.topbar-title p{font-size:12px;color:var(--muted)}
.topbar-actions{margin-left:auto;display:flex;gap:9px;align-items:center}

/* ============ BUTTONS ============ */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:7px;
  padding:9px 15px;border-radius:var(--radius-sm);font-size:13px;font-weight:600;
  border:1px solid transparent;cursor:pointer;transition:.15s;white-space:nowrap;
}
.btn-primary{background:var(--primary);color:#fff}
.btn-primary:hover{background:var(--primary-600)}
.btn-outline{background:var(--surface);border-color:var(--border);color:var(--text)}
.btn-outline:hover{background:var(--surface-2)}
.btn-ghost{background:transparent;color:var(--muted);border-color:var(--border)}
.btn-ghost:hover{background:var(--surface-2);color:var(--text)}
.btn-danger{background:var(--danger);color:#fff}
.btn-danger:hover{filter:brightness(.92)}
.btn-block{width:100%}
.btn-sm{padding:6px 11px;font-size:12px}

.icon-btn{
  width:36px;height:36px;border-radius:var(--radius-sm);display:inline-grid;place-items:center;
  background:var(--surface);border:1px solid var(--border);color:var(--muted);cursor:pointer;transition:.15s;
}
.icon-btn:hover{background:var(--surface-2);color:var(--text)}
.icon-btn.sm{width:30px;height:30px}

/* ============ CARDS ============ */
.card{
  background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);
  box-shadow:var(--shadow);overflow:hidden;
}
.card-head{
  padding:15px 18px;border-bottom:1px solid var(--border);
  display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;
}
.card-head h3{font-size:14px;font-weight:700}
.card-head p{font-size:12px;color:var(--muted)}
.card-body{padding:18px}

/* ============ STAT GRID ============ */
.stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:16px;margin-bottom:20px}
.stat{
  background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);
  padding:18px;box-shadow:var(--shadow);position:relative;overflow:hidden;
}
.stat::after{
  content:"";position:absolute;top:0;left:0;width:4px;height:100%;background:var(--accent,var(--primary));
}
.stat-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px}
.stat-label{font-size:11px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--muted)}
.stat-icon{
  width:34px;height:34px;border-radius:9px;display:grid;place-items:center;
  background:color-mix(in srgb,var(--accent,var(--primary)) 13%, transparent);
  color:var(--accent,var(--primary));
}
.stat-value{font-size:27px;font-weight:800;letter-spacing:-.5px;line-height:1.1}
.stat-sub{font-size:11.5px;color:var(--muted);margin-top:5px}

/* ============ GRID ============ */
.grid-2{display:grid;grid-template-columns:1.6fr 1fr;gap:18px;margin-bottom:20px}
.grid-3{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:18px}
@media(max-width:1000px){.grid-2{grid-template-columns:1fr}}

/* ============ TABLE ============ */
.table-wrap{overflow-x:auto}
table.data{width:100%;border-collapse:collapse;text-align:left}
table.data th{
  background:var(--surface-2);padding:11px 14px;font-size:11px;font-weight:700;
  letter-spacing:.05em;text-transform:uppercase;color:var(--muted);
  border-bottom:1px solid var(--border);white-space:nowrap;
}
table.data td{padding:13px 14px;font-size:13px;border-bottom:1px solid var(--border);vertical-align:top}
table.data tbody tr:hover{background:var(--surface-2)}
table.data tbody tr:last-child td{border-bottom:none}

.cell-name{font-weight:600;font-size:13.5px}
.cell-sub{font-size:11.5px;color:var(--muted);display:flex;align-items:center;gap:5px;margin-top:3px}

.row-actions{display:flex;gap:6px}
.act{
  width:30px;height:30px;border-radius:var(--radius-sm);display:inline-grid;place-items:center;
  font-size:12px;transition:.15s;border:1px solid transparent;
}
.act.wa{background:rgba(16,185,129,.13);color:#059669}
.act.wa:hover{background:rgba(16,185,129,.25)}
.act.call{background:rgba(59,130,246,.13);color:#2563eb}
.act.call:hover{background:rgba(59,130,246,.25)}
.act.view{background:rgba(100,116,139,.13);color:var(--muted)}
.act.view:hover{background:rgba(100,116,139,.25)}
.act.edit{background:rgba(245,158,11,.13);color:#d97706}
.act.edit:hover{background:rgba(245,158,11,.25)}
.act.del{background:rgba(239,68,68,.13);color:#dc2626}
.act.del:hover{background:rgba(239,68,68,.25)}

/* ============ PILLS ============ */
.pill{
  display:inline-flex;align-items:center;gap:5px;padding:3px 9px;border-radius:999px;
  font-size:11px;font-weight:700;letter-spacing:.02em;
  background:color-mix(in srgb,var(--pill) 15%, transparent);color:var(--pill);
}
.pill-soft{background:color-mix(in srgb,var(--pill) 12%, transparent)}
.pill::before{content:"";width:5px;height:5px;border-radius:50%;background:var(--pill)}

/* ============ FORMS ============ */
.form-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:15px}
.form-grid .span-2{grid-column:1/-1}
@media(max-width:700px){.form-grid{grid-template-columns:1fr}}
.field{display:flex;flex-direction:column;gap:6px}
.field label{font-size:12px;font-weight:600;color:var(--muted)}
.field .req{color:var(--danger)}
.input,select.input,textarea.input{
  width:100%;padding:10px 12px;border:1px solid var(--border);border-radius:var(--radius-sm);
  background:var(--surface);font-size:13.5px;outline:none;transition:.15s;
}
.input:focus{border-color:var(--primary);box-shadow:0 0 0 3px color-mix(in srgb,var(--primary) 16%, transparent)}
textarea.input{resize:vertical;min-height:110px}
.hint{font-size:11px;color:var(--muted)}

.toolbar{
  display:flex;gap:10px;flex-wrap:wrap;align-items:center;
  padding:14px 18px;border-bottom:1px solid var(--border);background:var(--surface);
}
.toolbar .search{position:relative;flex:1;min-width:220px}
.toolbar .search .ico{position:absolute;left:11px;top:50%;transform:translateY(-50%);color:var(--muted)}
.toolbar .search input{padding-left:36px}
.toolbar select.input{width:auto;min-width:140px}

.bulkbar{
  display:none;align-items:center;gap:10px;padding:10px 18px;
  background:var(--primary-soft);border-bottom:1px solid var(--border);font-size:13px;flex-wrap:wrap;
}
.bulkbar.show{display:flex}

/* ============ PAGINATION ============ */
.pager{display:flex;gap:5px;justify-content:center;padding:16px;flex-wrap:wrap}
.pg{
  min-width:34px;height:34px;padding:0 10px;border-radius:var(--radius-sm);display:grid;place-items:center;
  font-size:13px;font-weight:600;border:1px solid var(--border);background:var(--surface);
}
.pg:hover{background:var(--surface-2)}
.pg-on{background:var(--primary);color:#fff;border-color:var(--primary)}
.pg-off{opacity:.5;border-color:transparent}

/* ============ TOAST ============ */
.toast-stack{position:fixed;top:18px;right:18px;z-index:200;display:flex;flex-direction:column;gap:9px}
.toast{
  display:flex;align-items:center;gap:10px;padding:12px 15px;border-radius:var(--radius-sm);
  background:var(--surface);border:1px solid var(--border);box-shadow:var(--shadow);
  font-size:13px;font-weight:500;min-width:260px;max-width:380px;
  border-left:4px solid var(--primary);animation:slideIn .25s ease;
}
.toast-success{border-left-color:var(--success)}
.toast-error{border-left-color:var(--danger)}
.toast-warning{border-left-color:var(--warning)}
.toast-x{margin-left:auto;background:none;border:none;cursor:pointer;color:var(--muted)}
@keyframes slideIn{from{opacity:0;transform:translateX(24px)}to{opacity:1;transform:none}}

/* ============ EMPTY ============ */
.empty{padding:60px 20px;text-align:center;color:var(--muted)}
.empty h4{font-size:15px;color:var(--text);margin:12px 0 5px}
.empty p{font-size:13px;margin-bottom:16px}

/* ============ DETAIL / TIMELINE ============ */
.detail-head{
  display:flex;gap:18px;align-items:flex-start;flex-wrap:wrap;padding:22px;
  border-bottom:1px solid var(--border);
}
.detail-avatar{
  width:62px;height:62px;border-radius:16px;display:grid;place-items:center;
  font-size:24px;font-weight:800;color:#fff;background:linear-gradient(135deg,var(--primary),#7c3aed);
}
.detail-head h2{font-size:20px;font-weight:700}
.detail-meta{display:flex;gap:16px;flex-wrap:wrap;margin-top:8px;font-size:12.5px;color:var(--muted)}
.detail-meta span{display:flex;align-items:center;gap:6px}

.kv{display:grid;grid-template-columns:130px 1fr;gap:10px 14px;font-size:13px}
.kv dt{color:var(--muted);font-weight:600;font-size:12px}
.kv dd{font-weight:500;word-break:break-word}

.timeline{position:relative;padding-left:24px}
.timeline::before{content:"";position:absolute;left:7px;top:6px;bottom:6px;width:2px;background:var(--border)}
.tl-item{position:relative;padding-bottom:18px}
.tl-item::before{
  content:"";position:absolute;left:-21px;top:5px;width:10px;height:10px;border-radius:50%;
  background:var(--primary);border:2px solid var(--surface);
}
.tl-item p{font-size:13px}
.tl-item time{font-size:11px;color:var(--muted)}

.note{
  background:var(--surface-2);border:1px solid var(--border);border-radius:var(--radius-sm);
  padding:12px 14px;margin-bottom:10px;
}
.note-head{display:flex;justify-content:space-between;gap:10px;font-size:12px;color:var(--muted);margin-bottom:6px}
.note-head strong{color:var(--text)}
.note p{font-size:13px;white-space:pre-wrap}

/* ============ LOGIN ============ */
.auth-wrap{
  min-height:100vh;display:grid;place-items:center;padding:24px;
  background:radial-gradient(1000px 500px at 10% 0%, color-mix(in srgb,var(--primary) 18%, transparent), transparent),
             radial-gradient(800px 500px at 100% 100%, color-mix(in srgb,#7c3aed 15%, transparent), transparent),
             var(--bg);
}
.auth-card{
  width:100%;max-width:410px;background:var(--surface);border:1px solid var(--border);
  border-radius:18px;box-shadow:var(--shadow);padding:34px 30px;
}
.auth-brand{display:flex;align-items:center;gap:11px;margin-bottom:22px}
.auth-card h1{font-size:21px;font-weight:800;margin-bottom:5px}
.auth-card > p{font-size:13px;color:var(--muted);margin-bottom:22px}
.auth-card .field{margin-bottom:14px}
.alert{
  padding:11px 14px;border-radius:var(--radius-sm);font-size:13px;margin-bottom:16px;
  background:rgba(239,68,68,.1);color:#b91c1c;border:1px solid rgba(239,68,68,.25);
}

/* ============ MISC ============ */
.overlay{display:none;position:fixed;inset:0;background:rgba(15,23,42,.5);z-index:55}
.overlay.show{display:block}
.only-mobile{display:none}
.app-foot{
  padding:18px 24px;border-top:1px solid var(--border);display:flex;justify-content:space-between;
  font-size:11.5px;color:var(--muted);flex-wrap:wrap;gap:8px;
}
.text-muted{color:var(--muted)}
.mb-0{margin-bottom:0}
.mt-16{margin-top:16px}
.flex{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.spacer{flex:1}

/* ============ RESPONSIVE ============ */
@media(max-width:900px){
  .sidebar{transform:translateX(-100%)}
  .sidebar.open{transform:none}
  .main{margin-left:0}
  .sidebar-close{display:grid}
  .only-mobile{display:inline-grid}
  .content{padding:16px}
  .topbar{padding:12px 16px}
  .topbar-title p{display:none}
  .detail-head{padding:16px}
}