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

:root {
    --bg-app: #0e0a0c;
    --bg-chat: #181018;
    --bg-sidebar: #1c141a;
    --bg-input: #2a1d27;
    --bg-input-focus: #33212e;
    --bg-bubble-user: rgba(255, 105, 180, 0.18);
    --bg-bubble-ai: #241821;
    --bg-hover: rgba(255, 105, 180, 0.08);
    --border-subtle: rgba(255, 105, 180, 0.18);
    --border-focus: rgba(255, 105, 180, 0.55);
    --text-primary: #ffffff;
    --text-muted: #b8a0b0;
    --text-faint: #7a6670;
    --pink-1: #ff69b4;
    --pink-2: #ff1493;
    --pink-glow: rgba(255, 20, 147, 0.35);
    --sidebar-width: 280px;
    --composer-max-width: 760px;
}

html, body {
    height: 100vh;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'San Francisco', Arial, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ========== APP LAYOUT ========== */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    width: 100vw;
}

/* ========== SIDEBAR ========== */
.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid rgba(255, 255, 255, 0.04);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    overflow-y: auto;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    color: var(--pink-1);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, transform 120ms ease;
}

.new-chat-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-focus);
}

.new-chat-btn:active {
    transform: scale(0.98);
}

.new-chat-icon {
    font-size: 18px;
    line-height: 1;
    margin-top: -1px;
}

.sidebar-section-label {
    margin: 24px 6px 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.chat-list-empty {
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-faint);
    font-style: italic;
}

.chat-list-item {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 120ms ease, color 120ms ease;
}

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

.chat-list-item.active {
    background: rgba(255, 105, 180, 0.14);
    color: var(--text-primary);
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

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

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 105, 180, 0.25);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 105, 180, 0.45);
}

/* ========== CHAT AREA ========== */
.chat-area {
    background: var(--bg-chat);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* ========== TOPBAR ========== */
.topbar {
    position: absolute;
    top: 14px;
    right: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 5;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-user[hidden] {
    display: none;
}

.topbar-username {
    font-size: 13px;
    color: var(--text-muted);
    padding: 0 6px;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-btn {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--pink-1);
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, transform 120ms ease;
}

.topbar-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-focus);
}

.topbar-btn:active {
    transform: scale(0.98);
}

.topbar-btn-primary {
    background: linear-gradient(135deg, var(--pink-1), var(--pink-2));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 10px var(--pink-glow);
}

.topbar-btn-primary:hover {
    background: linear-gradient(135deg, var(--pink-1), var(--pink-2));
    border-color: transparent;
    box-shadow: 0 4px 14px var(--pink-glow);
    transform: translateY(-1px);
}

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

/* Greeting */
.greeting {
    position: absolute;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: left;
    pointer-events: none;
    transition: opacity 260ms ease, transform 260ms ease;
    width: min(90%, 720px);
}

.greeting-hi {
    font-size: 52px;
    font-weight: 500;
    line-height: 1.1;
    background: linear-gradient(90deg, #c792d1 0%, var(--pink-1) 45%, var(--pink-2) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.greeting-prompt {
    margin-top: 4px;
    font-size: 52px;
    font-weight: 500;
    line-height: 1.1;
    color: #c7b4bf;
}

.chat-area.has-messages .greeting {
    opacity: 0;
    transform: translate(-50%, calc(-50% - 20px));
    pointer-events: none;
}

/* Messages area */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
}

.messages > .msg-row:first-child {
    margin-top: auto;
}

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

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

.messages::-webkit-scrollbar-thumb {
    background: rgba(255, 105, 180, 0.3);
    border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 105, 180, 0.55);
}

.msg-row {
    width: 100%;
    display: flex;
    padding: 0 24px;
}

.msg-row.msg-user {
    justify-content: flex-end;
}

.msg-row.msg-ai {
    justify-content: flex-start;
}

.msg-bubble {
    max-width: min(720px, 75%);
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.msg-row.msg-user .msg-bubble {
    background: var(--bg-bubble-user);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    border-bottom-right-radius: 6px;
}

.msg-row.msg-ai .msg-bubble {
    background: var(--bg-bubble-ai);
    color: var(--text-primary);
    border-bottom-left-radius: 6px;
}

.msg-sender {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 4px;
    background: linear-gradient(90deg, var(--pink-1), var(--pink-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.msg-row.msg-user .msg-sender {
    color: var(--text-muted);
    background: none;
    -webkit-text-fill-color: var(--text-muted);
}

.msg-bubble.loading::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 4px;
    border-radius: 50%;
    background: var(--pink-1);
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* ========== COMPOSER ========== */
.composer-wrap {
    padding: 12px 24px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.composer {
    width: 100%;
    max-width: var(--composer-max-width);
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: 26px;
    padding: 10px 10px 10px 20px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.composer:focus-within {
    border-color: var(--border-focus);
    background: var(--bg-input-focus);
    box-shadow: 0 0 0 4px rgba(255, 20, 147, 0.08);
}

.composer-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    padding: 8px 0;
    max-height: 200px;
    min-height: 24px;
}

.composer-input::placeholder {
    color: var(--text-muted);
}

.composer-send {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--pink-1), var(--pink-2));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 120ms ease, box-shadow 160ms ease, opacity 160ms ease;
    box-shadow: 0 2px 10px var(--pink-glow);
}

.composer-send:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px var(--pink-glow);
}

.composer-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.composer-send svg {
    transform: translateX(1px);
}

/* Chips */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    width: 100%;
    max-width: var(--composer-max-width);
}

.chip {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.chip:hover {
    border-color: var(--border-focus);
    color: var(--text-primary);
    background: var(--bg-hover);
}

.composer-footnote {
    font-size: 11px;
    color: var(--text-faint);
    text-align: center;
}

/* ========== API KEY MODAL ========== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal[hidden] {
    display: none;
}

.modal-box {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-subtle);
    border-radius: 18px;
    padding: 28px;
    width: min(420px, 90vw);
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

.modal-box h3 {
    font-size: 20px;
    font-weight: 600;
    background: linear-gradient(90deg, var(--pink-1), var(--pink-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.modal-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.modal-sub a {
    color: var(--pink-1);
    text-decoration: none;
}

.modal-sub a:hover {
    text-decoration: underline;
}

#api-key-input {
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 160ms ease;
}

#api-key-input:focus {
    border-color: var(--border-focus);
}

#api-key-save {
    background: linear-gradient(135deg, var(--pink-1), var(--pink-2));
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 160ms ease;
}

#api-key-save:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px var(--pink-glow);
}

#api-key-save:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.modal-error {
    font-size: 13px;
    min-height: 18px;
    color: #ff8fa3;
}

.modal-error.success {
    color: #8fffd4;
}

/* ========== AUTH MODAL ========== */
.auth-tabs {
    display: flex;
    gap: 6px;
    padding: 4px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    margin-bottom: 4px;
}

.auth-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px 12px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 160ms ease, color 160ms ease;
}

.auth-tab:hover {
    color: var(--text-primary);
}

.auth-tab.active {
    background: linear-gradient(135deg, var(--pink-1), var(--pink-2));
    color: #fff;
    box-shadow: 0 2px 8px var(--pink-glow);
}

#auth-username,
#auth-password {
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 160ms ease;
}

#auth-username:focus,
#auth-password:focus {
    border-color: var(--border-focus);
}

#auth-submit {
    background: linear-gradient(135deg, var(--pink-1), var(--pink-2));
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 160ms ease;
}

#auth-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px var(--pink-glow);
}

#auth-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 720px) {
    :root {
        --sidebar-width: 0px;
    }
    .app {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: none;
    }
    .greeting-hi,
    .greeting-prompt {
        font-size: 36px;
    }
    .msg-bubble {
        max-width: 88%;
    }
}
