:root {
  --bg: #f7f5ef; --surface: #ffffff; --ink: #2b2a26; --muted: #77736a; --line: #e4dfd3;
  --accent: #3f6b3a; --accent-soft: #e6efe3; --warn: #a15c00; --warn-soft: #fff4e0;
  --danger: #a3261b; --danger-soft: #fde9e6; --user: #3f6b3a; --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1c1a; --surface: #252623; --ink: #ecebe6; --muted: #a29e94; --line: #3a3b36;
          --accent: #8cc47f; --accent-soft: #2e3a2b; --warn: #f0b45a; --warn-soft: #3a2f1c;
          --danger: #f08a7e; --danger-soft: #3d2320; --user: #4e7d48; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.55 -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; background: var(--bg); color: var(--ink); }
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px;
         background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-size: 18px; } .brand .sub { color: var(--muted); font-size: 13px; margin-left: 8px; }
nav { display: flex; gap: 4px; }
button { font: inherit; border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 7px 14px; border-radius: 8px; cursor: pointer; }
button.ghost, .tab { background: transparent; color: var(--ink); border-color: var(--line); }
.tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
button:disabled { opacity: .5; cursor: wait; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
textarea { width: 100%; resize: vertical; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.panel { display: none; } .panel.active { display: block; }
.muted { color: var(--muted); font-size: 13px; }
.pill { font-size: 12px; padding: 2px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.pill.emergency { background: var(--danger-soft); color: var(--danger); }

/* consult */
.consult-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.consult-body { display: grid; grid-template-columns: 1fr 300px; gap: 14px; }
.chat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
        height: calc(100vh - 250px); min-height: 360px; overflow-y: auto; }
.msg { margin: 0 0 14px; max-width: 92%; }
.msg .bubble { padding: 10px 14px; border-radius: var(--radius); background: var(--bg); border: 1px solid var(--line); overflow-x: auto; }
.msg.user { margin-left: auto; } .msg.user .bubble { background: var(--user); color: #fff; border-color: var(--user); white-space: pre-wrap; }
.msg.emergency .bubble { background: var(--danger-soft); border-color: var(--danger); }
.msg.warning .bubble { background: var(--warn-soft); border-color: var(--warn); }
.msg.diagnosis .bubble { background: var(--surface); border-left: 4px solid var(--accent); max-width: 100%; }
.msg.diagnosis { max-width: 100%; }
.bubble h2 { font-size: 16px; margin: 14px 0 6px; color: var(--accent); } .bubble h3 { font-size: 15px; }
.bubble table { border-collapse: collapse; } .bubble td, .bubble th { border: 1px solid var(--line); padding: 4px 8px; }
.bubble p { margin: 6px 0; }
.sources { margin-top: 8px; font-size: 13px; } .sources summary { cursor: pointer; color: var(--muted); }
.sources li { margin: 4px 0; } .sources .snip { color: var(--muted); display: block; }
.typing { color: var(--muted); font-style: italic; }
.case { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; font-size: 13px;
        height: calc(100vh - 250px); min-height: 360px; overflow-y: auto; }
.case h3 { margin: 0 0 8px; font-size: 14px; }
.case pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; color: var(--muted); }
.hyp { margin: 4px 0; } .hyp .bar { height: 6px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; }
.hyp .bar i { display: block; height: 100%; background: var(--accent); }
.composer { display: flex; gap: 8px; margin-top: 10px; } .composer button { align-self: stretch; min-width: 80px; }

/* kb */
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; min-width: 120px; }
.stat b { font-size: 22px; display: block; } .stat span { color: var(--muted); font-size: 12px; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin-top: 0; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); margin: 10px 0; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; }
.check { display: block; margin: 8px 0; font-size: 13px; }
table.docs { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
.docs th, .docs td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.docs th { font-size: 12px; color: var(--muted); font-weight: 600; }
.status-done { color: var(--accent); } .status-error { color: var(--danger); } .status-processing, .status-pending { color: var(--warn); }
.docs button { padding: 3px 8px; font-size: 12px; }

/* admin */
.account { display: flex; gap: 6px; align-items: center; }
.account span { display: inline-flex; gap: 6px; align-items: center; } .account [hidden] { display: none; }
.banner { background: var(--warn-soft); border: 1px solid var(--warn); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px;
          display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.banner[hidden] { display: none; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 20px; width: min(380px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h3 { margin: 0 0 12px; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
dialog input { display: block; width: 100%; margin-top: 4px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
dialog.wide { width: min(560px, calc(100vw - 32px)); }
.small { font-size: 12px; } button.small { padding: 4px 10px; }
button.danger { background: var(--danger); border-color: var(--danger); }
[hidden] { display: none !important; }

/* tài khoản người dùng */
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; }
.menu summary::-webkit-details-marker { display: none; }
.menu-items { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line);
              border-radius: var(--radius); padding: 6px; display: flex; flex-direction: column; gap: 4px; min-width: 180px; z-index: 10;
              box-shadow: 0 6px 20px rgba(0, 0, 0, .12); }
.menu-items button { text-align: left; border-color: transparent; }
.menu-items button:hover { background: var(--accent-soft); }
.history { max-height: min(60vh, 480px); overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.history .item { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.history .item.current { border-color: var(--accent); background: var(--accent-soft); }
.history .open { flex: 1; min-width: 0; text-align: left; background: transparent; border: 0; color: var(--ink); padding: 0; }
.history .open b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.history .del { padding: 3px 8px; font-size: 12px; }

/* lookup */
.lookup-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; } .lookup-bar input { flex: 1; min-width: 220px; }
.entities { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.entity { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; font-size: 14px; }
.entity h4 { margin: 0 0 6px; font-size: 16px; } .entity .type { font-size: 11px; text-transform: uppercase; color: var(--accent); letter-spacing: .05em; }
.entity dl { margin: 0; display: grid; grid-template-columns: 110px 1fr; gap: 3px 10px; }
.entity dt { color: var(--muted); font-size: 12px; } .entity dd { margin: 0; }
#askAnswer .bubble { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }

@media (max-width: 860px) {
  .consult-body, .cards { grid-template-columns: 1fr; }
  .case { height: auto; min-height: 0; max-height: 150px; order: -1; }
  .chat { height: calc(100vh - 330px); }
  main { padding: 10px 16px; } .docs th:nth-child(4), .docs td:nth-child(4), .docs th:nth-child(2), .docs td:nth-child(2) { display: none; }
}
