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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #20b2aa 0%, #008b8b 100%);
    min-height: 100vh;
    color: #333;
    overscroll-behavior-y: none;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.5;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

.header {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    border: 1px solid rgba(255,255,255,0.2);
}

.header h1 {
    color: #20b2aa;
    font-size: clamp(1.5rem, 4vw, 2rem);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 0.95rem;
    font-weight: 500;
}

.status-selector {
    padding: 8px 15px;
    border: 2px solid #20b2aa;
    border-radius: 25px;
    background: white;
    color: #20b2aa;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.status-selector:hover {
    background: #20b2aa;
    color: white;
}

.logout-btn {
    padding: 10px 20px;
    background: #ff4757;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.logout-btn:hover {
    background: #ff3742;
    transform: translateY(-2px);
}

.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
}

.login-form {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-form h2 {
    color: #20b2aa;
    margin-bottom: 30px;
    font-size: 1.75rem;
    font-weight: 700;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
    font-size: 0.95rem;
}

.form-group input {
    width: 100%;
    padding: 15px;
    border: 2px solid #e1e8ed;
    border-radius: 15px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: rgba(255,255,255,0.9);
}

.form-group input:focus {
    outline: none;
    border-color: #20b2aa;
    box-shadow: 0 0 0 3px rgba(32,178,170,0.1);
}

.login-btn {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, #20b2aa 0%, #008b8b 100%);
    color: white;
    border: none;
    border-radius: 15px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(32,178,170,0.3);
}

.dashboard {
    display: flex;
    gap: 20px;
    height: calc(100vh - 150px);
    flex-wrap: nowrap;
    transition: all 0.3s ease;
}

.chat-list-panel, .chat-panel, .sidebar {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    transition: all 0.3s ease;
}

.chat-list-panel {
    overflow: hidden;
    display: flex;
    flex: 0 0 320px;
    border-right: 1px solid #ddd;
    flex-direction: column;
}

.chat-panel {
    display: flex;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
    max-height: 100%;
    min-width: 400px;
}

.dashboard.sidebar-collapsed .chat-panel {
    flex: 1 1 auto;
    margin-right: 0;
}

.dashboard.sidebar-collapsed .sidebar {
    flex: 0 0 0;
    min-width: 0;
    max-width: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
    margin-left: -20px;
}

.panel-header {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

.panel-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.panel-title h3 {
    color: #20b2aa;
    font-size: 1.25rem;
    font-weight: 600;
}

.search-row {
    margin-bottom: 15px;
}

.search-row input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 2px solid #e1e8ed;
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.9);
    transition: all 0.3s ease;
}

.search-row input:focus {
    outline: none;
    border-color: #20b2aa;
    box-shadow: 0 0 0 3px rgba(32,178,170,0.1);
}

#chatSearch {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid #e1e8ed;
    border-radius: 10px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.9);
}

#chatSearch:focus {
    outline: none;
    border-color: #20b2aa;
    box-shadow: 0 0 0 3px rgba(32, 178, 170, 0.1);
}

#chatSearch:hover {
    border-color: #20b2aa;
}

.refresh-btn {
    background: #006400;
    border: none;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.refresh-btn:hover {
    background: #1a9a92;
    transform: scale(1.05);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px;
}

.chat-item {
    background: white;
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    position: relative;
}

.chat-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    border-color: #20b2aa;
}

.chat-item.active {
    background: linear-gradient(135deg, #20b2aa 0%, #008b8b 100%);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(32,178,170,0.3);
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.chat-phone {
    font-weight: 600;
    font-size: 1rem;
}

.chat-time {
    font-size: 0.85rem;
    color: #666;
    font-weight: 500;
}

.chat-item.active .chat-time {
    color: rgba(255, 255, 255, 0.9);
}

.chat-item-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

.chat-agent {
    font-size: 0.9rem;
    color: #555;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 150px;
}

.chat-item.active .chat-agent {
    color: white;
}

.chat-mode {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.mode-ai {
    background: #e3f2fd;
    color: #1976d2;
}

.mode-human {
    background: #e8f5e8;
    color: #388e3c;
}

.chat-item.active .mode-ai,
.chat-item.active .mode-human {
    background: rgba(255,255,255,0.2);
    color: white;
}

.unread-count {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
}

.chat-header {
    padding: 5px;
    border-bottom: 2px solid #f0f0f0;
    background: linear-gradient(135deg, #20b2aa 0%, #008b8b 100%);
    color: white;
    flex-shrink: 0;
    border-radius: 20px 20px 0 0;
}

.chat-header h3 {
    margin-bottom: 15px;
    font-size: 1.15rem;
    font-weight: 600;
    color: white;
}

.mode-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.mode-btn {
    padding: 6px 12px;
    border: 2px solid rgba(255,255,255,0.3);
    background: transparent;
    color: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.mode-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.05);
}

.mode-btn.active {
    background: white;
    color: #20b2aa;
}

.chat-messages {
    flex: 1;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: 20px;
    background: #f8fafc;
    height: 0;
    min-height: 300px;
}

.message {
    margin-bottom: 15px;
    display: flex;
}

.message.user {
    justify-content: flex-start;
}

.message.ai, .message.agent {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 20px;
    position: relative;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: #202c33;
    color: white;
    border-bottom-left-radius: 5px;
}

.message.ai .message-bubble {
    background: #008b8b;
    color: white;
    border-bottom-right-radius: 5px;
}

.message.agent .message-bubble {
    background: #20b2aa;
    color: white;
    border-bottom-right-radius: 5px;
}

.message-meta {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-bottom: 5px;
    font-weight: 500;
}

.message-input {
    padding: 20px;
    border-top: 2px solid #f0f0f0;
    background: white;
    flex-shrink: 0;
}

.input-group {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.message-textarea {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #e1e8ed;
    border-radius: 15px;
    resize: none;
    font-family: inherit;
    font-size: 0.95rem;
    max-height: 100px;
    transition: all 0.3s ease;
}

.message-textarea:focus {
    outline: none;
    border-color: #20b2aa;
    box-shadow: 0 0 0 3px rgba(32,178,170,0.1);
}

.send-btn {
    padding: 12px 20px;
    background: #20b2aa;
    color: white;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
}

.send-btn:hover {
    background: #1a9a92;
    transform: scale(1.05);
}

.send-btn:disabled {
    background: #ccc !important;
    cursor: not-allowed !important;
    opacity: 0.7;
    transform: none !important;
}

.sidebar {
    flex: 0 0 320px;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.sidebar-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
}

.sidebar-section:last-child {
    border-bottom: none;
}

.sidebar-section h4 {
    color: #20b2aa;
    margin-bottom: 15px;
    font-size: 1.1rem;
    font-weight: 600;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 5px 0;
}

.sidebar-toggle {
    display: flex;
    justify-content: flex-end;
    padding: 8px;
    border-bottom: 1px solid #ddd;
    background: #f8f9fa;
}

.collapse-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.3s ease;
    transform: rotate(-90deg);
}

.collapse-btn:hover {
    background: rgba(32, 178, 170, 0.1);
}

.collapse-btn.collapsed {
    transform: rotate(-90deg);
}

.collapse-btn:not(.collapsed) {
    transform: rotate(0deg);
}

.section-content {
    transition: max-height 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
}

.section-content.collapsed {
    max-height: 0 !important;
    opacity: 0;
    padding: 0;
    margin: 0;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    font-weight: 500;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.status-connected {
    background: #d4edda;
    color: #155724;
}

.status-disconnected {
    background: #f8d7da;
    color: #721c24;
}

.metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}

.metric:last-child {
    border-bottom: none;
}

.metric span:first-child {
    font-size: 0.9rem;
    color: #555;
    font-weight: 500;
}

.metric-value {
    font-weight: 600;
    color: #20b2aa;
    font-size: 1.1rem;
    transition: all 0.3s ease;
}

.quick-action-btn {
    width: 100%;
    padding: 12px 15px;
    background: #20b2aa;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    margin-bottom: 10px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.9rem;
}

.quick-action-btn:hover {
    background: #1a9a92;
    transform: translateY(-2px);
}

.quick-action-btn:disabled {
    background: #ccc !important;
    cursor: not-allowed !important;
    transform: none !important;
}

.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 10px;
    color: white;
    font-weight: 600;
    z-index: 1000;
    max-width: 400px;
    animation: slideInRight 0.3s ease-out;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-size: 0.9rem;
}

.notification.success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
}

.notification.error {
    background: linear-gradient(135deg, #dc3545 0%, #e74c3c 100%);
}

.notification.warning {
    background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
    color: #000;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 15px;
    opacity: 0.5;
}

.empty-state h3 {
    margin-bottom: 10px;
    font-size: 1.2rem;
    color: #555;
    font-weight: 600;
}

.empty-state p {
    margin: 0 0 15px 0;
    color: #777;
    font-size: 0.95rem;
}

#tokenUsageChart {
    width: 100% !important;
    height: 160px !important;
    max-height: 160px;
}

.toggle-btn {
    background: #20b2aa;
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.toggle-btn:hover {
    background: #1a9a92;
}

@media (max-width: 1200px) {
    .dashboard {
        flex-direction: column;
        height: auto;
    }

    .chat-list-panel, .chat-panel, .sidebar {
        flex: none;
        height: 400px;
    }

    .sidebar {
        height: auto;
    }

    .dashboard.sidebar-collapsed .sidebar {
        display: none;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
        padding: 15px;
    }

    .user-info {
        flex-direction: column;
        gap: 10px;
    }

    .dashboard {
        gap: 15px;
    }

    .chat-list-panel, .chat-panel, .sidebar {
        padding: 15px;
    }

    .search-row {
        flex-direction: column;
        gap: 10px;
    }

    #chatSearch {
        width: 100%;
    }

    .notification {
        left: 10px;
        right: 10px;
        top: 10px;
        max-width: none;
    }
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(241,241,241,0.5);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #20b2aa;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #1a9a92;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #20b2aa;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.sidebar.collapsed {
    display: none;
}

.dashboard.expanded .chat-panel {
    flex: 1 1 auto;
}

#debugToggle {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 1100;
    background: #111827;
    color: #fff;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 12px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

#debugToggle:hover {
    opacity: 1;
}

#debugPanel {
    position: fixed;
    bottom: 60px;
    left: 20px;
    z-index: 1100;
    background: rgba(17,24,39,.95);
    color: #fff;
    padding: 12px;
    border-radius: 12px;
    width: 420px;
    max-height: 40vh;
    overflow: auto;
    display: none;
    font-size: 12px;
}

#debugPanel pre {
    white-space: pre-wrap;
    word-break: break-word;
}

.system-prompt-modal {
    transition: opacity 0.3s ease;
}

.system-prompt-content {
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: rgba(255,255,255,0.95);
    --text-primary: #333;
    --text-secondary: #555;
    --text-tertiary: #666;
    --text-quaternary: #777;
    --border-primary: #e1e8ed;
    --border-secondary: #f0f0f0;
    --border-tertiary: #ddd;
    --accent-primary: #20b2aa;
    --accent-secondary: #008b8b;
    --accent-hover: #1a9a92;
    --gradient-bg: linear-gradient(135deg, #20b2aa 0%, #008b8b 100%);
    --gradient-login: linear-gradient(135deg, #20b2aa 0%, #008b8b 100%);
    --shadow-primary: 0 8px 32px rgba(0,0,0,0.1);
    --shadow-secondary: 0 5px 20px rgba(0,0,0,0.1);
    --notification-success: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    --notification-error: linear-gradient(135deg, #dc3545 0%, #e74c3c 100%);
    --notification-warning: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
}

[data-theme="dark"] {
    --bg-primary: #0F0F0F;
    --bg-secondary: #232D3F;
    --bg-tertiary: rgba(35, 45, 63, 0.95);
    --text-primary: #ffffff;
    --text-secondary: #e5e7eb;
    --text-tertiary: #d1d5db;
    --text-quaternary: #9ca3af;
    --border-primary: #374151;
    --border-secondary: #4b5563;
    --border-tertiary: #6b7280;
    --accent-primary: #008170;
    --accent-secondary: #005B41;
    --accent-hover: #006b5a;
    --gradient-bg: linear-gradient(135deg, #232D3F 0%, #0F0F0F 100%);
    --gradient-login: linear-gradient(135deg, #008170 0%, #005B41 100%);
    --shadow-primary: 0 8px 32px rgba(0,0,0,0.3);
    --shadow-secondary: 0 5px 20px rgba(0,0,0,0.2);
    --notification-success: linear-gradient(135deg, #008170 0%, #005B41 100%);
    --notification-error: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    --notification-warning: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

body {
    background: var(--gradient-bg);
    color: var(--text-primary);
}

.header, .chat-list-panel, .chat-panel, .sidebar, .login-form {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    box-shadow: var(--shadow-primary);
}

.form-group input, .message-textarea, #chatSearch, .search-row input, 
.status-selector, select, input[type="date"], input[type="datetime-local"], input[type="file"] {
    background: var(--bg-primary);
    border-color: var(--border-primary);
    color: var(--text-primary);
}

.form-group input:focus, .message-textarea:focus, #chatSearch:focus {
    border-color: var(--accent-primary);
}

.chat-item {
    background: var(--bg-primary);
    border-color: transparent;
}

.chat-item:hover {
    border-color: var(--accent-primary);
}

.chat-item.active {
    background: var(--gradient-login);
}

.chat-messages {
    background: var(--bg-secondary);
}

.message-input {
    background: var(--gradient-login);
}

.message.user .message-bubble {
    background: var(--accent-secondary);
}

.message.ai .message-bubble {
    background: var(--accent-primary);
}

.message.agent .message-bubble {
    background: var(--accent-primary);
}

.login-btn, .send-btn, .quick-action-btn {
    background: var(--gradient-login);
}

.login-btn:hover, .send-btn:hover, .quick-action-btn:hover {
    background: var(--accent-hover);
}

.refresh-btn {
    background: var(--accent-primary);
}

.refresh-btn:hover {
    background: var(--accent-hover);
}

.toggle-btn {
    background: var(--accent-primary);
}

.toggle-btn:hover {
    background: var(--accent-hover);
}

.chat-header {
    background: var(--gradient-login);
}

.mode-btn.active {
    background: var(--bg-primary);
    color: var(--accent-primary);
}

.notification.success {
    background: var(--notification-success);
}

.notification.error {
    background: var(--notification-error);
}

.notification.warning {
    background: var(--notification-warning);
}

.metric span:first-child, .chat-agent, .chat-time {
    color: var(--text-secondary);
}

.chat-item.active .chat-agent, .chat-item.active .chat-time {
    color: rgba(255, 255, 255, 0.9);
}

.sidebar-section h4, .panel-title h3, h1, h2, h3 {
    color: var(--accent-primary);
}

.sidebar-section {
    border-bottom-color: var(--border-secondary);
}

.metric {
    border-bottom-color: var(--border-secondary);
}

.message-input, .chat-header {
    border-color: var(--border-secondary);
}

.dark-mode-toggle {
    background: var(--accent-primary);
    color: var(--text-primary);
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.dark-mode-toggle:hover {
    background: var(--accent-hover);
}