/* ================================================================
   DrinksBox Chat — Stylesheet
   ================================================================ */

:root {
    --sidebar-width: 260px;
    --topbar-height: 52px;
    --color-bg: #f5f5f5;
    --color-surface: #ffffff;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-text: #1a1a1a;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-user-msg: #e8f0fe;
    --color-error: #dc2626;
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height — accounts for mobile browser chrome */
    overflow: hidden;
}

/* ── Login page ─────────────────────────────────────────────────── */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: var(--color-surface);
    padding: 48px 40px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    max-width: 400px;
    width: 100%;
}

.login-card h1 {
    font-size: 24px;
    margin-bottom: 8px;
}

.login-card p {
    color: var(--color-text-muted);
    margin-bottom: 24px;
    font-size: 14px;
}

.btn-google {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 24px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
}

.btn-google:hover { background: #f9fafb; }

.error-banner {
    background: #fef2f2;
    color: var(--color-error);
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}

/* ── Top bar ────────────────────────────────────────────────────── */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 700; font-size: 16px; }
.brand-logo { height: 24px; display: block; }

.powered-by {
    font-size: 11px;
    color: var(--color-text-muted);
    background: var(--color-bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
}

.topbar-right { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.avatar { border-radius: 50%; }
.admin-link {
    font-size: 11px;
    font-weight: 600;
    color: #7c3aed;
    background: #f3f0ff;
    padding: 2px 8px;
    border-radius: 4px;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.admin-link:hover { background: #ede9fe; }

.logout-link { color: var(--color-text-muted); text-decoration: none; font-size: 13px; }
.logout-link:hover { color: var(--color-text); }

/* ── App layout ─────────────────────────────────────────────────── */

.app-layout {
    display: flex;
    height: calc(100vh - var(--topbar-height));
    height: calc(100dvh - var(--topbar-height));
    margin-top: var(--topbar-height);
}

/* ── Sidebar ────────────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.btn-new-chat {
    margin: 12px;
    padding: 10px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

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

.sidebar-search {
    padding: 0 12px 8px;
}

.sidebar-search input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
}

.sidebar-search input:focus {
    border-color: var(--color-primary);
}

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

.conv-item {
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    margin-bottom: 2px;
    transition: background 0.1s;
}

.conv-item:hover { background: #f3f4f6; }
.conv-item.active { background: #e8f0fe; }

.conv-item-header {
    display: flex;
    align-items: center;
    gap: 4px;
}

.conv-item-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.conv-rename-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--color-text-muted);
    padding: 0 2px;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.conv-item:hover .conv-rename-btn { opacity: 1; }
.conv-rename-btn:hover { color: var(--color-text); }

.conv-rename-input {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    font-weight: 500;
    padding: 2px 6px;
    border: 1px solid var(--color-primary);
    border-radius: 4px;
    outline: none;
    font-family: inherit;
}

.conv-item-time {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* ── Chat main area ─────────────────────────────────────────────── */

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

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
}

/* ── Welcome state ──────────────────────────────────────────────── */

.welcome-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 32px 16px;
    text-align: center;
}

.welcome-icon {
    width: 52px; height: 52px;
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    border-radius: 13px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 16px;
    font-size: 26px;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.18);
}

.welcome-greeting {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 4px;
}

.welcome-subtitle {
    font-size: 14px;
    color: var(--color-text-muted);
    margin-bottom: 28px;
    max-width: 400px;
    line-height: 1.5;
}

.prompt-cards {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 680px;
}

.prompt-card {
    flex: 1;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 14px;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
}

.prompt-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.1);
    transform: translateY(-1px);
}

.prompt-card-icon {
    font-size: 18px;
    margin-bottom: 2px;
}

.prompt-card-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
    line-height: 1.4;
}

/* ── Message bubbles ────────────────────────────────────────────── */

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.55;
    position: relative;
}

.message.user {
    align-self: flex-end;
    background: var(--color-user-msg);
}

.message.assistant {
    align-self: flex-start;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}

.message .timestamp {
    display: none;
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 6px;
}

.message:hover .timestamp { display: block; }

/* Copy button on assistant messages */
.message.assistant .copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    color: var(--color-text-muted);
}

.message.assistant:hover .copy-btn { opacity: 1; }
.message.assistant .copy-btn:hover { background: #f3f4f6; }

/* Markdown content styling */
.message.assistant p { margin-bottom: 8px; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant pre {
    background: #f3f4f6;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}
.message.assistant code {
    font-size: 13px;
    font-family: "SFMono-Regular", Consolas, monospace;
}
.message.assistant ul, .message.assistant ol {
    margin: 8px 0;
    padding-left: 20px;
}

/* ── Model toggle ──────────────────────────────────────────────── */

.model-toggle {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--color-bg);
    border-radius: 6px;
    padding: 2px;
    margin-bottom: 8px;
}

.model-toggle button {
    padding: 4px 12px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    color: var(--color-text-muted);
    transition: background 0.15s, color 0.15s;
}

.model-toggle button.active {
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.model-toggle button:hover:not(.active) { color: var(--color-text); }

.model-indicator {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-left: auto;
    padding: 2px 8px;
    background: var(--color-bg);
    border-radius: 4px;
}

/* ── Input area ─────────────────────────────────────────────────── */

.input-area {
    padding: 12px 16px 16px;
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
}

#messageForm {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    resize: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    max-height: 120px; /* ~4 lines */
    outline: none;
    transition: border-color 0.15s;
}

#messageInput:focus { border-color: var(--color-primary); }

#sendBtn {
    padding: 10px 20px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

#sendBtn:hover:not(:disabled) { background: var(--color-primary-hover); }
#sendBtn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--color-text-muted);
    border-radius: 50%;
    animation: blink 1.4s infinite both;
}

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

@keyframes blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* ── Mobile responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
    .sidebar-toggle { display: block; }

    .sidebar {
        position: fixed;
        top: var(--topbar-height);
        left: 0;
        bottom: 0;
        z-index: 90;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .sidebar.open { transform: translateX(0); }

    .messages { padding: 16px 12px; }

    .prompt-cards { flex-direction: column; }
    .prompt-card { min-height: auto; }

    .input-area {
        padding: 8px 12px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .powered-by { display: none; }

    .topbar-right .username { display: none; }
}
