/* TapChat — Chat UI Styles */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-sidebar: #0f3460;
    --bg-input: #1a1a3e;
    --bg-user-msg: #1a3a5c;
    --bg-assistant-msg: #1e2a3a;
    --bg-tool: #0d2137;
    --text-primary: #e4e6eb;
    --text-secondary: #9aa0a8;
    --text-muted: #6c7680;
    --accent: #4da6ff;
    --accent-hover: #6db8ff;
    --border: #2a3a4a;
    --error: #ff6b6b;
    --success: #51cf66;
    --google-blue: #4285f4;
    --orcid-green: #a6ce39;
    --radius: 8px;
    --sidebar-width: 280px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* Layout */
#app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
    transition: width 0.2s ease;
}

#sidebar.collapsed {
    width: 0;
    border-right: none;
}

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

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent);
}

#sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

#sidebar-toggle:hover {
    background: rgba(255,255,255,0.1);
}

/* Auth section */
#auth-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.auth-hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 8px;
}

.user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
}

#user-name {
    font-weight: 500;
}

/* Buttons */
.btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 6px;
    transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }

.btn-google {
    background: var(--google-blue);
    color: #fff;
}

.btn-orcid {
    background: var(--orcid-green);
    color: #333;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    margin: 12px 16px;
    width: calc(100% - 32px);
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    text-decoration: underline;
}

/* Archive selector */
#archive-selector {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
}

#archive-selector label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

#profile-select {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
}

/* Chat list */
#chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: background 0.15s;
}

.chat-item:hover {
    background: rgba(255,255,255,0.05);
}

.chat-item.active {
    background: rgba(77,166,255,0.15);
    border-left: 3px solid var(--accent);
}

.chat-item-title {
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-item-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 8px;
    white-space: nowrap;
}

.chat-item-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    margin-left: 4px;
    border-radius: 4px;
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.15s;
}

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

.chat-item-delete:hover {
    color: var(--error);
    background: rgba(255,107,107,0.1);
}

/* Guest banner */
#guest-banner {
    padding: 12px 16px;
    background: rgba(77,166,255,0.1);
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Main chat area */
#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Messages container */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

.message {
    max-width: 800px;
    margin: 0 auto 16px;
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
}

.message-user {
    background: var(--bg-user-msg);
    margin-left: 60px;
}

.message-assistant {
    background: var(--bg-assistant-msg);
}

.message-role {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.message-content {
    font-size: 0.95rem;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-content p {
    margin-bottom: 0.5em;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* Markdown rendering */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin-top: 0.8em;
    margin-bottom: 0.4em;
    color: var(--accent);
}

.message-content h1 { font-size: 1.3rem; }
.message-content h2 { font-size: 1.1rem; }
.message-content h3 { font-size: 1rem; }

.message-content code {
    background: rgba(0,0,0,0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 0.85em;
}

.message-content pre {
    background: rgba(0,0,0,0.3);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

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

.message-content ul, .message-content ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}

.message-content a {
    color: var(--accent);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

/* Tables */
.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 0.85rem;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}

.message-content th {
    background: rgba(0,0,0,0.3);
    font-weight: 600;
}

/* Thinking section */
.thinking-block {
    margin: 8px 0;
    border-left: 3px solid var(--text-muted);
    padding-left: 12px;
}

.thinking-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 4px 0;
}

.thinking-toggle:hover {
    color: var(--text-secondary);
}

.thinking-content {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

.thinking-content.collapsed {
    display: none;
}

/* Tool call indicators */
.tool-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-tool);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 12px;
    margin: 6px 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.tool-indicator .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.tool-indicator.complete .spinner {
    display: none;
}

.tool-indicator.complete::before {
    content: "\2713";
    color: var(--success);
    font-weight: bold;
}

/* Inline plots */
.plot-container {
    margin: 12px 0;
    text-align: center;
}

.plot-container img {
    max-width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.plot-description {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Error messages */
.error-message {
    background: rgba(255,107,107,0.1);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    padding: 10px 14px;
    color: var(--error);
    font-size: 0.9rem;
    margin: 8px auto;
    max-width: 800px;
}

/* Input area */
#input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    max-width: 860px;
    margin: 0 auto;
    width: 100%;
}

#user-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    min-height: 42px;
    max-height: 200px;
    line-height: 1.4;
}

#user-input:focus {
    outline: none;
    border-color: var(--accent);
}

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

#send-btn {
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.15s;
    white-space: nowrap;
}

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

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

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

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

/* Responsive */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        z-index: 100;
        height: 100vh;
    }

    #sidebar.collapsed {
        width: 0;
    }

    .sidebar-open-btn {
        display: block;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 50;
        background: var(--bg-sidebar);
        border: 1px solid var(--border);
        border-radius: 4px;
        color: var(--text-primary);
        padding: 6px 10px;
        cursor: pointer;
    }
}
