:root {
  --bg: #f1eee8;
  --panel: #faf8f4;
  --side: #141414;
  --side-2: #262420;
  --side-text: #f1eee8;
  --side-muted: #9d978c;
  --text: #141414;
  --muted: #7a746a;
  --line: #e0dbd1;
  --accent: #141414;
  --accent-2: #33302b;
  --on-accent: #f1eee8;
  --lamp: #e2a54a;
  --user: #e6e1d6;
  --code-bg: #1b1a18;
  --code-text: #f1eee8;
  --shadow: 0 8px 30px rgba(20, 20, 20, .08);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212; --panel: #1c1b19; --side: #0a0a0a; --side-2: #1f1e1b;
    --text: #f1eee8; --muted: #a29c91; --line: #2f2d29; --user: #2a2824;
    --accent: #f1eee8; --accent-2: #ffffff; --on-accent: #141414;
    --code-bg: #0b0b0a; --shadow: 0 8px 30px rgba(0,0,0,.45);
  }
}
:root[data-theme="dark"] {
  --bg: #121212; --panel: #1c1b19; --side: #0a0a0a; --side-2: #1f1e1b;
  --text: #f1eee8; --muted: #a29c91; --line: #2f2d29; --user: #2a2824;
  --accent: #f1eee8; --accent-2: #ffffff; --on-accent: #141414;
  --code-bg: #0b0b0a; --shadow: 0 8px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Be Vietnam Pro", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6;
}
button { font: inherit; cursor: pointer; }
.app { display: flex; height: 100dvh; }

/* Sidebar */
.sidebar {
  width: 280px; flex-shrink: 0; background: var(--side); color: var(--side-text);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 8px; }
.logo { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.brand-name, .welcome h1, dialog h2 { font-family: "League Spartan", "Be Vietnam Pro", sans-serif; letter-spacing: -.01em; }
.brand-name { font-size: 18px !important; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--side-muted); }
.btn-new {
  background: var(--lamp); color: #141414; border: 0; border-radius: 12px;
  padding: 11px 14px; font-weight: 600; transition: background .15s;
}
.btn-new:hover { filter: brightness(1.07); }
.history-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--side-muted); padding: 4px 6px 0; }
.history { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.history li {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px;
  cursor: pointer; font-size: 14px; color: var(--side-text);
}
.history li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history li:hover, .history li.active { background: var(--side-2); }
.history li button { background: none; border: 0; color: var(--side-muted); opacity: 0; padding: 0 2px; }
.history li:hover button, .history li.active button { opacity: 1; }
.pomodoro { background: var(--side-2); border-radius: 14px; padding: 12px 14px; }
.pomo-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--side-muted); }
.pomo-phase { color: var(--lamp); font-weight: 600; }
.pomo-time { font-size: 34px; font-weight: 700; text-align: center; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.pomo-btns { display: flex; gap: 8px; }
.pomo-btns button { flex: 1; border: 0; border-radius: 10px; padding: 7px; background: var(--lamp); color: #141414; font-weight: 600; }
.pomo-btns .ghost { background: transparent; border: 1px solid var(--side-muted); color: var(--side-text); }
.side-note { font-size: 11.5px; color: var(--side-muted); margin: 0; padding: 0 4px; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 20px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.icon-btn {
  background: none; border: 0; font-size: 20px; width: 40px; height: 40px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text); flex-shrink: 0;
}
.icon-btn:hover { background: var(--line); }
.menu { display: none; }
.modes { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.modes::-webkit-scrollbar { display: none; }
.mode {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 7px 14px; white-space: nowrap; font-size: 14px; transition: all .15s;
}
.mode:hover { border-color: var(--accent); }
.mode.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }

.chat { flex: 1; overflow-y: auto; padding: 24px 20px; }
.welcome { max-width: 760px; margin: 6vh auto 0; text-align: center; }
.welcome-cup { font-size: 56px; }
.welcome-logo { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; box-shadow: var(--shadow); border: 1px solid var(--line); }
.welcome-cup.small { font-size: 40px; }
.welcome h1 { font-size: 30px; font-weight: 700; margin: 14px 0 8px; }
.welcome p { color: var(--muted); margin: 0 auto 22px; max-width: 520px; }
.suggest { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; text-align: left; }
.suggest button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  color: var(--text); text-align: left; transition: all .15s;
}
.suggest button:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.suggest b { display: block; font-size: 14px; }
.suggest small { color: var(--muted); }

.messages { max-width: 800px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 12px; }
.msg .avatar {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent); flex-shrink: 0; font-size: 17px;
}
.msg.user { flex-direction: row-reverse; }
.msg.ai .avatar { background: #f1eee8; overflow: hidden; border: 1px solid var(--line); }
.msg.ai .avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg.user .avatar { background: var(--user); }
.bubble { min-width: 0; max-width: 100%; }
.msg.user .bubble {
  background: var(--user); padding: 10px 14px; border-radius: var(--radius) 4px var(--radius) var(--radius);
  max-width: 85%; white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .bubble img { max-width: 220px; border-radius: 10px; display: block; margin-bottom: 6px; }
.msg.ai .bubble { flex: 1; padding-top: 4px; overflow-wrap: anywhere; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble pre {
  background: var(--code-bg); color: var(--code-text); padding: 14px; border-radius: 12px;
  overflow-x: auto; font-size: 13.5px; position: relative;
}
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.bubble :not(pre) > code { background: var(--line); padding: 1px 6px; border-radius: 6px; }
.bubble table { border-collapse: collapse; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 10px; }
.bubble th { background: var(--panel); }
.bubble a { color: inherit; text-decoration-color: var(--lamp); text-underline-offset: 3px; }
.bubble blockquote { border-left: 3px solid var(--lamp); margin: 0; padding-left: 12px; color: var(--muted); }
.copy-code {
  position: absolute; top: 8px; right: 8px; font-size: 12px; border: 0; border-radius: 6px;
  background: rgba(255,255,255,.12); color: var(--code-text); padding: 3px 8px;
}
.msg-actions { margin-top: 6px; display: flex; gap: 6px; }
.msg-actions button {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 8px; padding: 2px 10px; font-size: 12.5px;
}
.msg-actions button:hover { color: var(--text); border-color: var(--accent); }
.typing span {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--lamp);
  margin-right: 4px; animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* Composer */
.composer { padding: 10px 20px 14px; max-width: 840px; width: 100%; margin: 0 auto; }
.input-row {
  display: flex; align-items: flex-end; gap: 6px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 6px; box-shadow: var(--shadow);
}
.input-row:focus-within { border-color: var(--lamp); }
textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font: inherit; padding: 9px 4px; max-height: 200px;
}
.send {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--accent); color: var(--on-accent); font-size: 16px; flex-shrink: 0;
}
.send:disabled { opacity: .4; cursor: default; }
.send.stop { background: var(--lamp); color: #141414; }
.attach-preview { position: relative; display: inline-block; margin-bottom: 8px; }
.attach-preview img { height: 70px; border-radius: 10px; border: 1px solid var(--line); }
.attach-preview button {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  border: 0; background: var(--side); color: #fff; font-size: 11px;
}
.disclaimer { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 6px; }

/* Dialog */
dialog {
  border: 0; border-radius: 20px; padding: 28px; background: var(--panel); color: var(--text);
  width: min(380px, calc(100% - 32px)); text-align: center; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(28, 22, 18, .6); backdrop-filter: blur(4px); }
dialog h2 { margin: 6px 0; }
dialog p { color: var(--muted); margin: 0 0 14px; }
dialog input {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; text-align: center; letter-spacing: .08em;
  margin-bottom: 8px;
}
dialog .btn-new { width: 100%; }
.err { color: #c0392b !important; min-height: 1.2em; font-size: 13px; }

/* Mobile */
@media (max-width: 820px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%);
    transition: transform .25s; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; display: none; }
  .scrim.show { display: block; }
  .menu { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .chat { padding: 18px 16px; }
  .composer { padding: 8px 16px 12px; }
  .suggest { grid-template-columns: 1fr; }
  .welcome h1 { font-size: 22px; }
  .msg .avatar { width: 28px; height: 28px; font-size: 14px; }
}

/* Tạo ảnh / tạo file */
.kinds { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.kinds-label { font-size: 13px; color: var(--muted); margin-right: 2px; }
.kind {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 4px 12px; font-size: 13px;
}
.kind.active { background: var(--lamp); border-color: var(--lamp); color: #141414; font-weight: 600; }
.working { color: var(--muted); }
.working small { font-size: 12.5px; }
.gen-image { max-width: min(100%, 520px); border-radius: 14px; display: block; box-shadow: var(--shadow); }
.file-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.download {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 12px;
  background: var(--lamp); color: #141414 !important; font-weight: 600; text-decoration: none !important;
}
.download:hover { filter: brightness(1.07); }
.attach-name {
  display: inline-block; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); font-size: 13px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
