/* === Reset & Variables === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #242424;
    --bg-hover: #2a2a2a;
    --border: #333;
    --text: #e5e5e5;
    --text-secondary: #999;
    --text-muted: #666;
    --primary: #6366f1;
    --primary-hover: #5558e6;
    --accent: #818cf8;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --user-bubble: #2563eb;
    --assistant-bubble: #1e1e2e;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 150ms ease;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

/* === SVG Icons === */
.icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    color: var(--text);
    background: var(--bg-tertiary);
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-tertiary); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-icon { width: 32px; height: 32px; padding: 0; font-size: 18px; border-radius: 50%; }
.btn-send { padding: 8px 20px; }

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--text-secondary); font-size: 13px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    transition: border-color var(--transition);
}
.form-group input:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* === Alerts === */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.alert-error { background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.3); }

/* === Logo Styles === */
.login-logo {
    width: 120px;
    height: auto;
    margin-bottom: 16px;
    background: #fff;
    border-radius: 14px;
    padding: 10px 16px;
}
.login-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
}
.footer-logo-sm {
    width: 16px;
    height: auto;
    background: #fff;
    border-radius: 4px;
    padding: 1px 2px;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-logo {
    width: 28px;
    height: auto;
    background: #fff;
    border-radius: 6px;
    padding: 3px 4px;
}
.nav-logo {
    width: 32px;
    height: auto;
    background: #fff;
    border-radius: 6px;
    padding: 3px 5px;
}
.client-avatar {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    object-fit: contain;
    vertical-align: middle;
    margin-right: 6px;
    background: #fff;
    padding: 2px;
}
.chat-header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.chat-header-logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: contain;
    background: #fff;
    padding: 2px;
}
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
    max-width: 560px;
    width: 100%;
    padding: 20px;
}
.welcome-logo {
    width: 80px;
    height: auto;
    background: #fff;
    border-radius: 14px;
    padding: 8px 12px;
    margin-bottom: 4px;
}
.welcome-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}
.welcome-sub {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* Start chat button */
.btn-start-chat {
    margin-top: 12px;
    padding: 12px 28px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 50px;
    gap: 8px;
}
.btn-start-chat .icon {
    width: 20px;
    height: 20px;
}

/* Quick prompts */
.quick-prompts {
    margin-top: 28px;
    width: 100%;
}
.quick-prompts-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 12px;
}
.quick-prompts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.quick-prompt {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
}
.quick-prompt:hover {
    border-color: var(--primary);
    color: var(--text);
    background: var(--bg-tertiary);
}
svg.qp-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    stroke: var(--accent);
}
.qp-text {
    line-height: 1.3;
}
.client-card-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: contain;
    background: #fff;
    padding: 3px;
    margin-right: 10px;
}

/* === Login Page === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
}
.login-header { text-align: center; margin-bottom: 24px; }
.login-header h1 { font-size: 24px; margin-bottom: 4px; }
.login-header p { color: var(--text-secondary); font-size: 14px; }

/* === Chat Layout === */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 16px; }
.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.conv-item {
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    margin-bottom: 2px;
    transition: background var(--transition);
    display: flex;
    align-items: center;
    gap: 4px;
}
.conv-item:hover { background: var(--bg-tertiary); }
.conv-item.active { background: var(--bg-tertiary); border-left: 3px solid var(--primary); }
.conv-item .conv-content {
    flex: 1;
    min-width: 0;
}
.conv-item .conv-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-item .conv-preview {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
/* Archive action button - visible on hover */
.conv-item .conv-actions {
    opacity: 0;
    transition: opacity var(--transition);
    flex-shrink: 0;
}
.conv-item:hover .conv-actions { opacity: 1; }
.conv-action {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    transition: color var(--transition), background var(--transition);
}
.conv-action:hover {
    color: var(--text);
    background: var(--bg-secondary);
}
.conv-action .icon {
    width: 16px;
    height: 16px;
}
/* Archived section */
.archive-section {
    margin-top: 8px;
    border-top: 1px solid var(--border);
    padding-top: 4px;
}
.archive-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius);
    transition: background var(--transition);
    user-select: none;
}
.archive-header:hover { background: var(--bg-tertiary); }
.archive-chevron {
    width: 14px;
    height: 14px;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}
.archive-chevron.expanded {
    transform: rotate(90deg);
}
.archive-count {
    background: var(--bg-tertiary);
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 11px;
    margin-left: auto;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}
.user-info {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
}
.user-name { font-weight: 500; font-size: 13px; }
.user-role {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-left: 6px;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
}
.sidebar-actions { display: flex; gap: 6px; }

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 18px;
    cursor: pointer;
}

/* Chat Main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}
.chat-header h3 { font-size: 15px; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.chat-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    line-height: 1.6;
    word-wrap: break-word;
}
.message.user {
    align-self: flex-end;
    background: var(--user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.message.assistant {
    align-self: flex-start;
    background: var(--assistant-bubble);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}
.message.user .message-time { color: rgba(255,255,255,0.6); }

/* Markdown in messages */
.message pre {
    background: rgba(0,0,0,0.3);
    padding: 12px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}
.message code {
    background: rgba(0,0,0,0.2);
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 13px;
}
.message pre code { background: none; padding: 0; }
.message ul, .message ol { padding-left: 20px; margin: 8px 0; }
.message p { margin: 4px 0; }
.message strong { font-weight: 600; }
.message a { color: var(--accent); }

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}
.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Chat Input */
.chat-input-area {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}
.chat-form .input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.chat-form textarea {
    flex: 1;
    resize: none;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    max-height: 120px;
    line-height: 1.4;
}
.chat-form textarea:focus {
    outline: none;
    border-color: var(--primary);
}
.attachment-btn {
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius);
    transition: background var(--transition);
    display: flex;
    align-items: center;
}
.attachment-btn .icon {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}
.attachment-btn:hover .icon { color: var(--text); }
.attachment-btn:hover { background: var(--bg-tertiary); }
.attachment-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    font-size: 12px;
    color: var(--text-secondary);
}

/* === Admin Page === */
.admin-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}
.nav-brand { display: flex; align-items: center; gap: 12px; }
.nav-brand h2 { font-size: 16px; }
.nav-links { display: flex; gap: 8px; }
.back-link { color: var(--text-secondary); text-decoration: none; font-size: 14px; }
.back-link:hover { color: var(--text); }

.admin-content { padding: 24px; max-width: 1200px; margin: 0 auto; }
.admin-content h1 { font-size: 22px; margin-bottom: 20px; }

.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-header h1 { margin-bottom: 0; }

/* Client Cards */
.clients-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}
.client-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: all var(--transition);
}
.client-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.client-card-header {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}
.client-card-header h3 { font-size: 16px; flex: 1; }
.client-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(99,102,241,0.15);
    color: var(--accent);
}
.client-stats { display: flex; gap: 20px; margin-bottom: 12px; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 18px; font-weight: 600; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; }
.client-last-msg {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.client-inactive { opacity: 0.5; }

/* Conversations List */
.conversations-list { display: flex; flex-direction: column; gap: 8px; }
.conv-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: all var(--transition);
}
.conv-card:hover { border-color: var(--primary); }
.conv-card.conv-archived { opacity: 0.7; }
.conv-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 8px; }
.conv-card-title { font-weight: 500; display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.conv-card-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.conv-card-meta { font-size: 12px; color: var(--text-muted); }
.conv-card-preview { font-size: 13px; color: var(--text-secondary); }
.badge-archived {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    white-space: nowrap;
}
.btn-danger-ghost {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    color: var(--text-muted);
    transition: color var(--transition), background var(--transition);
}
.btn-danger-ghost:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Data Table */
.users-table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.data-table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}
.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }

.badge-active { color: var(--success); }
.badge-inactive { color: var(--danger); }

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}
.modal-large { max-width: 700px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100vh;
        z-index: 50;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: block; }

    .message { max-width: 90%; }

    .clients-grid { grid-template-columns: 1fr; }

    .admin-nav { padding: 12px 16px; }
    .admin-content { padding: 16px; }

    .login-logo { width: 80px; }
    .welcome-logo { width: 60px; }
    .quick-prompts-grid { grid-template-columns: 1fr; }
    .btn-start-chat { padding: 10px 24px; font-size: 14px; }
}
