/* ============================================================
   CRM Pro v2.2 — Stylesheet | assets/css/style.css
   Mobile-first, Fully Responsive
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

/* Font face fallback — agar Google Fonts load na ho */
:root {
  --font: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system,
          BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
}

:root {
  --primary:    #2563eb;
  --primary-lt: #eff6ff;
  --primary-dk: #1d4ed8;
  --success:    #16a34a;
  --success-lt: #f0fdf4;
  --danger:     #dc2626;
  --danger-lt:  #fef2f2;
  --warning:    #d97706;
  --warning-lt: #fffbeb;
  --purple:     #7c3aed;
  --purple-lt:  #f5f3ff;
  --text:       #1e293b;
  --text2:      #64748b;
  --text3:      #94a3b8;
  --border:     #e2e8f0;
  --border2:    #cbd5e1;
  --bg:         #f8fafc;
  --white:      #ffffff;
  --sidebar-w:  260px;
  --topbar-h:   56px;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,.08);
  --shadow-lg:  0 10px 30px rgba(0,0,0,.1);
  --bottom-nav-h: 60px;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 10px; }

/* ===== AUTH PAGE ===== */
.auth-body {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eff6ff 0%, #f8f4ff 50%, #f0fdf4 100%);
  padding: 16px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--white);
  border-radius: 20px;
  padding: 32px 24px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.auth-logo-wrap { text-align: center; margin-bottom: 24px; }
.auth-logo-icon {
  width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: #fff; margin: 0 auto 12px;
  box-shadow: 0 8px 20px rgba(37,99,235,.3);
}
.auth-logo-wrap h1 { font-size: 22px; font-weight: 800; }
.auth-logo-wrap p  { font-size: 13px; color: var(--text2); margin-top: 4px; }

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 1000;
  overflow-y: auto; overflow-x: hidden;
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  box-shadow: var(--shadow-md);
  -webkit-overflow-scrolling: touch;
}
.sb-brand {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  min-height: var(--topbar-h);
  flex-shrink: 0;
}
.sb-brand-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: #fff; flex-shrink: 0;
}
.sb-brand-name { font-size: 15px; font-weight: 800; }
.sb-brand-sub  { font-size: 10px; color: var(--text2); }
.sb-section    { padding: 14px 16px 5px; font-size: 10px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: 1.2px; }
.sb-link {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 14px; margin: 1px 8px;
  border-radius: var(--radius-sm);
  color: var(--text2); font-size: 13px; font-weight: 600;
  text-decoration: none; transition: .15s; position: relative;
  -webkit-tap-highlight-color: transparent;
  min-height: 42px;
}
.sb-link:hover, .sb-link.active { background: var(--primary-lt); color: var(--primary); }
.sb-link.active::before {
  content: ''; position: absolute; left: -8px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; background: var(--primary); border-radius: 0 3px 3px 0;
}
.sb-icon { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }
.sb-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 10px; min-width: 20px; text-align: center; }
.sb-footer { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); flex-shrink: 0; }
.sb-user {
  display: flex; align-items: center; gap: 9px;
  padding: 10px; background: var(--bg); border-radius: var(--radius-sm);
}
.sb-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; color: #fff; flex-shrink: 0;
}
.sb-uname { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-urole { font-size: 11px; color: var(--text2); }

/* ===== OVERLAY ===== */
.sb-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 999; }
.sb-overlay.show { display: block; }

/* ===== TOPBAR ===== */
.topbar {
  position: fixed; top: 0; left: var(--sidebar-w); right: 0;
  height: var(--topbar-h);
  background: var(--white); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px;
  z-index: 900; gap: 10px;
  box-shadow: var(--shadow);
}
.tb-menu-btn {
  display: none; background: none; border: none;
  font-size: 22px; color: var(--text); cursor: pointer;
  padding: 6px 8px; border-radius: var(--radius-sm);
  flex-shrink: 0; -webkit-tap-highlight-color: transparent;
}
.tb-title { font-size: 15px; font-weight: 700; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tb-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.ib {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; cursor: pointer; text-decoration: none; color: var(--text);
  position: relative; transition: .15s; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.ib:hover  { background: var(--primary-lt); color: var(--primary); }
.ib .dot   { position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; background: var(--danger); border-radius: 50%; border: 2px solid #fff; }

/* ===== MAIN CONTENT ===== */
.main-wrap  { margin-left: var(--sidebar-w); padding-top: var(--topbar-h); min-height: 100vh; }
.page-inner { padding: 20px 22px 24px; }

/* ===== PAGE HEADER ===== */
.ph { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; gap: 10px; flex-wrap: wrap; }
.ph-title { font-size: 18px; font-weight: 800; line-height: 1.3; }
.ph-sub   { font-size: 12px; color: var(--text2); margin-top: 3px; }

/* ===== STAT CARDS ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; align-items: flex-start; gap: 12px;
  box-shadow: var(--shadow); transition: .2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-icon {
  width: 42px; height: 42px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; flex-shrink: 0;
}
.si-blue   { background: var(--primary-lt); color: var(--primary); }
.si-green  { background: var(--success-lt); color: var(--success); }
.si-red    { background: var(--danger-lt);  color: var(--danger);  }
.si-yellow { background: var(--warning-lt); color: var(--warning); }
.si-purple { background: var(--purple-lt);  color: var(--purple);  }
.stat-val  { font-size: 22px; font-weight: 800; line-height: 1; }
.stat-lbl  { font-size: 11px; color: var(--text2); margin-top: 4px; font-weight: 600; }

/* ===== CARD ===== */
.card2 { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card2-header {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 13px; gap: 8px; flex-wrap: wrap;
}
.card2-body { padding: 14px 16px; }
.p-3 { padding: 12px !important; }

/* ===== TABLE ===== */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 400px; }
.tbl th {
  background: var(--bg); padding: 9px 12px;
  font-size: 10px; font-weight: 800; color: var(--text2);
  text-transform: uppercase; letter-spacing: .6px;
  border-bottom: 2px solid var(--border); white-space: nowrap; text-align: left;
}
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); color: var(--text2); vertical-align: middle; }
.tbl td strong { color: var(--text); }
.tbl tr:hover td { background: #f8fafe; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* ===== BADGES ===== */
.bx { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.bx-blue   { background: var(--primary-lt); color: var(--primary); }
.bx-green  { background: var(--success-lt); color: var(--success); }
.bx-red    { background: var(--danger-lt);  color: var(--danger);  }
.bx-yellow { background: var(--warning-lt); color: var(--warning); }
.bx-gray   { background: #f1f5f9;           color: var(--text2);   }
.bx-purple { background: var(--purple-lt);  color: var(--purple);  }

/* ===== FORMS ===== */
.form-label { font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; display: block; margin-bottom: 5px; }
.form-control, .form-select {
  width: 100%; padding: 10px 13px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--white); transition: .15s; outline: none;
  -webkit-appearance: none; appearance: none;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M6 8L0 0h12z' fill='%2364748b'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; cursor: pointer; }
.input-group { display: flex; }
.input-group .igt {
  padding: 10px 12px; background: var(--bg); border: 2px solid var(--border);
  border-right: none; border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  color: var(--text2); font-size: 15px; display: flex; align-items: center; flex-shrink: 0;
}
.input-group .form-control { border-radius: 0; flex: 1; }
.input-group .igt-end {
  padding: 10px 12px; background: var(--bg); border: 2px solid var(--border);
  border-left: none; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text2); font-size: 15px; display: flex; align-items: center; cursor: pointer; flex-shrink: 0;
}
.input-group .igt-end:hover { color: var(--primary); }
.input-group > .form-control:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ===== BUTTONS ===== */
.btn {
  font-family: inherit; font-weight: 600; border-radius: var(--radius-sm);
  transition: .15s; cursor: pointer; display: inline-flex; align-items: center;
  gap: 6px; border: none; padding: 9px 16px; font-size: 13px; text-decoration: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary         { background: var(--primary);  color: #fff; }
.btn-primary:hover   { background: var(--primary-dk); color: #fff; }
.btn-success         { background: var(--success);  color: #fff; }
.btn-success:hover   { background: #15803d; color: #fff; }
.btn-danger          { background: var(--danger);   color: #fff; }
.btn-danger:hover    { background: #b91c1c; color: #fff; }
.btn-outline         { background: transparent; border: 2px solid var(--border); color: var(--text2); }
.btn-outline:hover   { border-color: var(--primary); color: var(--primary); background: var(--primary-lt); }
.btn-outline-primary { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); color: #fff; }
.btn-outline-danger  { background: transparent; border: 2px solid var(--danger);  color: var(--danger); }
.btn-outline-danger:hover  { background: var(--danger);  color: #fff; }
.btn-outline-success { background: transparent; border: 2px solid var(--success); color: var(--success); }
.btn-outline-success:hover { background: var(--success); color: #fff; }
.btn-sm   { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg   { padding: 12px 24px; font-size: 15px; }
.btn-full { width: 100%; justify-content: center; }

/* ===== MODAL ===== */
.modal-content { border-radius: 16px; border: none; box-shadow: var(--shadow-lg); }
.modal-header  { border-bottom: 1px solid var(--border); padding: 14px 18px; }
.modal-title   { font-size: 15px; font-weight: 800; }
.modal-footer  { border-top: 1px solid var(--border); padding: 12px 18px; }
.modal-body    { padding: 16px 18px; }

/* ===== FOLLOW-UP CARDS ===== */
.fu-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--white); transition: .15s; }
.fu-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.fu-card.fu-today   { border-left: 3px solid var(--primary); background: var(--primary-lt); }
.fu-card.fu-overdue { border-left: 3px solid var(--danger);  background: var(--danger-lt);  }
.fu-name { font-weight: 700; font-size: 14px; }
.fu-meta { font-size: 12px; color: var(--text2); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ===== TOAST ===== */
#toast-wrap { position: fixed; top: 66px; right: 14px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; max-width: 300px; }
.toast-item {
  background: var(--white); border-radius: var(--radius);
  padding: 11px 14px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; font-weight: 500;
  border-left: 4px solid var(--primary);
  animation: toastIn .25s ease; pointer-events: all;
}
.toast-item.s { border-color: var(--success); }
.toast-item.e { border-color: var(--danger);  }
.toast-item.w { border-color: var(--warning); }
@keyframes toastIn { from { opacity:0; transform: translateX(40px); } to { opacity:1; transform: translateX(0); } }

/* ===== EMPTY STATE ===== */
.empty-st { text-align: center; padding: 40px 16px; }
.empty-st i { font-size: 48px; color: var(--border2); margin-bottom: 12px; display: block; }
.empty-st h5 { font-size: 15px; font-weight: 700; color: var(--text2); }
.empty-st p  { font-size: 13px; color: var(--text3); margin-top: 4px; }

/* ===== GRIDS ===== */
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.g3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ===== INSTALL BAR ===== */
#install-bar {
  display: none; position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff;
  padding: 11px 18px; border-radius: 50px; font-size: 13px; font-weight: 700;
  box-shadow: 0 8px 28px rgba(37,99,235,.4); z-index: 9990;
  align-items: center; gap: 10px; white-space: nowrap;
}
#install-bar.on { display: flex; }
#install-bar button {
  background: rgba(255,255,255,.25); border: none; color: #fff;
  padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; cursor: pointer;
}

/* ===== MISC ===== */
input[type="date"], input[type="datetime-local"], input[type="time"] { color-scheme: light; }
.overdue-row td { background: #fff5f5 !important; }
a { color: var(--primary); }
.text-primary { color: var(--primary) !important; }
.text-danger  { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-muted   { color: var(--text2) !important; }
.text-warning { color: var(--warning) !important; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.me-1 { margin-right: 4px; }
.me-2 { margin-right: 8px; }
.ms-1 { margin-left: 4px; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ====================================================
   RESPONSIVE — MOBILE FIRST
   ==================================================== */

/* Tablet + Mobile (< 900px) */
@media (max-width: 900px) {
  /* Sidebar — slide in from left */
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }

  /* Topbar full width */
  .topbar { left: 0; padding: 0 12px; }
  .tb-menu-btn { display: flex; align-items: center; justify-content: center; }

  /* Main content — no sidebar offset */
  .main-wrap { margin-left: 0; }
  .page-inner { padding: 14px 12px 24px; } /* no bottom nav = no extra bottom padding */

  /* Stats — 2 columns */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 12px 13px; gap: 10px; }
  .stat-icon { width: 38px; height: 38px; font-size: 17px; }
  .stat-val  { font-size: 20px; }

  /* Grids — single column */
  .g2, .g3 { grid-template-columns: 1fr; }

  /* Dashboard grid */
  div[style*="grid-template-columns:3fr 2fr"],
  div[style*="grid-template-columns: 3fr 2fr"] {
    display: block !important;
  }
  div[style*="grid-template-columns:3fr 2fr"] > div + div,
  div[style*="grid-template-columns: 3fr 2fr"] > div + div {
    margin-top: 14px;
  }

  /* Module count grid */
  div[style*="grid-template-columns:repeat(auto-fill,minmax(140px"] {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
  }

  /* Toast */
  #toast-wrap { right: 10px; left: 10px; max-width: none; }
  .toast-item { max-width: 100%; }

  /* Modal */
  .modal-dialog { margin: 10px; }
  .modal-content { border-radius: 14px; }

  /* Table */
  .tbl-wrap { border-radius: 0; margin: 0 -12px; }

  /* Card header */
  .card2-header { flex-wrap: wrap; gap: 8px; }

  /* PH */
  .ph { gap: 8px; }

  /* Action buttons — compact on mobile */
  .act-btn { width: 32px !important; height: 32px !important; font-size: 13px !important; }
  .actions { gap: 4px !important; flex-wrap: nowrap !important; }
}

/* Mobile only (< 640px) */
@media (max-width: 640px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-val { font-size: 18px; }
  .stat-lbl { font-size: 10px; }

  .ph-title { font-size: 16px; }
  .ph .btn  { font-size: 12px; padding: 7px 12px; }

  /* Auth */
  .auth-card { padding: 24px 18px; border-radius: 16px; }

  /* Table — hide less important columns on small screens */
  .tbl th:nth-child(n+5), .tbl td:nth-child(n+5) { display: none; }

  /* crm-tbl — show only key columns on mobile */
  .crm-tbl th:nth-child(n+5), .crm-tbl td:nth-child(n+5) { display: none; }
  .crm-tbl th:last-child, .crm-tbl td:last-child { display: table-cell; }

  /* Follow-up cards grid */
  div[style*="grid-template-columns:repeat(auto-fill,minmax(300px"],
  div[style*="grid-template-columns:repeat(auto-fill,minmax(280px"] {
    grid-template-columns: 1fr !important;
  }

  /* Role cards in employees */
  .role-selector { grid-template-columns: 1fr !important; }

  /* Module builder grid */
  div[style*="grid-template-columns:repeat(auto-fill,minmax(180px"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Page inner padding — no bottom nav */
  .page-inner { padding: 12px 10px 20px; }

  /* Buttons */
  .btn-sm { padding: 5px 9px; font-size: 11px; }
  .act-btn { width: 30px !important; height: 30px !important; font-size: 12px !important; }

  /* Modal full screen on small mobile */
  .modal-dialog { margin: 0; max-width: 100%; }
  .modal-content { border-radius: 0; min-height: 100vh; }
  .modal-dialog-centered { align-items: flex-end; }
  .modal-dialog-centered .modal-content { border-radius: 16px 16px 0 0; min-height: auto; }

  /* Toast */
  #toast-wrap { top: auto; bottom: 80px; right: 8px; left: 8px; }

  /* Cards */
  .card2-body { padding: 12px; }
  .card2-header { padding: 10px 12px; }
}

/* Very small (< 375px) */
@media (max-width: 375px) {
  .stat-grid { gap: 6px; }
  .stat-card { padding: 10px; gap: 8px; }
  .stat-icon { width: 34px; height: 34px; font-size: 15px; }
  .stat-val { font-size: 17px; }
  .page-inner { padding: 10px 8px 80px; }
}

/* Bottom nav removed — sidebar hamburger menu use karo */

@media (max-width: 900px) {
  /* sidebar toggle on mobile */
}

/* Desktop (>= 900px) */
@media (min-width: 901px) {
  .tb-menu-btn { display: none !important; }
}