:root {
    --bg-base: #000000; --bg-surface: #1c1c1e; --bg-sidebar: #0a0a0c; 
    --bg-bubble-ai: #1c1c1e; --bg-bubble-user: #0a84ff;
    --text-primary: #ffffff; --text-secondary: #8e8e93;
    --accent: #ffd60a; --border-light: rgba(255, 255, 255, 0.1); --danger: #ff453a;
}

body.owner-mode {
    --bg-base: #000000; --bg-surface: #1a1600; --bg-sidebar: #050400; 
    --bg-bubble-ai: #1a1600; --bg-bubble-user: #ffd60a;
    --text-primary: #ffffff; --border-light: rgba(255, 214, 10, 0.2);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
.no-select { user-select: none; -webkit-user-select: none; }
input, textarea { user-select: auto !important; -webkit-user-select: auto !important; }

body { background: var(--bg-base); color: var(--text-primary); height: 100dvh; width: 100vw; overflow: hidden; display: flex; flex-direction: column; }
.material-symbols-rounded { font-size: 24px; display: inline-block; vertical-align: middle; }

/* Toasts */
.toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: rgba(28, 28, 30, 0.9); backdrop-filter: blur(10px); color: var(--text-primary); padding: 12px 24px; border-radius: 100px; box-shadow: 0 10px 30px rgba(0,0,0,0.8); font-size: 14px; font-weight: 500; border: 1px solid var(--border-light); animation: slideDown 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }

/* Splash Screen */
.splash-screen { position: fixed; inset: 0; background: var(--bg-base); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 9999; transition: opacity 0.5s ease; }
.logo-box { width: 72px; height: 72px; background: var(--text-primary); color: var(--bg-base); border-radius: 20px; display: flex; justify-content: center; align-items: center; animation: pulse 1.5s ease-in-out infinite alternate; }
body.owner-mode .logo-box { background: var(--accent); color: #000; }
.splash-icon { font-size: 40px; }
.splash-text { margin-top: 24px; font-size: 22px; font-weight: 800; letter-spacing: 5px; color: var(--text-primary); }
@keyframes pulse { from { transform: scale(1); box-shadow: 0 0 20px rgba(255,255,255,0.1); } to { transform: scale(1.05); box-shadow: 0 0 40px rgba(255,255,255,0.3); } }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(5px); display: flex; justify-content: center; align-items: center; z-index: 2000; transition: 0.3s; }
.modal-overlay.hidden { opacity: 0; pointer-events: none; }
.modal-box { background: var(--bg-surface); padding: 32px; border-radius: 24px; width: 90%; max-width: 360px; text-align: center; border: 1px solid var(--border-light); box-shadow: 0 20px 50px rgba(0,0,0,0.8); transform: scale(1); transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.modal-overlay.hidden .modal-box { transform: scale(0.9); }
.small-logo { width: 56px; height: 56px; margin: 0 auto 20px; border-radius: 16px; animation: none; box-shadow: none; }
.modal-box h2, .modal-box h3 { font-size: 20px; margin-bottom: 8px; font-weight: 600; }
.modal-box p { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.modal-box input { width: 100%; padding: 14px 16px; margin-bottom: 24px; border-radius: 12px; border: 1px solid var(--border-light); background: var(--bg-base); color: var(--text-primary); outline: none; font-size: 16px; transition: 0.3s; }
.modal-box input:focus { border-color: var(--text-primary); }
body.owner-mode .modal-box input:focus { border-color: var(--accent); }
.modal-actions { display: flex; flex-direction: column; gap: 12px; }
.horizontal { flex-direction: row; }
.modal-actions button, .modal-box > button { width: 100%; padding: 14px; border-radius: 12px; font-weight: 600; font-size: 15px; border: none; cursor: pointer; transition: 0.2s; }
.btn-primary { background: var(--text-primary); color: var(--bg-base); }
.btn-primary:active { transform: scale(0.96); }
.btn-secondary { background: transparent; color: var(--text-primary); border: 1px solid var(--border-light); }
.btn-danger { background: rgba(255, 69, 58, 0.1); color: var(--danger); border: 1px solid rgba(255, 69, 58, 0.3); }

/* Layout & Sidebar */
.app-layout { display: flex; width: 100%; height: 100%; overflow: hidden; }
.sidebar { width: 280px; background: var(--bg-sidebar); display: flex; flex-direction: column; border-right: 1px solid var(--border-light); z-index: 100; transition: 0.3s; flex-shrink: 0; }
.sidebar-header { padding: 20px; }
.new-chat-btn { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; background: var(--bg-surface); color: var(--text-primary); padding: 14px; border-radius: 12px; cursor: pointer; font-size: 15px; font-weight: 500; border: 1px solid var(--border-light); transition: 0.2s; }
.new-chat-btn:active { transform: scale(0.96); background: var(--text-primary); color: var(--bg-base); }

.chat-list-container { flex: 1; overflow-y: auto; padding: 0 12px; }
.chat-list-container::-webkit-scrollbar { width: 0; }
.section-title { font-size: 12px; color: var(--text-secondary); margin-bottom: 12px; font-weight: 600; padding-left: 8px; }
#chat-history-list { list-style: none; }
.chat-item { padding: 14px 16px; border-radius: 12px; cursor: pointer; font-size: 15px; font-weight: 500; color: var(--text-secondary); display: flex; align-items: center; gap: 12px; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: 0.2s; }
.chat-item .material-symbols-rounded { font-size: 18px; }
.chat-item:active { background: var(--bg-surface); transform: scale(0.98); }
.chat-item.active { background: var(--bg-surface); color: var(--text-primary); }
body.owner-mode .chat-item.active { border-left: 3px solid var(--accent); border-radius: 0 12px 12px 0; }

.sidebar-footer { padding: 20px; border-top: 1px solid var(--border-light); }
.user-profile { display: flex; align-items: center; gap: 12px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--bg-surface); display: flex; justify-content: center; align-items: center; color: var(--text-primary); border: 1px solid var(--border-light); }
body.owner-mode .avatar { background: var(--accent); color: #000; border: none; }
.user-info { display: flex; flex-direction: column; }
.user-info strong { font-size: 15px; font-weight: 600; }
.user-info span { font-size: 12px; color: var(--text-secondary); }
body.owner-mode .user-info span { color: var(--accent); }

/* Main Chat Area */
.chat-main { flex: 1; display: flex; flex-direction: column; background: var(--bg-base); position: relative; height: 100%; }
.chat-header { flex: 0 0 auto; padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-light); background: rgba(0,0,0,0.8); backdrop-filter: blur(10px); z-index: 10; }
.header-left { display: flex; align-items: center; gap: 12px; }
#menu-toggle { display: none; }
.header-title { font-weight: 600; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.badge { background: var(--bg-surface); color: var(--text-primary); font-size: 10px; padding: 4px 8px; border-radius: 6px; font-weight: 600; border: 1px solid var(--border-light); letter-spacing: 1px; }
body.owner-mode .badge { background: var(--accent); color: #000; border: none; }
.icon-btn { background: transparent; border: none; color: var(--text-primary); cursor: pointer; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: 0.2s; }
.icon-btn:active { background: var(--bg-surface); }

.chat-scroll-area { flex: 1 1 auto; overflow-y: auto; padding: 24px 10% 120px; display: flex; flex-direction: column; gap: 24px; scroll-behavior: smooth; }
.chat-scroll-area::-webkit-scrollbar { width: 0px; }

.scroll-bottom-btn { position: absolute; bottom: 100px; right: 5%; background: rgba(28,28,30,0.8); backdrop-filter: blur(10px); color: var(--text-primary); border: 1px solid var(--border-light); width: 44px; height: 44px; border-radius: 50%; display: flex; justify-content: center; align-items: center; cursor: pointer; z-index: 20; transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); box-shadow: 0 4px 15px rgba(0,0,0,0.5); }
.scroll-bottom-btn.hidden { transform: scale(0.5); opacity: 0; pointer-events: none; }

.msg-wrapper { display: flex; gap: 12px; max-width: 800px; margin: 0 auto; width: 100%; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.msg-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border-light); }
body.owner-mode .msg-avatar { background: var(--accent); color: #000; border: none; }
.msg-avatar .material-symbols-rounded { font-size: 18px; }
.user .msg-avatar { display: none; }
.user { flex-direction: row-reverse; }

.msg-content-box { max-width: 85%; display: flex; flex-direction: column; }
.user .msg-content-box { align-items: flex-end; }
.msg-content { line-height: 1.5; font-size: 16px; overflow-wrap: break-word; font-weight: 400; }
.bot .msg-content { padding: 4px 0; color: var(--text-primary); }
.user .msg-content { background: var(--bg-bubble-user); padding: 12px 16px; border-radius: 20px; border-top-right-radius: 4px; color: #fff; }
body.owner-mode .user .msg-content { color: #000; font-weight: 500; }

.attached-img { max-width: 100%; max-height: 250px; border-radius: 12px; margin-bottom: 8px; border: 1px solid var(--border-light); object-fit: contain; }
.bot-actions { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.bot-action-btn { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; padding: 6px; border-radius: 8px; transition: 0.2s; }
.bot-action-btn .material-symbols-rounded { font-size: 18px; }
.bot-action-btn:active { background: var(--bg-surface); color: var(--text-primary); }

.typing-indicator { display: flex; align-items: center; gap: 5px; padding: 8px 0; width: max-content; }
.typing-indicator span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-secondary); animation: bounce 1s infinite ease-in-out both; }
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
body.owner-mode .typing-indicator span { background: var(--accent); }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1.2); opacity: 1; } }

pre { background: var(--bg-surface); padding: 14px; border-radius: 12px; border: 1px solid var(--border-light); overflow-x: auto; margin: 10px 0; font-size: 14px; }
code { background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 6px; font-family: monospace; font-size: 14px; }
body.owner-mode code { color: var(--accent); }

/* PERFECT INPUT AREA (The Ultimate Fix) */
.input-area-wrapper { flex: 0 0 auto; padding: 12px 10% 24px; background: var(--bg-base); z-index: 10; border-top: 1px solid var(--border-light); }
.input-container { background: var(--bg-surface); border-radius: 24px; padding: 8px; border: 1px solid var(--border-light); transition: 0.3s; display: flex; flex-direction: column; width: 100%; max-width: 800px; margin: 0 auto; }
.input-container:focus-within { border-color: var(--text-secondary); }
body.owner-mode .input-container:focus-within { border-color: var(--accent); }

.image-preview-container { display: none; margin: 0 8px 8px; position: relative; width: max-content; align-self: flex-start; }
#image-preview { max-height: 80px; border-radius: 10px; border: 1px solid var(--border-light); }
#remove-image-btn { position: absolute; top: -10px; right: -10px; background: var(--danger); color: white; border: none; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

.input-controls { display: flex; align-items: flex-end; gap: 4px; }
.action-btn { width: 40px; height: 40px; margin: 0; flex-shrink: 0; }

/* THE MATHEMATICAL FIX FOR INPUT BOX */
#chat-input { 
    flex: 1; 
    background: transparent; 
    border: none; 
    color: var(--text-primary); 
    font-size: 16px; /* Exactly 16px to prevent iOS zoom */
    outline: none; 
    padding: 10px 8px; 
    resize: none; 
    max-height: 120px; 
    min-height: 40px; /* Perfect match for 40px buttons */
    height: 40px;
    line-height: 20px; /* 10+20+10 = 40 exact */
    margin: 0;
    overflow-y: hidden;
}
#chat-input::placeholder { color: var(--text-secondary); }

.send-btn { background: var(--text-primary); color: var(--bg-base); border: none; border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.2s; flex-shrink: 0; margin: 0; }
.send-btn:active:not(:disabled) { transform: scale(0.9); }
.send-btn:disabled { background: transparent; color: var(--text-secondary); cursor: default; }
body.owner-mode .send-btn:not(:disabled) { background: var(--accent); color: #000; }

.disclaimer { text-align: center; font-size: 12px; color: var(--text-secondary); margin-top: 12px; font-weight: 500; opacity: 0.5; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 90; opacity: 0; transition: 0.3s ease; backdrop-filter: blur(3px); }
.sidebar-backdrop.show { display: block; opacity: 1; }

@media (max-width: 768px) {
    .sidebar { position: fixed; left: -280px; height: 100dvh; width: 280px; box-shadow: none; }
    .sidebar.open { transform: translateX(280px); box-shadow: 10px 0 40px rgba(0,0,0,0.8); }
    #menu-toggle { display: flex; }
    .chat-scroll-area { padding: 20px 15px; }
    .input-area-wrapper { padding: 12px 12px 16px; } /* Perfect mobile padding */
    .msg-wrapper { gap: 10px; }
    .scroll-bottom-btn { right: 15px; bottom: 90px; }
}
