:root {
  --bg: #f7efe3; --bg-2: #fffaf2; --card: #fffdf8;
  --ink: #3a2418; --ink-soft: #6f5444;
  --orange: #c4621f; --orange-deep: #9e4612;
  --ok: #2f7a55; --ok-bg: #dcefe3;
  --warn: #9a6a0b; --warn-bg: #f7e6bf;
  --bad: #b23a2e; --bad-bg: #f6d9d4;
  --info: #2d6274; --info-bg: #d6e7ee;
  --mute-bg: #ece3d6;
  --line: rgba(58, 36, 24, .13);
  --radius: 14px;
  --shadow: 0 12px 30px -18px rgba(90, 50, 20, .45);
  --display: "Baloo 2", system-ui, sans-serif;
  --body: "Be Vietnam Pro", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1611; --bg-2: #2a1e17; --card: #2d2119;
    --ink: #f6e9da; --ink-soft: #cdb6a3;
    --orange: #ec8a45; --orange-deep: #f2a26a;
    --ok: #8fd3ad; --ok-bg: #22392c; --warn: #f0c86e; --warn-bg: #3d3018;
    --bad: #f3a196; --bad-bg: #44241f; --info: #9cd0e2; --info-bg: #1f3540; --mute-bg: #3a2c22;
    --line: rgba(246, 233, 218, .14);
    --shadow: 0 12px 30px -18px rgba(0, 0, 0, .8);
  }
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--body); background: var(--bg); color: var(--ink); line-height: 1.5; font-size: 15px; }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0; }
a { color: var(--orange-deep); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; text-align: center; color: var(--ink-soft); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); background: var(--card); padding: 32px 28px; border-radius: 22px; box-shadow: var(--shadow); border: 1px solid var(--line); display: grid; gap: 14px; }
.login h1 { color: var(--orange-deep); font-size: 1.7rem; }
.login p { margin: 0; color: var(--ink-soft); }
.login .err { color: var(--bad); min-height: 1.4em; font-size: .9rem; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.shell > div { min-width: 0; }
.side { background: var(--bg-2); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.brand { font-family: var(--display); font-weight: 800; font-size: 1.25rem; color: var(--orange-deep); padding: 4px 10px 14px; display: flex; gap: 8px; align-items: center; }
.brand small { display: block; font-family: var(--body); font-weight: 500; font-size: .75rem; color: var(--ink-soft); }
.side a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); font-weight: 500; }
.side a:hover { background: var(--mute-bg); }
.side a.on { background: var(--orange); color: #fff; }
.side .grow { flex: 1; }
.who { padding: 12px; border-top: 1px solid var(--line); font-size: .85rem; color: var(--ink-soft); display: grid; gap: 8px; }
.who b { color: var(--ink); }
.menu-btn { display: none; }
main { padding: 24px clamp(16px, 3vw, 36px) 60px; min-width: 0; }
.head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 18px; }
.head h1 { font-size: 1.8rem; }
.head p { margin: 2px 0 0; color: var(--ink-soft); font-size: .9rem; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg-2); position: sticky; top: 0; z-index: 10; }
  main { padding: 18px 16px 60px; }
}
@media (min-width: 861px) { .topbar { display: none; } }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px; padding: 8px 16px; background: var(--orange); color: #fff; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--orange-deep); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--mute-bg); }
.btn.danger { background: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: progress; }
input, select, textarea { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--orange); outline-offset: -1px; }
textarea { min-height: 80px; resize: vertical; }
label { display: grid; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--ink-soft); }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.tools input, .tools select { width: auto; min-width: 150px; }
.tools .search { flex: 1; min-width: 180px; }

/* ---------- cards / stats ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 1.15rem; margin-bottom: 10px; }
.stat .n { font-family: var(--display); font-size: 2rem; font-weight: 800; color: var(--orange-deep); line-height: 1.1; }
.stat .l { color: var(--ink-soft); font-size: .85rem; }
.cols2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list li { display: flex; gap: 8px; justify-content: space-between; align-items: baseline; border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.list li:last-child { border: 0; }
.muted { color: var(--ink-soft); font-size: .88rem; }
.empty { color: var(--ink-soft); padding: 18px; text-align: center; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--mute-bg); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }

/* ---------- table ---------- */
.tbl-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-soft); background: var(--bg-2); position: sticky; top: 0; cursor: pointer; white-space: nowrap; user-select: none; }
tbody tr:hover { background: color-mix(in srgb, var(--orange) 6%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
td.act { white-space: nowrap; text-align: right; }
.tbl-wrap td:first-child b { display: inline-block; min-width: 140px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
tfoot td { font-weight: 700; background: var(--bg-2); }

/* grid điểm danh / thu phí */
.matrix td, .matrix th { text-align: center; padding: 6px 8px; }
.matrix td:first-child, .matrix th:first-child { text-align: left; position: sticky; left: 0; background: var(--card); z-index: 1; }
.matrix th:first-child { background: var(--bg-2); }
.cell { width: 34px; height: 30px; border-radius: 8px; border: 1px dashed var(--line); background: transparent; cursor: pointer; font-weight: 700; }
.cell.paid { background: var(--ok-bg); color: var(--ok); border-style: solid; }
.cell:disabled { cursor: default; }

.marks { display: grid; gap: 6px; max-height: 55vh; overflow-y: auto; padding-right: 4px; }
.mark-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 8px; border-radius: 10px; background: var(--bg-2); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 4px 12px; cursor: pointer; font-size: .85rem; }
.seg button.on[data-v="Có"] { background: var(--ok); color: #fff; }
.seg button.on[data-v="Vắng"] { background: var(--bad); color: #fff; }
.seg button.on[data-v="Phép"] { background: var(--warn); color: #fff; }

/* gantt timeline */
.gantt { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; overflow-x: auto; }
.g-inner { min-width: 760px; position: relative; }
.g-row { display: grid; grid-template-columns: 210px 1fr; align-items: center; min-height: 32px; border-bottom: 1px dashed var(--line); }
.g-row:last-child { border: 0; }
.g-name { font-size: .85rem; padding-right: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.g-track { position: relative; height: 32px; background: repeating-linear-gradient(90deg, transparent 0 calc(100% / 13 - 1px), var(--line) calc(100% / 13 - 1px) calc(100% / 13)); }
.g-bar { position: absolute; top: 7px; height: 18px; border-radius: 6px; min-width: 6px; background: var(--mute-bg); border: 1px solid var(--line); cursor: pointer; }
.g-bar.ok { background: var(--ok); border-color: var(--ok); }
.g-bar.info { background: var(--orange); border-color: var(--orange); }
.g-bar.bad { background: var(--bad-bg); border-color: var(--bad); }
.g-months { display: grid; grid-template-columns: 210px repeat(13, 1fr); font-size: .75rem; color: var(--ink-soft); font-weight: 600; padding-bottom: 6px; }
.g-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bad); z-index: 2; pointer-events: none; }

.bar { height: 8px; border-radius: 999px; background: var(--mute-bg); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--orange); }

/* ---------- modal ---------- */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(640px, calc(100vw - 32px)); background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(30, 18, 10, .45); }
dialog form { padding: 22px; display: grid; gap: 14px; }
dialog h2 { font-size: 1.35rem; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.fields .full { grid-column: 1 / -1; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px 12px; max-height: 200px; overflow-y: auto; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); font-weight: 400; color: var(--ink); }
.checks label { display: flex; gap: 6px; align-items: center; font-weight: 400; color: var(--ink); }
.checks input { width: auto; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions .left { margin-right: auto; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); color: #fff; }
.note { background: var(--warn-bg); color: var(--warn); padding: 10px 14px; border-radius: 10px; font-size: .88rem; margin-bottom: 14px; }

/* sidebar: gen */
.gen-box { margin: 0 4px 12px; padding: 10px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); display: grid; gap: 2px; font-size: .85rem; }
.gen-box b { font-family: var(--display); font-size: 1.2rem; color: var(--orange-deep); }
.gen-box select { margin-top: 4px; }

/* tour hướng dẫn */
.tour-block { position: fixed; inset: 0; z-index: 59; }
.tour-spot { position: fixed; z-index: 60; border-radius: 12px; pointer-events: none; box-shadow: 0 0 0 3px var(--orange), 0 0 0 9999px rgba(25, 14, 8, .62); transition: all .28s ease; }
.tour-card { position: fixed; z-index: 61; width: min(340px, calc(100vw - 32px)); background: var(--card); color: var(--ink); border-radius: 16px; padding: 16px 18px; box-shadow: 0 20px 50px -10px rgba(0, 0, 0, .5); transition: left .28s ease, top .28s ease; }
.tour-card h3 { font-size: 1.2rem; margin: 2px 0 6px; color: var(--orange-deep); }
.tour-card p { margin: 0 0 14px; font-size: .92rem; }
.tour-step { font-size: .75rem; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.tour-actions { display: flex; gap: 6px; align-items: center; }
.tour-actions .grow { flex: 1; }
@media (prefers-reduced-motion: reduce) { .tour-spot, .tour-card { transition: none; } }

/* kế hoạch chi tiết sự kiện */
.steps { display: grid; gap: 18px; }
.stage h3 { font-size: 1.1rem; margin: 0 0 8px; color: var(--orange-deep); }
.step { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
.step.done { opacity: .72; }
.step.note-step { background: var(--warn-bg); }
.step-st { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); background: var(--bg-2); display: grid; place-items: center; font-weight: 800; color: var(--ok); }
button.step-st { cursor: pointer; }
button.step-st:hover { border-color: var(--orange); }
.step.done .step-st { background: var(--ok-bg); border-color: var(--ok); }
.step-body { min-width: 0; flex: 1; display: grid; gap: 4px; }
.step-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.step-act { margin-left: auto; display: inline-flex; gap: 4px; }
.step-text { white-space: pre-line; font-size: .9rem; }
.step-note { color: var(--ink-soft); }

/* dữ liệu CLB */
.lib { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; }
.lib-list { display: grid; gap: 12px; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; padding-right: 4px; }
.lib-group h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); margin: 4px 0 6px; font-family: var(--body); }
.lib-item { display: flex; gap: 10px; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; margin-bottom: 6px; cursor: pointer; }
.lib-item:hover { border-color: var(--orange); }
.lib-item.on { border-color: var(--orange); box-shadow: 0 0 0 2px color-mix(in srgb, var(--orange) 30%, transparent); }
.lib-item small { display: block; color: var(--ink-soft); font-size: .78rem; line-height: 1.35; margin-top: 2px; }
.lib-hidden { font-size: .85rem; background: var(--bg-2); border: 1px dashed var(--line); border-radius: 12px; padding: 8px 12px; }
.lib-hidden summary { cursor: pointer; color: var(--ink-soft); }
.lib-hidden ul { padding-left: 18px; margin: 8px 0; display: grid; gap: 6px; }
.lib-view { min-height: 60vh; }
.lib-doc-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 14px; }
.lib-doc-head h2 { font-size: 1.4rem; margin: 0 0 4px; }
.lib-doc-head p { margin: 2px 0; }
.md { line-height: 1.65; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { margin: 1.1em 0 .4em; color: var(--orange-deep); }
.md h2 { font-size: 1.25rem; } .md h3 { font-size: 1.08rem; }
.md ul, .md ol { padding-left: 1.4em; }
.md table { margin: 10px 0; display: block; overflow-x: auto; }
.md th { position: static; cursor: default; }
.md blockquote { margin: 8px 0; padding: 6px 14px; border-left: 3px solid var(--orange); background: var(--bg-2); border-radius: 0 8px 8px 0; }
.md code { background: var(--mute-bg); padding: 1px 5px; border-radius: 5px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.lib-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.lib-images figure { margin: 0; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.lib-images img { width: 100%; aspect-ratio: 1; object-fit: contain; background: repeating-conic-gradient(var(--mute-bg) 0 25%, transparent 0 50%) 0 0 / 16px 16px; }
.lib-images figcaption { padding: 8px 10px; display: grid; gap: 4px; font-size: .85rem; }
@media (max-width: 860px) { .lib { grid-template-columns: 1fr; } .lib-list { position: static; max-height: none; } }

/* tham khảo: xếp hạng gen */
.ref-rank { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; margin-bottom: 12px; }
.ref-gen { text-align: left; display: grid; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; cursor: pointer; }
.ref-gen:hover { border-color: var(--orange); }
.ref-gen.on { border-color: var(--orange); box-shadow: 0 0 0 2px color-mix(in srgb, var(--orange) 30%, transparent); }
.ref-gen-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-family: var(--display); font-size: 1.05rem; }
.ref-gen small { color: var(--ink-soft); font-size: .78rem; line-height: 1.4; }
.ref-docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; margin-bottom: 18px; }
.ref-docs .lib-item { text-decoration: none; color: inherit; margin: 0; }
