/* ═══════════════════════════════════════════════════
   AGENTE SEMANAS — DESIGN SYSTEM
   ═══════════════════════════════════════════════════ */

:root {
    --primary: #6C5CE7;
    --primary-dark: #5A4BD1;
    --primary-light: #A29BFE;
    --bg: #0F0F14;
    --bg-secondary: #16161D;
    --bg-card: #1C1C26;
    --bg-hover: #22222E;
    --bg-input: #1A1A24;
    --text: #E8E8ED;
    --text-secondary: #8B8B9E;
    --text-muted: #5C5C70;
    --border: #2A2A38;
    --border-light: #333345;
    --success: #00B894;
    --error: #FF6B6B;
    --warning: #FDCB6E;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --transition: 200ms ease;
    --sidebar-width: 280px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Screens ──────────────────────────────────────── */
.screen { display: none; height: 100vh; width: 100vw; }
.screen.active { display: flex; }

/* ═══════════════════════════════════════════════════
   LOGIN
   ═══════════════════════════════════════════════════ */
.login-bg {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(108, 92, 231, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(162, 155, 254, 0.1) 0%, transparent 50%),
        var(--bg);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    box-shadow: var(--shadow);
    animation: fadeIn 0.5s ease;
}

.login-header {
    text-align: center;
    margin-bottom: 36px;
}

.logo {
    display: inline-flex;
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 6px;
    background: linear-gradient(135deg, var(--text), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ── Inputs ───────────────────────────────────────── */
.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

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

.input-icon {
    position: absolute;
    left: 14px;
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

.input-wrapper input {
    width: 100%;
    height: 48px;
    padding: 0 16px 0 44px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.input-wrapper input::placeholder { color: var(--text-muted); }

.input-wrapper input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

/* ── Buttons ──────────────────────────────────────── */
.btn-primary {
    width: 100%;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    color: #FFF;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: background var(--transition), transform 80ms ease;
    margin-top: 8px;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Error ────────────────────────────────────────── */
.error-msg {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.3);
    color: var(--error);
    font-size: 13px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.hidden { display: none !important; }

/* ── Spinner ──────────────────────────────────────── */
.spinner {
    width: 20px; height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #FFF;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ═══════════════════════════════════════════════════
   CHAT LAYOUT
   ═══════════════════════════════════════════════════ */
#chat-screen {
    flex-direction: row;
}

/* ── Sidebar ──────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}

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

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
}

.btn-icon {
    width: 36px; height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--border-light);
}

.btn-icon svg { width: 18px; height: 18px; }

.sidebar-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
}

.sidebar-sessions h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 4px 12px 8px;
}

#sessions-list {
    list-style: none;
}

#sessions-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#sessions-list li:hover {
    background: var(--bg-hover);
    color: var(--text);
}

#sessions-list li.active {
    background: rgba(108, 92, 231, 0.12);
    color: var(--primary-light);
}

#sessions-list li svg {
    width: 16px; height: 16px;
    min-width: 16px;
    opacity: 0.5;
}

.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid var(--border);
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-logout:hover {
    background: rgba(255, 107, 107, 0.1);
    color: var(--error);
}

.btn-logout svg { width: 18px; height: 18px; }

/* ── Chat Main ────────────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.header-info h2 {
    font-size: 16px;
    font-weight: 600;
}

.db-badges {
    display: flex;
    gap: 6px;
    margin-top: 2px;
}

.db-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 100px;
    background: rgba(108, 92, 231, 0.12);
    color: var(--primary-light);
    font-weight: 500;
}

/* ── Messages Container ───────────────────────────── */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    scroll-behavior: smooth;
}

/* ── Empty State ──────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px 20px;
    animation: fadeIn 0.6s ease;
}

.empty-icon {
    color: var(--text-muted);
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 28px;
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    max-width: 600px;
}

.suggestion-chip {
    padding: 10px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 100px;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
}

.suggestion-chip:hover {
    border-color: var(--primary);
    color: var(--primary-light);
    background: rgba(108, 92, 231, 0.08);
}

/* ── Messages ─────────────────────────────────────── */
.message {
    padding: 8px 24px;
    animation: fadeIn 0.3s ease;
}

.message-row {
    display: flex;
    gap: 14px;
    max-width: 800px;
    margin: 0 auto;
}

.message-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: var(--primary);
    color: #FFF;
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, #6C5CE7, #A29BFE);
    color: #FFF;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-content .role-label {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}

.message-content .msg-body {
    font-size: 14.5px;
    line-height: 1.7;
    color: var(--text);
}

.message.user .msg-body {
    color: var(--text-secondary);
}

/* Markdown styling inside messages */
.msg-body p { margin-bottom: 10px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body strong { color: var(--text); font-weight: 600; }
.msg-body ul, .msg-body ol { padding-left: 20px; margin-bottom: 10px; }
.msg-body li { margin-bottom: 4px; }
.msg-body code {
    background: rgba(108, 92, 231, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Fira Code', 'Consolas', monospace;
    color: var(--primary-light);
}
.msg-body pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    overflow-x: auto;
    margin: 10px 0;
}
.msg-body pre code {
    background: none;
    padding: 0;
    color: var(--text);
}
.msg-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 13px;
}
.msg-body table th,
.msg-body table td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
.msg-body table th {
    background: var(--bg-secondary);
    font-weight: 600;
}
.msg-body table tr:hover {
    background: var(--bg-hover);
}

/* ── Typing indicator ─────────────────────────────── */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* ── Chat Input ───────────────────────────────────── */
.chat-input-area {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.chat-form {
    max-width: 800px;
    margin: 0 auto;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 10px 10px 18px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input-container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.12);
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    outline: none;
}

#chat-input::placeholder { color: var(--text-muted); }

.btn-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    color: #FFF;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-send:hover:not(:disabled) { background: var(--primary-dark); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-send svg { width: 18px; height: 18px; }

.input-hint {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
}

/* ═══════════════════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ═══════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════ */
.mobile-only { display: none; }

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    .mobile-only { display: flex; }

    .login-card { padding: 36px 24px; }

    .message { padding: 8px 16px; }
    .chat-header { padding: 14px 16px; }
    .chat-input-area { padding: 12px 16px 16px; }
}

/* ═══════════════════════════════════════════════════
   OVERLAY (mobile sidebar)
   ═══════════════════════════════════════════════════ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.active { display: block; }
