/* ChatNBH Custom UI
 *
 * Color palette:
 *   Background:  #2d2d2d (charcoal)
 *   Sidebar:     #252525 (darker)
 *   Surface:     #333333 (cards/inputs)
 *   User bubble: #3a3a3a
 *   Text:        #e0e0e0 (off-white)
 *   Accent/Gold: #d4a843
 *   Muted text:  #888888
 *   Border:      #444444
 */

/* =====================================================
   RESET & BASE
   ===================================================== */

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

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: #e0e0e0;
    background: #2d2d2d;
}

body {
    display: flex;
}

a {
    color: #d4a843;
    text-decoration: none;
}

a:hover {
    color: #e0bc5f;
}

/* =====================================================
   SCROLLBAR
   ===================================================== */

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

::-webkit-scrollbar-track {
    background: #2d2d2d;
}

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

::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* =====================================================
   LOGO
   ===================================================== */

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    padding: 20px 20px 10px;
}

.logo-img {
    height: 42px;
    width: auto;
}

.logo-chat {
    color: #e0e0e0;
}

.logo-nbh {
    color: #d4a843;
}

/* =====================================================
   LOGIN PAGE
   ===================================================== */

.login-body {
    display: flex;
    height: 100vh;
}

.login-sidebar {
    width: 320px;
    background: #252525;
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
}

.login-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2d2d2d;
}

.login-card {
    width: 360px;
}

.login-card h2 {
    font-size: 1.4rem;
    font-weight: 400;
    color: #ccc;
    margin-bottom: 24px;
}

.login-card input {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    font-family: inherit;
    background: transparent;
    color: #e0e0e0;
    border: 1px solid #555;
    border-radius: 6px;
    outline: none;
    margin-bottom: 12px;
    transition: border-color 0.2s;
}

.login-card input:focus {
    border-color: #d4a843;
}

.login-card input::placeholder {
    color: #888;
}

.password-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.password-row input {
    flex: 1;
    margin-bottom: 0;
}

.submit-btn {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #d4a843;
    border: 1px solid #d4a843;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.submit-btn:hover {
    background: rgba(212, 168, 67, 0.15);
}

.error-msg {
    color: #e57373;
    font-size: 13px;
    margin-top: 12px;
}

.success-msg {
    color: #81c784;
    font-size: 13px;
    margin-top: 12px;
}

.toggle-link {
    margin-top: 24px;
    font-size: 13px;
    color: #888;
}

/* =====================================================
   SIDEBAR (Chat page)
   ===================================================== */

.sidebar {
    width: 320px;
    background: #252525;
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    height: 100vh;
    flex-shrink: 0;
}

.sidebar-top {
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
}

.new-chat-btn {
    display: block;
    width: calc(100% - 40px);
    margin: 10px 20px 0;
    padding: 8px;
    font-size: 14px;
    font-family: inherit;
    color: #ccc;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s;
}

.new-chat-btn:hover {
    background: #333;
}

.sidebar-history {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.sidebar-history h4 {
    font-size: 12px;
    font-weight: 500;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.history-item {
    padding: 6px 8px;
    font-size: 14px;
    color: #ccc;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item:hover {
    background: #333;
}

.history-item.active {
    background: #333;
    color: #d4a843;
}

.sidebar-bottom {
    border-top: 1px solid #333;
    padding: 10px 20px 16px;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px;
    font-size: 14px;
    font-family: inherit;
    color: #ccc;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s;
}

.logout-btn[hidden] {
    display: none;
}

.logout-btn:hover {
    background: #333;
}

.user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 8px;
    font-size: 14px;
    color: #ccc;
    background: #333;
    border-radius: 6px;
    margin-top: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.user-info:hover {
    background: #3a3a3a;
}

.user-info-chevron {
    transition: transform 0.2s;
}

.user-info.open .user-info-chevron {
    transform: rotate(180deg);
}

/* =====================================================
   MAIN CHAT AREA
   ===================================================== */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 40px 60px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    align-items: center;
}

.chat-messages > * {
    width: 100%;
    max-width: 680px;
}

.welcome-msg {
    text-align: center;
    padding-top: 20vh;
}

.welcome-msg h2 {
    font-size: 1.5rem;
    font-weight: 400;
    color: #ccc;
}

/* Message bubbles */

.msg {
    line-height: 1.7;
}

.msg-user {
    background: #3a3a3a;
    padding: 14px 18px;
    border-radius: 12px;
    color: #e0e0e0;
    margin-left: auto;
    max-width: 85%;
    width: fit-content;
}

.msg-assistant {
    color: #e0e0e0;
}

.msg-assistant p {
    margin-bottom: 12px;
}

.msg-assistant p:last-child {
    margin-bottom: 0;
}

/* Markdown content styling */
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3 {
    margin-top: 16px;
    margin-bottom: 8px;
    color: #f0f0f0;
}

.msg-assistant ul, .msg-assistant ol {
    margin: 8px 0 8px 24px;
}

.msg-assistant li {
    margin-bottom: 4px;
}

.msg-assistant code {
    background: #3a3a3a;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 13px;
}

.msg-assistant pre {
    background: #1e1e1e;
    padding: 14px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.msg-assistant pre code {
    background: transparent;
    padding: 0;
}

.msg-assistant blockquote {
    border-left: 3px solid #d4a843;
    padding-left: 14px;
    color: #bbb;
    margin: 8px 0;
}

.msg-assistant strong {
    color: #f0f0f0;
}

/* Sources */
.msg-sources {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #444;
    font-size: 13px;
    color: #888;
}

.msg-sources h4 {
    font-size: 13px;
    font-weight: 600;
    color: #aaa;
    margin-bottom: 6px;
}

.msg-sources li {
    margin-bottom: 3px;
    color: #888;
}

.msg-sources a {
    color: #d4a843;
    text-decoration: none;
}

.msg-sources a:hover {
    text-decoration: underline;
    color: #e0bc5f;
}

/* Thinking indicator */
.thinking-text, .thinking-dots {
    color: #888;
    font-style: italic;
}

.thinking-dots {
    display: inline-block;
    min-width: 24px;
}

.thinking {
    display: flex;
    gap: 6px;
    padding: 10px 0;
}

.thinking span {
    width: 8px;
    height: 8px;
    background: #888;
    border-radius: 50%;
    animation: pulse 1.4s ease-in-out infinite;
}

.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking 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); }
}

/* =====================================================
   COMPOSER
   ===================================================== */

.chat-composer {
    padding: 16px 60px 24px;
    display: flex;
    justify-content: center;
}

.composer-box {
    border: 1px solid #555;
    border-radius: 10px;
    background: #333;
    overflow: hidden;
    width: 100%;
    max-width: 680px;
}

.composer-box textarea {
    width: 100%;
    padding: 14px 18px;
    font-size: 15px;
    font-family: inherit;
    line-height: 1.5;
    color: #e0e0e0;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
}

.composer-box textarea::placeholder {
    color: #888;
}

.composer-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
}

.output-select {
    padding: 6px 10px;
    font-size: 13px;
    font-family: inherit;
    color: #ccc;
    background: #2d2d2d;
    border: 1px solid #555;
    border-radius: 5px;
    outline: none;
    cursor: pointer;
}

.output-select:focus {
    border-color: #d4a843;
}

.attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    color: #888;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: color 0.15s;
}

.attach-btn:hover {
    color: #d4a843;
}

.file-name {
    font-size: 12px;
    color: #d4a843;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.file-name:hover {
    text-decoration: line-through;
    opacity: 0.7;
}

/* Download link in chat */
.download-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 10px 16px;
    font-size: 14px;
    color: #d4a843;
    background: rgba(212, 168, 67, 0.1);
    border: 1px solid #d4a843;
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.2s;
}

.download-link:hover {
    background: rgba(212, 168, 67, 0.2);
    color: #e0bc5f;
}

.send-btn {
    width: 42px;
    height: 42px;
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #d4a843;
    border: 1.5px solid #d4a843;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.send-btn:hover {
    background: rgba(212, 168, 67, 0.15);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* =====================================================
   ADMIN PANEL
   ===================================================== */

.admin-panel {
    background: #333;
    border-radius: 8px;
    padding: 16px 20px;
    max-width: 600px;
}

.admin-panel p {
    margin-bottom: 10px;
    color: #ccc;
}

.admin-actions {
    display: flex;
    gap: 12px;
}

.admin-btn {
    padding: 8px 14px;
    font-size: 13px;
    font-family: inherit;
    color: #d4a843;
    background: transparent;
    border: 1px solid #555;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.admin-btn:hover {
    background: rgba(212, 168, 67, 0.1);
    border-color: #d4a843;
}

.admin-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.admin-output {
    margin-top: 12px;
    padding: 12px;
    background: #2d2d2d;
    border-radius: 6px;
    font-size: 13px;
    color: #ccc;
    white-space: pre-wrap;
}

/* =====================================================
   MODAL
   ===================================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-overlay[hidden] {
    display: none !important;
}

.modal-content {
    background: #333;
    border-radius: 10px;
    width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #444;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: #e0e0e0;
}

.modal-close {
    font-size: 22px;
    color: #888;
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: #e0e0e0;
}

.modal-body {
    padding: 16px 20px;
    font-size: 14px;
    color: #ccc;
    line-height: 1.6;
}

.modal-body table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 13px;
}

.modal-body th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid #555;
    color: #aaa;
    font-weight: 500;
}

.modal-body td {
    padding: 6px 8px;
    border-bottom: 1px solid #3a3a3a;
}

/* =====================================================
   RESPONSIVE
   ===================================================== */

@media (max-width: 768px) {
    .sidebar, .login-sidebar {
        display: none;
    }

    .chat-messages {
        padding: 20px;
    }

    .chat-composer {
        padding: 12px 20px 16px;
    }
}
