/* BlogReach CRM v17 — Complete Stylesheet */
/* Dark + Light theme via CSS variables */

:root {
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-w: 56px;
    --sidebar-w-open: 220px;
    --header-h: 0px;
    --transition: .2s ease;
}

/* ═══ DARK THEME (default) ═══ */
[data-theme="dark"], :root {
    --bg-app: #0e0f11;
    --bg-sidebar: #131417;
    --bg-card: #17181c;
    --bg-surface: #1c1d22;
    --bg-hover: #22232a;
    --bg-active: #282a33;
    --bg-input: #1c1d22;
    --border: rgba(255,255,255,.07);
    --border-hover: rgba(255,255,255,.12);
    --text-primary: #e8e6e0;
    --text-secondary: #a09e96;
    --text-muted: #6b6a64;
    --text-dim: #4a4944;
    --blue: #3b82f6;
    --green: #10b981;
    --amber: #f59e0b;
    --red: #ef4444;
    --purple: #8b5cf6;
    --blue-bg: rgba(59,130,246,.1);
    --green-bg: rgba(16,185,129,.1);
    --amber-bg: rgba(245,158,11,.1);
    --red-bg: rgba(239,68,68,.1);
    --purple-bg: rgba(139,92,246,.1);
    --shadow: 0 1px 3px rgba(0,0,0,.3);
}

/* ═══ LIGHT THEME ═══ */
[data-theme="light"] {
    --bg-app: #f5f5f0;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --bg-surface: #fafaf7;
    --bg-hover: #f0f0eb;
    --bg-active: #e8e8e3;
    --bg-input: #ffffff;
    --border: rgba(0,0,0,.08);
    --border-hover: rgba(0,0,0,.15);
    --text-primary: #1a1a18;
    --text-secondary: #5a5955;
    --text-muted: #8a8983;
    --text-dim: #b5b4ae;
    --blue: #2563eb;
    --green: #059669;
    --amber: #d97706;
    --red: #dc2626;
    --purple: #7c3aed;
    --blue-bg: rgba(37,99,235,.08);
    --green-bg: rgba(5,150,105,.08);
    --amber-bg: rgba(217,119,6,.08);
    --red-bg: rgba(220,38,38,.08);
    --purple-bg: rgba(124,58,237,.08);
    --shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* ═══ RESET ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-sans); background: var(--bg-app); color: var(--text-primary); font-size: 14px; line-height: 1.5; overflow-x: hidden; }
a { color: var(--blue); text-decoration: none; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ═══ APP LAYOUT ═══ */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ═══ SIDEBAR ═══ */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width .2s ease, min-width .2s ease;
    overflow: hidden;
    z-index: 100;
    position: relative;
}
.sidebar:hover {
    width: var(--sidebar-w-open);
    min-width: var(--sidebar-w-open);
}
.sidebar:hover .sb-label { opacity: 1; }
.sidebar:hover .sb-brand-text { opacity: 1; width: auto; }

.sb-brand {
    padding: 14px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    min-height: 56px;
}
.sb-logo {
    width: 32px; height: 32px; border-radius: 8px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; color: #fff; flex-shrink: 0;
}
.sb-brand-text { opacity: 0; white-space: nowrap; transition: opacity .15s; }
.sb-brand-name { font-weight: 700; font-size: 15px; color: var(--text-primary); }
.sb-brand-sub { font-size: 11px; color: var(--text-muted); }

.sb-nav { flex: 1; padding: 8px 6px; display: flex; flex-direction: column; gap: 2px; }

.sb-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-radius: var(--radius);
    cursor: pointer; transition: all .12s ease;
    color: var(--text-secondary); white-space: nowrap;
    border: none; background: none; width: 100%; text-align: left;
    font-size: 13px;
}
.sb-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.sb-item.active { background: var(--bg-active); color: var(--text-primary); font-weight: 600; }
.sb-item svg { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; }
.sb-label { opacity: 0; transition: opacity .15s; }
.sb-badge { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 10px; background: var(--blue); color: #fff; margin-left: auto; }

.sb-footer {
    padding: 8px 6px; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 2px;
}

.sb-theme-toggle {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-radius: var(--radius);
    cursor: pointer; color: var(--text-muted); border: none; background: none;
    width: 100%; text-align: left; font-size: 12px;
}
.sb-theme-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.sb-theme-toggle svg { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; }

.sb-user {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; cursor: pointer;
}
.sb-user-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--purple-bg); color: var(--purple);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.sb-user-name { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }

/* ═══ MAIN CONTENT ═══ */
.main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 28px;
    min-width: 0;
}

/* ═══ PAGE HEADER ═══ */
.page-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px;
}
.page-title { font-size: 20px; font-weight: 700; }
.page-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ═══ STATS GRID ═══ */
.stats-row {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px; margin-bottom: 20px;
}
.stat-box {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 16px; position: relative; overflow: hidden;
}
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 2px; font-family: var(--font-mono); }

/* ═══ STAGE TABS ═══ */
.stage-tabs {
    display: flex; gap: 0; margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.stage-tab {
    padding: 10px 16px; font-size: 13px; font-weight: 500;
    color: var(--text-muted); cursor: pointer; border: none; background: none;
    border-bottom: 2px solid transparent; transition: all .12s;
    display: flex; align-items: center; gap: 6px;
}
.stage-tab:hover { color: var(--text-primary); }
.stage-tab.active { color: var(--text-primary); border-bottom-color: var(--blue); font-weight: 600; }
.stage-tab .tab-count {
    font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px;
    background: var(--bg-surface); color: var(--text-muted);
}
.stage-tab.active .tab-count { background: var(--blue-bg); color: var(--blue); }

/* ═══ TOOLBAR ═══ */
.toolbar {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 14px; flex-wrap: wrap;
}
.search-input {
    background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 7px 12px 7px 34px; font-size: 13px; color: var(--text-primary);
    width: 240px; outline: none; transition: border .15s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b6a64' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 10px center;
}
.search-input:focus { border-color: var(--blue); }
.search-input::placeholder { color: var(--text-dim); }

/* ═══ CRM TABLE ═══ */
.crm-table {
    width: 100%; border-collapse: collapse;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); overflow: hidden;
}
.crm-table thead { background: var(--bg-surface); }
.crm-table th {
    padding: 10px 14px; font-size: 11px; font-weight: 600;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px;
    text-align: left; border-bottom: 1px solid var(--border);
    white-space: nowrap; cursor: pointer; user-select: none;
}
.crm-table th:hover { color: var(--text-primary); }
.crm-table td {
    padding: 10px 14px; font-size: 13px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 200px;
}
.crm-table tr:last-child td { border-bottom: none; }
.crm-table tbody tr { transition: background .1s; }
.crm-table tbody tr:hover { background: var(--bg-hover); }

.td-domain {
    font-weight: 600; color: var(--text-primary);
    display: flex; align-items: center; gap: 10px;
}
.td-avatar {
    width: 28px; height: 28px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 700; flex-shrink: 0;
}
.td-email { color: var(--green); font-family: var(--font-mono); font-size: 12px; }
.td-muted { color: var(--text-muted); font-size: 12px; }
.td-dim { color: var(--text-dim); font-size: 12px; }

/* Stage pills */
.stage-pill {
    display: inline-block; padding: 3px 10px; border-radius: 12px;
    font-size: 11px; font-weight: 600; white-space: nowrap;
}
.stage-pill-new { background: var(--bg-surface); color: var(--text-muted); }
.stage-pill-ready { background: var(--blue-bg); color: var(--blue); }
.stage-pill-contacted { background: var(--amber-bg); color: var(--amber); }
.stage-pill-replied { background: var(--green-bg); color: var(--green); }
.stage-pill-staff { background: var(--purple-bg); color: var(--purple); }

/* Stage inline dropdown */
.stage-select {
    padding: 4px 8px; border-radius: 6px; font-size: 11px; font-weight: 600;
    border: 1px solid var(--border); background: var(--bg-input); color: var(--text-primary);
    cursor: pointer; outline: none;
}

/* Status dots */
.status-dot {
    width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px;
}

/* ═══ BUTTONS ═══ */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500;
    cursor: pointer; border: 1px solid var(--border); background: var(--bg-card);
    color: var(--text-primary); transition: all .12s; white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 8px; font-size: 11px; }

.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { opacity: .9; }
.btn-green { background: var(--green); color: #fff; border-color: var(--green); }
.btn-green:hover { opacity: .9; }
.btn-danger { color: var(--red); border-color: var(--red-bg); background: var(--red-bg); }
.btn-danger:hover { background: rgba(239,68,68,.15); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-icon-only {
    width: 32px; height: 32px; padding: 0; border-radius: var(--radius);
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid transparent; cursor: pointer;
    color: var(--text-muted); transition: all .12s;
}
.btn-icon-only:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border); }

/* ═══ FORM ELEMENTS ═══ */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.form-input {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg-input); color: var(--text-primary); font-size: 13px; outline: none;
    transition: border .15s;
}
.form-input:focus { border-color: var(--blue); }

/* ═══ CARDS ═══ */
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px 20px;
    margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }

/* ═══ MODAL ═══ */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,.5); display: flex; align-items: center;
    justify-content: center; z-index: 1000; animation: fadeIn .15s;
}
.modal {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 24px;
    width: 90%; max-width: 600px; max-height: 90vh; overflow-y: auto;
    animation: slideUp .2s ease;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px) } to { opacity: 1; transform: translateY(0) } }

/* ═══ DETAIL PANEL (slide-out) ═══ */
.detail-panel {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px;
    margin-top: 16px; animation: slideUp .2s ease;
}

/* ═══ PROGRESS BAR ═══ */
.progress-bar { background: var(--bg-surface); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; transition: width .3s; }

/* ═══ TOAST ═══ */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; }
.toast {
    padding: 10px 18px; border-radius: var(--radius); font-size: 13px; font-weight: 500;
    animation: slideUp .2s ease; margin-bottom: 8px; max-width: 400px;
}
.toast-success { background: var(--green); color: #fff; }
.toast-error { background: var(--red); color: #fff; }

/* ═══ LOGIN ═══ */
.login-wrapper {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: var(--bg-app);
}
.login-box {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 32px;
    width: 380px; max-width: 90%;
}
.login-logo {
    width: 48px; height: 48px; border-radius: 12px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 20px; color: #fff; margin: 0 auto 16px;
}
.login-title { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: var(--text-muted); text-align: center; margin-bottom: 20px; }

/* ═══ UPLOAD AREA ═══ */
.upload-area {
    border: 1px dashed var(--border); border-radius: var(--radius);
    padding: 16px; margin-bottom: 14px; transition: border-color .15s;
}
.upload-area:hover { border-color: var(--blue); }

/* ═══ GRID HELPERS ═══ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.text-right { text-align: right; }

/* ═══ QUEUE STATUS ═══ */
.queue-banner {
    background: var(--amber-bg); border: 1px solid rgba(245,158,11,.15);
    border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
}

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 900px) {
    .main-content { padding: 16px; }
    .grid-2 { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .search-input { width: 100%; }
}

/* ═══ SPINNER ═══ */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { animation: spin 1s linear infinite; }

/* ═══ TABLE EMPTY STATE ═══ */
.empty-state {
    padding: 48px 20px; text-align: center; color: var(--text-muted); font-size: 13px;
}
.empty-icon { font-size: 32px; margin-bottom: 12px; opacity: .5; }

/* ═══ BULK ACTION BAR ═══ */
.bulk-bar {
    background: var(--blue-bg);
    border: 1px solid rgba(59,130,246,.2);
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 12px;
    animation: slideUp .15s ease;
}
.row-checked { background: var(--blue-bg) !important; }
.crm-table th input[type="checkbox"],
.crm-table td input[type="checkbox"] {
    width: 16px; height: 16px; cursor: pointer;
    accent-color: var(--blue);
}

/* ═══ NEW STAGE PILLS ═══ */
.stage-pill-staff-done { background: rgba(245,158,11,.1); color: var(--amber); }
.stage-pill-nocontact { background: rgba(239,68,68,.1); color: var(--red); }

/* ═══ STAFF TABLE INPUTS ═══ */
.staff-input {
    width: 100%; padding: 5px 8px; font-size: 12px;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: 4px; color: var(--text-primary); outline: none;
    font-family: var(--font-mono); transition: border .15s;
}
.staff-input:focus { border-color: var(--blue); }
.staff-input::placeholder { color: var(--text-dim); font-family: var(--font-sans); }
.staff-select {
    width: 100%; padding: 5px 6px; font-size: 11px; font-weight: 600;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: 4px; color: var(--text-primary); outline: none; cursor: pointer;
}
.staff-select:focus { border-color: var(--blue); }
#staff-tbl td { padding: 8px 6px; vertical-align: middle; }
#staff-tbl th { padding: 8px 6px; }

/* ═══ EMAIL VALIDATION ═══ */
.staff-email-input { transition: border-color .2s; }
.staff-email-input[title]:not([title=""]):hover::after { content: attr(title); }
