:root {
    --bg-color: #f5f5f5;
    --card-bg: #ffffff;
    --sidebar-bg: #ffffff;
    --primary: #4a8c3f;
    --primary-light: #e8f5e3;
    --primary-hover: #3d7534;
    --text-main: #333333;
    --text-muted: #888888;
    --border: #e8e8e8;
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success: #27ae60;
    --warning: #f39c12;
    --header-green: #4a8c3f;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
}

a { text-decoration: none; color: var(--primary); }
a:hover { color: var(--primary-hover); }

h1, h2, h3, h4 { font-weight: 600; color: var(--text-main); }

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

/* Sidebar */
.sidebar {
    width: 220px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
}

.sidebar-brand {
    padding: 1.5rem 1.25rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
}

.sidebar-brand span {
    color: var(--text-main);
}

.sidebar-nav {
    list-style: none;
    padding: 1rem 0;
    flex: 1;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    color: var(--text-muted);
    font-size: 0.9375rem;
    font-weight: 500;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.sidebar-nav li a:hover {
    color: var(--primary);
    background: var(--primary-light);
}

.sidebar-nav li a.active {
    color: var(--primary);
    background: var(--primary-light);
    border-left-color: var(--primary);
    font-weight: 600;
}

.sidebar-nav li a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 220px;
}

/* Top Bar */
.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
}

/* Page Header */
.page-title {
    background: var(--primary);
    color: white;
    padding: 1.5rem 2rem;
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-date {
    font-size: 0.9rem;
    font-weight: 400;
    opacity: 0.9;
    margin-left: auto;
    text-align: right;
}

/* Container */
.container {
    padding: 2rem;
    max-width: 100%;
}

/* ========== LOGIN ========== */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
}

.login-card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
    text-align: center;
}

.login-card h2 {
    margin-bottom: 1.5rem;
    color: var(--primary);
}

.form-group { margin-bottom: 1rem; text-align: left; }
.form-group label { display: block; margin-bottom: 0.5rem; font-size: 0.875rem; font-weight: 500; }
.form-group input {
    width: 100%; padding: 0.75rem; border: 1px solid var(--border);
    border-radius: 6px; font-size: 1rem;
}
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74,140,63,0.15); }

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.5rem 1rem; border-radius: 6px; font-weight: 500; font-size: 0.875rem;
    cursor: pointer; border: 1px solid transparent; transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; font-size: 0.8rem; padding: 0.35rem 0.75rem; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text-main); }
.btn-outline:hover { background: var(--bg-color); }

/* ========== STATS GRID ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.25rem 1.5rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stat-card .stat-text h4 {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.stat-card .stat-text .value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-card .stat-text .sub {
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 500;
    margin-top: 0.25rem;
}

.stat-icon-wrap {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon-wrap svg {
    width: 22px;
    height: 22px;
    color: var(--primary);
}

/* Status summary */
.status-summary {
    display: flex; gap: 0.75rem; flex-wrap: wrap;
}
.status-badge {
    padding: 0.2rem 0.6rem; border-radius: 9999px; font-size: 0.7rem; font-weight: 600;
}
.status-New { background: #dbeafe; color: #1e40af; }
.status-Contacted { background: #fef3c7; color: #92400e; }
.status-Converted { background: #d1fae5; color: #065f46; }
.status-Not { background: #fee2e2; color: #991b1b; }

/* ========== TABLE SECTION ========== */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-bar select, .filter-bar input[type="date"] {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 0.8125rem;
    background: white;
}

.search-box {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 0.8125rem;
    width: 200px;
    background: white;
}

.search-box:focus { outline: none; border-color: var(--primary); }

.table-container {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th, td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    font-size: 0.875rem;
}

th {
    background: #fafafa;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 600;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafa; }

/* Cell content */
.lead-name { color: var(--primary); font-weight: 600; }

/* Colored Status Selects */
.status-select {
    padding: 0.3rem 0.4rem;
    border-radius: 4px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    appearance: auto;
}

.status-color-new {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.status-color-contacted {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.status-color-converted {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.status-color-lost {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.notes-input {
    width: 100%;
    min-width: 180px;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 0.4rem;
    font-size: 0.8125rem;
    font-family: inherit;
    resize: vertical;
    min-height: 36px;
    background: transparent;
    transition: all 0.15s;
}

.notes-input:hover, .notes-input:focus {
    border-color: var(--border);
    background: #fafafa;
    outline: none;
}

.save-indicator {
    font-size: 0.7rem;
    color: var(--success);
    opacity: 0;
    transition: opacity 0.3s;
}
.save-indicator.show { opacity: 1; }

.meta-info { font-size: 0.8125rem; color: var(--text-muted); }

/* ========== SETTINGS PAGE ========== */
.settings-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
    max-width: 500px;
}

.settings-card h3 {
    margin-bottom: 0.25rem;
}

.settings-desc {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

.settings-form .form-group {
    margin-bottom: 1rem;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

/* Password eye toggle */
.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrapper input {
    width: 100%;
    padding-right: 2.5rem;
}

.eye-btn {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.25rem;
    display: flex;
    align-items: center;
}

.eye-btn:hover { color: var(--text-main); }

/* Toast notification (bottom) */
.toast-success {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: #065f46;
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    animation: slideUp 0.4s ease;
    transition: opacity 0.4s, transform 0.4s;
    z-index: 999;
}

.toast-success.hide {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(30px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ========== FILTER PILLS ========== */
.filter-pills {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.pill {
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid var(--border);
    background: white;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.pill:hover {
    border-color: var(--primary);
    color: var(--primary);
    text-decoration: none;
}

.pill.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.range-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.range-inputs input[type="date"] {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 0.8125rem;
}

.range-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ========== CHARTS ========== */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

.chart-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
}

.chart-card h4 {
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.chart-card canvas {
    width: 100% !important;
}

/* Source table */
.source-table {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.source-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.source-row:last-child { border-bottom: none; }

.source-name { font-weight: 500; }

.source-count { font-weight: 600; }

/* ========== PERMISSION TOGGLE CARDS ========== */
.perm-card {
    cursor: pointer;
    display: block;
}
.perm-card input[type="checkbox"] {
    display: none;
}
.perm-card-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    transition: all 0.2s ease;
    background: var(--bg);
}
.perm-card:hover .perm-card-inner {
    border-color: #bbb;
}
.perm-card input:checked + .perm-card-inner {
    border-color: var(--primary);
    background: rgba(74, 140, 63, 0.04);
}
.perm-card-icon {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.perm-card-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.perm-card-text strong {
    font-size: 0.9rem;
    color: var(--text);
}
.perm-card-text span {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}
.perm-toggle {
    width: 40px;
    height: 22px;
    border-radius: 11px;
    background: #ccc;
    position: relative;
    transition: background 0.2s ease;
    flex-shrink: 0;
}
.perm-toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.perm-card input:checked + .perm-card-inner .perm-toggle {
    background: var(--primary);
}
.perm-card input:checked + .perm-card-inner .perm-toggle::after {
    transform: translateX(18px);
}

/* ========== SLIDE-IN DRAWER ========== */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.drawer-overlay.active {
    opacity: 1;
    visibility: visible;
}
.drawer-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 90vw;
    height: 100vh;
    background: #ffffff;
    box-shadow: -8px 0 30px rgba(0,0,0,0.15);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.drawer-panel.active {
    transform: translateX(0);
}
.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.drawer-header h3 {
    font-size: 1.1rem;
    color: var(--text);
}
.drawer-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0 0.25rem;
    transition: color 0.2s;
}
.drawer-close:hover {
    color: var(--danger);
}
.drawer-form {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.drawer-body .form-group {
    margin-bottom: 0;
}
.drawer-body input,
.drawer-body select,
.drawer-body textarea {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s;
}
.drawer-body input:focus,
.drawer-body select:focus,
.drawer-body textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74,140,63,0.1);
}
.drawer-footer {
    display: flex;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.drawer-footer .btn {
    flex: 1;
    justify-content: center;
    text-align: center;
}

/* ========== WHATSAPP TEMPLATES ========== */
.wa-templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.wa-template-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.wa-template-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.wa-template-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--primary);
}

.wa-template-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.wa-template-body {
    font-size: 0.85rem;
    color: var(--text-main);
    line-height: 1.6;
    background: #f9f9f9;
    padding: 0.75rem;
    border-radius: 6px;
    border-left: 3px solid #25d366;
}

.wa-template-actions {
    display: flex;
    gap: 0.5rem;
}

/* WhatsApp send dropdown on dashboard */
.wa-send-wrapper {
    position: relative;
    display: inline-block;
}

.wa-send-btn {
    background: #25d366;
    color: white;
    border: none;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: background 0.15s;
}

.wa-send-btn:hover { background: #1da851; }

.wa-dropdown {
    display: none;
    position: absolute;
    bottom: 100%;
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    min-width: 200px;
    z-index: 100;
    margin-bottom: 4px;
}

.wa-dropdown.show { display: block; }

.wa-dropdown-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.75rem;
    border: none;
    background: none;
    font-size: 0.8125rem;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.1s;
}

.wa-dropdown-item:hover { background: #f0f0f0; }

.wa-dropdown-item:first-child { border-radius: 6px 6px 0 0; }
.wa-dropdown-item:last-child { border-radius: 0 0 6px 6px; }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; }
    .page-title { font-size: 1.25rem; padding: 1rem 1.5rem; }
    .container { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
}
