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

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-sidebar: #13151d;
    --bg-input: #222638;
    --border: #2a2e3f;
    --text: #e4e6ed;
    --text-muted: #8b8fa3;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* === LOGIN === */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f1117 0%, #1a1d27 100%);
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 48px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow);
}
.login-logo {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: var(--primary);
    color: #fff;
    font-size: 24px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 32px; }

/* === FORMS === */
.form-group { margin-bottom: 16px; text-align: left; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted); }
.input, .select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
}
.input:focus, .select:focus { border-color: var(--primary); }
textarea.input { resize: vertical; }
.select { cursor: pointer; }

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, opacity .15s;
}
.btn:hover { opacity: .9; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-full { width: 100%; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 12px; }

/* === APP LAYOUT === */
.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

/* === SIDEBAR === */
.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}
.logo-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.logo-text { font-size: 16px; font-weight: 700; }
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all .15s;
}
.nav-item:hover { color: var(--text); background: rgba(99,102,241,.08); }
.nav-item.active { color: var(--primary); border-left-color: var(--primary); background: rgba(99,102,241,.1); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.user-label { font-size: 12px; color: var(--text-muted); }

/* === MAIN CONTENT === */
.main-content { padding: 32px; overflow-y: auto; }
.page h2 { font-size: 22px; font-weight: 700; margin-bottom: 24px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header h2 { margin-bottom: 0; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page-actions .select, .page-actions .input { width: auto; min-width: 160px; }

/* === CARDS === */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

/* === STATS GRID === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-value.green { color: var(--success); }
.stat-value.red { color: var(--danger); }
.stat-value.blue { color: var(--info); }
.stat-value.yellow { color: var(--warning); }

/* === TABLE === */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.table th { font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: .5px; }
.table tr:hover td { background: rgba(99,102,241,.04); }
.table td { vertical-align: middle; }

/* === STATUS BADGES === */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-new { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-analyzed { background: rgba(139,92,246,.15); color: #a78bfa; }
.badge-qualified { background: rgba(34,197,94,.15); color: #4ade80; }
.badge-email_generated { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-sent { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-replied { background: rgba(34,197,94,.15); color: #4ade80; }
.badge-negotiating { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-offer_sent { background: rgba(249,115,22,.15); color: #fb923c; }
.badge-closed_won { background: rgba(34,197,94,.2); color: #22c55e; }
.badge-closed_lost { background: rgba(239,68,68,.15); color: #f87171; }
.badge-archived { background: rgba(107,114,128,.15); color: #9ca3af; }
.badge-initial_contact { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-interested { background: rgba(34,197,94,.15); color: #4ade80; }
.badge-objection_handling { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-pending_approval { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-approved { background: rgba(34,197,94,.15); color: #4ade80; }
.badge-edited { background: rgba(139,92,246,.15); color: #a78bfa; }

/* === PAGINATION === */
.pagination { display: flex; gap: 4px; justify-content: center; padding-top: 16px; }
.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.pagination button.active { background: var(--primary); border-color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

/* === WIDGETS === */
.widgets-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.widget-content { max-height: 300px; overflow-y: auto; }
.widget-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.widget-item:last-child { border-bottom: none; }

/* === MODAL === */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal-content { position: relative; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; width: 90%; max-width: 500px; max-height: 85vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,.4); }
.modal-lg { max-width: 800px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 16px; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 24px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }

/* === ANALYTICS === */
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.analytics-grid canvas { max-height: 280px; }

/* === SETTINGS TABS === */
.settings-tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.tab-btn {
    padding: 8px 20px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* === CONVERSATION DETAIL === */
.conv-messages { display: flex; flex-direction: column; gap: 12px; }
.conv-msg {
    padding: 12px 16px;
    border-radius: var(--radius);
    max-width: 80%;
    font-size: 14px;
    line-height: 1.5;
}
.conv-msg.incoming { background: var(--bg-input); align-self: flex-start; border: 1px solid var(--border); }
.conv-msg.outgoing { background: rgba(99,102,241,.15); align-self: flex-end; border: 1px solid rgba(99,102,241,.3); }
.conv-msg .msg-label { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }
.conv-msg .msg-meta { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

/* === DETAIL SECTIONS === */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-field { margin-bottom: 12px; }
.detail-label { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); margin-bottom: 2px; }
.detail-value { font-size: 14px; }

/* === MISC === */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-top: 12px; }
.alert-success { background: rgba(34,197,94,.15); color: #4ade80; border: 1px solid rgba(34,197,94,.3); }
.alert-error { background: rgba(239,68,68,.15); color: #f87171; border: 1px solid rgba(239,68,68,.3); }
.text-muted { color: var(--text-muted); font-size: 13px; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; display: inline-block; vertical-align: middle; }
code { background: var(--bg-input); padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.empty-state { text-align: center; padding: 48px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }

.setting-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }
.setting-key { font-weight: 600; min-width: 200px; font-size: 13px; }
.setting-value { flex: 1; font-size: 13px; color: var(--text-muted); }

.prompt-preview { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; font-family: monospace; font-size: 12px; white-space: pre-wrap; max-height: 300px; overflow-y: auto; margin-top: 8px; }

.action-btns { display: flex; gap: 4px; }

/* Responsive */
@media (max-width: 768px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .widgets-row { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .analytics-grid { grid-template-columns: 1fr; }
}
