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

:root {
    /* Color System */
    --bg-primary: #0a0a1a;
    --bg-secondary: #111128;
    --bg-card: rgba(17, 17, 40, 0.7);
    --bg-card-hover: rgba(25, 25, 55, 0.8);
    --border: rgba(99, 102, 241, 0.15);
    --border-hover: rgba(99, 102, 241, 0.35);

    --text-primary: #f1f1f8;
    --text-secondary: #a0a0c0;
    --text-muted: #6b6b8d;

    --accent-indigo: #6366f1;
    --accent-purple: #a855f7;
    --accent-pink: #ec4899;
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-red: #ef4444;
    --accent-sky: #0ea5e9;

    --gradient-primary: linear-gradient(135deg, #6366f1, #a855f7);
    --gradient-hot: linear-gradient(135deg, #ef4444, #f97316);
    --gradient-warm: linear-gradient(135deg, #f59e0b, #fbbf24);
    --gradient-cold: linear-gradient(135deg, #3b82f6, #6366f1);
    --gradient-dnc: linear-gradient(135deg, #64748b, #94a3b8);

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);

    /* Font */
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── Background Effects ──────────────────────────────────────────── */
.bg-effects {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.35;
    animation: orbFloat 20s ease-in-out infinite;
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, #6366f1, transparent 70%);
    top: -200px;
    right: -100px;
    animation-delay: 0s;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #a855f7, transparent 70%);
    bottom: -200px;
    left: -100px;
    animation-delay: -7s;
}

.orb-3 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, #ec4899, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -14s;
}

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(50px, -30px) scale(1.05); }
    50% { transform: translate(-20px, 40px) scale(0.95); }
    75% { transform: translate(30px, 20px) scale(1.02); }
}

/* ─── Glass Effect ────────────────────────────────────────────────── */
.glass {
    background: var(--bg-card);
    border: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* ─── Header ──────────────────────────────────────────────────────── */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: rgba(10, 10, 26, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.logo-text .accent {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 100px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--accent-red);
    transition: all 0.3s ease;
}

.status-badge.connected {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.2);
    color: var(--accent-emerald);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

/* ─── Buttons ─────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
}

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

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.45);
}

.btn-secondary {
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent-indigo);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.btn-secondary:hover {
    background: rgba(99, 102, 241, 0.2);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ─── Spinner ─────────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
    border-color: rgba(99, 102, 241, 0.2);
    border-top-color: var(--accent-indigo);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── Main Content ────────────────────────────────────────────────── */
.main-content {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px;
}

/* ─── Login Section ───────────────────────────────────────────────── */
.login-section {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 130px);
}

.login-card {
    width: 100%;
    max-width: 440px;
    padding: 40px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: fadeSlideUp 0.6s ease;
}

.card-header {
    text-align: center;
    margin-bottom: 32px;
}

.card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    background: rgba(99, 102, 241, 0.1);
    margin-bottom: 16px;
}

.card-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ─── Form ────────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 20px;
}

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

.form-group input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.95rem;
    transition: all 0.2s ease;
    outline: none;
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-group input:focus {
    border-color: var(--accent-indigo);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
    background: rgba(255, 255, 255, 0.06);
}

.login-error {
    margin-top: 16px;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--accent-red);
    font-size: 0.85rem;
    text-align: center;
}

.login-note {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 20px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ─── Stats Bar ───────────────────────────────────────────────────── */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
    animation: fadeSlideUp 0.5s ease;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    border-radius: var(--radius-lg);
    transition: all 0.2s ease;
}

.stat-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ─── Action Bar ──────────────────────────────────────────────────── */
.action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    animation: fadeSlideUp 0.6s ease;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.section-title .highlight {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

/* ─── Table ───────────────────────────────────────────────────────── */
.table-container {
    border-radius: var(--radius-lg);
    overflow: hidden;
    animation: fadeSlideUp 0.7s ease;
}

.table-loading,
.table-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 32px;
    text-align: center;
}

.table-loading p {
    margin-top: 16px;
    font-weight: 500;
    color: var(--text-secondary);
}

.loading-sub {
    font-size: 0.85rem;
    color: var(--text-muted) !important;
    margin-top: 4px !important;
}

.empty-icon {
    margin-bottom: 16px;
    color: var(--text-muted);
}

.table-empty h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.table-empty p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

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

.messages-table thead {
    background: rgba(99, 102, 241, 0.05);
}

.messages-table th {
    padding: 14px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.messages-table td {
    padding: 14px 16px;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(99, 102, 241, 0.06);
    vertical-align: middle;
}

.messages-table tbody tr {
    transition: background 0.15s ease;
    cursor: pointer;
}

.messages-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.05);
}

.th-select {
    width: 40px;
}

.th-name {
    width: 180px;
}

.th-phone {
    width: 140px;
}

.th-status {
    width: 120px;
}

.th-date {
    width: 130px;
}

.th-actions {
    width: 100px;
}

/* Contact Cell */
.contact-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.contact-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: white;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.contact-name {
    font-weight: 600;
}

.contact-phone {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Status badges */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 0.78rem;
    font-weight: 600;
}

.status-pill.no-status {
    background: rgba(245, 158, 11, 0.1);
    color: var(--accent-amber);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.status-pill.hot-lead {
    background: rgba(239, 68, 68, 0.1);
    color: var(--accent-red);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-pill.warm-lead {
    background: rgba(245, 158, 11, 0.1);
    color: var(--accent-amber);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.status-pill.not-interested {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-sky);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.status-pill.dnc {
    background: rgba(100, 116, 139, 0.1);
    color: #94a3b8;
    border: 1px solid rgba(100, 116, 139, 0.2);
}

/* Message preview */
.message-preview {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* ─── Modal ───────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 640px;
    max-height: 80vh;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    animation: modalSlideUp 0.3s ease;
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-title h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-badge {
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(245, 158, 11, 0.1);
    color: var(--accent-amber);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.5;
}

.chat-bubble.incoming {
    align-self: flex-start;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-bottom-left-radius: 4px;
}

.chat-bubble.outgoing {
    align-self: flex-end;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.15);
    border-bottom-right-radius: 4px;
}

.chat-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.chat-time {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.chat-notice {
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.2);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.ai-section .ai-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.status-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.status-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 100px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.status-btn:hover:not(:disabled) {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--accent-indigo);
    color: var(--text-primary);
}

.status-btn.hot { border-color: rgba(239, 68, 68, 0.3); color: #f87171; }
.status-btn.warm { border-color: rgba(245, 158, 11, 0.3); color: #fbbf24; }
.status-btn.not-interested { border-color: rgba(59, 130, 246, 0.3); color: #60a5fa; }
.status-btn.dnc { border-color: rgba(100, 116, 139, 0.3); color: #94a3b8; }

.status-btn.hot:hover { background: rgba(239,68,68,0.12); border-color: #ef4444; }
.status-btn.warm:hover { background: rgba(245,158,11,0.12); border-color: #f59e0b; }
.status-btn.not-interested:hover { background: rgba(59,130,246,0.12); border-color: #3b82f6; }
.status-btn.dnc:hover { background: rgba(100,116,139,0.12); border-color: #64748b; }

/* Modal badge color variants */
.modal-badge.status-hot-lead { background: rgba(239,68,68,0.1); color: #f87171; border-color: rgba(239,68,68,0.3); }
.modal-badge.status-warm-lead { background: rgba(245,158,11,0.1); color: #fbbf24; border-color: rgba(245,158,11,0.3); }
.modal-badge.status-not-interested { background: rgba(59,130,246,0.1); color: #60a5fa; border-color: rgba(59,130,246,0.3); }
.modal-badge.status-dnc { background: rgba(100,116,139,0.1); color: #94a3b8; border-color: rgba(100,116,139,0.3); }

/* Sub-phone under contact name */
.contact-phone-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Skeleton loader for chat */
.chat-skeleton {
    height: 40px;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, rgba(99,102,241,0.06) 0%, rgba(99,102,241,0.14) 50%, rgba(99,102,241,0.06) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    max-width: 70%;
}
.chat-skeleton.short { max-width: 45%; align-self: flex-end; }

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── Debug Panel ─────────────────────────────────────────────────── */
.debug-panel {
    margin-top: 24px;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.debug-title {
    padding: 16px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

.debug-title:hover {
    color: var(--text-primary);
}

.debug-content {
    padding: 0 20px 20px;
}

.debug-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.debug-log {
    padding: 16px;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.3);
    font-family: "SF Mono", "Fira Code", "Courier New", monospace;
    font-size: 0.78rem;
    color: var(--accent-emerald);
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

#debug-screenshot-container img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-top: 12px;
}

/* ─── Animations ──────────────────────────────────────────────────── */
@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ─── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.4);
}

/* ─── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }

    .action-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .main-content {
        padding: 16px;
    }

    .app-header {
        padding: 12px 16px;
    }
}

@media (max-width: 600px) {
    .stats-bar {
        grid-template-columns: 1fr;
    }

    .modal {
        padding: 16px;
    }

    .login-card {
        padding: 24px;
    }
}
