/* ============================================================
   Admin Al Tahoor — Global Stylesheet
   Migrated from inline plugin CSS + enhanced for standalone app
   ============================================================ */

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

/* ── CSS Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --brand-dark:    #0f172a;
    --brand-green:   #066649;
    --brand-green-l: #16a34a;
    --accent:        #3b82f6;
    --accent-yellow: #eab308;
    --surface:       #ffffff;
    --surface-2:     #f8fafc;
    --surface-3:     #f1f5f9;
    --border:        #e2e8f0;
    --border-2:      #f1f5f9;
    --text-primary:  #0f172a;
    --text-secondary:#334155;
    --text-muted:    #64748b;
    --text-subtle:   #94a3b8;
    --shadow-sm:     0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:     0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg:     0 10px 15px -3px rgba(0,0,0,0.07), 0 4px 6px -4px rgba(0,0,0,0.05);
    --shadow-xl:     0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
    --radius-sm:     6px;
    --radius-md:     10px;
    --radius-lg:     14px;
    --radius-xl:     18px;
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --transition:    all 0.2s ease;
}

html { font-size: 16px; }
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--surface-2);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

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

/* ── Sidebar ──────────────────────────────────────────────── */
.crm-sidebar {
    width: var(--sidebar-width);
    background: var(--brand-dark);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: var(--transition);
    z-index: 100;
    flex-shrink: 0;
}

.crm-sidebar.collapsed {
    width: 68px;
}

.crm-sidebar.collapsed .brand-text,
.crm-sidebar.collapsed .nav-label,
.crm-sidebar.collapsed .user-info,
.crm-sidebar.collapsed .user-role {
    display: none;
}

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

.crm-sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 12px 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-icon {
    font-size: 28px;
    flex-shrink: 0;
}

.brand-name {
    font-size: 15px;
    font-weight: 800;
    color: #f1f5f9;
    letter-spacing: -0.3px;
    white-space: nowrap;
}

.brand-sub {
    font-size: 11px;
    color: #64748b;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: var(--radius-md);
    text-decoration: none;
    color: #94a3b8;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

.nav-item:hover {
    background: rgba(255,255,255,0.07);
    color: #f1f5f9;
}

.nav-item.active {
    background: linear-gradient(135deg, #066649 0%, #16a34a 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(6,102,73,0.4);
}

.nav-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 22px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #066649, #16a34a);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 11px;
    color: #64748b;
    font-weight: 500;
}

.logout-btn {
    color: #64748b;
    display: flex;
    align-items: center;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    text-decoration: none;
    flex-shrink: 0;
}

.logout-btn:hover { color: #ef4444; background: rgba(239,68,68,0.1); }

/* ── Main Content ─────────────────────────────────────────── */
.crm-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Top Bar ──────────────────────────────────────────────── */
.crm-topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.topbar-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
}

.topbar-toggle:hover { background: var(--surface-3); color: var(--text-primary); }

.topbar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-time {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Page Content ─────────────────────────────────────────── */
.crm-content {
    padding: 28px;
    flex: 1;
}

/* ── KPI Stats Cards ──────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-2);
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.kpi-card.total::before  { background: var(--brand-dark); }
.kpi-card.new::before    { background: var(--accent); }
.kpi-card.working::before { background: var(--accent-yellow); }
.kpi-card.closed::before { background: var(--brand-green-l); }

.kpi-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 36px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.kpi-card.new .kpi-value    { color: var(--accent); }
.kpi-card.working .kpi-value { color: var(--accent-yellow); }
.kpi-card.closed .kpi-value { color: var(--brand-green-l); }

.kpi-icon {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 42px;
    opacity: 0.07;
}

/* ── Filter Bar ───────────────────────────────────────────── */
.filter-bar {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.filter-bar-left {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-bar-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.search-wrap {
    position: relative;
}

.search-wrap .search-icon {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 16px;
    pointer-events: none;
}

.search-input {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 14px 8px 36px;
    font-size: 14px;
    color: var(--text-secondary);
    font-family: inherit;
    width: 240px;
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.filter-select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 14px;
    color: var(--text-secondary);
    font-family: inherit;
    background: var(--surface);
    cursor: pointer;
    transition: var(--transition);
}

.filter-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--brand-dark);
    color: #fff;
}
.btn-primary:hover { background: #1e293b; color: #fff; transform: translateY(-1px); }

.btn-green {
    background: var(--brand-green);
    color: #fff;
}
.btn-green:hover { background: #055038; color: #fff; }

.btn-danger {
    background: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
}
.btn-danger:hover { background: #fee2e2; }

.btn-outline {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--surface-3); color: var(--text-primary); }

.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Bulk Actions Bar ─────────────────────────────────────── */
.bulk-bar {
    display: none;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin-bottom: 16px;
    align-items: center;
    gap: 12px;
}

.bulk-bar.visible { display: flex; }

/* ── Table ────────────────────────────────────────────────── */
.table-wrapper {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    border: 1px solid var(--border-2);
}

.crm-table {
    width: 100%;
    border-collapse: collapse;
}

.crm-table th {
    background: transparent;
    padding: 14px 16px;
    text-align: left;
    border-bottom: 2px solid var(--border-2);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    white-space: nowrap;
}

.crm-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-2);
    vertical-align: middle;
    font-size: 14px;
    color: var(--text-secondary);
}

.crm-table tr:last-child td { border-bottom: none; }
.crm-table tbody tr:hover { background: #f8fafc; }

.lead-name {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 15px;
    margin-bottom: 3px;
}

.lead-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.status-select {
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.assign-select {
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    max-width: 140px;
}

.crm-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--brand-green);
}

.wa-link {
    color: #16a34a;
    font-weight: 600;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
    font-size: 13px;
}

.wa-link:hover { text-decoration: underline; }

.email-link {
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
}

.email-link:hover { color: var(--accent); }

/* ── Pagination ───────────────────────────────────────────── */
.crm-pagination {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    margin-top: 24px;
    flex-wrap: wrap;
}

.crm-page-btn {
    min-width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: var(--transition);
    padding: 0 10px;
}

.crm-page-btn:hover { background: var(--surface-3); border-color: var(--accent); color: var(--accent); }
.crm-page-btn.active {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
    color: #fff;
}

/* ── Cards ────────────────────────────────────────────────── */
.crm-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-2);
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

/* ── Lead Detail Layout ───────────────────────────────────── */
.lead-detail-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
    align-items: start;
}

.detail-field {
    margin-bottom: 18px;
}

.detail-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 5px;
}

.detail-value {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.lead-avatar-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.lead-avatar-circle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #dbeafe, #eff6ff);
    color: #0284c7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 800;
    flex-shrink: 0;
}

.badge-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 700;
}

.badge-blue  { background: #dbeafe; color: #1e40af; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-amber { background: #fef9c3; color: #854d0e; }

/* ── Notes System ─────────────────────────────────────────── */
.note-card {
    background: var(--surface-2);
    border-radius: var(--radius-md);
    padding: 18px;
    border-left: 4px solid var(--accent);
    margin-bottom: 14px;
}

.note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.note-author {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 14px;
}

.note-date {
    font-size: 12px;
    color: var(--text-muted);
}

.note-body {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.note-empty {
    text-align: center;
    padding: 40px;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    border: 1px dashed var(--border);
    color: var(--text-muted);
}

.note-textarea {
    width: 100%;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 12px 14px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-secondary);
    resize: vertical;
    transition: var(--transition);
    min-height: 90px;
}

.note-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

/* ── Analytics Charts ─────────────────────────────────────── */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-top: 20px;
}

.chart-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-2);
}

.chart-card-full { grid-column: 1 / -1; }

.chart-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 14px;
}

.chart-container {
    position: relative;
    height: 280px;
    width: 100%;
}

/* ── Settings Page ────────────────────────────────────────── */
.settings-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 24px;
    align-items: start;
}

.settings-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.settings-right {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input, .form-select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    color: var(--text-secondary);
    background: var(--surface);
    transition: var(--transition);
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.conn-type-badge {
    background: #dbeafe;
    color: #1e40af;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.method-card { display: none; }
.method-card.visible { display: block; }

/* ── Login Page ───────────────────────────────────────────── */
.login-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 48px 44px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
}

.login-brand {
    text-align: center;
    margin-bottom: 36px;
}

.login-brand-icon {
    font-size: 44px;
    margin-bottom: 12px;
}

.login-brand-name {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.login-brand-sub {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

.login-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.login-input {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--surface);
    transition: var(--transition);
}

.login-input:focus {
    outline: none;
    border-color: var(--brand-green);
    box-shadow: 0 0 0 3px rgba(6,102,73,0.12);
}

.login-btn {
    width: 100%;
    padding: 13px;
    background: linear-gradient(135deg, #066649, #16a34a);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 8px;
    box-shadow: 0 4px 12px rgba(6,102,73,0.35);
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(6,102,73,0.45);
}

.login-btn:active { transform: translateY(0); }

.remember-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.remember-row label {
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Empty State ──────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon { font-size: 48px; margin-bottom: 14px; }
.empty-state h3 { font-size: 18px; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 14px; }

/* ── Divider ──────────────────────────────────────────────── */
hr.crm-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

/* ── Utility ──────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: 13px; }
.text-xs    { font-size: 11px; }
.fw-bold    { font-weight: 700; }
.mt-4       { margin-top: 16px; }
.mb-4       { margin-bottom: 16px; }
.gap-8      { gap: 8px; }
.flex       { display: flex; }
.items-center { align-items: center; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .chart-grid { grid-template-columns: 1fr; }
    .settings-grid { grid-template-columns: 1fr; }
    .lead-detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    :root { --sidebar-width: 0px; }
    .crm-sidebar { transform: translateX(-100%); }
    .crm-sidebar.open { transform: translateX(0); width: 260px; }
    .crm-main { margin-left: 0; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .crm-content { padding: 16px; }
}
