/* =========================================================
   MINI CRM — Design tokens
   Palette: Ink Violet (brand) / Signal Amber (action) / Leaf (WhatsApp)
   Type: Sora (display) + Inter (body) + JetBrains Mono (data)
========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600&display=swap');

:root{
  --ink:        #14132B;   /* sidebar / dark surface */
  --ink-2:      #201F3E;
  --violet:     #3730A3;   /* brand primary */
  --violet-2:   #4F46E5;
  --violet-soft:#EEF0FF;
  --amber:      #F59E0B;   /* primary action / CTA */
  --amber-dark: #D97706;
  --leaf:       #22C55E;   /* whatsapp / success */
  --leaf-soft:  #E7F9EE;
  --red:        #EF4444;
  --red-soft:   #FDECEC;
  --blue-soft:  #E8F0FE;
  --purple-soft:#F3ECFE;

  --bg:         #F5F6FB;
  --surface:    #FFFFFF;
  --border:     #E7E8F1;
  --text:       #1D1B39;
  --text-dim:   #6B6B85;
  --text-faint: #9A9AB0;

  --radius-sm:  10px;
  --radius:     16px;
  --radius-lg:  22px;
  --shadow-sm:  0 1px 3px rgba(20,19,43,0.06);
  --shadow:     0 8px 24px rgba(20,19,43,0.08);
  --shadow-lg:  0 16px 40px rgba(20,19,43,0.14);

  --font-display: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --topbar-h: 64px;
  --sidebar-w: 236px;
  --bottomnav-h: 64px;
}

*{ box-sizing:border-box; }
html{ overflow-x:hidden; max-width:100%; }
html,body{ margin:0; padding:0; }
body{
  font-family:var(--font-body);
  background:var(--bg);
  color:var(--text);
  -webkit-font-smoothing:antialiased;
  overflow-x:hidden;
  max-width:100%;
}
h1,h2,h3,h4,.font-display{ font-family:var(--font-display); letter-spacing:-0.01em; }
a{ text-decoration:none; color:inherit; }
button{ font-family:var(--font-body); cursor:pointer; }
.mono{ font-family:var(--font-mono); }
::selection{ background:var(--violet); color:#fff; }

/* Scrollbar */
::-webkit-scrollbar{ width:6px; height:6px; }
::-webkit-scrollbar-thumb{ background:#D6D7E5; border-radius:10px; }

/* ---------------- Layout shell ---------------- */
.app-shell{ display:flex; min-height:100vh; }

.sidebar{
  width:var(--sidebar-w);
  background:linear-gradient(180deg,var(--ink) 0%, var(--ink-2) 100%);
  color:#fff;
  position:fixed; top:0; left:0; bottom:0;
  display:flex; flex-direction:column;
  padding:22px 16px;
  z-index:40;
}
.brand{ display:flex; align-items:center; gap:10px; padding:0 8px 24px; }
.brand-mark{
  width:36px; height:36px; border-radius:10px;
  background:linear-gradient(135deg,var(--amber),#FBBF24);
  display:flex; align-items:center; justify-content:center;
  font-family:var(--font-display); font-weight:800; color:var(--ink); font-size:16px;
}
.brand-name{ font-family:var(--font-display); font-weight:700; font-size:16px; color:#fff; }
.brand-sub{ font-size:11px; color:#8B89B3; margin-top:1px; }

.nav-group-label{ font-size:11px; text-transform:uppercase; letter-spacing:.08em; color:#7B7AA0; margin:16px 10px 8px; }

.nav-link{
  display:flex; align-items:center; gap:12px;
  padding:10px 12px; border-radius:12px; margin:2px 0;
  color:#C7C6E2; font-size:14px; font-weight:500;
  transition:background .15s, color .15s;
}
.nav-link svg{ width:19px; height:19px; flex-shrink:0; }
.nav-link:hover{ background:rgba(255,255,255,0.06); color:#fff; }
.nav-link.active{ background:rgba(245,158,11,0.14); color:var(--amber); }
.nav-link .nl-badge{ margin-left:auto; background:var(--amber); color:var(--ink); font-size:10px; font-weight:700; padding:1px 7px; border-radius:20px; }

.sidebar-foot{ margin-top:auto; }
.user-chip{ display:flex; align-items:center; gap:10px; padding:10px; border-radius:12px; background:rgba(255,255,255,0.05); }
.avatar{ width:34px; height:34px; border-radius:10px; background:var(--violet-2); display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; color:#fff; flex-shrink:0; }
.user-chip .un{ font-size:13px; font-weight:600; color:#fff; }
.user-chip .ur{ font-size:11px; color:#8B89B3; text-transform:capitalize; }

.main-area{ flex:1; margin-left:var(--sidebar-w); min-width:0; display:flex; flex-direction:column; }

.topbar{
  height:var(--topbar-h); position:sticky; top:0; z-index:30;
  background:rgba(245,246,251,0.85); backdrop-filter:blur(10px);
  display:flex; align-items:center; justify-content:space-between;
  padding:0 24px; border-bottom:1px solid var(--border);
}
.page-title{ font-size:19px; font-weight:700; font-family:var(--font-display); }
.page-sub{ font-size:12.5px; color:var(--text-dim); margin-top:1px; }
.topbar-actions{ display:flex; align-items:center; gap:10px; }

.content{ padding:22px 24px 100px; flex:1; }

/* ---------------- Buttons ---------------- */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  padding:10px 16px; border-radius:12px; border:none; font-size:13.5px; font-weight:600;
  transition:transform .1s, box-shadow .15s, background .15s; white-space:nowrap;
}
.btn:active{ transform:scale(0.97); }
.btn svg{ width:16px; height:16px; }
.btn-primary{ background:var(--amber); color:var(--ink); box-shadow:0 4px 14px rgba(245,158,11,0.35); }
.btn-primary:hover{ background:var(--amber-dark); }
.btn-dark{ background:var(--violet); color:#fff; }
.btn-dark:hover{ background:var(--violet-2); }
.btn-ghost{ background:var(--surface); color:var(--text); border:1px solid var(--border); }
.btn-ghost:hover{ background:#F0F1F8; }
.btn-leaf{ background:var(--leaf); color:#fff; }
.btn-danger{ background:var(--red-soft); color:var(--red); }
.btn-sm{ padding:7px 12px; font-size:12.5px; border-radius:10px; }
.btn-icon{ width:38px; height:38px; padding:0; border-radius:11px; }
.btn-block{ width:100%; }
.fab{
  position:fixed; right:20px; bottom:calc(var(--bottomnav-h) + 20px);
  width:56px; height:56px; border-radius:18px; background:var(--amber); color:var(--ink);
  display:flex; align-items:center; justify-content:center; box-shadow:0 10px 24px rgba(245,158,11,0.45);
  z-index:45; border:none;
}
@media(min-width:901px){ .fab{ display:none; } }

/* ---------------- Cards / stat tiles ---------------- */
.grid{ display:grid; gap:16px; }
.grid-4{ grid-template-columns:repeat(4,1fr); }
.grid-3{ grid-template-columns:repeat(3,1fr); }
.grid-2{ grid-template-columns:repeat(2,1fr); }
.dash-grid{ grid-template-columns:1.4fr 1fr; }
@media(max-width:1100px){ .grid-4{ grid-template-columns:repeat(2,1fr); } .grid-3{ grid-template-columns:repeat(2,1fr);} }
@media(max-width:900px){ .dash-grid{ grid-template-columns:1fr; } }
@media(max-width:640px){ .grid-4,.grid-3,.grid-2{ grid-template-columns:1fr 1fr; gap:10px; } }
@media(max-width:420px){ .grid-4{ grid-template-columns:1fr; } }

.card{ background:var(--surface); border-radius:var(--radius); border:1px solid var(--border); box-shadow:var(--shadow-sm); min-width:0; }
.card-pad{ padding:18px; }

.stat-tile{ background:var(--surface); border-radius:var(--radius); padding:16px 18px; border:1px solid var(--border); box-shadow:var(--shadow-sm); position:relative; overflow:hidden; min-width:0; }
.stat-tile .st-icon{ width:36px; height:36px; border-radius:10px; display:flex; align-items:center; justify-content:center; margin-bottom:12px; }
.stat-tile .st-icon svg{ width:18px; height:18px; }
.stat-tile .st-val{ font-family:var(--font-display); font-size:24px; font-weight:700; }
.stat-tile .st-label{ font-size:12px; color:var(--text-dim); margin-top:2px; }
.stat-tile .st-trend{ position:absolute; top:16px; right:16px; font-size:11px; font-weight:700; padding:3px 8px; border-radius:20px; font-family:var(--font-mono); }
.tone-violet{ background:var(--violet-soft); color:var(--violet); }
.tone-amber{ background:#FEF3E2; color:var(--amber-dark); }
.tone-leaf{ background:var(--leaf-soft); color:#15803D; }
.tone-red{ background:var(--red-soft); color:var(--red); }
.tone-blue{ background:var(--blue-soft); color:#1D4ED8; }

/* ---------------- Badges ---------------- */
.badge{ display:inline-flex; align-items:center; gap:5px; font-size:11px; font-weight:700; padding:4px 10px; border-radius:20px; white-space:nowrap; }
.badge-blue{ background:var(--blue-soft); color:#1D4ED8; }
.badge-amber{ background:#FEF3E2; color:var(--amber-dark); }
.badge-purple{ background:var(--purple-soft); color:#7C3AED; }
.badge-green{ background:var(--leaf-soft); color:#15803D; }
.badge-red{ background:var(--red-soft); color:var(--red); }
.badge-gray{ background:#F1F1F6; color:var(--text-dim); }
.dot{ width:6px; height:6px; border-radius:50%; background:currentColor; }

/* ---------------- Score ring (signature element) ---------------- */
.score-ring{ position:relative; width:38px; height:38px; }
.score-ring svg{ transform:rotate(-90deg); width:38px; height:38px; }
.score-ring circle{ fill:none; stroke-width:3.5; }
.score-ring .bg{ stroke:#EDEDF5; }
.score-ring .fg{ stroke:var(--leaf); stroke-linecap:round; transition:stroke-dashoffset .4s; }
.score-ring .val{ position:absolute; inset:0; display:flex; align-items:center; justify-content:center; font-size:10.5px; font-weight:700; font-family:var(--font-mono); }

/* ---------------- Data list — table on desktop, app-style cards on mobile ---------------- */
.data-table{ width:100%; border-collapse:collapse; }
.data-table th{ text-align:left; font-size:11px; text-transform:uppercase; letter-spacing:.05em; color:var(--text-faint); padding:12px 16px; border-bottom:1px solid var(--border); }
.data-table td{ padding:13px 16px; border-bottom:1px solid var(--border); font-size:13.5px; vertical-align:middle; }
.data-table tr:last-child td{ border-bottom:none; }
.data-table tr:hover td{ background:#FAFAFD; }
.row-name{ font-weight:600; }
.row-sub{ font-size:12px; color:var(--text-dim); }

/* Mobile: transform table rows into app-style swipe cards */
@media(max-width:800px){
  .data-table thead{ display:none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td{ display:block; width:100%; }
  .data-table tr{
    background:var(--surface); border:1px solid var(--border); border-radius:16px;
    margin-bottom:10px; padding:14px 14px; box-shadow:var(--shadow-sm);
  }
  .data-table td{ border:none; padding:3px 0; }
  .data-table td[data-label]:before{
    content:attr(data-label); display:block; font-size:10.5px; color:var(--text-faint);
    text-transform:uppercase; letter-spacing:.04em; margin-bottom:2px;
  }
  .mcard-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:4px; }
}

/* ---------------- App-style list rows (leads/appointments mobile) ---------------- */
.app-row{
  display:flex; align-items:center; gap:12px; background:var(--surface);
  border:1px solid var(--border); border-radius:16px; padding:13px 14px; margin-bottom:10px; box-shadow:var(--shadow-sm);
}
.app-row .ar-avatar{ width:42px; height:42px; border-radius:12px; background:var(--violet-soft); color:var(--violet); display:flex; align-items:center; justify-content:center; font-weight:700; flex-shrink:0; }
.app-row .ar-body{ flex:1; min-width:0; }
.app-row .ar-title{ font-weight:600; font-size:14px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.app-row .ar-sub{ font-size:12px; color:var(--text-dim); margin-top:1px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.app-row .ar-meta{ text-align:right; flex-shrink:0; }

/* ---------------- Forms ---------------- */
.form-group{ margin-bottom:16px; }
label{ display:block; font-size:12.5px; font-weight:600; color:var(--text-dim); margin-bottom:6px; }
input[type=text],input[type=email],input[type=password],input[type=number],input[type=date],input[type=time],input[type=tel],select,textarea{
  width:100%; padding:11px 13px; border-radius:11px; border:1.5px solid var(--border); background:var(--surface);
  font-size:14px; color:var(--text); font-family:var(--font-body); transition:border-color .15s;
}
input:focus,select:focus,textarea:focus{ outline:none; border-color:var(--violet-2); }
textarea{ resize:vertical; min-height:80px; }
.form-row{ display:grid; grid-template-columns:1fr 1fr; gap:14px; }
@media(max-width:600px){ .form-row{ grid-template-columns:1fr; } }
.help-text{ font-size:11.5px; color:var(--text-faint); margin-top:5px; }

/* ---------------- Kanban (Deals) ---------------- */
.kanban-wrap{ display:flex; gap:14px; overflow-x:auto; padding-bottom:14px; -webkit-overflow-scrolling:touch; }
.kanban-col{ flex:0 0 270px; background:#EFF0F7; border-radius:var(--radius); padding:12px; max-height:calc(100vh - 220px); display:flex; flex-direction:column; }
.kanban-col-head{ display:flex; align-items:center; gap:8px; padding:4px 6px 12px; }
.kanban-col-head .stage-dot{ width:9px; height:9px; border-radius:50%; }
.kanban-col-head .stage-name{ font-weight:700; font-size:13.5px; flex:1; }
.kanban-col-head .stage-count{ font-size:11px; background:#fff; padding:2px 8px; border-radius:20px; font-weight:700; color:var(--text-dim); }
.kanban-list{ overflow-y:auto; flex:1; display:flex; flex-direction:column; gap:10px; }
.deal-card{ background:var(--surface); border-radius:14px; padding:12px; box-shadow:var(--shadow-sm); border:1px solid var(--border); cursor:grab; }
.deal-card:active{ cursor:grabbing; }
.deal-card .dc-title{ font-weight:600; font-size:13.5px; margin-bottom:4px; }
.deal-card .dc-lead{ font-size:12px; color:var(--text-dim); margin-bottom:8px; }
.deal-card .dc-foot{ display:flex; align-items:center; justify-content:space-between; }
.deal-card .dc-value{ font-family:var(--font-mono); font-weight:700; font-size:13px; color:var(--violet); }
.kanban-col.drag-over{ background:#E3E5F5; }
.deal-card.dragging{ opacity:.4; }

/* ---------------- Chat (WhatsApp) ---------------- */
.chat-wrap{ display:flex; height:calc(100vh - var(--topbar-h) - 20px); border-radius:var(--radius); overflow:hidden; border:1px solid var(--border); background:var(--surface); }
.chat-list{ width:300px; border-right:1px solid var(--border); overflow-y:auto; flex-shrink:0; }
.chat-list-item{ display:flex; gap:10px; padding:12px 14px; border-bottom:1px solid var(--border); }
.chat-list-item.active{ background:var(--violet-soft); }
.chat-main{ flex:1; display:flex; flex-direction:column; min-width:0; }
.chat-header{ padding:14px 18px; border-bottom:1px solid var(--border); display:flex; align-items:center; gap:12px; }
.chat-body{ flex:1; overflow-y:auto; padding:18px; background:#EDEEF6 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3C/svg%3E"); display:flex; flex-direction:column; gap:8px; }
.bubble{ max-width:70%; padding:9px 13px; border-radius:14px; font-size:13.5px; line-height:1.45; position:relative; }
.bubble.out{ align-self:flex-end; background:var(--leaf-soft); border-bottom-right-radius:3px; }
.bubble.in{ align-self:flex-start; background:#fff; border-bottom-left-radius:3px; box-shadow:var(--shadow-sm); }
.bubble .b-time{ font-size:10px; color:var(--text-faint); margin-top:4px; text-align:right; }
.chat-input{ padding:12px 16px; border-top:1px solid var(--border); display:flex; gap:10px; }
@media(max-width:800px){ .chat-list{ display:none; } }

/* ---------------- Calendar ---------------- */
.cal-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; }
.cal-grid{ display:grid; grid-template-columns:repeat(7,1fr); gap:6px; }
.cal-dow{ text-align:center; font-size:11px; font-weight:700; color:var(--text-faint); padding:6px 0; }
.cal-cell{ background:var(--surface); border:1px solid var(--border); border-radius:12px; min-height:88px; padding:7px; position:relative; }
.cal-cell.empty{ background:transparent; border:none; }
.cal-cell.today{ border-color:var(--amber); box-shadow:0 0 0 2px rgba(245,158,11,0.25); }
.cal-daynum{ font-size:12px; font-weight:700; }
.cal-evt{ font-size:10px; margin-top:4px; padding:2px 6px; border-radius:6px; background:var(--violet-soft); color:var(--violet); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
@media(max-width:700px){ .cal-cell{ min-height:60px; } .cal-evt{ display:none; } .cal-cell.has-evt:after{ content:''; position:absolute; bottom:6px; left:50%; transform:translateX(-50%); width:5px; height:5px; border-radius:50%; background:var(--amber); } }

/* ---------------- Bottom nav (mobile app feel) ---------------- */
.bottom-nav{
  display:none; position:fixed; left:0; right:0; bottom:0; height:var(--bottomnav-h);
  background:rgba(255,255,255,0.96); backdrop-filter:blur(10px); border-top:1px solid var(--border);
  z-index:50; align-items:center; justify-content:space-around; padding-bottom:env(safe-area-inset-bottom);
}
.bn-item{ display:flex; flex-direction:column; align-items:center; gap:3px; color:var(--text-faint); font-size:10px; font-weight:600; flex:1; padding:6px 0; }
.bn-item svg{ width:21px; height:21px; }
.bn-item.active{ color:var(--violet); }
.bn-item.active svg{ stroke:var(--violet); }

/* ---------------- Toast / Confirm popups (custom, no browser alerts) ---------------- */
#toastHost{ position:fixed; top:16px; right:16px; z-index:9999; display:flex; flex-direction:column; gap:10px; }
.toast{ min-width:240px; max-width:320px; background:var(--ink); color:#fff; padding:13px 16px; border-radius:13px; font-size:13px; box-shadow:var(--shadow-lg); display:flex; align-items:center; gap:10px; animation:slideIn .25s ease; }
.toast.success{ border-left:4px solid var(--leaf); }
.toast.error{ border-left:4px solid var(--red); }
.toast.info{ border-left:4px solid var(--violet-2); }
@keyframes slideIn{ from{ transform:translateX(30px); opacity:0; } to{ transform:translateX(0); opacity:1; } }

.modal-overlay{ position:fixed; inset:0; background:rgba(20,19,43,0.5); backdrop-filter:blur(2px); z-index:200; display:none; align-items:center; justify-content:center; padding:20px; }
.modal-overlay.show{ display:flex; }
.modal-box{ background:var(--surface); border-radius:var(--radius-lg); max-width:460px; width:100%; padding:24px; box-shadow:var(--shadow-lg); animation:popIn .18s ease; max-height:88vh; overflow-y:auto; }
.modal-box.modal-lg{ max-width:640px; }
@keyframes popIn{ from{ transform:scale(.95); opacity:0; } to{ transform:scale(1); opacity:1; } }
.modal-title{ font-family:var(--font-display); font-size:17px; font-weight:700; margin-bottom:4px; }
.modal-actions{ display:flex; gap:10px; justify-content:flex-end; margin-top:20px; }

/* ---------------- Auth screens ---------------- */
.auth-wrap{ min-height:100vh; display:flex; align-items:center; justify-content:center; background:linear-gradient(160deg,var(--ink) 0%, var(--violet) 130%); padding:20px; }
.auth-card{ background:var(--surface); border-radius:var(--radius-lg); padding:36px 32px; width:100%; max-width:380px; box-shadow:var(--shadow-lg); }

/* ---------------- Misc ---------------- */
.section-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; flex-wrap:wrap; gap:10px; }
.filters{ display:flex; gap:8px; flex-wrap:wrap; }
.chip-select{ padding:8px 12px; border-radius:10px; border:1.5px solid var(--border); background:var(--surface); font-size:12.5px; font-weight:600; }
.empty-state{ text-align:center; padding:50px 20px; color:var(--text-dim); }
.empty-state svg{ width:52px; height:52px; color:var(--text-faint); margin-bottom:12px; }
.progress-bar{ height:6px; background:#EDEDF5; border-radius:6px; overflow:hidden; }
.progress-bar > div{ height:100%; background:var(--leaf); }
.tab-strip{ display:flex; gap:4px; background:#EFF0F7; padding:4px; border-radius:12px; margin-bottom:16px; width:fit-content; }
.tab-btn{ padding:8px 16px; border-radius:9px; font-size:13px; font-weight:600; color:var(--text-dim); border:none; background:transparent; }
.tab-btn.active{ background:var(--surface); color:var(--text); box-shadow:var(--shadow-sm); }

/* ---------------- Responsive shell switching ---------------- */
@media(max-width:900px){
  .sidebar{ display:none; }
  .main-area{ margin-left:0; }
  .bottom-nav{ display:flex; }
  .content{ padding:16px 14px 90px; }
  .topbar{ padding:0 16px; }
  .grid-4, .grid-3{ grid-template-columns:1fr 1fr; }
  .kanban-col{ flex:0 0 82vw; }
}
@media(min-width:901px){
  .mobile-only{ display:none !important; }
}
@media(max-width:900px){
  .desktop-only{ display:none !important; }
}
