:root {
    --primary: #2563eb; /* Royal Blue */
    --primary-hover: #1d4ed8;
    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-light: #e2e8f0;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --escalated-bg: #fff7ed;
    --escalated-border: #fed7aa;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 10px 24px rgba(15, 23, 42, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    border-bottom: 1px solid var(--border-light);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-logo {
    height: 40px;
    width: auto;
}

.logo-text h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

.logo-text p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

button {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-light);
    background: white;
    color: var(--text-main);
}

button:hover {
    background: #f1f5f9;
    transform: translateY(-1px);
}

button:active {
    transform: scale(0.98);
}

.header-actions button:last-child {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

#desktop-refresh-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mobile-menu-container {
    display: none;
}

/* Stats Section */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    padding: 2rem;
}

.stat-card {
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 0.75rem;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.stat-card .label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Main Layout */
main {
    padding: 0 2rem 2rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
}

.section-header {
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

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

/* Priority Block */
.priority-block {
    animation: fadeIn 0.5s ease-out;
}

.priority-table {
    border: 1px solid var(--escalated-border) !important;
    background: var(--escalated-bg) !important;
}

.status-indicator-pulse {
    width: 10px;
    height: 10px;
    background-color: var(--error);
    border-radius: 50%;
    box-shadow: 0 0 0 rgba(239, 68, 68, 0.4);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Tables */
.table-container {
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
}

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

th {
    padding: 1rem 1.5rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    background: #f8fafc;
    border-bottom: 1px solid var(--border-light);
}

td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.9rem;
}

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

tr:hover {
    background-color: #f1f5f9;
}

.action-cell {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
}

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

.view-btn:hover {
    background: var(--primary-hover);
}

/* Conversation Inbox */
.conversation-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.priority-list {
    border: 1px solid var(--escalated-border);
    background: var(--escalated-bg);
    border-radius: 8px;
    padding: 0.75rem;
}

.conversation-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 1rem;
    align-items: center;
    padding: 1rem;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.conversation-card:hover {
    border-color: #bfdbfe;
    box-shadow: var(--shadow-md);
}

.conversation-card-main {
    min-width: 0;
}

.conversation-card-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.45rem;
}

.conversation-thread {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.05rem;
    color: var(--text-main);
}

.conversation-time {
    flex: 0 0 auto;
    color: var(--text-main);
    font-size: 0.95rem;
}

.conversation-preview {
    color: var(--text-main);
    font-size: 0.98rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 0.7rem;
}

.conversation-preview span {
    font-weight: 700;
}

.conversation-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.conversation-ai-control {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
    font-size: 0.8rem;
    font-weight: 700;
}

.conversation-ai-control .status-active,
.conversation-ai-control .status-escalated {
    background: transparent;
}

.conversation-card-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    position: relative;
}

.icon-action-btn {
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: var(--text-muted);
}

.icon-action-btn.primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.icon-action-btn.danger:hover {
    color: var(--error);
    border-color: #fecaca;
    background: #fef2f2;
}

.conversation-overflow-menu {
    position: relative;
}

.conversation-overflow-menu summary {
    list-style: none;
    width: 2rem;
    height: 2.25rem;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.conversation-overflow-menu summary::-webkit-details-marker {
    display: none;
}

.conversation-overflow-menu summary:hover {
    color: var(--text-main);
}

.conversation-overflow-panel {
    position: absolute;
    top: calc(100% + 0.35rem);
    right: 0;
    min-width: 9rem;
    padding: 0.35rem;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    z-index: 20;
}

.conversation-overflow-panel button {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--error);
    padding: 0.65rem 0.75rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: left;
}

.conversation-overflow-panel button:hover {
    background: #fef2f2;
    color: #b91c1c;
    transform: none;
}

.empty-state {
    min-height: 12rem;
    display: grid;
    place-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 8px;
}

.empty-state .material-symbols-rounded {
    font-size: 2rem;
    color: #94a3b8;
}

/* Badges */
.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.status-active { background: #dcfce7; color: #166534; }
.status-escalated { background: #fee2e2; color: #991b1b; }
.status-resolved { background: #f1f5f9; color: #475569; }

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.active { display: flex; }

.modal-content {
    background: white;
    width: 95%;
    max-width: 800px;
    height: 85vh;
    border-radius: 1rem;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: slideUp 0.3s ease-out;
}

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

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.modal-title-section h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.modal-badges {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

/* AI Toggle Switch */
.ai-toggle-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}

.switch.small {
    width: 36px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

.switch.small .slider:before {
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
}

input:checked + .slider {
    background-color: var(--primary);
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.switch.small input:checked + .slider:before {
    transform: translateX(16px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

.status-active { color: var(--primary); }
.status-escalated { color: var(--error); }

/* Messages */
#messages-container {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: #fdfdfd;
}

.message {
    max-width: 85%;
    padding: 0.6rem 0.8rem;
    border-radius: 0.75rem;
    font-size: 0.92rem;
    line-height: 1.45;
    position: relative;
    display: flex;
    flex-direction: column;
}

.message-content {
    word-break: break-word;
    white-space: pre-wrap;
}

.message-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.25rem;
    font-size: 0.7rem;
    opacity: 0.6;
}

.message-time {
    font-weight: 500;
}

.message-status {
    font-size: 0.8rem;
    line-height: 1;
}

.message.user {
    align-self: flex-end;
    background: #f1f5f9;
    color: var(--text-main);
    border-bottom-right-radius: 0;
}

.message.assistant {
    align-self: flex-start;
    background: white;
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 0;
}

.reply-area {
    padding: 1.5rem;
    background: white;
    border-top: 1px solid var(--border-light);
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
}

input {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-light);
    outline: none;
    font-size: 0.95rem;
}

input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

#send-reply-btn {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.close-modal {
    font-size: 1.5rem;
    border: none;
    background: none;
    color: var(--text-muted);
    padding: 0;
    line-height: 1;
}

.close-modal:hover {
    background: none;
    color: var(--error);
}

/* Dedicated Chat Page */
.chat-body {
    height: 100dvh;
    overflow: hidden;
    background: #f8fafc;
}

.conversation-page {
    height: 100dvh;
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: white;
    border-left: 1px solid var(--border-light);
    border-right: 1px solid var(--border-light);
}

.page-header {
    flex: 0 0 auto;
    min-height: 4.5rem;
    padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 1rem 0.75rem 1rem;
    background: white;
    border-bottom: 1px solid var(--border-light);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.chat-back-button {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.chat-back-button:hover {
    background: #eff6ff;
}

.chat-title-block {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.chat-title-block h1 {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1rem;
    line-height: 1.2;
    color: var(--text-main);
}

.chat-title-block > span {
    font-size: 0.78rem;
    font-weight: 700;
}

.page-header .header-controls {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.chat-body #messages-container {
    flex: 1;
    min-height: 0;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    background: #f8fafc;
}

.chat-body .message {
    max-width: min(78%, 34rem);
    padding: 0.72rem 0.85rem 0.55rem 0.85rem;
    border-radius: 1rem;
    font-size: 0.96rem;
    line-height: 1.42;
    box-shadow: var(--shadow-sm);
}

.chat-body .message.assistant {
    align-self: flex-start;
    background: white;
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 0.25rem;
}

.chat-body .message.user {
    align-self: flex-end;
    background: #eaf1fb;
    color: var(--text-main);
    border-bottom-right-radius: 0.25rem;
}

.chat-body .message-footer {
    margin-top: 0.35rem;
    color: var(--text-muted);
    opacity: 1;
}

.chat-body .reply-area {
    flex: 0 0 auto;
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px)) 1rem;
    background: white;
    border-top: 1px solid var(--border-light);
}

.chat-body .input-wrapper {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.6rem;
    align-items: center;
}

.chat-body #reply-input {
    width: 100%;
    height: 3rem;
    min-width: 0;
    border-radius: 999px;
    background: #f8fafc;
    border: 1px solid var(--border-light);
    padding: 0 1rem;
    font-size: 1rem;
}

.send-icon-btn {
    width: 3rem;
    height: 3rem;
    padding: 0;
    border-radius: 999px;
    border-color: var(--primary);
    background: var(--primary);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.send-icon-btn:hover {
    background: var(--primary-hover);
}

.send-icon-btn .material-symbols-rounded {
    font-size: 1.35rem;
}

/* Login Modal Specifics */
.login-modal {
    max-width: 420px;
    height: auto;
    max-height: 90vh;
    text-align: center;
}

.login-modal .modal-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    padding: 3rem 1rem 1rem 1rem;
    border-bottom: none;
}

.login-logo {
    height: 60px;
    width: auto;
    margin-bottom: 0.5rem;
}

.login-body {
    padding: 2.5rem 2rem;
}

.login-body p {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 1rem;
}

.input-group {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    text-align: left;
}

.input-group label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-left: 0.25rem;
}

.input-group input {
    width: 100%;
}

#login-btn {
    width: 100%;
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    padding: 0.9rem;
    margin-top: 1rem;
    font-weight: 600;
    font-size: 1rem;
}

#login-error {
    text-align: center;
    margin-top: 1.25rem;
    font-weight: 500;
}

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

/* Mobile Responsiveness */
@media (max-width: 768px) {
    header {
        position: relative;
        padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 1rem 0.75rem 1rem;
        flex-direction: column;
        gap: 0;
        align-items: flex-start;
    }

    .logo-text p {
        display: block; /* Keep subtitle */
        font-size: 0.75rem;
    }

    .logo-text h1 {
        font-size: 1.15rem;
    }

    .header-actions {
        display: none !important;
    }

    .mobile-menu-container {
        display: block;
        position: absolute;
        top: calc(0.75rem + env(safe-area-inset-top, 0px));
        right: 1rem;
        z-index: 1000;
    }

    #burger-menu-btn {
        background: transparent;
        border: none;
        color: var(--primary);
        font-size: 1.5rem;
        cursor: pointer;
        padding: 0.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .dropdown-menu {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        background: white;
        border-radius: 12px;
        box-shadow: var(--shadow-lg);
        border: 1px solid var(--border-light);
        min-width: 180px;
        margin-top: 0.5rem;
        overflow: hidden;
    }

    .dropdown-menu.active {
        display: flex;
        flex-direction: column;
    }

    .dropdown-menu button {
        padding: 0.85rem 1rem;
        border: none;
        background: transparent;
        text-align: left;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-dark);
        display: flex;
        align-items: center;
        gap: 0.75rem;
        border-bottom: 1px solid var(--border-light);
        width: 100%;
    }

    .dropdown-menu button:last-child {
        border-bottom: none;
    }

    .dropdown-menu button .material-symbols-rounded {
        font-size: 1.25rem;
        color: var(--primary);
    }

    .dropdown-menu button#enable-notifications-btn {
        background: var(--success-bg, rgba(16, 185, 129, 0.1));
        color: var(--success);
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.75rem 0.25rem;
        text-align: center;
    }

    .stat-card .value {
        font-size: 1.25rem;
    }

    .stat-card .label {
        font-size: 0.65rem;
        text-transform: uppercase;
        letter-spacing: 0.2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    main {
        padding: 0 1rem 1rem 1rem;
    }

    .section-header {
        margin-top: 0.75rem;
    }

    .section-header h2 {
        font-size: 1.45rem;
    }

    .conversation-list,
    .priority-list {
        gap: 0.6rem;
    }

    .priority-list {
        padding: 0;
        border: none;
        background: transparent;
    }

    .conversation-card {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.75rem;
        padding: 0.9rem 0.95rem;
        box-shadow: none;
    }

    .conversation-thread {
        font-size: 1.05rem;
    }

    .conversation-time {
        font-size: 0.9rem;
    }

    .conversation-preview {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }

    .conversation-card-actions {
        display: none;
    }

    .conversation-card-meta {
        align-items: flex-end;
    }

    /* --- Dedicated Conversation Page --- */
    .chat-body {
        background: white;
    }

    .conversation-page {
        height: 100dvh;
        max-width: none;
        overflow: hidden;
        border: none;
    }

    .page-header {
        min-height: 4.25rem;
        padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 0.75rem 0.6rem 0.75rem;
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 0.45rem;
    }

    .chat-back-button {
        width: 2.25rem;
        height: 2.25rem;
    }

    .chat-title-block h1 {
        font-size: 0.95rem;
    }

    .chat-title-block > span {
        font-size: 0.72rem;
    }

    .page-header .status-badge {
        display: none;
    }

    .page-header .header-controls {
        gap: 0.35rem;
    }

    #messages-container {
        padding: 0.85rem;
        background: #fdfdfd;
    }

    .reply-area {
        padding: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        background: white;
        border-top: 1px solid var(--border-light);
    }
    .ai-toggle-group {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    #page-ai-toggle-label {
        font-size: 0.65rem;
        font-weight: 700;
        white-space: nowrap;
        color: var(--primary);
    }
}
