/* ═══════════════════════════════════════════
   DESIGN SYSTEM — Professional Light Mode
   Clean, modern, and business-focused
   ═══════════════════════════════════════════ */

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

:root {
    /* Base Colors - Soft White/Slate */
    --bg-color: #f8fafc;
    --bg-deep: #f1f5f9;
    
    /* Surfaces */
    --surface-color: #ffffff;
    --surface-hover: #f1f5f9;
    --surface-raised: #ffffff;

    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    /* Accents - Trustworthy Blue */
    --accent-primary: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-glow: rgba(37, 99, 235, 0.1);
    
    /* Secondary Accent - Subtle Indigo */
    --accent-secondary: #4f46e5;

    /* Semantic */
    --success: #10b981;
    --success-bg: #ecfdf5;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --danger: #ef4444;
    --danger-bg: #fef2f2;

    /* Effects */
    --border: #e2e8f0;
    --border-highlight: #cbd5e1;
    --glass-border: 1px solid var(--border);
    --glass-blur: blur(12px);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 15px rgba(37, 99, 235, 0.1);
    
    /* Layout */
    --radius-pill: 9999px;
    --radius-card: 0.75rem;
    --radius-sm: 0.5rem;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-8px); }
    100% { transform: translateY(0px); }
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

#app-container {
    opacity: 0;
    animation: fadeInApp 0.8s ease forwards;
    animation-delay: 0.2s;
    width: 100%;
}

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

/* ── Top Navigation ── */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 64px;
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

.nav-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 0.5rem;
}

.nav-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
}

.nav-right .tabs {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    height: 64px;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
    border-radius: 0;
}

.nav-right .tab-btn {
    height: 64px;
    padding: 0 0.5rem;
    border-radius: 0;
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 2px solid transparent;
    background: transparent;
    border-top: none;
    border-left: none;
    border-right: none;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.nav-right .tab-btn:hover {
    background: transparent;
    color: var(--text-primary);
}

.nav-right .tab-btn.active {
    background: transparent;
    color: var(--accent-primary);
    border-bottom: 2px solid var(--accent-primary);
    box-shadow: none;
}

/* ── Sub Navigation ── */
.sub-tabs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-left: 1rem;
}

.sub-tab-btn {
    padding: 0.5rem 1.25rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.sub-tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-deep);
}

.sub-tab-btn.active {
    color: var(--accent-primary);
    background: var(--accent-glow);
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.05);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-badge {
    width: 36px;
    height: 36px;
    background: var(--bg-deep);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.main-content {
    max-width: 100%;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

/* ── Table container ── */
.table-container {
    width: 100%;
    background: var(--surface-color);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    margin-top: 1rem;
    margin-bottom: 4rem;
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    text-align: left;
}

th,
td {
    padding: 1rem 1.25rem;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    background: var(--surface-color);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    z-index: 2;
    border-top: none;
}

tr:last-child td {
    border-bottom: none;
}

tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background: #f8fafc;
}

.lead-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.lead-meta {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Buttons ── */
.btn {
    background: #ffffff;
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: var(--shadow-sm);
}

.btn:hover:not(:disabled) {
    background: #f8fafc;
    border-color: var(--border-highlight);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--bg-deep);
    color: var(--text-muted);
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    border: none;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    color: white;
}

.icon-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--surface-hover);
    color: var(--accent-primary);
    transform: translateX(-2px);
}

.btn-export {
    background: #f0f9ff !important;
    color: #0369a1 !important;
    border: 1px solid #bae6fd !important;
    font-size: 0.8rem !important;
    padding: 0.4rem 0.8rem !important;
}

.btn-export:hover {
    background: #e0f2fe !important;
    border-color: #7dd3fc !important;
}

.btn-no-transfer {
    background: #fdf2f2 !important;
    color: #991b1b !important;
    border: 1px solid #fee2e2 !important;
}

.btn-danger {
    background: #ef4444 !important;
    color: white !important;
    border: none !important;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-outline:hover {
    background: var(--bg-deep);
    border-color: var(--border-highlight);
    color: var(--text-primary);
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

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

/* ── Status Colors ── */
.status-badge {
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-transform: uppercase;
}

.status-badge::before {
    content: '';
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
}

.status-pending { background: #f1f5f9; color: #64748b; }
.status-pending::before { background: #64748b; }

.status-initiating { background: #eff6ff; color: #2563eb; }
.status-initiating::before { background: #2563eb; }

.status-in_progress, .status-completed { background: var(--success-bg); color: var(--success); }
.status-in_progress::before, .status-completed::before { background: var(--success); }

.status-failed, .status-busy, .status-no_answer, .status-canceled { background: var(--danger-bg); color: var(--danger); }
.status-failed::before, .status-busy::before, .status-no_answer::before, .status-canceled::before { background: var(--danger); }

/* ── Outcome Badges ── */
.outcome-badge {
    display: inline-block;
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    background: #f1f5f9;
    color: var(--text-secondary);
}
.outcome-interested { color: var(--success); background: var(--success-bg); }
.outcome-not_interested, .outcome-failed { color: var(--danger); background: var(--danger-bg); }
.outcome-callback_requested { color: var(--warning); background: var(--warning-bg); }

/* ── Toast Notifications ── */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-sm);
    background: #ffffff;
    border: 1px solid var(--border-highlight);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-success { border-left: 4px solid var(--success); }
.toast-danger { border-left: 4px solid var(--danger); }

/* ── Login Overlay ── */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.login-box {
    background: #ffffff;
    padding: 2.5rem;
    border-radius: var(--radius-card);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-box h2 {
    margin-top: 0;
    color: var(--text-primary);
    font-weight: 800;
    font-size: 1.75rem;
    letter-spacing: -0.02em;
}

.login-input {
    background: #f8fafc;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s;
    width: 100%;
    margin-bottom: 1rem;
}

.login-input:focus {
    border-color: var(--accent-primary);
    background: #ffffff;
    box-shadow: 0 0 0 4px var(--accent-glow);
}

.logout-btn {
    background: #ffffff;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
}

/* ── Modals & Transcripts ── */
.modal-overlay, .modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.show, .modal-overlay.show {
    display: flex;
}

.modal-content {
    background: #ffffff;
    border-radius: 1.25rem;
    width: 100%;
    max-width: 550px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 
        0 0 1px rgba(0,0,0,0.1),
        0 4px 6px -1px rgba(0,0,0,0.1),
        0 20px 40px -10px rgba(15, 23, 42, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.8);
    transform: translateY(0) scale(1);
    animation: modalContentPop 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

@keyframes modalContentPop {
    from { transform: translateY(30px) scale(0.96); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
    padding: 1.75rem 2rem;
    background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.modal-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 40px;
    height: 1px;
    background: var(--accent-primary);
    box-shadow: 0 0 10px var(--accent-primary);
}

.modal-body {
    padding: 2.25rem 2rem;
    overflow-y: auto;
    flex: 1;
    background: #ffffff;
}

.close-modal {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-deep);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.close-modal:hover {
    background: var(--danger-bg);
    color: var(--danger);
    transform: rotate(90deg) scale(1.1);
}

/* ── Form Elements ── */
.form-group {
    margin-bottom: 1.75rem;
}

.form-label {
    display: block;
    font-size: 0.825rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.65rem;
    text-transform: none;
    letter-spacing: 0.01em;
}

.form-input {
    width: 100%;
    padding: 0.85rem 1.15rem;
    background: #ffffff;
    border: 1.5px solid var(--border);
    border-radius: 0.75rem;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.form-input:hover {
    border-color: var(--border-highlight);
    background: var(--bg-color);
}

.form-input:focus {
    background: white;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px var(--accent-glow);
    transform: translateY(-1px);
}

.form-input::placeholder {
    color: #cbd5e1;
}

select.form-input {
    cursor: pointer;
}

/* ── Chat bubbles ── */
.chat-bubble {
    margin-bottom: 1.25rem;
    padding: 1rem 1.25rem;
    border-radius: 1.25rem;
    max-width: 85%;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.bubble-user {
    background: var(--accent-primary);
    color: white;
    align-self: flex-end;
    margin-left: auto;
    border-bottom-right-radius: 0.25rem;
}

.bubble-assistant {
    background: #f1f5f9;
    color: var(--text-primary);
    align-self: flex-start;
    margin-right: auto;
    border-bottom-left-radius: 0.25rem;
}

.bubble-meta {
    display: block;
    font-size: 0.65rem;
    margin-top: 0.5rem;
    opacity: 0.7;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Badges ── */
.badge {
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
}

.badge-primary {
    background: var(--accent-glow);
    color: var(--accent-primary);
}

.badge-secondary {
    background: var(--bg-deep);
    color: var(--text-secondary);
}

/* ── Phone Editing ── */
.phone-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.phone-input {
    padding: 0.4rem 0.6rem;
    border: 1.5px solid var(--accent-primary);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: 'JetBrains Mono', monospace;
    outline: none;
    background: #f8fafc;
    width: 160px;
}

.phone-input:focus {
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.edit-icon {
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.edit-icon:hover {
    opacity: 1;
}

.save-btn, .cancel-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
}

.transfer-required-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--danger);
    font-size: 0.8rem;
    font-weight: 600;
}

/* ── Admin Only ── */
.admin-only-cell {
    display: none;
}

body.is-admin .admin-only-cell {
    display: table-cell;
}

/* ── Page Content Area ── */
#app {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* ═══════════════════════════════════════════
   RESPONSIVE DESIGN (Media Queries)
   ═══════════════════════════════════════════ */

@media (max-width: 1024px) {
    /* Allow tabs to scroll on medium/small screens */
    .nav-right .tabs {
        overflow-x: auto;
        max-width: calc(100vw - 250px); /* Leave room for logo/user */
        scrollbar-width: none; /* Hide scrollbar for clean look */
    }
    .nav-right .tabs::-webkit-scrollbar {
        display: none;
    }
}

@media (max-width: 768px) {
    /* Top Nav wrapping */
    .top-nav {
        flex-direction: column;
        height: auto;
        padding: 1rem;
        gap: 1rem;
    }
    
    .nav-left {
        width: 100%;
        justify-content: space-between; /* Space out logo and toggle if needed */
    }

    .nav-subtitle {
        display: none; /* Hide subtitle to save space */
    }

    .nav-right {
        width: 100%;
        justify-content: space-between;
    }

    .nav-right .tabs {
        max-width: 100%;
        gap: 0.5rem;
    }

    .nav-right .tab-btn {
        height: 48px;
        font-size: 0.85rem;
        padding: 0 0.5rem;
        white-space: nowrap;
    }

    /* Reduce App padding */
    #app {
        padding: 1rem;
    }

    /* Sub Tabs */
    .sub-tabs {
        overflow-x: auto;
        padding-left: 0;
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
    }

    /* Table containers */
    .table-container {
        border-radius: 0;
        border-left: none;
        border-right: none;
        overflow-x: auto; /* Enable horizontal scrolling */
        -webkit-overflow-scrolling: touch;
    }

    th, td {
        padding: 0.75rem 1rem; /* slightly tighter on mobile */
        white-space: nowrap; /* keep table cells from crushing text */
    }

    /* Modals */
    .modal-content {
        max-width: 95%;
        margin: 1rem;
        max-height: 85vh;
    }

    .modal-header, .modal-body {
        padding: 1.25rem 1rem;
    }

    /* Toast */
    .toast {
        width: 90%;
        padding: 0.75rem 1rem;
        font-size: 0.85rem;
    }

    /* Login Box */
    .login-box {
        padding: 2rem 1.5rem;
        margin: 1rem;
        width: 90%;
    }
}
