:root {
  --bg: #17171a;
  --sidebar: #111114;
  --surface: #212126;
  --surface-hover: #2a2a31;
  --border: #30313a;
  --text: #ececf1;
  --muted: #9a9ba8;
  --accent: #6366f1;
  --accent-h: #4f46e5;
  --green: #10a37f;
  --danger: #ef4444;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; font-size: 14px; line-height: 1.55; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12.5px; margin: 0; }

/* AUTH */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(circle at top, #1f2233, #111114 60%); }
.auth-card { width: 100%; max-width: 390px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 30px; box-shadow: 0 24px 60px rgba(0,0,0,0.45); }
.auth-logo { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, #6366f1, #8b5cf6); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; margin-bottom: 14px; }
.auth-card h1 { margin: 0 0 6px; font-size: 21px; }
.stack { display: flex; flex-direction: column; gap: 13px; margin-top: 20px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 600; color: #cbd5e1; }
input[type="text"], input[type="password"] {
  background: #141418; color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; font-family: inherit; outline: none; width: 100%;
}
input:focus { border-color: var(--accent); }
.err { color: #fca5a5; font-size: 13px; background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.35); padding: 9px 11px; border-radius: 9px; }

/* BUTTONS */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid transparent; font-weight: 600; font-size: 13px; cursor: pointer; color: #fff; background: transparent; text-decoration: none; transition: 0.15s; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.full { width: 100%; }
.btn-primary { background: var(--accent); }
.btn-primary:hover { background: var(--accent-h); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #0d8a6a; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-hover); }
.btn-new-chat { background: var(--surface); border-color: var(--border); color: var(--text); justify-content: flex-start; }
.btn-new-chat:hover { background: var(--surface-hover); }
.icon-btn { background: transparent; border: 1px solid transparent; color: var(--muted); border-radius: 8px; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 15px; }
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* SHELL */
.chat-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 268px; background: var(--sidebar); border-right: 1px solid #22232a; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-top { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #6366f1, #8b5cf6); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px; }
.brand-name { font-weight: 700; font-size: 14.5px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.sidebar-label { padding: 4px 16px 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; color: #6e7080; }
.history-list { flex: 1; overflow-y: auto; padding: 0 10px 10px; display: flex; flex-direction: column; gap: 4px; }
.history-item { padding: 9px 11px; border-radius: 9px; cursor: pointer; border: 1px solid transparent; position: relative; }
.history-item:hover { background: #1a1a20; }
.history-item.active { background: #22232c; border-color: #323442; }
.history-item-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.history-item-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.history-del-btn { background: transparent; border: 0; color: #6e7080; cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 5px; opacity: 0.7; flex-shrink: 0; }
.history-del-btn:hover { background: rgba(239,68,68,0.18); color: #fca5a5; opacity: 1; }
.mini-clear-btn { background: none; border: 0; color: #7c7f94; font-size: 11px; cursor: pointer; padding: 0; }
.mini-clear-btn:hover { color: #fca5a5; text-decoration: underline; }
.history-item-sub { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; justify-content: space-between; }
.sidebar-bottom { padding: 12px; border-top: 1px solid #22232a; }
.user-bar { display: flex; align-items: center; gap: 9px; padding: 8px; border-radius: 10px; background: #18181d; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: #2f3349; color: #c7d2fe; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { font-size: 11px; color: var(--muted); }

/* MAIN */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; background: var(--bg); }
.chat-header { min-height: 54px; padding: 8px 20px; border-bottom: 1px solid #23242b; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.header-left { display: flex; align-items: center; gap: 10px; }
.header-title { font-weight: 700; font-size: 14.5px; color: #e2e4ec; }
.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.top-select, .top-input {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 10px; font-size: 12.5px; outline: none;
}
.top-input { width: 195px; }
.mobile-only { display: none; }
@media (max-width: 820px) {
  .sidebar { position: fixed; left: -275px; top: 0; bottom: 0; z-index: 40; transition: left 0.2s; }
  .sidebar.open { left: 0; }
  .mobile-only { display: inline-flex; }
}

.chat-scroll { flex: 1; overflow-y: auto; padding: 24px 20px; scroll-behavior: smooth; }
.welcome-hero { max-width: 720px; margin: 6vh auto 0; text-align: center; padding: 20px; }
.welcome-orb { width: 56px; height: 56px; border-radius: 16px; background: linear-gradient(135deg, #6366f1, #8b5cf6); display: inline-flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 800; margin-bottom: 18px; box-shadow: 0 12px 32px rgba(99,102,241,0.35); }
.welcome-hero h1 { margin: 0 0 10px; font-size: 28px; font-weight: 700; }
.welcome-hint { margin: 0 auto 24px; max-width: 600px; color: var(--muted); font-size: 14.5px; line-height: 1.6; }
.welcome-hint strong { color: #d8dce8; }
.starter-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.starter-chip { background: var(--surface); border: 1px solid var(--border); color: #d5d7e3; padding: 8px 13px; border-radius: 999px; font-size: 12.5px; cursor: pointer; }
.starter-chip:hover { background: var(--surface-hover); border-color: #4a4c5c; }

/* MESSAGES */
.chat-messages { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; padding-bottom: 16px; }
.msg-row { display: flex; gap: 12px; align-items: flex-start; }
.msg-row.user { justify-content: flex-end; }
.msg-avatar { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, #6366f1, #8b5cf6); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; flex-shrink: 0; margin-top: 2px; }
.msg-user-card { max-width: 82%; background: #262730; border: 1px solid #353744; border-radius: 18px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.msg-files-part { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 8px; border-bottom: 1px solid #353744; }
.msg-file-chip { display: inline-flex; align-items: center; gap: 6px; background: #191a21; border: 1px solid #333544; border-radius: 10px; padding: 5px 9px; font-size: 12px; color: #d5d7e3; max-width: 220px; }
.msg-file-chip img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.msg-file-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-text-part { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.msg-meta-row { font-size: 11px; color: var(--muted); display: flex; gap: 8px; justify-content: flex-end; }

.msg-assistant-body { flex: 1; min-width: 0; }
.msg-assistant-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12.5px; color: var(--muted); }
.msg-assistant-head strong { color: var(--text); }
.msg-bubble { background: #1d1e25; border: 1px solid #2e303c; border-radius: 16px; padding: 14px 16px; }
.msg-summary { font-size: 14px; color: #f1f3f9; margin-bottom: 12px; }

/* VIDEO RAW CARDS GRID */
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-top: 10px; }
.video-card { background: #14151b; border: 1px solid #2c2e3a; border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.video-preview { width: 100%; height: 220px; background: #0c0d12; object-fit: contain; display: block; }
.video-card-body { padding: 10px 11px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.video-card-title { font-weight: 700; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.video-card-vo { font-size: 11.5px; color: var(--muted); line-height: 1.4; flex: 1; }
.video-dl-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid #2c2e3a; flex-wrap: wrap; }

.msg-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.act-btn { background: transparent; border: 1px solid #2e303c; color: var(--muted); border-radius: 8px; padding: 5px 10px; font-size: 12px; cursor: pointer; }
.act-btn:hover { background: var(--surface-hover); color: var(--text); }
.act-btn.active-up { border-color: var(--green); color: #6ee7b7; background: rgba(16,185,129,0.14); }
.act-btn.active-down { border-color: var(--danger); color: #fca5a5; background: rgba(239,68,68,0.14); }

.typing-box { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13.5px; padding: 12px 16px; background: #1d1e25; border: 1px solid #2e303c; border-radius: 14px; }
.dot-pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: 0.3; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1.2); } }

/* COMPOSER */
.composer-dock { padding: 8px 20px 14px; flex-shrink: 0; background: linear-gradient(to top, var(--bg) 78%, transparent); }
.composer-wrap { max-width: 860px; margin: 0 auto; }
.composer-box { background: #212126; border: 1px solid #353640; border-radius: 22px; padding: 12px 14px 10px; box-shadow: 0 12px 36px rgba(0,0,0,0.35); }
.composer-box:focus-within { border-color: #555870; }
.attachment-strip { display: flex; flex-wrap: wrap; gap: 10px; padding-bottom: 10px; margin-bottom: 8px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.att-card { position: relative; width: 88px; height: 88px; border-radius: 12px; overflow: hidden; background: #15161c; border: 1px solid #333544; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.att-card img { width: 100%; height: 100%; object-fit: cover; }
.att-card-label { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.72); font-size: 10px; padding: 2px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-remove { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(0,0,0,0.78); color: #fff; cursor: pointer; font-size: 11px; line-height: 20px; }

.prompt-input { width: 100%; background: transparent; border: 0; outline: none; color: var(--text); font-family: inherit; font-size: 14.5px; resize: none; max-height: 160px; padding: 4px 2px; }
.composer-toolbar { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; gap: 10px; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; }
.plus-btn { width: 34px; height: 34px; border-radius: 50%; border: 1px solid #3a3c4a; background: #2a2b34; color: #fff; font-size: 20px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.plus-btn:hover { background: #383a47; }
.attach-summary { font-size: 12px; color: var(--muted); }
.mini-select { background: #191a21; color: #d5d7e3; border: 1px solid #333544; border-radius: 9px; padding: 6px 8px; font-size: 12px; outline: none; }
.send-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 17px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.send-btn:hover { background: var(--accent-h); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.quota-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; padding: 0 6px; font-size: 11.5px; color: var(--muted); gap: 10px; flex-wrap: wrap; }
.quota-left { display: flex; align-items: center; gap: 8px; }
.quota-bar { width: 100px; height: 5px; border-radius: 99px; background: #262730; overflow: hidden; }
.quota-fill { height: 100%; background: var(--accent); transition: width 0.2s; }

.drag-overlay { position: absolute; inset: 0; background: rgba(17,17,20,0.84); display: flex; align-items: center; justify-content: center; z-index: 30; backdrop-filter: blur(4px); }
.drag-overlay-card { background: var(--surface); border: 2px dashed var(--accent); border-radius: 20px; padding: 34px 42px; text-align: center; }

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 999; }
.toast { background: #242632; border: 1px solid var(--accent); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13px; box-shadow: 0 8px 28px rgba(0,0,0,0.45); }
