/* Core Variables & Reset */
:root {
    --bg-gradient: radial-gradient(circle at 50% 50%, #171926 0%, #0d0e15 100%);
    --card-bg: rgba(22, 24, 38, 0.55);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(99, 102, 241, 0.2);
    
    --primary: #6366f1; /* Indigo */
    --primary-glow: rgba(99, 102, 241, 0.5);
    --primary-hover: #4f46e5;
    
    --success: #10b981; /* Emerald */
    --success-glow: rgba(16, 185, 129, 0.4);
    
    --danger: #ef4444; /* Rose Red */
    --danger-glow: rgba(239, 68, 68, 0.4);
    --danger-hover: #dc2626;

    --warning: #f59e0b; /* Amber */
    --warning-glow: rgba(245, 158, 11, 0.4);

    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-dim: #6b7280;
    
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-medium: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --border-radius: 16px;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.01);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.18);
}

.hidden {
    display: none !important;
}

/* Glassmorphism Styles */
.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
    transition: border-color var(--transition-medium), box-shadow var(--transition-medium);
}

.glass-card:hover {
    border-color: rgba(99, 102, 241, 0.18);
    box-shadow: 0 8px 32px 0 rgba(99, 102, 241, 0.08);
}

/* Utility Layout elements */
.flex-column {
    display: flex;
    flex-direction: column;
}
.flex-grow {
    flex-grow: 1;
    min-height: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 10px 18px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 0 12px var(--primary-glow);
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 0 18px var(--primary-glow);
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--border-color);
    color: var(--text-main);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-success {
    background: var(--success);
    color: #fff;
    box-shadow: 0 0 12px var(--success-glow);
}
.btn-success:hover {
    background: #059669;
    box-shadow: 0 0 18px var(--success-glow);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    box-shadow: 0 0 12px var(--danger-glow);
}
.btn-danger:hover {
    background: var(--danger-hover);
    box-shadow: 0 0 18px var(--danger-glow);
    transform: translateY(-1px);
}

.btn-icon-only {
    padding: 10px;
    border-radius: 10px;
}

.btn-block {
    width: 100%;
}

/* Inputs */
.input-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper i {
    position: absolute;
    left: 14px;
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.input-wrapper input {
    padding-left: 42px;
}

input[type="text"],
input[type="password"],
textarea {
    width: 100%;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-main);
    font-family: var(--font-family);
    font-size: 0.9375rem;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.input-help {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 4px;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-admin {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.badge-business {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
    border: 1px solid rgba(99, 102, 241, 0.3);
}
.badge-neutral {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

/* ================= 1. LOGIN SCREEN ================= */
#login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 40px 30px;
}

.brand {
    text-align: center;
    margin-bottom: 35px;
}

.logo-glow {
    width: 70px;
    height: 70px;
    background: rgba(99, 102, 241, 0.1);
    border: 2px solid var(--primary);
    box-shadow: 0 0 20px var(--primary-glow);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    animation: pulse 2.5s infinite;
}

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--primary);
}

.brand h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.brand p {
    color: var(--text-muted);
    font-size: 0.9375rem;
    margin-top: 4px;
}

/* ================= 2. MAIN LAYOUT ================= */
#dashboard-container {
    padding: 24px;
    max-width: 1440px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Header */
.glass-header {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    backdrop-filter: blur(16px);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

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

.app-logo {
    width: 38px;
    height: 38px;
    color: var(--primary);
}

.title-area h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.title-area {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

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

#user-display {
    font-size: 0.875rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.03);
    padding: 8px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

/* Bodies & Panels */
.dashboard-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Grid splits */
.grid-2 {
    display: grid;
    grid-template-columns: 480px 1fr;
    gap: 24px;
    align-items: start;
}

/* Table Card */
.table-card {
    padding: 12px;
    overflow: hidden;
}

.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9375rem;
}

th, td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

tbody tr:hover {
    background: rgba(255, 255, 255, 0.015);
}

/* Status Cards & Connection states */
.status-card {
    padding: 24px;
}

.card-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.card-title h4 {
    font-size: 1rem;
    font-weight: 600;
}

.active-biz-header {
    color: var(--primary);
    font-weight: 600;
    font-size: 0.875rem;
}

.status-container {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.indicator {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}

.indicator.disconnected {
    background: var(--danger);
    box-shadow: 0 0 12px var(--danger-glow);
}

.indicator.connecting {
    background: var(--warning);
    box-shadow: 0 0 12px var(--warning-glow);
    animation: blink 1.5s infinite;
}

.indicator.qr_ready {
    background: var(--primary);
    box-shadow: 0 0 12px var(--primary-glow);
    animation: blink 1.5s infinite;
}

.indicator.connected {
    background: var(--success);
    box-shadow: 0 0 12px var(--success-glow);
}

.status-details h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.status-details p {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.status-actions {
    display: flex;
    gap: 12px;
}

/* QR Code */
#qr-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 24px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 20px;
    border: 1px dashed var(--border-color);
}

.qr-box {
    width: 220px;
    height: 220px;
    background: #fff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.qr-box img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.qr-help {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.qr-help i {
    width: 16px;
    height: 16px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Config / Prompt Form Card */
.config-card {
    padding: 24px;
}

/* Conversation history list & Transcript */
.history-card {
    padding: 24px;
    height: calc(100vh - 120px);
}

.history-split {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 20px;
    margin-top: 16px;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    padding-right: 4px;
    border-right: 1px solid var(--border-color);
}

.chat-item {
    padding: 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(99, 102, 241, 0.3);
}

.chat-item.active {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.1);
}

.chat-item h5 {
    font-size: 0.875rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item p {
    font-size: 0.75rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 4px;
}

.chat-item span {
    font-size: 0.6875rem;
    color: var(--text-dim);
    display: block;
    margin-top: 6px;
    text-align: right;
}

/* Transcript Area */
.chat-transcript {
    overflow: hidden;
}

.transcript-placeholder {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-dim);
    text-align: center;
    padding: 40px;
}

.transcript-placeholder i {
    width: 48px;
    height: 48px;
}

.transcript-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 16px;
}

.customer-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.customer-info h5 {
    font-size: 0.9375rem;
    font-weight: 600;
}

.customer-info i {
    width: 16px;
    height: 16px;
    color: var(--primary);
}

.messages-area {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 6px;
}

/* Chat bubble styling */
.msg-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.875rem;
    position: relative;
    word-break: break-word;
}

.msg-bubble.incoming {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 2px;
    color: var(--text-main);
}

.msg-bubble.outgoing {
    align-self: flex-end;
    background: var(--primary);
    border-bottom-right-radius: 2px;
    color: #fff;
}

.msg-time {
    font-size: 0.6875rem;
    display: block;
    margin-top: 4px;
    text-align: right;
    opacity: 0.7;
}

/* ================= 3. MODALS ================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.25s ease-out;
}

.modal-card {
    width: 90%;
    max-width: 500px;
    padding: 24px;
    animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.btn-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 6px;
    transition: all var(--transition-fast);
}

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

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* Toast System */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
}

.toast {
    background: rgba(22, 24, 38, 0.9);
    border: 1px solid var(--border-color);
    padding: 12px 20px;
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
    font-size: 0.875rem;
    animation: slideInLeft 0.3s ease-out forwards;
    backdrop-filter: blur(8px);
}

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

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

.toast.info {
    border-left: 4px solid var(--primary);
}

/* Keyframe Animations */
@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 10px var(--primary-glow); }
    50% { transform: scale(1.05); box-shadow: 0 0 25px rgba(99, 102, 241, 0.7); }
    100% { transform: scale(1); box-shadow: 0 0 10px var(--primary-glow); }
}
@keyframes blink {
    0% { opacity: 0.4; }
    50% { opacity: 1; }
    100% { opacity: 0.4; }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes scaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
@keyframes slideInLeft {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive configurations */
@media (max-width: 1024px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }
    .history-card {
        height: 500px;
    }
}
