:root {
    --sidebar-width: 260px;
    --bg-dark: #0d1117;
    --bg-sidebar: #161b22;
    --bg-input: #21262d;
    --border-color: #30363d;
    --accent: #FF0101;
    --accent-hover: #d40000;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
}

/* Override Bootstrap success colors to red */
.text-success { color: #FF0101 !important; }
.bg-success { background-color: #FF0101 !important; }
.btn-success { background-color: #FF0101 !important; border-color: #FF0101 !important; }
.btn-success:hover, .btn-success:focus { background-color: #d40000 !important; border-color: #d40000 !important; }
.btn-outline-success { color: #FF0101 !important; border-color: #FF0101 !important; }
.btn-outline-success:hover { background-color: #FF0101 !important; color: #fff !important; }
.border-success { border-color: #FF0101 !important; }
.form-check-input:checked { background-color: #FF0101 !important; border-color: #FF0101 !important; }
.link-success { color: #FF0101 !important; }

body {
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body.chat-layout {
    overflow: hidden;
}

.min-vh-100 { min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    height: 100vh;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
}

.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.btn-new-chat {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-new-chat:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}

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

.chat-item {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: all 0.15s;
}

.chat-item:hover,
.chat-item.active {
    background: var(--bg-input);
    color: var(--text-primary);
}

.chat-item .title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 8px;
}

.chat-item .delete-btn {
    opacity: 0;
    transition: opacity 0.15s;
    padding: 2px 4px;
    border-radius: 4px;
}

.chat-item:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    color: #f85149;
    background: rgba(248, 81, 73, 0.1);
}

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

.main-content {
    margin-left: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

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

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}

.message-row {
    padding: 16px 20px;
    display: flex;
    gap: 16px;
}

.message-row.user {
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-color);
}

.message-row.assistant {
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
}

.avatar {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.avatar.user {
    background: #5436da;
    color: white;
}

.avatar.assistant {
    background: var(--accent);
    color: white;
}

.message-content {
    flex: 1;
    max-width: 800px;
    line-height: 1.6;
    word-wrap: break-word;
}

.message-content pre {
    background: #161b22;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-content code {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.85em;
    background: rgba(110, 118, 129, 0.2);
    padding: 2px 6px;
    border-radius: 3px;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.input-area {
    padding: 12px 20px 20px;
    background: var(--bg-dark);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

.chat-input {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 48px 12px 16px;
    color: var(--text-primary);
    width: 100%;
    resize: none;
    min-height: 52px;
    max-height: 200px;
    font-size: 1rem;
    line-height: 1.5;
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}

.btn-send {
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--accent);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

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

.btn-send:disabled {
    background: var(--border-color);
    cursor: not-allowed;
}

.spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 20px;
}

.welcome-screen h1 {
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    background: linear-gradient(90deg, #10a37f, #19c59f);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-screen p {
    color: var(--text-secondary);
    max-width: 500px;
}

.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 600px;
    margin-top: 24px;
}

.suggestion-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.suggestion-card:hover {
    background: var(--bg-input);
    border-color: var(--accent);
}

.suggestion-card small {
    color: var(--text-secondary);
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    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% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* First mobile block removed - see consolidated block below */

/* Admin */
.admin-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
}

.badge-pending { background: #d29922; color: #000; }
.badge-approved { background: #10a37f; color: #fff; }

.user-menu-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 4px;
    display: none;
}

.user-menu-dropdown.show {
    display: block;
}

.user-menu-dropdown a {
    display: block;
    padding: 8px 12px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.875rem;
}

.user-menu-dropdown a:hover {
    background: var(--bg-sidebar);
}

/* Code blocks with copy */
.code-block-wrapper {
    position: relative;
    margin: 8px 0;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}
.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 12px;
    background: #0d1117;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
}
.code-lang {
    color: var(--text-secondary);
    text-transform: lowercase;
}
.btn-copy-code {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s;
}
.btn-copy-code:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.1);
}

/* Message actions */
.msg-actions {
    display: flex !important;
    gap: 8px;
    opacity: 1 !important;
    visibility: visible !important;
    margin-top: 8px;
}
.msg-actions .btn-tts,
.msg-actions .btn-copy {
    background: rgba(33, 38, 45, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: #e6edf3;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 6px 10px;
    display: inline-flex;
    align-items: center;
    line-height: 1;
}
.msg-actions .btn-tts:hover,
.msg-actions .btn-copy:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Auto-export buttons for structured data */
.auto-export .btn-export {
    background: rgba(16, 163, 127, 0.15) !important;
    border-color: #10a37f !important;
    color: #10a37f !important;
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: 500;
}
.auto-export .btn-export:hover {
    background: #10a37f !important;
    color: white !important;
}
.auto-export .btn-export i {
    margin-right: 4px;
}
.msg-actions .btn-tts.active {
    background: #da3633;
    border-color: #f85149;
    color: white;
}

/* Contextual suggestions */
.contextual-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.context-suggestion {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}
.context-suggestion:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(16,163,127,0.1);
}

/* Attach button */
.btn-attach {
    position: absolute;
    left: 8px;
    bottom: 8px;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: color 0.2s;
    z-index: 2;
}
.btn-attach:hover {
    color: var(--text-primary);
}
.chat-input {
    padding-left: 48px !important;
}

/* Search chats */
.search-chats input {
    background: var(--bg-dark) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
}
.search-chats input:focus {
    border-color: var(--accent) !important;
    box-shadow: none !important;
}

/* Focus mode */
body.focus-mode .sidebar,
body.focus-mode .chat-header {
    display: none !important;
}
body.focus-mode .main-content {
    margin-left: 0 !important;
}

/* Document preview */
#documentPreview {
    max-width: 800px;
    margin: 0 auto;
}

kbd {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8rem;
}

/* Retry button */
.btn-retry {
    border: 1px solid var(--accent);
    color: var(--accent);
    background: transparent;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-retry:hover {
    background: var(--accent);
    color: white;
}

/* Dark theme form labels visibility */
.form-label.text-muted,
.form-text.text-muted {
    color: #8b949e !important;
}
body.bg-dark .form-label,
body.bg-dark .form-text {
    color: #8b949e !important;
}

/* Modals dark theme */
.modal-content.bg-dark {
    background: var(--bg-sidebar) !important;
    color: var(--text-primary) !important;
}
.modal-header.border-secondary {
    border-color: var(--border-color) !important;
}
.modal-content.bg-dark .modal-body,
.modal-content.bg-dark .modal-body .text-muted {
    color: var(--text-secondary) !important;
}
.modal-content.bg-dark kbd {
    background: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color);
}

/* Mobile top bar - visible only on mobile */
.mobile-top-bar {
    display: none;
    padding: 8px 12px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    justify-content: space-between;
    z-index: 50;
}
.mobile-top-bar .btn {
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 99;
}
.sidebar-overlay.show {
    display: block;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 85vw;
        max-width: 320px;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        height: 100vh;
        height: 100dvh;
    }
    .mobile-top-bar {
        display: flex;
    }
    .chat-header {
        padding: 8px 12px;
    }
    .chat-header #mobileMenuBtn {
        display: none;
    }
    .input-area {
        padding: 8px 12px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }
    .chat-messages {
        padding: 10px 0;
    }
    .message-row {
        padding: 12px;
    }
    /* Prevent horizontal scroll on mobile */
    .message-content {
        max-width: 100%;
        word-break: break-word;
        overflow-wrap: break-word;
    }
    .message-content pre {
        max-width: 100%;
        overflow-x: auto;
        white-space: pre;
        word-wrap: normal;
    }
    .message-content pre code {
        word-break: break-all;
        white-space: pre;
    }
    .message-content table {
        display: block;
        overflow-x: auto;
        max-width: 100%;
    }
    .suggestion-cards {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .btn-new-chat {
        font-size: 0.85rem;
        padding: 8px;
    }
    .user-menu-dropdown {
        left: auto;
        right: 0;
    }
    .welcome-screen {
        padding: 20px 16px;
    }
    .welcome-screen h1 {
        font-size: 1.8rem;
    }
}

@media (min-width: 769px) {
    .main-content {
        margin-left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
    }
}

/* Touch improvements */
button, .btn, .chat-item { -webkit-tap-highlight-color: transparent; }
.chat-item { min-height: 44px; }
.suggestion-card { min-height: 80px; }

/* Ensure input area stays visible on mobile */
@supports (height: 100dvh) {
    body.chat-layout {
        height: 100dvh;
    }
    body.chat-layout .main-content {
        height: 100dvh;
    }
}
