:root {
  --accent: #5B3FD9;
  --heart: #7C3AED;
  --accent-ink: #FFFFFF;
  --bg: #F7F4FF;
  --surface: #FFFFFF;
  --line: #E3DEF3;
  --field: #CFC7E8;
  --muted: #5E5873;
  --text: #1F1B2E;
  --soft: #ECE7FF;
  --soft-ink: #3E2A9E;
  --ok-bg: #D9F2EC; --ok-ink: #135A48;
  --warn-bg: #FFF1CC; --warn-ink: #6B4A00;
  --danger: #B42318; --danger-bg: #FDE7E4;
  --radius: 12px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #8C75FF; --heart: #B79CFF; --accent-ink: #14102A;
    --bg: #14111F; --surface: #1C1830; --line: #2E2848; --field: #3F3862;
    --muted: #B3ABCB; --text: #F1EEFB; --soft: #2A2350; --soft-ink: #CFC5FF;
    --ok-bg: #14382F; --ok-ink: #8FE0C8; --warn-bg: #3A2F10; --warn-ink: #F3D27A;
    --danger: #FF8A80; --danger-bg: #3A1B18;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 12px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* ---- nút & form ---------------------------------------------------------- */
.btn { min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link-btn { background: none; border: 0; min-height: 32px; padding: 0 8px; color: var(--muted); font-size: 12px; font-weight: 500; }
.link-btn:hover { color: var(--accent); text-decoration: underline; }
.icon-btn { width: 44px; height: 44px; border: 0; background: transparent; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.icon-btn:hover { background: var(--soft); color: var(--text); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; }
.input, select.input, textarea.input { min-height: 48px; width: 100%; padding: 0 14px; border: 1px solid var(--field); border-radius: 12px; background: var(--surface); }
textarea.input { padding: 12px 14px; min-height: 96px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.error { color: var(--danger); background: var(--danger-bg); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.notice { background: var(--soft); color: var(--soft-ink); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.notice a { text-decoration: underline; font-weight: 600; word-break: break-all; }

/* ---- avatar / badge ------------------------------------------------------ */
.av { flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; overflow: hidden; border: 0; padding: 0; }
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.lg { width: 56px; height: 56px; font-size: 22px; }
.av.sq { border-radius: 12px; font-weight: 700; font-size: 13px; background: var(--soft); color: var(--soft-ink); width: 40px; height: 40px; }
.av.c0 { background: #ECE7FF; color: #3E2A9E; } .av.c1 { background: #FFE3DD; color: #8A2E1C; }
.av.c2 { background: #D9F2EC; color: #135A48; } .av.c3 { background: #FFF1CC; color: #6B4A00; }
.av.c4 { background: #DCEBFF; color: #1D3F8A; } .av.c5 { background: #FBE0F0; color: #8A1C5E; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 1px 6px; background: var(--soft); color: var(--soft-ink); }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #2BA37F; display: inline-block; }

/* ---- shell --------------------------------------------------------------- */
.app { display: flex; height: 100vh; height: 100dvh; }
.side { flex: 0 0 272px; background: var(--surface); border-right: 1px solid var(--line); padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.mob-title { display: none; font-size: 24px; font-weight: 700; padding: 24px 8px 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 12px; font-weight: 700; font-size: 18px; }
.brand .logo { width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.sec { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 12px 8px 4px; }
.nav-item { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 8px; border-radius: 8px; font-size: 14px; background: none; border: 0; width: 100%; text-align: left; }
.nav-item:hover { background: var(--soft); }
.nav-item[aria-current="page"] { background: var(--soft); font-weight: 600; }
.nav-item svg { flex: 0 0 16px; }
.nav-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.accent { color: var(--accent); font-weight: 600; }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); }
.page { flex: 1; overflow-y: auto; padding: 24px; background: var(--bg); }
.page-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.page h1 { font-size: 24px; font-weight: 700; }
.h2 { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.card.col { align-items: stretch; }
.list { display: flex; flex-direction: column; gap: 8px; }
.tabs-bar { display: none; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); }
.tabs-bar a { flex: 1; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; font-weight: 600; color: var(--muted); position: relative; }
.tabs-bar a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.tabs-bar .badge { position: absolute; top: 2px; left: calc(50% + 6px); }
.pillnav { display: flex; gap: 8px; flex-wrap: wrap; }
.pillnav button { min-height: 44px; padding: 0 16px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; font-weight: 600; }
.pillnav button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---- chat ---------------------------------------------------------------- */
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.chat-head h1 { font-size: 18px; font-weight: 700; }
.back { display: none; }
.chat-body { flex: 1; min-height: 0; display: flex; }
.chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.msgs { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 12px; max-width: 100%; }
.msg .body { min-width: 0; }
.msg .meta { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.msg .meta .who { font-weight: 600; font-size: 14px; background: none; border: 0; padding: 0; }
.msg .meta .who:hover { text-decoration: underline; }
.msg .text { font-size: 15px; line-height: 1.5; margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .text.gone { color: var(--muted); font-style: italic; }
.msg img.pic { display: block; max-width: min(320px, 100%); max-height: 320px; border-radius: 12px; margin-top: 6px; cursor: zoom-in; }
.quote { display: block; background: none; border-top: 0; border-right: 0; border-bottom: 0; text-align: left; cursor: pointer; font-family: inherit; font-size: 13px; color: var(--muted); border-left: 3px solid var(--line); padding: 2px 8px; margin: 4px 0; max-width: 480px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .actions { display: flex; gap: 4px; margin-top: 2px; opacity: 0; transition: opacity .1s; }
.msg:hover .actions, .msg:focus-within .actions { opacity: 1; }
@media (hover: none) { .msg .actions { opacity: 1; } }
.heart { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 8px; border: 0; background: transparent; border-radius: 16px; color: var(--muted); font-size: 12px; font-weight: 600; }
.heart:hover:not(:disabled) { background: var(--soft); color: var(--heart); }
.heart.on { color: var(--heart); }
.heart:disabled { cursor: default; }
.msg:not(:hover):not(:focus-within) .heart:not(.on) .hc:empty { display: none; }
.msg:not(:hover):not(:focus-within) .heart:not(.on):has(.hc:empty) { opacity: 0; }
@media (hover: none) { .msg .heart { opacity: 1 !important; } }
.msg.own { flex-direction: row-reverse; }
.msg.own .body { display: flex; flex-direction: column; align-items: flex-end; max-width: 75%; }
.msg.own .bubble { background: var(--accent); color: var(--accent-ink); border-radius: 14px 4px 14px 14px; padding: 8px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.own .quote { border-color: var(--line); }
.msg.own .meta { justify-content: flex-end; }
.day { text-align: center; font-size: 12px; color: var(--muted); }
.composer { padding: 12px 20px 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; position: relative; }
.composer form { display: flex; gap: 8px; align-items: center; }
.composer .input { min-height: 48px; }
.replybar { display: flex; align-items: center; gap: 8px; background: var(--soft); border-radius: 10px; padding: 6px 10px; font-size: 13px; }
.preview { position: relative; width: 84px; }
.preview img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; }
.preview button { position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); }
.emoji-panel { position: absolute; bottom: 74px; left: 20px; right: 20px; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; box-shadow: 0 8px 24px rgba(0,0,0,.14); z-index: 5; }
.emoji-panel button { border: 0; background: none; font-size: 22px; min-height: 40px; border-radius: 8px; }
.emoji-panel button:hover { background: var(--soft); }
.info { flex: 0 0 300px; border-left: 1px solid var(--line); padding: 24px 20px; display: flex; flex-direction: column; gap: 24px; overflow-y: auto; background: var(--surface); }
.gate { margin: auto; text-align: center; max-width: 380px; padding: 24px; display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* ---- modal / toast ------------------------------------------------------- */
.backdrop { position: fixed; inset: 0; background: rgba(20, 16, 42, .5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 18px; padding: 20px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal h2 { font-size: 18px; }
.modal .btns { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.toasts { position: fixed; top: 12px; right: 12px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 24px)); }
.toast { background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 14px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.lightbox img { max-width: 100%; max-height: 80vh; border-radius: 12px; }

/* ---- đăng nhập / đăng ký --------------------------------------------------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 20px; }
.auth h1 { font-size: 26px; line-height: 1.2; }
.geo-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

@media (max-width: 899px) {
  .app { flex-direction: column; }
  .side { display: none; flex: 1; border: 0; padding: 16px 12px; }
  .app.show-side .side { display: flex; }
  .app.show-side .main { display: none; }
  .tabs-bar { display: flex; }
  .app.in-chat .tabs-bar { display: none; }
  .back { display: inline-flex; }
  .page { padding: 16px; }
  .msgs { padding: 16px; }
  .chat-head { padding: 8px 12px; }
  .composer { padding: 10px 12px 12px; }
  .info.wide { display: none; }
  .brand { display: none; }
  .mob-title { display: block; }
  .side-foot { display: none; }
}
@media (max-width: 1099px) { .info.wide { display: none; } }
@media (min-width: 1100px) { .info-btn { display: none; } }

.msg.flash .body { animation: flash 1.6s ease; border-radius: 10px; }
@keyframes flash { 0%, 60% { background: var(--soft); box-shadow: 0 0 0 6px var(--soft); } 100% { background: transparent; box-shadow: 0 0 0 6px transparent; } }
@media (prefers-reduced-motion: reduce) { .msg.flash .body { animation: none; } }
