/* Theme Variables */
:root {
    --bg-page: #F3F4F6;
    --bg-container: white;
    --bg-header: white;
    --bg-input: white;
    --bg-input-container: white;
    --bg-assistant-msg: #f1f3f4;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --text-assistant: #333;
    --border-color: #ddd;
    --border-input-container: #e0e0e0;
    --border-accent: #6B2B34;
    --bg-tool-use: #fff3cd;
    --border-tool-use: #f59e0b;
    --text-tool-use: #856404;
    --bg-error: #fef2f2;
    --border-error: #fecaca;
    --text-error: #ef4444;
    --bg-sample-btn: white;
    --border-sample-btn: #D1D5DB;
    --text-sample-btn: #374151;
    --bg-help-popup: white;
    --bg-help-example: #F3F4F6;
    --text-help-example: #374151;
    --bg-code-inline: rgba(0,0,0,0.1);
    --bg-code-inline-assistant: rgba(0,0,0,0.08);
    --bg-send-disabled: #ccc;
    --shadow: rgba(0,0,0,0.1);
}

[data-theme="dark"] {
    --bg-page: #111827;
    --bg-container: #1F2937;
    --bg-header: #1F2937;
    --bg-input: #374151;
    --bg-input-container: #1F2937;
    --bg-assistant-msg: #374151;
    --text-primary: #F9FAFB;
    --text-secondary: #9CA3AF;
    --text-assistant: #E5E7EB;
    --border-color: #4B5563;
    --border-input-container: #4B5563;
    --border-accent: #8B3B44;
    --bg-tool-use: #422006;
    --border-tool-use: #b45309;
    --text-tool-use: #fbbf24;
    --bg-error: #451a1a;
    --border-error: #7f1d1d;
    --text-error: #fca5a5;
    --bg-sample-btn: #374151;
    --border-sample-btn: #4B5563;
    --text-sample-btn: #E5E7EB;
    --bg-help-popup: #1F2937;
    --bg-help-example: #374151;
    --text-help-example: #E5E7EB;
    --bg-code-inline: rgba(255,255,255,0.1);
    --bg-code-inline-assistant: rgba(255,255,255,0.1);
    --bg-send-disabled: #4B5563;
    --shadow: rgba(0,0,0,0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-page);
    min-height: 100vh;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-container);
    box-shadow: 0 0 20px var(--shadow);
}

header {
    padding: 16px 24px;
    background: var(--bg-header);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 2px solid var(--border-accent);
}

.header-logo {
    height: 40px;
    width: auto;
}

header h1 {
    font-size: 24px;
    font-weight: 600;
}

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

header .subtitle .framework-link {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}

.env-badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    vertical-align: middle;
}

.env-badge.env-production {
    background: rgba(220, 53, 69, 0.15);
    color: #dc3545;
    border: 1px solid rgba(220, 53, 69, 0.4);
}

.env-badge.env-staging {
    background: rgba(255, 165, 0, 0.15);
    color: #e8930c;
    border: 1px solid rgba(255, 165, 0, 0.4);
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    opacity: 0.7;
    margin-top: 6px;
    text-align: right;
}

.header-nav {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-nav .nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
}

.header-nav .nav-link:hover {
    background: var(--bg-assistant-msg);
    color: var(--text-primary);
}

#user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

#user-email {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Slash commands below input */
.slash-commands {
    display: flex;
    gap: 16px;
    padding: 4px 24px 8px;
    background: var(--bg-input-container);
}

.slash-commands button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: monospace;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

.slash-commands button:hover {
    color: var(--text-primary);
    background: var(--bg-assistant-msg);
}

#sign-out-btn {
    background: #6B2B34;
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

#sign-out-btn:hover {
    background: #8B3B44;
}

/* Theme Toggle */
#theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color 0.2s, border-color 0.2s;
}

#theme-toggle:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

#theme-toggle svg {
    width: 20px;
    height: 20px;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Login Screen */
#login-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #111827;
}

.login-box {
    background: #1F2937;
    padding: 48px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    text-align: center;
}

.login-box h2 {
    margin-bottom: 8px;
    color: white;
}

.login-box p {
    color: #9CA3AF;
    margin-bottom: 24px;
}


/* Chat Screen */
#chat-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 12px;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
    max-width: 85%;
}

.message.assistant {
    align-self: flex-start;
    max-width: 100%;
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
}

.message.user .message-content {
    background: #6C3333;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--bg-assistant-msg);
    color: var(--text-assistant);
    border-bottom-left-radius: 4px;
}

.message-content p {
    margin-bottom: 8px;
}

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

.message-content ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content pre {
    background: #282c34;
    color: #abb2bf;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}

.message-content code {
    background: var(--bg-code-inline);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.message.assistant .message-content code {
    background: var(--bg-code-inline-assistant);
}

.message.user .message-content code {
    background: rgba(255,255,255,0.2);
}

/* Tool use indicator */
.tool-use {
    background: var(--bg-tool-use);
    border: 1px solid var(--border-tool-use);
    border-radius: 6px;
    padding: 8px 12px;
    margin: 8px 0;
    font-size: 13px;
    color: var(--text-tool-use);
}

.tool-use .tool-name {
    font-weight: 600;
}

/* Tool progress during streaming */
.tool-progress {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tool-running {
    opacity: 0.85;
}

.tool-done {
    opacity: 0.6;
}

.tool-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-tool-use);
    border-top-color: var(--text-tool-use);
    border-radius: 50%;
    animation: tool-spin 0.8s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
}

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

/* Feedback buttons */
.feedback-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    padding-left: 4px;
}

.feedback-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 4px 6px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.feedback-btn:hover:not(:disabled) {
    color: var(--text-primary);
    background: var(--bg-assistant-msg);
    border-color: var(--border-color);
}

.feedback-btn:disabled {
    cursor: default;
    opacity: 0.5;
}

.feedback-btn.selected {
    color: #6C3333;
    opacity: 1;
}

.download-btn,
.copy-btn {
    margin-left: 4px;
}

.feedback-hint {
    margin-left: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    animation: hintNudge 2s ease-in-out infinite;
}

.feedback-hint::before {
    content: '\2190  ';
}

@keyframes hintNudge {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Chat Input */
#chat-input-container {
    padding: 16px 24px;
    border-top: 1px solid var(--border-input-container);
    display: flex;
    gap: 12px;
    background: var(--bg-input-container);
}

#chat-input {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 15px;
    resize: none;
    max-height: 150px;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-primary);
}

#chat-input:focus {
    outline: none;
    border-color: #6C3333;
    box-shadow: 0 0 0 2px rgba(108, 51, 51, 0.2);
}

#send-btn {
    background: #6C3333;
    border: none;
    border-radius: 8px;
    width: 48px;
    height: 48px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

#send-btn:hover {
    background: #5a2a2a;
}

#send-btn:disabled {
    background: var(--bg-send-disabled);
    cursor: not-allowed;
}

#send-btn svg {
    width: 24px;
    height: 24px;
}

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

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

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

.typing-indicator .esc-hint {
    width: auto;
    height: auto;
    background: none;
    border-radius: 0;
    animation: none;
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.6;
    margin-left: 8px;
    white-space: nowrap;
}

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Stop button mode */
#send-btn.stop-mode {
    background: #b33;
}

#send-btn.stop-mode:hover {
    background: #922;
}

#send-btn.stop-mode svg {
    display: none;
}

#send-btn.stop-mode::after {
    content: '■';
    font-size: 18px;
    color: white;
}

/* Error message */
.error-message {
    background: var(--bg-error);
    border: 1px solid var(--border-error);
    color: var(--text-error);
    padding: 12px 16px;
    border-radius: 8px;
    margin: 8px 0;
}

/* System message (e.g., cancelled) */
.system-message {
    color: var(--text-secondary);
    text-align: center;
    padding: 8px 16px;
    margin: 8px 0;
    font-size: 0.85rem;
    font-style: italic;
}

/* Sample questions */
.sample-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.sample-question {
    background: var(--bg-sample-btn);
    border: 1px solid var(--border-sample-btn);
    color: var(--text-sample-btn);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.sample-question:hover {
    background: #6C3333;
    border-color: #6C3333;
    color: white;
}

/* Better markdown styling */
.message-content h2 {
    font-size: 18px;
    margin: 16px 0 8px 0;
    font-weight: 600;
}

.message-content h3 {
    font-size: 16px;
    margin: 12px 0 6px 0;
    font-weight: 600;
}

.message-content h4 {
    font-size: 14px;
    margin: 10px 0 4px 0;
    font-weight: 600;
}

.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content li {
    margin-bottom: 4px;
    line-height: 1.5;
}

.followup-link {
    color: #60a5fa;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
    cursor: pointer;
}

.followup-link:hover {
    color: #93c5fd;
    text-decoration-style: solid;
}

[data-theme="light"] .followup-link {
    color: #2563eb;
}

[data-theme="light"] .followup-link:hover {
    color: #1d4ed8;
}

.message-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    font-size: 13px;
    line-height: 1.4;
}

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

.message-content table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
    font-size: 14px;
}

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

.message-content th {
    background: var(--bg-page);
    font-weight: 600;
}

.message-content tr:nth-child(even) td {
    background: var(--bg-page);
}

/* Help icon and popup */
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: #6C3333;
    color: white;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    margin-left: 4px;
    vertical-align: middle;
    line-height: 1;
}

.help-icon:hover {
    background: #5a2a2a;
}

.help-popup {
    position: absolute;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: var(--bg-help-popup);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 4px 16px var(--shadow);
    padding: 16px;
    z-index: 100;
}

.help-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 14px;
}

.help-close {
    cursor: pointer;
    font-size: 20px;
    color: var(--text-secondary);
    line-height: 1;
    padding: 0 4px;
}

.help-close:hover {
    color: var(--text-primary);
}

.help-popup ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-popup li.help-example {
    padding: 8px 12px;
    margin: 4px 0;
    background: var(--bg-help-example);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-help-example);
    transition: background 0.15s;
}

.help-popup li.help-example:hover {
    background: #6C3333;
    color: white;
}

.help-note {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
}

/* Position the li containing the popup as relative */
.message-content li {
    position: relative;
}

/* Help Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-container);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    color: var(--text-primary);
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    cursor: pointer;
    font-size: 24px;
    color: var(--text-secondary);
    line-height: 1;
    padding: 0 4px;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 16px 24px 24px;
}

.help-section {
    margin-bottom: 16px;
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.help-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-section li {
    padding: 4px 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
}

.help-section li strong {
    color: var(--text-primary);
}

.help-section a {
    color: #60a5fa;
    text-decoration: none;
}

.help-section a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        max-width: 100%;
    }

    header {
        padding: 12px 16px;
    }

    header h1 {
        font-size: 20px;
    }

    #chat-messages {
        padding: 16px;
    }

    .message {
        max-width: 95%;
    }

    #chat-input-container {
        padding: 12px 16px;
    }
}
