:root {
  --blue: #3d6bf5;
  --ink: #1d2433;
  --muted: #55607a;
  --line: #e3e6ee;
  --field: #d5d9e4;
  --bg: #f6f7fb;
  --hint-bg: #fff4d6;
  --hint-ink: #8a6100;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; line-height: 1.5; background: var(--bg); color: var(--ink); }
main { max-width: 28rem; margin: 0 auto; padding: 1rem; }
.card { display: grid; gap: 0.75rem; }
label { display: grid; gap: 0.25rem; }
input, button, textarea { font: inherit; padding: 0.6rem; }
.error { color: #b00020; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

button.primary, a.primary.button {
  background: var(--blue); color: #fff; border: 0; border-radius: 999px;
  padding: 0.7rem 1.4rem; font-weight: 600; text-decoration: none; text-align: center; cursor: pointer;
}
button.wide { width: 100%; }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; }

.notice { margin-top: 15vh; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 1.25rem; text-align: center; }
.notice h1 { margin: 0; }

/* ---- header (chat and list) --------------------------------------------- */
.chat-top {
  background: var(--blue); color: #fff; padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.chat-top .brand { font-size: 16px; }
.top-link { color: #fff; opacity: .9; font-size: 13px; text-decoration: none; white-space: nowrap; }

/* ---- chat page ------------------------------------------------------------ */
.chat-body { height: 100vh; height: 100dvh; overflow: hidden; }
.chat { display: flex; flex-direction: column; height: 100%; max-width: 40rem; margin: 0 auto; background: var(--bg); }
.stale-note { margin: 0; padding: 6px 14px; font-size: 13px; background: var(--hint-bg); color: var(--hint-ink); }
.log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }

.msg { border-radius: 16px; padding: 8px 12px; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--blue); color: #fff; border-radius: 16px 16px 4px 16px; max-width: 78%; }
.msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; max-width: 85%; min-width: 3rem; }
.msg.me .text { white-space: pre-wrap; }
.msg.me .photo { display: block; max-width: 100%; max-height: 220px; border-radius: 10px; margin-bottom: 6px; background: #dfe4f0; }
.msg .note { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .5em; }
.md ul, .md ol { margin: 0 0 .5em; padding-left: 1.3em; }
.md pre { background: #f1f3f8; border-radius: 8px; padding: 8px; overflow-x: auto; font-size: 13px; }
.md code { font-size: .92em; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 3px 6px; }
.md img { max-width: 100%; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.md .katex { font-size: 1.1em; }

/* "**Gợi ý N:**" from the model, styled as the mockup's yellow chip */
.md strong.hint {
  display: inline-block; font-size: 11px; font-weight: 600; line-height: 1.6;
  background: var(--hint-bg); color: var(--hint-ink); border-radius: 8px; padding: 0 7px; margin: 0 4px 4px 0;
}

.dgm { margin: 6px 0; overflow-x: auto; }
.dgm svg { max-width: 100%; height: auto; }
.dgm-pending, .dgm-note { color: var(--muted); font-size: 13px; }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #b8c0d4; animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* ---- composer --------------------------------------------------------------- */
.composer { border-top: 1px solid var(--line); background: #fff; padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.status { margin: 0 0 6px; font-size: 13px; color: #b42318; }
.previews { display: flex; gap: 6px; flex-wrap: wrap; }
.previews:not(:empty) { margin-bottom: 8px; }
.preview { position: relative; }
.preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; display: block; }
.preview .remove {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border: 0;
  border-radius: 50%; background: var(--ink); color: #fff; font-size: 14px; line-height: 22px; cursor: pointer;
}
.cam {
  flex: none; width: 48px; height: 48px; border-radius: 50%; background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 22px; cursor: pointer;
}
.cam:active { transform: scale(.95); }
.composer textarea {
  flex: 1; min-width: 0; resize: none; border: 1px solid var(--field); border-radius: 20px;
  padding: 11px 14px; font-size: 16px; line-height: 1.4; max-height: 140px; background: #fff; color: var(--ink);
}
.send {
  flex: none; width: 44px; height: 48px; padding: 0; border: 0; background: none;
  color: var(--blue); font-size: 24px; font-weight: bold; cursor: pointer;
}
.send:disabled { color: #b8c0d4; cursor: default; }

/* ---- conversation list -------------------------------------------------------- */
.convs { display: grid; gap: 12px; }
.conv-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.conv-list a {
  display: grid; gap: 2px; padding: 10px 12px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; color: inherit; text-decoration: none;
}
.conv-list .when { font-size: 12px; color: var(--muted); }
.conv-list .preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-list .empty { color: var(--muted); text-align: center; padding: 1rem; }
.chip { display: inline-block; font-size: 11px; border-radius: 10px; padding: 0 8px; background: #e3ecff; color: #2346b0; }
.logout { text-align: center; }

/* ---- parent pages ------------------------------------------------------------- */
.parent-body { background: var(--bg); }
.dash-top {
  background: var(--ink); color: #fff; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center;
}
.dash-top a { color: #fff; opacity: .7; text-decoration: none; padding: 4px 0; }
.dash-top a.active { opacity: 1; font-weight: 600; box-shadow: inset 0 -2px 0 #fff; }
.dash-brand { margin-right: 6px; }
.dash-logout { margin-left: auto; }
.dash-logout button { color: #fff; opacity: .7; padding: 4px 0; }
.dash-body { max-width: 56rem; display: flex; flex-direction: column; gap: 14px; padding: 16px; font-size: 14px; }
.card2 { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.card2 h4 { margin: 0 0 8px 0; font-size: 14px; }
.card2.urgent { border-color: #f1a3a3; background: #fff3f3; }
.card2.askp { border-color: #f3d18a; background: #fffaf0; }
.card2 .item + .item { margin-top: 6px; }
.card2 p { margin: 0; }
.card2 .more { margin-top: 8px; }
.muted { color: var(--muted); }
.about-note { font-size: 13px; text-align: center; margin: 16px 0 4px; }
.back { margin: 0; }
.dash-body a { color: var(--blue); }
.dash-body .primary { color: #fff; }

.chip.t-toan { background: #e3ecff; color: #2346b0; }
.chip.t-tin { background: #e2f7ec; color: #18794a; }
.chip.t-van { background: #fde8f1; color: #a3245c; }
.chip.t-anh { background: #f0e9ff; color: #5b34b5; }
.chip.t-khoa { background: #fff1de; color: #a15a00; }
.chip.t-su { background: #e8f3f6; color: #1c6577; }
.chip.t-khac { background: #eef1f8; color: var(--muted); }
.card2 .chip { margin-right: 6px; }

.bars { display: grid; grid-template-columns: auto 1fr 2.5rem; gap: 6px; align-items: center; font-size: 13px; margin-bottom: 10px; }
.bar { height: 8px; border-radius: 4px; background: var(--blue); display: inline-block; vertical-align: middle; }
.bar.t-toan { background: #3d6bf5; }
.bar.t-tin { background: #18794a; }
.bar.t-van { background: #a3245c; }
.bar.t-anh { background: #5b34b5; }
.bar.t-khoa { background: #d9822b; }
.bar.t-su { background: #2a8ba3; }
.bar.t-khac { background: #8a93a8; }
.clamp { max-height: 12em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
[data-md]:not([data-rendered]) { white-space: pre-wrap; }

table.cv { width: 100%; border-collapse: collapse; font-size: 13px; }
table.cv td { padding: 6px 4px; border-top: 1px solid #eef0f5; vertical-align: top; }
.cv-when { white-space: nowrap; color: var(--muted); }
.cv-outcome { white-space: nowrap; text-align: right; }
.cv-what a { color: inherit; text-decoration: none; }
.cv-what .who { color: var(--muted); }
.ok { color: #18794a; }
.mid { color: #8a6100; }
.bad { color: #b42318; }
.none { color: var(--muted); }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 8px; margin-bottom: 12px; align-items: end; }
.filters select, .filters input { width: 100%; padding: 0.45rem; font-size: 14px; }
.filter-actions { display: flex; gap: 12px; align-items: center; }
.filter-actions .primary { padding: 0.45rem 1.2rem; }

.transcript { display: flex; flex-direction: column; gap: 10px; }
.transcript .msg.me { max-width: 85%; }
.transcript .msg.bot { max-width: 92%; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 8px; padding: 0 7px; margin-top: 6px; }
.badge-flag { background: var(--hint-bg); color: var(--hint-ink); }
.badge-alert { background: #ffe1e1; color: #b42318; }
.msg.me .badge { background: #fff; }

@media (max-width: 600px) {
  .dash-body { padding: 12px; }
  table.cv, table.cv tbody, table.cv tr, table.cv td { display: block; }
  table.cv tr { padding: 8px 0; border-top: 1px solid #eef0f5; }
  table.cv td { border: 0; padding: 1px 0; }
  .cv-outcome { text-align: left; }
}

/* ---- admin pages ---------------------------------------------------------------- */
.flash-ok, .flash-warn { margin: 0; padding: 10px 14px; border-radius: 10px; }
.flash-ok { background: #e2f7ec; color: #18794a; }
.flash-warn { background: #fffaf0; color: #8a6100; border: 1px solid #f3d18a; }
.error-box { background: #fff3f3; border: 1px solid #f1a3a3; border-radius: 10px; padding: 10px 14px; }
.acct + .acct { border-top: 1px solid #eef0f5; margin-top: 10px; padding-top: 10px; }
.acct.is-off .acct-head b { text-decoration: line-through; }
.acct-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin-bottom: 6px; }
.acct-forms { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: end; }
.inline-form { display: flex; gap: 8px; align-items: end; }
.inline-form input, .grid-form input, .grid-form select { width: 100%; padding: 0.45rem; font-size: 14px; }
.inline-form .primary, .grid-form .primary { padding: 0.45rem 1.2rem; }
button.plain { background: #fff; border: 1px solid var(--field); border-radius: 8px; padding: 0.4rem 0.9rem; cursor: pointer; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 10px; align-items: end; }
.cost-now { font-size: 22px; }
