/* ============================================================
   RE-CRM Pro — Main Stylesheet v3
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; }

:root {
    --sidebar-w: 268px;
    --sidebar-bg: #0f1623;
    --sidebar-bg2: #141e2d;
    --sidebar-border: rgba(255,255,255,0.07);
    --sidebar-text: #9ab0c8;
    --sidebar-active-bg: linear-gradient(90deg, rgba(59,130,246,.18) 0%, rgba(59,130,246,.05) 100%);
    --sidebar-active-color: #60a5fa;
    --sidebar-active-border: #3b82f6;
    --sidebar-section: rgba(148,163,184,.5);
    --topbar-h: 64px;
    --primary: #3b82f6;
    --primary-dark: #1d4ed8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --font: 'Prompt', 'Sarabun', 'Segoe UI', sans-serif;
    --card-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

body {
    font-family: var(--font);
    font-size: 0.9rem;
    background: #f1f5f9;
    color: #1e293b;
    margin: 0;
    line-height: 1.6;
}

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

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

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1040;
    transition: transform var(--transition);
    overflow: hidden;
    border-right: 1px solid var(--sidebar-border);
}

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
.brand-icon { font-size: 28px; line-height: 1; }
.brand-name { font-size: 1rem; font-weight: 700; color: #f1f5f9; letter-spacing: .5px; }
.brand-sub  { font-size: 0.72rem; color: var(--sidebar-section); }
.btn-sidebar-close { background: none; border: none; color: var(--sidebar-text); font-size: 1.1rem; padding: 4px; cursor: pointer; margin-left: auto; }

/* Search */
.sidebar-search {
    padding: 10px 12px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
.sidebar-search .form-control::placeholder { color: rgba(148,163,184,.6); font-size: 0.82rem; }
.sidebar-search .form-control { color: #e2e8f0; font-size: 0.82rem; }

/* Nav */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

.nav-section {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--sidebar-section);
    padding: 14px 18px 4px;
}

.sidebar-menu {
    list-style: none;
    margin: 0;
    padding: 0 8px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 400;
    transition: all var(--transition);
    margin-bottom: 2px;
    border-left: 3px solid transparent;
}
.sidebar-link i { font-size: 1rem; flex-shrink: 0; width: 18px; }
.sidebar-link:hover { background: rgba(255,255,255,.07); color: #e2e8f0; }
.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-color);
    border-left-color: var(--sidebar-active-border);
    font-weight: 500;
}
.sidebar-toggle .toggle-icon { font-size: .7rem; margin-left: auto; transition: transform var(--transition); }
.sidebar-toggle:not(.collapsed) .toggle-icon { transform: rotate(-180deg); }

.sidebar-submenu {
    list-style: none;
    margin: 0;
    padding: 0 0 4px 16px;
}
.sidebar-sublink {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    color: rgba(148,163,184,.9);
    text-decoration: none;
    font-size: 0.82rem;
    margin-bottom: 1px;
    transition: all var(--transition);
}
.sidebar-sublink i { font-size: .85rem; width: 16px; }
.sidebar-sublink:hover { background: rgba(255,255,255,.06); color: #cbd5e1; }
.sidebar-sublink.active { color: var(--sidebar-active-color); background: rgba(59,130,246,.1); }

/* User Footer */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid var(--sidebar-border);
    background: var(--sidebar-bg2);
    flex-shrink: 0;
}
.user-avatar-sm {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 700; font-size: .9rem;
    flex-shrink: 0;
}
.user-name-sm { font-size: .82rem; color: #e2e8f0; font-weight: 500; }
.user-role-sm { font-size: .68rem; color: var(--sidebar-section); }
.btn-logout-sm {
    margin-left: auto;
    color: rgba(148,163,184,.7);
    font-size: 1.1rem;
    text-decoration: none;
    transition: color var(--transition);
    padding: 4px;
}
.btn-logout-sm:hover { color: var(--danger); }

/* Overlay */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1039;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
    height: var(--topbar-h);
    background: white;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 999;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    flex-shrink: 0;
}
.topbar-title { font-size: 1.05rem; font-weight: 600; color: #1e293b; }
.topbar-subtitle { font-size: 0.78rem; color: #64748b; }
.btn-toggle-sidebar {
    background: none; border: none;
    font-size: 1.3rem; color: #64748b;
    cursor: pointer; padding: 6px; border-radius: 8px;
    transition: background var(--transition);
}
.btn-toggle-sidebar:hover { background: #f1f5f9; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-btn {
    background: none; border: none;
    color: #64748b; font-size: 1.1rem;
    cursor: pointer; padding: 8px; border-radius: 8px;
    position: relative; transition: background var(--transition);
}
.topbar-btn:hover { background: #f1f5f9; color: #1e293b; }
.notif-badge {
    position: absolute; top: 4px; right: 4px;
    width: 16px; height: 16px;
    background: var(--danger); color: white;
    border-radius: 50%; font-size: .6rem;
    display: flex; align-items: center; justify-content: center;
}
.breadcrumb { font-size: 0.78rem; margin: 0; }
.breadcrumb-item + .breadcrumb-item::before { color: #94a3b8; }

/* ============================================================
   PAGE CONTENT
   ============================================================ */
.page-content {
    flex: 1;
    padding: 24px;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-title { font-size: 1.4rem; font-weight: 700; color: #1e293b; margin: 0; }
.page-subtitle { font-size: 0.82rem; color: #64748b; margin: 0; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    background: white;
}
.card-header {
    background: none;
    border-bottom: 1px solid #f1f5f9;
    padding: 16px 20px;
    font-weight: 600;
    border-radius: var(--radius) var(--radius) 0 0 !important;
    display: flex; align-items: center; gap: 8px;
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--card-shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform var(--transition), box-shadow var(--transition);
    text-decoration: none;
    color: inherit;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.1); color: inherit; }
.stat-icon {
    width: 56px; height: 56px;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; flex-shrink: 0;
}
.stat-icon.blue   { background: rgba(59,130,246,.12);  color: #3b82f6; }
.stat-icon.green  { background: rgba(34,197,94,.12);   color: #22c55e; }
.stat-icon.orange { background: rgba(245,158,11,.12);  color: #f59e0b; }
.stat-icon.red    { background: rgba(239,68,68,.12);   color: #ef4444; }
.stat-icon.purple { background: rgba(139,92,246,.12);  color: #8b5cf6; }
.stat-icon.teal   { background: rgba(20,184,166,.12);  color: #14b8a6; }
.stat-icon.pink   { background: rgba(236,72,153,.12);  color: #ec4899; }
.stat-icon.indigo { background: rgba(99,102,241,.12);  color: #6366f1; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: #1e293b; line-height: 1; }
.stat-label { font-size: 0.78rem; color: #64748b; margin-top: 2px; }
.stat-change { font-size: 0.72rem; color: #22c55e; }
.stat-change.down { color: var(--danger); }

/* ============================================================
   TABLE
   ============================================================ */
.table-card { border-radius: var(--radius); overflow: hidden; box-shadow: var(--card-shadow); }
.table { margin: 0; font-size: .875rem; }
.table thead th {
    background: #f8fafc;
    color: #475569;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 2px solid #e2e8f0;
    padding: 12px 16px;
    white-space: nowrap;
}
.table td { padding: 12px 16px; vertical-align: middle; border-color: #f1f5f9; }
.table tbody tr:hover { background: #fafbfc; }
.table-actions { display: flex; gap: 4px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-label { font-weight: 500; color: #374151; margin-bottom: 4px; font-size: .875rem; }
.form-control, .form-select {
    border-color: #e2e8f0;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-section {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.form-section-title {
    font-weight: 600; font-size: .875rem; color: #3b82f6;
    margin-bottom: 16px; display: flex; align-items: center; gap: 6px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn { border-radius: var(--radius-sm); font-size: .875rem; font-weight: 500; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

/* ============================================================
   BADGES & STATUS
   ============================================================ */
.badge { font-size: .72rem; padding: 4px 8px; border-radius: 6px; font-weight: 500; }

/* ============================================================
   PIPELINE / KANBAN
   ============================================================ */
.pipeline-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.pipeline-col {
    min-width: 230px; width: 230px;
    background: #f8fafc;
    border-radius: var(--radius);
    padding: 12px;
    flex-shrink: 0;
}
.pipeline-col-header {
    font-weight: 600; font-size: .82rem;
    padding: 8px 12px; border-radius: 8px;
    margin-bottom: 8px;
    display: flex; align-items: center; justify-content: space-between;
}
.pipeline-card {
    background: white;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    cursor: pointer;
    transition: box-shadow var(--transition);
}
.pipeline-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.12); }

/* ============================================================
   MATRIX TABLE (Unit Status)
   ============================================================ */
.matrix-table { border-collapse: separate; border-spacing: 4px; }
.matrix-cell {
    width: 70px; height: 52px;
    border-radius: 8px;
    text-align: center; vertical-align: middle;
    font-size: .72rem; font-weight: 600;
    cursor: pointer; transition: transform .15s, opacity .15s;
    border: 2px solid transparent;
}
.matrix-cell:hover { transform: scale(1.05); }
.matrix-cell.available  { background: rgba(34,197,94,.15); color: #15803d; border-color: #22c55e; }
.matrix-cell.reserved   { background: rgba(245,158,11,.15); color: #92400e; border-color: #f59e0b; }
.matrix-cell.booked     { background: rgba(59,130,246,.15); color: #1e40af; border-color: #3b82f6; }
.matrix-cell.sold       { background: rgba(239,68,68,.15); color: #991b1b; border-color: #ef4444; }
.matrix-cell.transferred{ background: rgba(99,102,241,.15); color: #3730a3; border-color: #6366f1; }
.matrix-cell.hold       { background: rgba(148,163,184,.15); color: #475569; border-color: #94a3b8; }

/* ============================================================
   TIMELINE
   ============================================================ */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: #e2e8f0; }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-dot {
    position: absolute; left: -20px; top: 4px;
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--primary); border: 2px solid white;
    box-shadow: 0 0 0 2px var(--primary);
}
.timeline-content { background: white; border-radius: 10px; padding: 12px 16px; box-shadow: var(--card-shadow); }
.timeline-time { font-size: .72rem; color: #94a3b8; }

/* ============================================================
   MODAL ENHANCEMENTS
   ============================================================ */
.modal-content { border-radius: var(--radius); border: none; }
.modal-header { border-bottom: 1px solid #f1f5f9; padding: 20px 24px; }
.modal-footer { border-top: 1px solid #f1f5f9; padding: 16px 24px; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert { border-radius: var(--radius-sm); border: none; font-size: .875rem; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .main-content { margin-left: 0; }
}

@media (max-width: 575.98px) {
    .page-content { padding: 16px; }
    .stat-value { font-size: 1.5rem; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.cursor-pointer { cursor: pointer; }
.text-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hover-lift { transition: transform var(--transition); }
.hover-lift:hover { transform: translateY(-2px); }
.glass {
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* ============================================================
   SEARCH FILTER BAR
   ============================================================ */
.filter-bar {
    background: white;
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: #94a3b8;
}
.empty-state i { font-size: 3rem; margin-bottom: 12px; display: block; }
.empty-state h5 { color: #64748b; }

/* ============================================================
   CRM TOUCHPOINT / FOLLOW-UP TRACKING SYSTEM
   ============================================================ */

/* Lead Temperature */
.temp-hot  { background: rgba(239,68,68,.15); color: #dc2626; border: 1px solid #fca5a5; border-radius: 20px; padding: 2px 10px; font-size: .75rem; font-weight: 600; display:inline-block; }
.temp-warm { background: rgba(245,158,11,.15); color: #d97706; border: 1px solid #fcd34d; border-radius: 20px; padding: 2px 10px; font-size: .75rem; font-weight: 600; display:inline-block; }
.temp-cold { background: rgba(59,130,246,.15); color: #2563eb; border: 1px solid #93c5fd; border-radius: 20px; padding: 2px 10px; font-size: .75rem; font-weight: 600; display:inline-block; }

/* Channel Badges */
.channel-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: .75rem; font-weight: 500; }
.channel-call       { background: #dcfce7; color: #166534; }
.channel-email      { background: #dbeafe; color: #1e40af; }
.channel-line       { background: #dcfce7; color: #15803d; }
.channel-whatsapp   { background: #dcfce7; color: #166534; }
.channel-meeting    { background: #ede9fe; color: #6d28d9; }
.channel-facebook   { background: #dbeafe; color: #1d4ed8; }
.channel-sms        { background: #fef9c3; color: #854d0e; }
.channel-site_visit { background: #ffedd5; color: #9a3412; }

/* Touchpoint Timeline */
.touch-timeline { position: relative; padding-left: 36px; }
.touch-timeline::before { content:''; position:absolute; left:16px; top:0; bottom:0; width:2px; background: linear-gradient(180deg,#3b82f6 0%,#e2e8f0 100%); }
.touch-item { position: relative; margin-bottom: 16px; }
.touch-dot { position:absolute; left:-24px; top:10px; width:18px; height:18px; border-radius:50%; border:3px solid white; box-shadow:0 0 0 2px #3b82f6; display:flex; align-items:center; justify-content:center; font-size:9px; }
.touch-card { background:white; border-radius:10px; padding:12px 16px; box-shadow:0 1px 3px rgba(0,0,0,.08); border-left:3px solid #3b82f6; }
.touch-card.hot  { border-left-color: #ef4444; }
.touch-card.warm { border-left-color: #f59e0b; }
.touch-card.cold { border-left-color: #3b82f6; }

/* Result Badges (subtle variants) */
.result-won          { background:#dcfce7; color:#166534; }
.result-interested   { background:#dbeafe; color:#1e40af; }
.result-not_interested{ background:#fee2e2; color:#991b1b; }
.result-considering  { background:#fef9c3; color:#854d0e; }
.result-no_answer    { background:#f1f5f9; color:#475569; }

/* Bootstrap subtle colors (compat for older BS5 patch) */
.bg-success-subtle  { background-color: #dcfce7 !important; }
.bg-danger-subtle   { background-color: #fee2e2 !important; }
.bg-warning-subtle  { background-color: #fef9c3 !important; }
.bg-info-subtle     { background-color: #dbeafe !important; }
.bg-primary-subtle  { background-color: #eff6ff !important; }
.bg-secondary-subtle{ background-color: #f1f5f9 !important; }
.bg-purple-subtle   { background-color: #ede9fe !important; }
.text-purple        { color: #6d28d9 !important; }
