:root {
  --bg: #ffffff;
  --surface: #f7f7f7;
  --border: #e0e0e0;
  --text: #111111;
  --text-sub: #666666;
  --primary: #111111;
  --radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body { font-family: 'Helvetica Neue', Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* AUTH */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; border: 1px solid var(--border); border-radius: 12px; padding: 40px 36px; }
.auth-card h1 { font-size: 1.8rem; font-weight: 300; margin-bottom: 6px; }
.auth-card p.sub { color: var(--text-sub); font-size: 0.9rem; margin-bottom: 28px; }
.auth-tabs { display: flex; gap: 0; margin-bottom: 24px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.auth-tab { flex: 1; padding: 10px; background: none; border: none; font-size: 0.9rem; font-weight: 500; color: var(--text-sub); transition: .2s; }
.auth-tab.active { background: var(--text); color: #fff; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.82rem; font-weight: 500; margin-bottom: 6px; color: var(--text-sub); }
.field input { width: 100%; padding: 11px 14px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; outline: none; transition: border-color .2s; }
.field input:focus { border-color: var(--text); }
.btn-primary { width: 100%; padding: 13px; background: var(--text); color: #fff; border: none; border-radius: 6px; font-size: 15px; font-weight: 600; transition: opacity .2s; margin-bottom: 12px; }
.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-google { width: 100%; padding: 12px; background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-weight: 500; display: flex; align-items: center; justify-content: center; gap: 10px; transition: background .2s; }
.btn-google:hover { background: var(--surface); }
.divider { text-align: center; color: var(--text-sub); font-size: 0.8rem; margin: 14px 0; position: relative; }
.divider::before, .divider::after { content: ''; position: absolute; top: 50%; width: 42%; height: 1px; background: var(--border); }
.divider::before { left: 0; } .divider::after { right: 0; }
.err-msg { color: #e53e3e; font-size: 0.82rem; margin-top: -8px; margin-bottom: 12px; }

/* CHAT LAYOUT */
.chat-layout { display: flex; height: 100vh; overflow: hidden; }

/* SIDEBAR */
.sidebar { width: 260px; min-width: 260px; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--surface); }
.sidebar-header { padding: 18px 16px 12px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 1.1rem; font-weight: 600; }
.sidebar-header .user-info { font-size: 0.78rem; color: var(--text-sub); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.new-chat-btn { margin: 12px; padding: 10px; background: var(--text); color: #fff; border: none; border-radius: 6px; font-size: 0.88rem; font-weight: 600; width: calc(100% - 24px); }
.new-chat-btn:hover { opacity: 0.85; }
.sessions-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.session-item { padding: 10px 12px; border-radius: 6px; cursor: pointer; font-size: 0.85rem; color: var(--text); transition: background .15s; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.session-item:hover { background: var(--border); }
.session-item.active { background: var(--text); color: #fff; }
.session-item .s-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .s-del { opacity: 0; font-size: 0.75rem; padding: 2px 5px; border-radius: 4px; border: none; background: transparent; color: inherit; }
.session-item:hover .s-del { opacity: 0.6; }
.session-item.active .s-del { opacity: 0.7; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.logout-btn { width: 100%; padding: 9px; background: none; border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; color: var(--text-sub); }
.logout-btn:hover { background: var(--border); }

/* CHAT MAIN */
.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-topbar { padding: 14px 20px; border-bottom: 1px solid var(--border); font-size: 0.9rem; font-weight: 500; color: var(--text-sub); }
.messages-area { flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 18px; }
.msg-row { display: flex; gap: 10px; align-items: flex-start; }
.msg-row.user { flex-direction: row-reverse; }
.msg-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--border); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; flex-shrink: 0; }
.msg-row.user .msg-avatar { background: var(--text); color: #fff; }
.msg-bubble { max-width: 70%; padding: 12px 16px; border-radius: 12px; font-size: 0.9rem; line-height: 1.6; position: relative; }
.msg-row.ai .msg-bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 4px 12px 12px 12px; }
.msg-row.user .msg-bubble { background: var(--text); color: #fff; border-radius: 12px 4px 12px 12px; }
.msg-actions { display: none; gap: 6px; margin-top: 6px; }
.msg-row:hover .msg-actions { display: flex; }
.msg-actions button { font-size: 0.75rem; padding: 3px 8px; border-radius: 4px; border: 1px solid var(--border); background: var(--bg); color: var(--text-sub); }
.msg-actions button:hover { background: var(--border); }
.msg-time { font-size: 0.7rem; color: var(--text-sub); margin-top: 4px; }
.msg-row.user .msg-time { text-align: right; }
.chat-input-area { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-end; }
.chat-input-area textarea { flex: 1; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; resize: none; outline: none; max-height: 140px; line-height: 1.5; }
.chat-input-area textarea:focus { border-color: var(--text); }
.send-btn { padding: 12px 20px; background: var(--text); color: #fff; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; align-self: flex-end; }
.send-btn:hover { opacity: 0.85; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.model-select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.8rem; background: var(--bg); outline: none; margin-bottom: 0; }
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-sub); gap: 8px; }
.empty-state h3 { font-size: 1.4rem; font-weight: 300; color: var(--text); }
.typing-indicator { display: flex; gap: 4px; align-items: center; padding: 12px 16px; }
.typing-indicator span { width: 7px; height: 7px; background: var(--text-sub); border-radius: 50%; animation: bounce 1.2s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* ADMIN */
.admin-layout { display: flex; height: 100vh; overflow: hidden; }
.admin-sidebar { width: 220px; min-width: 220px; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; }
.admin-sidebar h2 { padding: 20px 16px 14px; font-size: 1rem; font-weight: 700; border-bottom: 1px solid var(--border); }
.admin-nav { padding: 10px 8px; flex: 1; }
.admin-nav-item { display: block; padding: 10px 12px; border-radius: 6px; font-size: 0.88rem; cursor: pointer; color: var(--text-sub); border: none; background: none; width: 100%; text-align: left; font-family: inherit; }
.admin-nav-item:hover { background: var(--border); color: var(--text); }
.admin-nav-item.active { background: var(--text); color: #fff; }
.admin-main { flex: 1; overflow-y: auto; padding: 30px; }
.admin-main h1 { font-size: 1.5rem; font-weight: 300; margin-bottom: 24px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.admin-table th { text-align: left; padding: 10px 14px; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-sub); font-size: 0.78rem; text-transform: uppercase; letter-spacing: .5px; }
.admin-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table tr:hover td { background: var(--surface); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.badge-green { background: #d4edda; color: #155724; }
.badge-red { background: #f8d7da; color: #721c24; }
.badge-blue { background: #d1ecf1; color: #0c5460; }
.admin-btn { padding: 5px 12px; border-radius: 4px; border: 1px solid var(--border); background: var(--bg); font-size: 0.78rem; cursor: pointer; font-family: inherit; }
.admin-btn:hover { background: var(--border); }
.admin-btn.danger { border-color: #e53e3e; color: #e53e3e; }
.admin-btn.danger:hover { background: #e53e3e; color: #fff; }
.admin-btn.warn { border-color: #d69e2e; color: #d69e2e; }
.admin-btn.warn:hover { background: #d69e2e; color: #fff; }
.search-bar { padding: 10px 14px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; outline: none; width: 280px; margin-bottom: 18px; }
.search-bar:focus { border-color: var(--text); }
.msg-preview { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-sub); font-size: 0.82rem; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 999; }
.modal { background: #fff; border-radius: 10px; padding: 28px; width: 90%; max-width: 560px; max-height: 80vh; overflow-y: auto; }
.modal h3 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; }
.modal-close { float: right; background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-sub); }
.msg-thread { display: flex; flex-direction: column; gap: 10px; }
.msg-thread-item { padding: 10px 14px; border-radius: 8px; font-size: 0.85rem; line-height: 1.5; }
.msg-thread-item.user { background: var(--text); color: #fff; align-self: flex-end; max-width: 80%; }
.msg-thread-item.ai { background: var(--surface); border: 1px solid var(--border); align-self: flex-start; max-width: 80%; }
.msg-thread-item .meta { font-size: 0.7rem; opacity: 0.6; margin-top: 4px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card { border: 1px solid var(--border); border-radius: 8px; padding: 18px; }
.stat-card .val { font-size: 2rem; font-weight: 300; }
.stat-card .lbl { font-size: 0.8rem; color: var(--text-sub); margin-top: 4px; }

@media (max-width: 640px) {
  .sidebar { width: 200px; min-width: 200px; }
  .msg-bubble { max-width: 85%; }
  .admin-sidebar { width: 180px; min-width: 180px; }
}
