/* ==============================================================================
   TERAS LAND CRM — SAAS MODERN RESPONSIVE STYLING
   Brand Identity:
   - Hijau Tua: #0D4A2F (Primary Brand)
   - Emas Aksen: #C8A24A (Luxury Accent)
   - Abu-abu Terang Background: #F5F7F6
   - Putih: #FFFFFF
   - Teks Utama: #1F2937 (Slate Charcoal)
   - Font: Plus Jakarta Sans / Inter
   ============================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Brand Colors */
    --crm-primary: #0D4A2F;          /* Hijau Tua Utama */
    --crm-primary-hover: #083320;    /* Hijau Gelap Hover */
    --crm-primary-light: #E8F3EE;    /* Hijau Muda Lembut */
    --crm-gold: #C8A24A;             /* Emas Aksen */
    --crm-gold-hover: #B59039;       /* Emas Gelap */
    --crm-gold-light: #FDF9EE;       /* Emas Pucat Lembut */
    
    /* Neutral & Backgrounds */
    --crm-bg-body: #F5F7F6;          /* Abu-abu Terang Bersih */
    --crm-card-bg: #FFFFFF;          /* Putih */
    --crm-border: #E5E7EB;           /* Garis Halus */
    --crm-border-subtle: #F3F4F6;
    
    /* Typography */
    --crm-text-main: #1F2937;        /* Teks Utama Charcoal */
    --crm-text-muted: #6B7280;       /* Teks Keterangan */
    --crm-text-light: #9CA3AF;
    
    /* Sidebar Theme */
    --crm-sidebar-bg: #072B1B;       /* Hijau Hutan Pekat */
    --crm-sidebar-brand: #0A3A25;
    --crm-sidebar-text: #E5E7EB;
    --crm-sidebar-muted: #9CA3AF;
    --crm-sidebar-hover: rgba(200, 162, 74, 0.12);
    --crm-sidebar-active: #0D4A2F;
    --crm-sidebar-active-border: #C8A24A;
    
    /* Layout & Geometry */
    --crm-radius: 12px;              /* Sudut Membulat 10-14px */
    --crm-radius-sm: 8px;
    --crm-radius-lg: 16px;
    --crm-radius-pill: 9999px;
    
    /* Shadows */
    --crm-shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    --crm-shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.03);
    --crm-shadow-md: 0 4px 6px -1px rgba(13, 74, 47, 0.06), 0 2px 4px -2px rgba(13, 74, 47, 0.04);
    --crm-shadow-lg: 0 10px 15px -3px rgba(13, 74, 47, 0.08), 0 4px 6px -4px rgba(13, 74, 47, 0.04);
    
    /* Touch Target */
    --crm-touch-target: 44px;
}

/* ==============================================================================
   BASE & RESET
   ============================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--crm-bg-body);
    color: var(--crm-text-main);
    font-size: 0.925rem;
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==============================================================================
   LAYOUT ARCHITECTURE (DESKTOP, TABLET, MOBILE)
   ============================================================================== */
.crm-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
    overflow-x: hidden;
}

/* ==============================================================================
   SIDEBAR (DESKTOP & OFF-CANVAS MOBILE DRAWER)
   ============================================================================== */
.crm-sidebar {
    width: 260px;
    background-color: var(--crm-sidebar-bg);
    color: var(--crm-sidebar-text);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1040;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), width 0.28s ease;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

/* Brand Header */
.crm-sidebar-brand {
    height: 64px;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background-color: var(--crm-sidebar-brand);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    text-decoration: none;
    color: #ffffff;
    overflow: hidden;
}

.crm-sidebar-brand:hover {
    color: #ffffff;
}

.crm-sidebar-brand .brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--crm-gold), #8E6F27);
    border-radius: var(--crm-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(200, 162, 74, 0.3);
    flex-shrink: 0;
}

.crm-sidebar-brand .brand-text {
    line-height: 1.2;
    min-width: 0;
}

.crm-sidebar-brand .brand-title {
    font-weight: 800;
    font-size: 0.975rem;
    letter-spacing: -0.01em;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-sidebar-brand .brand-sub {
    font-size: 0.7rem;
    color: var(--crm-gold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

/* Mobile Close Button di Sidebar Header */
.crm-sidebar-close {
    display: none;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.5rem;
    padding: 0.5rem;
    margin-left: auto;
    cursor: pointer;
    line-height: 1;
}

.crm-sidebar-close:hover {
    color: #ffffff;
}

/* Navigation List */
.crm-sidebar-nav {
    padding: 1rem 0.75rem;
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.crm-nav-header {
    font-size: 0.675rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.4);
    padding: 0.75rem 0.75rem 0.35rem 0.75rem;
}

.crm-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.85rem;
    color: #CBD5E1;
    text-decoration: none;
    border-radius: var(--crm-radius-sm);
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.18s ease;
    margin-bottom: 0.25rem;
    min-height: var(--crm-touch-target);
}

.crm-nav-link i {
    font-size: 1.15rem;
    width: 22px;
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    transition: color 0.18s ease, transform 0.18s ease;
    flex-shrink: 0;
}

.crm-nav-link:hover {
    background-color: var(--crm-sidebar-hover);
    color: #FFFFFF;
}

.crm-nav-link:hover i {
    color: var(--crm-gold);
    transform: scale(1.1);
}

.crm-nav-link.active {
    background-color: var(--crm-sidebar-active);
    color: #FFFFFF;
    font-weight: 600;
    border-left: 3px solid var(--crm-gold);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.crm-nav-link.active i {
    color: var(--crm-gold);
}

.crm-sidebar-footer {
    padding: 0.875rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background-color: rgba(0, 0, 0, 0.15);
}

/* Sidebar Overlay Backdrop (Mobile/Tablet) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(2px);
    z-index: 1035;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* ==============================================================================
   MAIN CONTENT AREA & TOPBAR
   ============================================================================== */
.crm-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: 100%;
}

.crm-topbar {
    height: 64px;
    background-color: var(--crm-card-bg);
    border-bottom: 1px solid var(--crm-border);
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1020;
    box-shadow: var(--crm-shadow-xs);
}

.crm-content {
    padding: 1.5rem;
    flex-grow: 1;
    max-width: 100%;
}

/* ==============================================================================
   CARDS & CONTAINERS
   ============================================================================== */
.card-crm {
    background: var(--crm-card-bg);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
}

.card-crm-hover:hover {
    transform: translateY(-2px);
    box-shadow: var(--crm-shadow-md);
    border-color: rgba(13, 74, 47, 0.2);
}

.card-crm .card-header {
    background-color: var(--crm-card-bg);
    border-bottom: 1px solid var(--crm-border);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.card-crm .card-body {
    padding: 1.25rem;
}

/* Metric / Stat Cards */
.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--crm-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.15;
    color: var(--crm-text-main);
}

.stat-label {
    font-size: 0.775rem;
    color: var(--crm-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ==============================================================================
   TABLE SYSTEM (RESPONSIVE TOUCH-SCROLL & STYLING)
   ============================================================================== */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: var(--crm-radius);
}

.table-crm {
    margin-bottom: 0;
    vertical-align: middle;
    width: 100%;
}

.table-crm th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--crm-text-muted);
    background-color: #F9FAFB;
    border-bottom: 1px solid var(--crm-border);
    padding: 0.85rem 1rem;
    white-space: nowrap;
}

.table-crm td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--crm-border-subtle);
    font-size: 0.875rem;
    color: var(--crm-text-main);
}

.table-crm tr:hover td {
    background-color: rgba(13, 74, 47, 0.02);
}

/* Custom Scrollbar for local table scroll */
.table-responsive::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #F3F4F6;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}

/* ==============================================================================
   FORM CONTROLS & TOUCH TARGETS (>= 44px)
   ============================================================================== */
.form-control, .form-select {
    min-height: var(--crm-touch-target);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius-sm);
    font-size: 0.9rem;
    color: var(--crm-text-main);
    padding: 0.55rem 0.85rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(13, 74, 47, 0.15);
    outline: none;
}

.form-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--crm-text-main);
    margin-bottom: 0.35rem;
}

/* ==============================================================================
   BUTTONS & ACTIONS
   ============================================================================== */
.btn {
    min-height: var(--crm-touch-target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    border-radius: var(--crm-radius-sm);
    transition: all 0.18s ease;
    gap: 0.35rem;
}

.btn-sm {
    min-height: 36px;
    font-size: 0.825rem;
    padding: 0.35rem 0.75rem;
}

.btn-crm-primary {
    background-color: var(--crm-primary);
    border-color: var(--crm-primary);
    color: #FFFFFF;
}

.btn-crm-primary:hover, .btn-crm-primary:focus {
    background-color: var(--crm-primary-hover);
    border-color: var(--crm-primary-hover);
    color: #FFFFFF;
    box-shadow: 0 4px 10px rgba(13, 74, 47, 0.25);
}

.btn-whatsapp {
    background-color: #25D366;
    border-color: #25D366;
    color: #FFFFFF;
}

.btn-whatsapp:hover, .btn-whatsapp:focus {
    background-color: #1EBE5D;
    border-color: #1EBE5D;
    color: #FFFFFF;
    box-shadow: 0 4px 10px rgba(37, 211, 102, 0.25);
}

.btn-gold {
    background-color: var(--crm-gold);
    border-color: var(--crm-gold);
    color: #FFFFFF;
}

.btn-gold:hover, .btn-gold:focus {
    background-color: var(--crm-gold-hover);
    border-color: var(--crm-gold-hover);
    color: #FFFFFF;
    box-shadow: 0 4px 10px rgba(200, 162, 74, 0.25);
}

/* ==============================================================================
   BADGES & TAGS
   ============================================================================== */
.badge {
    padding: 0.35em 0.65em;
    font-weight: 600;
    letter-spacing: 0.02em;
    border-radius: 6px;
}

.badge-duplicate {
    background-color: #FEF2F2;
    color: #B91C1C;
    border: 1px solid #FECACA;
    font-weight: 600;
}

/* ==============================================================================
   TIMELINE DETAIL LEAD
   ============================================================================== */
.timeline-item {
    position: relative;
    padding-left: 2rem;
    padding-bottom: 1.5rem;
    border-left: 2px solid var(--crm-border);
}

.timeline-item:last-child {
    border-left-color: transparent;
    padding-bottom: 0;
}

.timeline-icon {
    position: absolute;
    left: -0.65rem;
    top: 0;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 50%;
    background-color: var(--crm-primary);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

/* ==============================================================================
   RESPONSIVE BREAKPOINTS (DESKTOP, TABLET, MOBILE)
   ============================================================================== */

/* --- TABLET & MOBILE VIEWPORT (< 992px) --- */
@media (max-width: 991.98px) {
    .crm-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1050;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .crm-sidebar.show {
        transform: translateX(280px);
    }

    .crm-sidebar-close {
        display: block;
    }

    .crm-topbar {
        padding: 0 1rem;
    }

    .crm-content {
        padding: 1rem;
    }
}

/* --- MOBILE SPECIFIC (< 768px) --- */
@media (max-width: 767.98px) {
    .crm-content {
        padding: 0.875rem 0.75rem;
    }

    .card-crm .card-header {
        padding: 0.85rem 1rem;
    }

    .card-crm .card-body {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.15rem;
    }

    /* Modal Mobile: hampir layar penuh dengan margin tipis */
    .modal-dialog {
        margin: 0.75rem;
    }

    /* Form Mobile: tombol mudah disentuh penuh */
    .btn-mobile-block {
        width: 100%;
    }

    /* Filter panel collapsible padding */
    .filter-card-mobile {
        padding: 0.75rem;
    }
}

/* --- EXTRA SMALL MOBILE (< 576px, e.g. 320px - 430px) --- */
@media (max-width: 575.98px) {
    body {
        font-size: 0.875rem;
    }

    .h3, h1.h3 {
        font-size: 1.35rem;
    }

    .crm-topbar {
        padding: 0 0.75rem;
        height: 58px;
    }

    .stat-value {
        font-size: 1.35rem;
    }

    .table-crm th, .table-crm td {
        padding: 0.65rem 0.75rem;
        font-size: 0.825rem;
    }

    .breadcrumb {
        font-size: 0.75rem;
    }
}

/* --- DESKTOP COLLAPSIBLE SIDEBAR (> 992px) --- */
@media (min-width: 992px) {
    body.crm-sidebar-collapsed .crm-sidebar {
        width: 76px;
    }

    body.crm-sidebar-collapsed .crm-sidebar .brand-text,
    body.crm-sidebar-collapsed .crm-sidebar .crm-nav-header,
    body.crm-sidebar-collapsed .crm-sidebar .crm-nav-link span,
    body.crm-sidebar-collapsed .crm-sidebar-footer .overflow-hidden {
        display: none !important;
    }

    body.crm-sidebar-collapsed .crm-sidebar .crm-nav-link {
        justify-content: center;
        padding: 0.75rem;
    }

    body.crm-sidebar-collapsed .crm-sidebar .crm-sidebar-brand {
        justify-content: center;
        padding: 0;
    }
}
