/* ============================================================================
   R4-P17 Web Chat — Star Wars Cockpit Theme
   ============================================================================ */

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

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #111;
    --bg-card: #1a1a1a;
    --bg-input: #151515;
    --border: #2a2a2a;
    --border-light: #333;
    --accent: #e8a735;
    --accent-dim: #b8841a;
    --accent-glow: rgba(232, 167, 53, 0.15);
    --text-primary: #e0e0e0;
    --text-secondary: #888;
    --text-muted: #555;
    --bot-bg: #1a1d22;
    --user-bg: #1a2a1a;
    --error-bg: #2a1a1a;
    --user-border: #2a3a2a;
    --bot-border: #252830;
    --error-border: #3a2222;
    --error-label: #e85555;
    --strong-text: #fff;
    --code-bg: rgba(255, 255, 255, 0.06);
    --overlay-bg: rgba(0, 0, 0, 0.6);
    --send-btn-text: #0a0a0a;
    --sidebar-width: 280px;
}

/* --- Light Theme --- */
html[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #f0f2f5;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --border: #d0d5dd;
    --border-light: #c0c5cd;
    --accent: #d4960a;
    --accent-dim: #b8841a;
    --accent-glow: rgba(212, 150, 10, 0.1);
    --text-primary: #1a1a2e;
    --text-secondary: #555;
    --text-muted: #999;
    --bot-bg: #e8ecf2;
    --user-bg: #e0f0e0;
    --error-bg: #fde8e8;
    --user-border: #c0d8c0;
    --bot-border: #d0d5e0;
    --error-border: #f0c0c0;
    --error-label: #cc3333;
    --strong-text: #000;
    --code-bg: rgba(0, 0, 0, 0.06);
    --overlay-bg: rgba(0, 0, 0, 0.3);
    --send-btn-text: #fff;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
}

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

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    overflow-y: auto;
}

.sidebar-header {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--accent);
    font-family: 'Courier New', monospace;
    letter-spacing: 2px;
    text-shadow: 0 0 20px var(--accent-glow);
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-top: 0.25rem;
}

/* --- Action Buttons --- */
.actions {
    flex: 1;
}

.actions-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 0.75rem;
    padding-left: 0.5rem;
}

.action-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s ease;
    margin-bottom: 0.4rem;
    font-family: inherit;
}

.action-btn:hover {
    background: var(--accent-glow);
    border-color: var(--border-light);
}

.action-icon {
    font-size: 1.3rem;
    width: 2rem;
    text-align: center;
    flex-shrink: 0;
}

.action-text {
    display: flex;
    flex-direction: column;
}

.action-title {
    font-size: 0.85rem;
    font-weight: 600;
}

.action-desc {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.1rem;
}

/* --- Sidebar Footer --- */
.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.reset-btn {
    width: 100%;
    padding: 0.6rem;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    transition: all 0.15s ease;
}

.reset-btn:hover {
    border-color: var(--accent-dim);
    color: var(--accent);
}

.theme-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1002;
    padding: 6px 12px;
    background: rgba(26, 26, 26, 0.8);
    border: 1px solid var(--border);
    border-radius: 9999px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    font-family: Arial, sans-serif;
    transition: all 0.15s ease;
}

html[data-theme="light"] .theme-toggle {
    background: rgba(255, 255, 255, 0.8);
}

.theme-toggle:hover {
    color: var(--text-primary);
}

.back-link {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s ease;
}

.back-link:hover {
    color: var(--text-secondary);
}

/* --- Hamburger (mobile) --- */
.hamburger {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem;
    cursor: pointer;
    flex-direction: column;
    gap: 4px;
}

.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: all 0.2s ease;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    z-index: 999;
}

/* --- Chat Area --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* --- Message Bubbles --- */
.message {
    max-width: 85%;
    padding: 0.85rem 1.1rem;
    border-radius: 12px;
    line-height: 1.55;
    font-size: 0.9rem;
    word-wrap: break-word;
    animation: fadeIn 0.2s ease;
}

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

.message.user {
    align-self: flex-end;
    background: var(--user-bg);
    border: 1px solid var(--user-border);
    border-bottom-right-radius: 4px;
}

.message.bot,
.message.interim {
    align-self: flex-start;
    background: var(--bot-bg);
    border: 1px solid var(--bot-border);
    border-bottom-left-radius: 4px;
}

.message.bot .msg-label,
.message.interim .msg-label {
    display: block;
    font-size: 0.65rem;
    color: var(--accent);
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 0.35rem;
    font-family: 'Courier New', monospace;
}

.message.system {
    align-self: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-align: center;
    max-width: 70%;
}

.message.error {
    align-self: flex-start;
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-bottom-left-radius: 4px;
}

.message.error .msg-label {
    color: var(--error-label);
}

/* Message content HTML */
.msg-content strong {
    color: var(--strong-text);
    font-weight: 600;
}

.msg-content em {
    color: var(--accent-dim);
    font-style: italic;
}

.msg-content code {
    background: var(--code-bg);
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
}

/* --- Typing Indicator --- */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.5rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--accent-dim);
    border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out;
}

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

@keyframes pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* --- Input Bar --- */
.input-bar {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.input-bar input {
    flex: 1;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease;
}

.input-bar input:focus {
    border-color: var(--accent-dim);
}

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

.input-bar button {
    padding: 0.75rem 1.25rem;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: var(--send-btn-text);
    font-weight: 700;
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease;
}

.input-bar button:hover {
    background: var(--accent-dim);
}

.input-bar button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* --- Scrollbar --- */
.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100%;
        z-index: 1000;
        transition: left 0.25s ease;
    }

    .sidebar.open {
        left: 0;
    }

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

    .hamburger {
        display: flex;
    }

    .chat-area {
        padding-top: 0;
    }

    .messages {
        padding-top: 3.5rem; /* room for hamburger */
    }

    .message {
        max-width: 95%;
    }
}
