:root {
    --bg-body: #ffffff;
    --bg-panel: #ffffff;
    --bg-sidebar: #f9fafb;
    --border: #f3f4f6;
    --primary: #000000;
    --primary-hover: #333333;
    --text-main: #111827;
    --text-sub: #9ca3af;
    --bubble-user: #000000;
    --bubble-ai: #f3f4f6;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.03), 0 4px 6px -2px rgba(0, 0, 0, 0.01);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
    background-color: var(--bg-body);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    position: fixed;
    -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); border: none; outline: none; font-family: inherit; }
input, textarea, select { font-family: inherit; outline: none; appearance: none; }

.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
    background-color: #fafafa;
}

.glass-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 2.5rem;
    border-radius: 24px;
    width: 90%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}

.glass-panel h2 { margin-bottom: 2rem; text-align: center; font-weight: 700; letter-spacing: -0.5px; }

input[type="text"], input[type="password"] {
    width: 100%;
    padding: 14px 16px;
    margin: 8px 0;
    background: #f9fafb;
    border: 1px solid transparent;
    border-radius: 16px;
    font-size: 16px;
    transition: all 0.2s;
}

input[type="text"]:focus, input[type="password"]:focus { background: #fff; border-color: #e5e7eb; box-shadow: 0 0 0 4px rgba(0,0,0,0.03); }

button.auth-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border-radius: 16px;
    margin-top: 1.5rem;
    font-weight: 600;
    font-size: 1rem;
}
button.auth-btn:active { transform: scale(0.98); }

.toggle-link { text-align: center; margin-top: 1.5rem; font-size: 0.85rem; color: var(--text-sub); cursor: pointer; }
.toggle-link:hover { color: var(--text-main); }

.chat-layout { 
    display: flex; 
    width: 100vw; 
    height: 100dvh;
    position: relative;
    overflow: hidden;
}

.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    height: 100%;
    flex-shrink: 0;
    z-index: 20;
}

.new-chat-btn {
    width: 100%;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text-main);
    margin-bottom: 1.5rem;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.new-chat-btn:hover { border-color: #e5e7eb; transform: translateY(-1px); }

#history-list { overflow-y: auto; flex: 1; padding-right: 4px; }

.history-item {
    padding: 12px 14px;
    font-size: 0.9rem;
    color: var(--text-sub);
    border-radius: 12px;
    cursor: pointer;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.2s;
}
.history-item:hover { background: rgba(0,0,0,0.03); color: var(--text-main); }
.history-item.active { background: #fff; color: var(--text-main); font-weight: 600; box-shadow: var(--shadow-sm); }

.logout-area { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); }
.logout-btn {
    width: 100%;
    padding: 12px;
    background: #fff;
    color: #ef4444;
    border: 1px solid #fee2e2;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 500;
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    height: 100%;
    min-width: 0;
    position: relative;
}

.chat-header {
    flex: 0 0 60px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(20px);
    z-index: 10;
}

.mobile-menu-btn { display: none; background: transparent; padding: 4px; margin-right: 12px; }

.model-select {
    background: transparent;
    border: none;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
}
.model-select:hover { background: #f3f4f6; }

.secure-badge {
    font-size: 0.75rem;
    color: #10b981;
    background: #d1fae5;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 500;
}

.messages {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1.5rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

@keyframes message-enter {
    0% { opacity: 0; transform: translateY(10px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.msg {
    max-width: 80%;
    padding: 14px 18px;
    line-height: 1.6;
    font-size: 15px;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
    animation: message-enter 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
    opacity: 0; 
}

.msg.user {
    background: var(--bubble-user);
    color: #fff;
    align-self: flex-end;
    margin-left: auto;
    border-radius: 20px 20px 4px 20px;
}

.msg.assistant {
    background: var(--bubble-ai);
    color: var(--text-main);
    border-radius: 20px 20px 20px 4px;
}

.reasoning {
    font-size: 0.85rem;
    color: #6b7280;
    background: #fff;
    border-left: 2px solid #e5e7eb;
    padding: 10px 14px;
    margin-bottom: 8px;
    border-radius: 8px;
}

.input-box {
    flex: 0 0 auto;
    padding: 16px 20px;
    background: #fff;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 30;
}

.input-wrapper {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 26px;
    padding: 6px 6px 6px 16px;
    background: #f9fafb;
    display: flex;
    align-items: center;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
}
.input-wrapper:focus-within { background: #fff; border-color: #e5e7eb; box-shadow: 0 0 0 4px rgba(0,0,0,0.02); }

textarea {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 0;
    resize: none;
    height: 44px;
    max-height: 120px;
    font-size: 16px;
    line-height: 24px;
    color: var(--text-main);
}
textarea::placeholder { color: #9ca3af; }

.send-btn {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    flex-shrink: 0;
    transition: transform 0.2s;
}
.send-btn:hover { transform: scale(1.05); }
.send-btn:active { transform: scale(0.95); }
.send-btn svg { width: 18px; height: 18px; stroke-width: 2.5; }

.typing-indicator { display: flex; gap: 5px; padding: 4px 2px; }
.typing-dot {
    width: 6px; height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing-wave 1.4s ease-in-out infinite both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-wave {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.mobile-overlay { display: none; }

@media (max-width: 768px) {
    .mobile-menu-btn { display: block; }
    .secure-badge { display: none; }
    .chat-header { padding: 0 1rem; }
    .messages { padding: 1rem; gap: 1rem; }
    .msg { max-width: 88%; padding: 12px 16px; }
    .input-box { padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
    
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 80%; max-width: 320px;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: 2px 0 24px rgba(0,0,0,0.1);
        background: #fff;
        z-index: 50;
    }
    .sidebar.open { transform: translateX(0); }
    
    .mobile-overlay {
        display: block;
        position: fixed;
        top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(0,0,0,0.2);
        backdrop-filter: blur(2px);
        z-index: 40;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }
    .mobile-overlay.active { opacity: 1; pointer-events: auto; }
}