/* App Trợ lý — giao diện gần app Claude (nền kem, chữ đậm nhạt, ô chat dưới đáy, menu trái), tối giản cho iPhone.
   0 hiệu ứng (Ben ghét nhún nhảy): không transition / animation ở bất kỳ đâu. Sáng + tối theo máy. */
:root {
  --bg: #faf9f5; --bg2: #f0eee6; --card: #ffffff; --line: #e3dfd3; --ink: #1f1e1d; --ink2: #5e5d59; --ink3: #8a8780;
  --acc: #c96442; --acc-ink: #ffffff; --user: #f0eee6; --code: #f3f1ea; --err: #b3261e; --ok: #2e7d32;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, "New York", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624; --bg2: #30302e; --card: #30302e; --line: #45443f; --ink: #f5f4ef; --ink2: #c3c0b6; --ink3: #9a978d;
    --acc: #d97757; --acc-ink: #1f1e1d; --user: #3a3936; --code: #1f1e1d; --err: #f28b82; --ok: #81c995;
  }
}
*, *::before, *::after { box-sizing: border-box; transition: none !important; animation: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); -webkit-text-size-adjust: 100%; }
body { overflow: hidden; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.serif { font-family: var(--serif); font-weight: 500; }
.muted { color: var(--ink2); }
.small { font-size: 14px; }
.err { color: var(--err); min-height: 1.4em; margin: 8px 0 0; }
#app { height: 100%; }
.view { height: 100%; display: flex; flex-direction: column; }

/* Nút */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; min-height: 44px; padding: 8px 16px; font-weight: 500; }
.btn.primary { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
.btn.danger { color: var(--err); }
.btn.link { border: 0; background: none; color: var(--ink2); text-decoration: underline; min-height: 40px; }
.btn.sm { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 44px; height: 44px; border: 0; background: none; border-radius: 12px; display: grid; place-items: center; color: var(--ink); }
input[type=password], input[type=text], input[type=search], input[type=number], input:not([type]), textarea.field {
  width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); padding: 10px 14px; font-size: 16px; }
textarea.field { min-height: 120px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }

/* Đăng nhập */
.login { margin: auto; width: min(380px, 92vw); text-align: center; padding: 24px 0; }
.login-logo { border-radius: 18px; }
.login h1 { font-size: 34px; margin: 10px 0 2px; }
.prof-pick { display: grid; gap: 12px; margin: 22px 0; }
.prof { display: flex; align-items: center; gap: 14px; min-height: 64px; border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 10px 16px; font-size: 18px; text-align: left; }
.av { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--acc); color: var(--acc-ink); font-weight: 700; flex: none; }
#login-form { display: grid; gap: 12px; margin-top: 20px; }
.who { font-size: 18px; margin: 0; }

/* Thanh trên */
.top { display: flex; align-items: center; gap: 4px; padding: calc(var(--safe-t) + 6px) 8px 6px; border-bottom: 1px solid var(--line); background: var(--bg); flex: none; }
.top-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.money { font-size: 13px; color: var(--ink2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.money:empty { display: none; }
.money.low { color: var(--err); border-color: var(--err); }

.page { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page.scroll { overflow-y: auto; padding: 16px 16px calc(var(--safe-b) + 24px); display: block; -webkit-overflow-scrolling: touch; }
.page.scroll > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.pg-h { font-size: 26px; margin: 4px auto 8px; }

/* Trò chuyện */
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 16px 8px; -webkit-overflow-scrolling: touch; }
.welcome { text-align: center; margin: 12vh auto 0; max-width: 520px; padding: 0 8px; }
.welcome h2 { font-size: 30px; margin: 0 0 8px; }
.msgs { max-width: 760px; margin: 0 auto; }
.msg { margin: 0 0 18px; overflow-wrap: anywhere; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user); border-radius: 18px; padding: 10px 14px; max-width: 88%; white-space: pre-wrap; }
.msg.user .m-files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; max-width: 88%; }
.thumb { width: 84px; height: 84px; border-radius: 12px; object-fit: cover; background: var(--bg2); border: 1px solid var(--line); }
.pdf-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; background: var(--card); font-size: 14px; max-width: 220px; }
.pdf-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-chip.gone { color: var(--ink3); font-size: 13px; background: transparent; border-style: dashed; }
.msg.asst .md { font-size: 16.5px; }
.m-acts { display: flex; gap: 2px; align-items: center; margin-top: 4px; color: var(--ink3); flex-wrap: wrap; }
.m-acts button { border: 0; background: none; min-width: 40px; min-height: 40px; border-radius: 10px; color: var(--ink3); display: inline-flex; align-items: center; justify-content: center; gap: 4px; font-size: 13px; padding: 0 8px; }
.m-acts svg { width: 18px; height: 18px; }
.m-usd { font-size: 12px; color: var(--ink3); margin-left: 4px; }
.status { color: var(--ink2); font-size: 14px; display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--acc); flex: none; }
details.think { margin: 4px 0 8px; color: var(--ink2); font-size: 14px; border-left: 2px solid var(--line); padding-left: 10px; }
details.think summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; }
details.think > div { white-space: pre-wrap; max-height: 260px; overflow-y: auto; }
.sources { margin: 8px 0 0; font-size: 13px; color: var(--ink2); }
.sources a { color: var(--ink2); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 3px 0; }
.note { font-size: 13px; color: var(--ink3); margin-top: 4px; }
.msg .retry { margin-top: 8px; min-height: 44px; min-width: 96px; }
.mem-card { border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 10px 12px; margin-top: 8px; font-size: 14px; }
.mem-card .row { display: flex; gap: 8px; margin-top: 8px; }
.proj-banner { max-width: 760px; margin: 0 auto 12px; font-size: 13px; color: var(--ink2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; width: fit-content; }

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .75em; }
.md h3, .md h4, .md h5 { font-family: var(--serif); font-weight: 600; margin: 1.1em 0 .4em; line-height: 1.3; }
.md h3 { font-size: 1.25em; } .md h4 { font-size: 1.1em; } .md h5 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 .75em; padding-left: 1.4em; }
.md li { margin: .25em 0; }
.md li > ul, .md li > ol { margin: .25em 0; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--code); border-radius: 6px; padding: .1em .35em; }
.md pre { background: var(--code); border: 1px solid var(--line); border-radius: 12px; padding: 12px; overflow-x: auto; margin: 0 0 .8em; }
.md pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.5; white-space: pre; }
.md blockquote { margin: 0 0 .8em; padding: 2px 0 2px 12px; border-left: 3px solid var(--line); color: var(--ink2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md a { color: var(--acc); }
.md .tbl { overflow-x: auto; margin: 0 0 .9em; border: 1px solid var(--line); border-radius: 12px; -webkit-overflow-scrolling: touch; }
.md table { border-collapse: collapse; min-width: 100%; font-size: 14.5px; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--bg2); font-weight: 600; white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }
.md .math-d { overflow-x: auto; overflow-y: hidden; margin: .4em 0 .9em; padding: 2px 0; }
.md .katex { font-size: 1.08em; }
.md .math-err { font-family: var(--mono); font-size: .9em; color: var(--ink2); }

/* Ô nhập */
.composer-wrap { flex: none; padding: 6px 10px calc(var(--safe-b) + 8px); background: var(--bg); position: relative; }
.composer { max-width: 760px; margin: 0 auto; border: 1px solid var(--line); background: var(--card); border-radius: 22px; padding: 8px 8px 6px; box-shadow: 0 1px 4px rgba(0,0,0,.05); }
#inp { width: 100%; border: 0; background: none; resize: none; padding: 6px 8px; max-height: 40vh; line-height: 1.45; font-size: 16px; outline: none; display: block; }
.c-row { display: flex; align-items: center; gap: 2px; }
.c-row .grow { flex: 1; }
.c-btn { width: 42px; height: 42px; border: 0; background: none; border-radius: 12px; display: grid; place-items: center; color: var(--ink2); }
.c-btn.on { background: var(--acc); color: var(--acc-ink); }
.c-pill { height: 36px; border: 1px solid var(--line); background: none; border-radius: 999px; display: inline-flex; align-items: center; gap: 2px; padding: 0 8px 0 12px; font-size: 14px; color: var(--ink2); margin-left: 2px; }
.c-pill svg { width: 16px; height: 16px; }
.send { width: 42px; height: 42px; border: 0; border-radius: 12px; background: var(--acc); color: var(--acc-ink); display: grid; place-items: center; margin-left: 4px; }
.send:disabled { opacity: .4; }
.send .i-stop { display: none; }
.send.busy .i-send { display: none; }
.send.busy .i-stop { display: block; }
.atts { max-width: 760px; margin: 0 auto 6px; display: flex; gap: 8px; overflow-x: auto; padding: 2px; }
.att { position: relative; flex: none; }
.att .thumb { width: 64px; height: 64px; }
.att .x { position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; padding: 0; }
.att .x svg { width: 14px; height: 14px; }
.att .st { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; text-align: center; background: rgba(0,0,0,.55); color: #fff; border-radius: 0 0 12px 12px; }
.edit-bar { max-width: 760px; margin: 0 auto 6px; display: flex; align-items: center; justify-content: space-between; font-size: 14px; color: var(--ink2); padding: 0 6px; }
.pop { position: absolute; bottom: calc(100% - 4px); left: max(10px, calc(50% - 370px)); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.12); min-width: 230px; z-index: 20; }
.pop button { display: flex; width: 100%; align-items: baseline; gap: 8px; border: 0; background: none; text-align: left; border-radius: 10px; min-height: 44px; padding: 8px 10px; }
.pop button.sel { background: var(--bg2); }
.pop small { color: var(--ink3); }

/* Menu trượt */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 30; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(310px, 84vw); background: var(--bg); border-right: 1px solid var(--line); z-index: 31; display: flex; flex-direction: column; padding: calc(var(--safe-t) + 10px) 10px calc(var(--safe-b) + 10px); }
.dr-head { display: flex; align-items: center; gap: 10px; font-size: 20px; padding: 6px 8px 12px; }
.dr-head img { border-radius: 8px; }
.dr-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 46px; border: 0; background: none; border-radius: 12px; padding: 8px 10px; text-align: left; font-size: 16px; }
.dr-item.strong { font-weight: 600; }
.dr-item.cur { background: var(--bg2); }
.dr-sec { font-size: 13px; color: var(--ink3); padding: 14px 10px 4px; }
.dr-recent { flex: 1; min-height: 0; overflow-y: auto; }
.dr-recent button { display: block; width: 100%; min-height: 42px; border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; color: var(--ink); }
.dr-recent button.cur { background: var(--bg2); }
.dr-foot { border-top: 1px solid var(--line); padding: 10px 8px 0; font-size: 14px; color: var(--ink2); display: flex; align-items: center; gap: 10px; }

/* Danh sách */
.search { margin: 4px auto 12px; }
.list { display: grid; gap: 2px; }
.li { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); min-height: 52px; }
.li .main { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 10px 4px; }
.li .t { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.li .s { display: block; font-size: 13px; color: var(--ink3); }
.li .icon-btn { width: 40px; height: 40px; color: var(--ink3); }
.li .icon-btn svg { width: 19px; height: 19px; }
.empty { color: var(--ink3); padding: 18px 4px; text-align: center; }
.row-form { display: flex; gap: 8px; margin: 12px auto; }
.row-form input { flex: 1; }

/* Thẻ mục (cài đặt, dự án, chi tiêu) */
.sec { border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 14px; margin: 0 auto 14px; }
.sec h3 { margin: 0 0 8px; font-size: 17px; }
.sec .hint { font-size: 13px; color: var(--ink3); margin: 4px 0 8px; }
.sw { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; border-bottom: 1px solid var(--line); }
.sw:last-child { border-bottom: 0; }
.sw input[type=checkbox] { width: 46px; height: 28px; appearance: none; -webkit-appearance: none; border-radius: 999px; background: var(--line); position: relative; flex: none; }
.sw input[type=checkbox]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.sw input[type=checkbox]:checked { background: var(--acc); }
.sw input[type=checkbox]:checked::after { left: 21px; }
.sw select { min-height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 0 8px; }
.mem { display: flex; gap: 6px; align-items: flex-start; border-bottom: 1px solid var(--line); padding: 6px 0; }
.mem:last-child { border-bottom: 0; }
.mem .b { flex: 1; min-width: 0; font-size: 15px; padding-top: 8px; overflow-wrap: anywhere; }
.mem .icon-btn { width: 40px; height: 40px; color: var(--ink3); }
.mem .icon-btn svg { width: 18px; height: 18px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.imp-line { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.imp-line input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
.bar-warn { font-size: 13px; color: var(--err); }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv:last-child { border-bottom: 0; }

/* Chi tiêu */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 auto 14px; }
.card { border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 10px; }
.card .k { font-size: 12px; color: var(--ink3); }
.card .v { font-size: 20px; font-weight: 600; margin-top: 2px; }
.card .s { font-size: 12px; color: var(--ink2); }
.chart { width: 100%; max-width: 520px; height: auto; display: block; }
.chart .bar { fill: var(--acc); stroke: none; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--ink3); stroke: none; font-weight: 400; font-size: 11px; font-family: var(--sans); }
.tbl-wrap { overflow-x: auto; }
table.days { width: 100%; border-collapse: collapse; font-size: 14px; }
table.days th, table.days td { text-align: right; padding: 7px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.days th:first-child, table.days td:first-child { text-align: left; }

/* Xem ảnh lớn, thông báo, hộp thoại */
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50; display: grid; place-items: center; }
.viewer img { max-width: 100%; max-height: 100%; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 96px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 60; max-width: min(92vw, 520px); font-size: 15px; text-align: center; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--bg); border: 1px solid var(--line); border-radius: 18px; padding: 18px; width: min(460px, 100%); max-height: 88vh; overflow-y: auto; }
.modal h3 { margin: 0 0 10px; }
.modal .btn-row { justify-content: flex-end; }

@media (min-width: 900px) {
  .chat-scroll { padding-top: 28px; }
}
