/* Social Media Tools — Global Styles */

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-width: 240px;
    --header-height: 60px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);

    /* Platform colors */
    --facebook: #1877f2;
    --instagram: #e4405f;
    --twitter: #000000;
    --pinterest: #e60023;
    --google: #4285f4;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ──────────────────────────────────────────────────── */

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 20px;
    font-size: 18px;
    font-weight: 700;
    border-bottom: 1px solid var(--gray-700);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-brand i { color: var(--primary); }

.sidebar-nav {
    list-style: none;
    padding: 10px 0;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--gray-300);
    font-size: 14px;
    transition: background .15s, color .15s;
}

.sidebar-nav li a:hover {
    background: var(--gray-800);
    color: #fff;
    text-decoration: none;
}

.sidebar-nav li a.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-nav li a i {
    width: 20px;
    text-align: center;
    font-size: 15px;
}

.sidebar-section {
    padding: 15px 20px 5px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--gray-500);
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}

/* ── Top Bar ─────────────────────────────────────────────────── */

.topbar {
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title {
    font-size: 18px;
    font-weight: 600;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-user img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.topbar-user a {
    color: var(--gray-500);
    font-size: 13px;
}

/* ── Page Content ────────────────────────────────────────────── */

.page-content {
    padding: 24px;
    max-width: 1200px;
}

/* ── Cards ───────────────────────────────────────────────────── */

.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body { padding: 20px; }

/* ── Stat Cards ──────────────────────────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--gray-500);
    margin-bottom: 4px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-900);
}

/* ── Buttons ─────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background .15s, opacity .15s;
}

.btn:hover { opacity: .9; text-decoration: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-100); }

.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }

/* Platform connect buttons */
.btn-facebook { background: var(--facebook); color: #fff; }
.btn-instagram { background: var(--instagram); color: #fff; }
.btn-twitter { background: var(--twitter); color: #fff; }
.btn-pinterest { background: var(--pinterest); color: #fff; }

/* ── Forms ───────────────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--gray-700);
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color .15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}

textarea.form-control { resize: vertical; min-height: 100px; }

select.form-control {
    appearance: auto;
    cursor: pointer;
}

/* ── Tables ──────────────────────────────────────────────────── */

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.table th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--gray-500);
    font-weight: 600;
}

.table tbody tr:hover { background: var(--gray-50); }

/* ── Badges ──────────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* Platform badges */
.badge-facebook { background: #e8f0fe; color: var(--facebook); }
.badge-instagram { background: #fce4ec; color: var(--instagram); }
.badge-twitter { background: #f5f5f5; color: var(--twitter); }
.badge-pinterest { background: #fce4ec; color: var(--pinterest); }

/* ── Alerts ──────────────────────────────────────────────────── */

.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Modal ───────────────────────────────────────────────────── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

.modal-header .close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--gray-400);
}

.modal-body { padding: 20px; }

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ── Empty State ─────────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--gray-400);
}

.empty-state i { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { color: var(--gray-600); margin-bottom: 8px; }

/* ── Utilities ───────────────────────────────────────────────── */

.text-muted { color: var(--gray-500); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 10px; }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-google { color: var(--google); }
.text-facebook { color: var(--facebook); }
.text-pinterest { color: var(--pinterest); }
.font-medium { font-weight: 500; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.p-6 { padding: 24px; }
.d-flex { display: flex; }
.d-inline { display: inline; }
.gap-2 { gap: 8px; }
.align-center { align-items: center; }
.align-self-center { align-self: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none; }
.cursor-pointer { cursor: pointer; }
.max-w-140 { max-width: 140px; }
.max-w-160 { max-width: 160px; }
.max-w-180 { max-width: 180px; }
.max-w-200 { max-width: 200px; }
.max-w-300 { max-width: 300px; }
.max-w-500 { max-width: 500px; }
.max-w-600 { max-width: 600px; }

/* ── Notification Toast ──────────────────────────────────────── */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
    box-shadow: var(--shadow-md);
    animation: slideIn .3s ease;
    max-width: 400px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}


/* ── Responsive (≤768px) ───────────────────────────────────── */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--gray-700);
    cursor: pointer;
    padding: 8px 12px;
    margin-right: 8px;
}
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 90;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 100;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-backdrop.open {
        display: block;
    }
    .main-content {
        margin-left: 0;
    }
    .sidebar-toggle {
        display: inline-flex;
        align-items: center;
    }
    .page-content {
        padding: 16px;
    }
    /* Tables get horizontal scroll inside their card/panel */
    .card-body, .panel {
        overflow-x: auto;

    }
    /* Filter bars stack */
    .crm-filters {
        flex-direction: column;
    }
    .crm-filters select,
    .crm-filters input {
        width: 100%;
    }
    /* Lead-header buttons below name on narrow screens */
    .lead-header { flex-direction: column; align-items: flex-start; }
    .lead-header-actions { width: 100%; justify-content: flex-start; }
}

@media (max-width: 480px) {
    .page-content { padding: 12px; }
    .topbar-title { font-size: 16px; }
    .topbar-user span { display: none; }
}

/* Prevent whole-page horizontal scroll on mobile
   (off-canvas sidebar transform + wide tables would otherwise overflow) */
html, body { overflow-x: hidden; }

@media (max-width: 768px) {
    .layout { overflow-x: hidden; width: 100%; }
    .main-content { max-width: 100%; overflow-x: hidden; }
    /* Scope table min-width to scroll containers so loose tables don't blow out */
}

/* ── Mobile card + content tightening ───────────────────────── */
@media (max-width: 768px) {
    .card-body { padding: 14px; }
    .card-header { padding: 12px 14px; }
    .card { margin-left: 0; margin-right: 0; }
    /* Long URLs / emails / handles wrap instead of blowing out */
    .edit-field, .notes-view, .social-list a, .attach-list a,
    .activity-list li, .lead-field span {
        overflow-wrap: anywhere;
        word-break: break-word;
    }
    .social-list li { flex-wrap: wrap; }
    .modal { max-width: calc(100vw - 20px); margin: 10px; }
}

/* ── Dark mode ─────────────────────────────────────────────── */
/* Toggle sets data-theme on <html>.  User preference is persisted in
   localStorage; applied before first paint to avoid flash. */

html[data-theme="dark"] {
    --gray-50:  #1f2937;
    --gray-100: #1f2937;
    --gray-200: #374151;
    --gray-300: #4b5563;
    --gray-400: #6b7280;
    --gray-500: #9ca3af;
    --gray-600: #d1d5db;
    --gray-700: #e5e7eb;
    --gray-800: #f3f4f6;
    --gray-900: #f9fafb;
    --shadow:    0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 4px 6px rgba(0,0,0,.5), 0 2px 4px rgba(0,0,0,.4);
    color-scheme: dark;
}
html[data-theme="dark"] body { background: #0f172a; color: #e5e7eb; }
html[data-theme="dark"] .card,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .topbar {
    background: #1e293b;
    color: #e5e7eb;
    border-color: #334155;
}
html[data-theme="dark"] .card-header,
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
    border-color: #334155;
    background: #172033;
}
html[data-theme="dark"] .form-control {
    background: #0f172a;
    color: #e5e7eb;
    border-color: #334155;
}
html[data-theme="dark"] .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.2);
}
html[data-theme="dark"] .table th,
html[data-theme="dark"] .table td { border-color: #334155; }
html[data-theme="dark"] .edit-field:hover { background: #172033; border-color: #334155; }
html[data-theme="dark"] .activity-list li,
html[data-theme="dark"] .social-list li,
html[data-theme="dark"] .attach-list li,
html[data-theme="dark"] .todo-list li { border-color: #334155; }
html[data-theme="dark"] .alert-success { background: #064e3b; color: #d1fae5; border-color: #065f46; }
html[data-theme="dark"] .alert-danger  { background: #7f1d1d; color: #fee2e2; border-color: #991b1b; }
html[data-theme="dark"] .alert-warning { background: #78350f; color: #fef3c7; border-color: #92400e; }
html[data-theme="dark"] .alert-info    { background: #1e3a8a; color: #dbeafe; border-color: #1e40af; }
html[data-theme="dark"] .btn-outline { background: transparent; color: #e5e7eb; border-color: #334155; }
html[data-theme="dark"] .btn-outline:hover { background: #172033; }
html[data-theme="dark"] .sidebar-toggle { color: #e5e7eb; }
html[data-theme="dark"] a { color: #818cf8; }
html[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.7); }

/* Theme toggle button (shown in top bar) */
.theme-toggle {
    background: none;
    border: none;
    padding: 8px 10px;
    cursor: pointer;
    color: var(--gray-700);
    font-size: 16px;
    border-radius: 4px;
}
.theme-toggle:hover { background: var(--gray-100); }
html[data-theme="dark"] .theme-toggle { color: #e5e7eb; }
html[data-theme="dark"] .theme-toggle:hover { background: #172033; }

/* Stats grid: 2x2 on phones instead of stacking */
@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 24px; }
    .stat-label { font-size: 11px; }
}

/* Fix hardcoded #fff backgrounds in dark mode */
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .login-card,
html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .toast {
    background: #1e293b;
    color: #e5e7eb;
}
html[data-theme="dark"] .stat-card .stat-label { color: #94a3b8; }
html[data-theme="dark"] .stat-card .stat-value { color: #f1f5f9; }
html[data-theme="dark"] .badge-info    { background: #1e3a8a; color: #dbeafe; }
html[data-theme="dark"] .badge-success { background: #064e3b; color: #d1fae5; }
html[data-theme="dark"] .badge-danger  { background: #7f1d1d; color: #fee2e2; }
html[data-theme="dark"] .badge-warning { background: #78350f; color: #fef3c7; }
html[data-theme="dark"] .badge-gray    { background: #374151; color: #e5e7eb; }

/* Center stat card content */
.stat-card { text-align: center; }

/* Sidebar: stay visually dark in both themes (CSS var flip was making it light) */
html[data-theme="dark"] .sidebar { background: #0b1220; color: #e5e7eb; }
html[data-theme="dark"] .sidebar-brand { border-bottom-color: #1f2937; }
html[data-theme="dark"] .sidebar-nav li a { color: #cbd5e1; }
html[data-theme="dark"] .sidebar-nav li a:hover { background: #172033; color: #fff; }
html[data-theme="dark"] .sidebar-nav li a.active { background: var(--primary); color: #fff; }
html[data-theme="dark"] .sidebar-section { color: #64748b; }
html[data-theme="dark"] .sidebar-nav li a i { color: inherit; }

/* Client-row action buttons: 2-col grid with bigger tap targets */

/* Client-row action buttons: 2-col grid (shrink to content, big tap targets) */
.client-actions {
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.client-actions .btn {
    padding: 8px 10px;
    min-height: 36px;
    min-width: 36px;
    font-size: 14px;
}

/* Clients table: centered data, smaller headers, 17px cell font */
.clients-table th {
    text-align: center;
    vertical-align: middle;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gray-500);
}
.clients-table td {
    text-align: center;
    vertical-align: middle;
    font-size: 17px;
}
.clients-table th.text-left,
.clients-table td:first-child { text-align: left; }
.clients-table td:first-child .text-muted { font-size: 14px; }
.clients-table .badge { font-size: 14px; padding: 4px 10px; }
.clients-table .actions-cell { width: 1%; white-space: nowrap; padding: 6px 4px; }
.clients-table .actions-cell .client-actions { justify-content: flex-end; }

/* Actions: right-aligned single row on tablet/desktop, 2-col grid on mobile */
@media (min-width: 769px) {
    .clients-table .actions-cell { text-align: right; }
    .client-actions {
        display: inline-flex;
        gap: 6px;
    }
}
