/* ============================================================
   SISY — chat web
   Giao diện trò chuyện toàn màn hình (sisy.mimir.vn).
   Cùng bộ màu / font với mimir.vn.
   ============================================================ */

:root {
  --paper: #ffffff;
  --paper-2: #f2f3f6;
  --ink: #121317;
  --ink-2: #4b4f58;
  --ink-3: #676a72;

  --blue: #3186ff;
  --green: #00b95c;
  --violet: #7a5cff;

  --font: "Google Sans Flex", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Code", Consolas, ui-monospace, monospace;
  --line: rgba(18, 19, 23, .09);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  font-weight: 400;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { display: block; }

.grad {
  background: linear-gradient(90deg, var(--blue), var(--green));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 264px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "topbar topbar"
    "side   chat"
    "side   composer";
}

/* Trang mo dau: hang dem phia duoi day khung nhap len giua man hinh */
.app.is-welcome {
  grid-template-rows: auto 1fr auto 1fr;
  grid-template-areas:
    "topbar topbar"
    "side   chat"
    "side   composer"
    "side   spacer";
}
.center-spacer { display: none; }
.app.is-welcome .center-spacer { display: block; grid-area: spacer; }
/* Loi chao tut xuong sat khung nhap thay vi bam dinh vung chat */
.app.is-welcome .chat { display: flex; flex-direction: column; justify-content: flex-end; }

/* ============================================================
   SIDEBAR — danh sach hoi thoai gan day
   ============================================================ */
.sidebar {
  grid-area: side;
  display: flex; flex-direction: column; gap: 8px;
  min-height: 0; padding: 12px 10px;
  background: var(--paper-2);
  border-right: 1px solid var(--line);
}
.new-chat-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; height: 40px; padding: 0 12px;
  border-radius: 12px;
  font-size: 14px; font-weight: 500; color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(18, 19, 23, .04);
  transition: box-shadow .15s ease, transform .12s ease;
}
.new-chat-btn:hover { box-shadow: 0 6px 16px rgba(18, 19, 23, .09); }
.new-chat-btn:active { transform: scale(.97); }
.side-title {
  padding: 6px 10px 2px;
  font-size: 11px; font-weight: 500; letter-spacing: .07em;
  text-transform: uppercase; color: var(--ink-3);
}
.side-list {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.convo-row {
  position: relative;
  display: flex; align-items: center;
  border-radius: 10px;
  transition: background .15s ease;
}
.convo-row:hover { background: rgba(18, 19, 23, .06); }
.convo-row.is-active {
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(18, 19, 23, .05);
}
.convo-item {
  flex: 1; min-width: 0; text-align: left;
  padding: 9px 10px; border-radius: 10px;
  font-size: 13.5px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color .15s ease, padding .15s ease;
}
.convo-row.is-active .convo-item { color: var(--ink); font-weight: 500; }
/* Chua cho hai nut ben phai, de ten khong chui xuong duoi nut */
.convo-row:hover .convo-item,
.convo-row:focus-within .convo-item { color: var(--ink); padding-right: 60px; }

.convo-acts {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  display: none; gap: 2px;
}
.convo-row:hover .convo-acts,
.convo-row:focus-within .convo-acts { display: flex; }
.convo-act {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 7px;
  color: var(--ink-3);
  transition: background .15s ease, color .15s ease, transform .12s ease;
}
.convo-act:hover { background: rgba(18, 19, 23, .1); color: var(--ink); }
.convo-act.is-danger:hover { background: rgba(214, 60, 60, .12); color: #d63c3c; }
.convo-act:active { transform: scale(.86); }
.convo-act svg { width: 15px; height: 15px; }

.convo-rename {
  flex: 1; min-width: 0;
  margin: 3px 4px; padding: 6px 8px;
  font-family: var(--font); font-size: 13.5px; color: var(--ink);
  background: var(--paper);
  border: 1px solid rgba(49, 134, 255, .55);
  border-radius: 8px; outline: none;
}
.side-empty { padding: 8px 10px; font-size: 12.5px; color: var(--ink-3); }

/* Nut mo sidebar + lop phu — chi dung tren man hinh hep */
.topbar .side-toggle { display: none; width: 36px; padding: 0; justify-content: center; }
.side-backdrop { display: none; }

.topbar { grid-area: topbar; }
.chat { grid-area: chat; min-height: 0; }
.composer-wrap { grid-area: composer; }

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 10;
}

.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 500; font-size: 17px; letter-spacing: .01em;
  flex: 1; min-width: 0;
}
.brand img { width: 26px; height: 26px; border-radius: 7px; }
.brand-name { white-space: nowrap; }
/* Logo + nút Tài liệu nằm TRONG khung nhập (composer) */
.sisy-logo {
  width: 30px; height: 30px; flex: none;
  object-fit: contain;
}
.logo-menu { position: relative; flex: none; display: flex; align-items: center; }

/* Logo Sisy + nut dinh kem: nen trong suot, khong vien bao */
.sisy-logo-btn,
.attach-btn {
  background: transparent;
  border: 0;
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
}
.sisy-logo-btn:focus-visible,
.attach-btn:focus-visible {
  outline: 2px solid rgba(49, 134, 255, .55);
  outline-offset: 2px;
}

.sisy-logo-btn {
  display: inline-flex; padding: 0;
  border-radius: 9px; cursor: pointer;
  transition: transform .12s ease, opacity .15s ease;
}
.sisy-logo-btn:hover { opacity: .85; }
.sisy-logo-btn:active { transform: scale(.88); }
.sisy-logo-btn.is-pressed { animation: press-pop .3s ease; }

/* Bang thong tin model — hien khi di chuot len logo */
.logo-tip {
  position: absolute; bottom: calc(100% + 10px); left: 0;
  display: flex; flex-direction: column; gap: 3px;
  min-width: 224px; padding: 10px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 38px rgba(18, 19, 23, .16);
  opacity: 0; transform: translateY(6px); pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
  z-index: 40;
}
.sisy-logo-btn:focus-visible + .logo-tip { opacity: 1; transform: none; }
@media (hover: hover) {
  .logo-menu:hover .logo-tip { opacity: 1; transform: none; }
}
.tip-name { font-size: 14px; font-weight: 500; line-height: 1.3; }
.tip-desc { font-size: 11.5px; color: var(--ink-3); line-height: 1.45; }
.tip-hint {
  margin-top: 5px; padding-top: 6px;
  border-top: 1px solid var(--line);
  font-size: 11px; color: var(--blue);
}

.attach-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  color: var(--ink-2);
  flex: none;
  transition: color .18s ease, transform .12s ease;
}
.attach-btn:hover { color: var(--ink); }
.attach-btn:active { color: var(--ink); transform: scale(.85); }
.attach-btn.is-pressed { animation: press-pop .3s ease; }
.attach-btn svg { width: 20px; height: 20px; }

@keyframes press-pop {
  0%   { transform: scale(.85); }
  55%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.tb-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 13px; border-radius: 999px;
  font-size: 13.5px; font-weight: 450; color: var(--ink-2);
  border: 1px solid var(--line); background: var(--paper);
  transition: background .18s ease, color .18s ease;
}
.tb-btn:hover { background: var(--paper-2); color: var(--ink); }

/* ============================================================
   CHAT AREA
   ============================================================ */
.chat { overflow-y: auto; scroll-behavior: smooth; }
.messages {
  max-width: 780px; margin: 0 auto;
  padding: 30px 24px 40px;
  display: flex; flex-direction: column; gap: 22px;
}

/* ---- Welcome / empty state ---- */
.welcome {
  margin: 0 auto;
  text-align: center;
  max-width: 560px;
  display: flex; flex-direction: column; align-items: center;
}
/* Logo con cu — dong bo voi logo trong khung nhap */
.welcome-logo {
  width: 76px; height: 76px;
  object-fit: contain;
  margin-bottom: 20px;
}
.welcome h1 {
  font-size: clamp(26px, 4vw, 34px);
  font-weight: 450; letter-spacing: -0.015em;
}


/* ---- Messages ---- */
.msg { display: flex; gap: 12px; }
.msg.user { justify-content: flex-end; }


.bubble { max-width: min(82%, 640px); }

.bubble.ai .body {
  font-size: 15.5px; color: var(--ink);
}
.bubble.user .body {
  background: var(--ink); color: #fff;
  padding: 11px 16px; border-radius: 18px 18px 4px 18px;
  font-size: 15px; white-space: pre-wrap; word-break: break-word;
}
.attach { display: flex; flex-direction: column; gap: 8px; }
.attach-img img { max-width: 230px; max-height: 180px; border-radius: 10px; display: block; }
.attach-doc {
  display: inline-flex; align-items: center; gap: 10px; max-width: 260px;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 12px; padding: 9px 12px;
}
.doc-ext {
  font-size: 10.5px; font-weight: 600; letter-spacing: .04em;
  padding: 3px 8px; border-radius: 6px;
  background: rgba(255, 255, 255, .18); color: #fff; flex: none;
}
.doc-name { font-size: 13px; color: #fff; word-break: break-all; }

/* markdown content */
.body p { margin: 0 0 10px; }
.body p:last-child { margin-bottom: 0; }
.body h1, .body h2, .body h3 {
  font-size: 17px; font-weight: 550; margin: 16px 0 8px; letter-spacing: -0.01em;
}
.body ul, .body ol { margin: 0 0 10px; padding-left: 22px; }
.body li { margin: 4px 0; }
.body strong { font-weight: 600; }
.body code {
  font-family: var(--mono); font-size: .86em;
  background: var(--paper-2); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 6px;
}
.body pre {
  background: #0e0f13; color: #e8eaf0;
  border-radius: 12px; padding: 14px 16px; overflow-x: auto;
  margin: 0 0 10px;
}
.body pre code { background: none; border: 0; padding: 0; color: inherit; font-size: 13px; }

/* streaming caret */
.bubble.ai.streaming .body::after {
  content: ""; display: inline-block;
  width: 8px; height: 1.05em; margin-left: 3px;
  vertical-align: text-bottom;
  background: currentColor; border-radius: 2px;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* typing indicator */
.typing {
  display: inline-flex; gap: 5px; align-items: center;
  padding: 12px 16px; border-radius: 18px;
  background: var(--paper-2); border: 1px solid var(--line);
}
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-3);
  animation: tp 1.2s ease-in-out infinite;
}
.typing-label { font-size: 13px; color: var(--ink-3); margin-left: 5px; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes tp { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

/* sources */
.sources {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px;
}
.source {
  font-size: 12px; color: var(--ink-2);
  background: #eef2fb; border: 1px solid rgba(49, 134, 255, .18);
  padding: 5px 11px; border-radius: 8px;
}
.source b { color: var(--blue); font-weight: 600; }
/* Nguồn Internet — bậc tin cậy 4, chưa kiểm chứng: phải nhìn ra ngay */
.source.is-web {
  background: #fff6e8;
  border-color: rgba(190, 120, 20, .3);
  color: #8a5a12;
}
.source.is-web .src-web {
  color: #b0741a; font-weight: 600;
  text-transform: uppercase; font-size: 10px; letter-spacing: .05em;
}

/* actions */
.actions { display: flex; gap: 6px; margin-top: 8px; opacity: 0; transition: opacity .18s ease; }
.msg:hover .actions { opacity: 1; }
.act {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--ink-3);
  padding: 4px 9px; border-radius: 8px;
  border: 1px solid transparent;
  transition: background .15s ease, color .15s ease;
}
.act:hover { background: var(--paper-2); color: var(--ink); }

/* ============================================================
   COMPOSER
   ============================================================ */
.composer-wrap {
  padding: 12px 24px 14px;
  background: linear-gradient(to top, var(--paper) 70%, rgba(255,255,255,0));
}
.composer {
  max-width: 780px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  background: var(--paper);
  border: 1px solid rgba(18, 19, 23, .16);
  border-radius: 22px;
  padding: 10px 10px 10px 18px;
  box-shadow: 0 10px 34px rgba(18, 19, 23, .08);
}
.composer:focus-within { border-color: rgba(49, 134, 255, .5); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: none;
  font-family: var(--font); font-size: 15px; color: var(--ink);
  background: transparent;
  max-height: 140px; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--ink-3); }
/* Nut gui — nen trang, giu vien den, co hieu ung bam */
.composer #send {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--paper); color: var(--ink);
  border: 1.5px solid var(--ink);
  display: grid; place-items: center;
  transition: transform .12s ease, background .15s ease, opacity .15s ease;
}
.composer #send:hover { transform: translateY(-1px); background: var(--paper-2); }
.composer #send:active { transform: translateY(0) scale(.88); background: var(--paper-2); }
.composer #send.is-pressed { animation: press-pop .3s ease; }
.composer button:disabled { opacity: .35; cursor: default; transform: none; }
.composer-note {
  max-width: 780px; margin: 9px auto 0;
  text-align: center; font-size: 12px; color: var(--ink-3);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
/* Sidebar thanh ngan keo — man hinh hep */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "chat" "composer";
  }
  .app.is-welcome {
    grid-template-areas: "topbar" "chat" "composer" "spacer";
  }
  .sidebar {
    position: fixed; top: 56px; bottom: 0; left: 0; width: 272px;
    z-index: 60; transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(18, 19, 23, .18);
  }
  .app.side-open .sidebar { transform: none; }
  .side-backdrop {
    display: block; position: fixed; inset: 56px 0 0 0; z-index: 50;
    background: rgba(18, 19, 23, .35);
    opacity: 0; pointer-events: none;
    transition: opacity .22s ease;
  }
  .app.side-open .side-backdrop { opacity: 1; pointer-events: auto; }
  .topbar .side-toggle { display: inline-flex; }
}

@media (max-width: 720px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .tb-btn { width: 36px; padding: 0; justify-content: center; }
  .messages { padding: 22px 16px 32px; }
  .bubble { max-width: 88%; }
  .composer-wrap { padding: 10px 12px 12px; }
  .composer { gap: 8px; padding-left: 12px; }
  .sisy-logo { width: 26px; height: 26px; }
  .attach-btn { width: 34px; height: 34px; }
}
