/* Brand palette from the Royal Nam Viet logo: wine red + gold */
:root {
  --bg: #faf7f2; --panel: #ffffff; --panel-2: #fcf9f4; --ink: #1f1a1a; --ink-2: #3d3434; --muted: #6f6461;
  --line: #ece2d4; --line-2: #dccdb8;
  --brand: #8b1a1f; --brand-ink: #6b1116; --brand-soft: #f8ebe9; --brand-2: #b7791f;
  --gold: #e8ae34; --gold-2: #f6d27a; --gold-soft: #fdf4df; --gold-ink: #7a5208;
  --side: #2a0b0e; --side-ink: #f6e9d6; --side-muted: #c9a46a; --side-active: #451419;
  --ring: conic-gradient(from 210deg, #e8ae34, #f6d27a, #b7791f, #8b1a1f, #c2402f, #e8ae34);
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --err: #b91c1c; --err-soft: #fee2e2;
  --info: #1d4ed8; --info-soft: #dbeafe; --gray-soft: #eef0f2;
  --radius: 10px; --shadow: 0 1px 2px rgba(40, 25, 10, .06), 0 2px 8px rgba(40, 25, 10, .05);
  --accent-text: #8b1a1f; --field: #ffffff; --row-hover: #fcf7f1; --row-hl: #fff4e0; --kcol: #f3ece2; --overlay: rgba(30, 20, 10, .42);
  color-scheme: light;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; color: var(--ink); }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
h4 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
p { margin: 0 0 8px; }
ul { margin: 4px 0; padding-left: 20px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ── layout */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { padding: 16px 16px 14px; border-bottom: 1px solid #44161b; display: flex; align-items: center; gap: 12px; }
.side .brand .logo-tile { width: 54px; height: 54px; border-radius: 12px; background: #fffaf0; display: grid; place-items: center; flex: none; box-shadow: 0 0 0 2px rgba(232, 174, 52, .55); }
.side .brand .logo-tile img { width: 44px; height: auto; }
.side .brand b { display: block; font-size: 14.5px; letter-spacing: .03em; color: #fff; line-height: 1.25; }
.side .brand small { color: var(--side-muted); font-size: 12px; }
.side .copy { padding: 6px 14px 12px; font-size: 11px; color: var(--side-muted); text-align: center; }
.side nav { padding: 10px 8px; flex: 1; }
.side nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); padding: 12px 10px 4px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--side-ink); font-size: 14px; }
.side nav a:hover { background: var(--side-active); text-decoration: none; }
.side nav a.on { background: var(--brand); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.side nav .sec { color: var(--side-muted); }
.side nav a svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.side .me { padding: 12px 14px 6px; border-top: 1px solid #44161b; font-size: 13px; display: flex; align-items: center; gap: 10px; }
.side .me .who { flex: 1; min-width: 0; }
.side .me .who b { display: block; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side .me .who small { color: var(--side-muted); }
.side .me button { background: none; border: 1px solid #6b2a30; color: var(--side-ink); border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 12px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.page-foot { margin-top: auto; padding: 14px 28px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.page-foot b { color: var(--accent-text); font-weight: 600; }
/* top app bar: page title + light/dark switch in the top-right corner */
.appbar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.appbar .menu-btn { display: none; background: none; border: 0; color: var(--ink); font-size: 22px; cursor: pointer; padding: 0 4px; }
.appbar .appbar-logo { display: none; height: 30px; width: auto; }
.appbar-title { font-weight: 650; font-size: 15px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--field); color: var(--ink); display: grid; place-items: center; cursor: pointer; flex: none; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--gold-soft); color: var(--gold-ink); border-color: var(--gold); }
.appbar-me { display: inline-flex; flex: none; }
.page { padding: 22px 28px 48px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .appbar { padding: 8px 16px; }
  .appbar .menu-btn, .appbar .appbar-logo { display: inline-block; }
  .page { padding: 16px 16px 40px; }
}

/* ── components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; } .mt-s { margin-top: 8px; } .mb { margin-bottom: 16px; }
.right { text-align: right; }
.hr { height: 1px; background: var(--line); margin: 14px 0; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: var(--field); color: var(--ink); border-radius: 8px; padding: 7px 13px; font: inherit; font-size: 13.5px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.danger { color: var(--err); border-color: #f3c4c4; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea { font: inherit; color: var(--ink); border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 10px; background: var(--field); width: 100%; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f3d9a0; border-color: var(--gold); }
label.f { display: block; }
label.f > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 550; }
.inline-input { width: auto; }
.search { max-width: 280px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--gray-soft); color: var(--ink-2); white-space: nowrap; }
.st-draft { background: var(--gray-soft); color: #475569; }
.st-wait { background: var(--warn-soft); color: var(--warn); }
.st-live { background: var(--ok-soft); color: var(--ok); }
.st-off { background: var(--err-soft); color: var(--err); }
.st-todo { background: var(--info-soft); color: var(--info); }
.st-doing { background: #ede9fe; color: #6d28d9; }
.b-sample { background: #fff7ed; color: #c2410c; border: 1px dashed #fdba74; }
.b-over { background: var(--err-soft); color: var(--err); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
/* avatar: photo (or initials) inside a white inner border, wrapped by a brand gradient ring */
.av-ring { display: inline-block; border-radius: 50%; background: var(--ring); flex: none; box-sizing: border-box; line-height: 0; vertical-align: middle; box-shadow: 0 1px 3px rgba(60, 10, 10, .18); }
.av-ring > .av-in { width: 100%; height: 100%; border-radius: 50%; border-style: solid; border-color: var(--panel); box-sizing: border-box; object-fit: cover; display: grid; place-items: center; color: #fff; font-weight: 700; line-height: 1; background: var(--panel); }
.av-edit { position: relative; display: inline-block; cursor: pointer; border: 0; background: none; padding: 0; }
.av-edit .cam { position: absolute; right: 0; bottom: 2px; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; border: 2px solid var(--panel); display: grid; place-items: center; box-shadow: var(--shadow); }
.av-edit:hover .cam { background: var(--brand-ink); }
.av-edit.sm .cam { width: 17px; height: 17px; right: -3px; bottom: -2px; border-width: 1.5px; opacity: 0; transition: opacity .15s; }
.av-edit.sm:hover .cam, .av-edit.sm:focus-visible .cam, tr:hover .av-edit.sm .cam { opacity: 1; }
.cropper { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: start; }
@media (max-width: 640px) { .cropper { grid-template-columns: 1fr; justify-items: center; } }
.crop-stage { width: 280px; height: 280px; border-radius: 12px; background: repeating-conic-gradient(#f1ebe2 0 25%, #fff 0 50%) 0 0 / 20px 20px; position: relative; overflow: hidden; touch-action: none; cursor: grab; }
.crop-stage:active { cursor: grabbing; }
.crop-stage canvas { display: block; }
.crop-stage .mask { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(circle at 50% 50%, transparent 119px, rgba(30, 8, 10, .55) 121px); }
input[type=range] { accent-color: var(--brand); padding: 0; border: 0; }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); }
.crop-stage .circle { position: absolute; left: 20px; top: 20px; width: 240px; height: 240px; border-radius: 50%; border: 2px dashed rgba(255, 255, 255, .85); pointer-events: none; }
.onode .ppl .pp { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 3px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); font-size: 12.5px; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; color: var(--accent-text); font-weight: 600; }

table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); background: var(--panel-2); border-bottom: 1px solid var(--line); padding: 8px 10px; position: sticky; top: 0; z-index: 1; }
table.t td { border-bottom: 1px solid var(--line); padding: 8px 10px; vertical-align: top; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--row-hover); }
table.t tr.hl td { background: var(--row-hl); }
.table-wrap { overflow: auto; max-width: 100%; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px; font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--accent-text); border-color: var(--brand); font-weight: 600; }

.stat { padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.bar { height: 8px; background: var(--gray-soft); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand-2); border-radius: 99px; }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.note { background: var(--gold-soft); border: 1px solid #f1dca7; border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--gold-ink); }
.warnbox { background: var(--warn-soft); border: 1px solid #fcd34d; border-radius: 8px; padding: 10px 12px; font-size: 13px; color: #78350f; }

/* modal & drawer */
.overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 80; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 720px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 1100px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--panel-2); border-radius: 0 0 12px 12px; }
.drawer-ov { position: fixed; inset: 0; background: rgba(30,20,10,.3); z-index: 70; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--panel); z-index: 71; box-shadow: -10px 0 40px rgba(0,0,0,.18); display: flex; flex-direction: column; }
.drawer .dh { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.drawer .db { padding: 14px 18px; overflow-y: auto; flex: 1; }
.x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: var(--shadow); font-size: 14px; max-width: 90vw; }
.toast.err { background: var(--err); }

/* ── login */
.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: radial-gradient(1200px 600px at 80% 110%, rgba(232, 174, 52, .35), transparent 60%), linear-gradient(140deg, #1c0608 0%, #4a0f14 50%, #8b1a1f 100%); padding: 16px; }
.login .card { width: 100%; max-width: 410px; padding: 26px 28px 22px; border-top: 4px solid var(--gold); }
.login .logo { display: block; width: 128px; height: auto; margin: 0 auto 12px; }
.login .copy { color: rgba(246, 233, 214, .8); font-size: 12px; }

/* ── org chart (CSS tree) */
.org-wrap { overflow: auto; padding: 10px 0 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.org-zoom { display: inline-block; min-width: 100%; padding: 16px 20px; }
.tree > li:only-child > .onode::before { display: none; }
.leaves { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 22px; }
.leaves::before { content: ''; position: absolute; top: 0; bottom: 24px; left: 50%; border-left: 1.5px solid var(--line-2); }
.leaves .leafitem { position: relative; z-index: 1; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { display: flex; justify-content: center; padding-top: 22px; position: relative; }
.tree li { display: flex; flex-direction: column; align-items: center; position: relative; padding: 22px 6px 0; }
.tree > li { padding-top: 0; }
.tree li::before, .tree li::after { content: ''; position: absolute; top: 0; width: 50%; height: 22px; border-top: 1.5px solid var(--line-2); }
.tree li::before { right: 50%; }
.tree li::after { left: 50%; border-left: 1.5px solid var(--line-2); }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:only-child { padding-top: 22px; }
.tree > li:only-child { padding-top: 0; }
.tree li:first-child::before, .tree li:last-child::after { border: 0 none; }
.tree li:last-child::before { border-right: 1.5px solid var(--line-2); border-radius: 0 6px 0 0; }
.tree li:first-child::after { border-radius: 6px 0 0 0; }
.tree ul::before { content: ''; position: absolute; top: 0; left: 50%; height: 22px; border-left: 1.5px solid var(--line-2); }
.tree li:only-child > .onode::before { content: ''; position: absolute; top: -22px; left: 50%; height: 22px; border-left: 1.5px solid var(--line-2); }
.onode { position: relative; background: var(--panel); border: 1px solid var(--line-2); border-top: 4px solid var(--c, var(--brand)); border-radius: 8px; padding: 8px 10px; min-width: 150px; max-width: 190px; text-align: center; cursor: pointer; box-shadow: var(--shadow); }
.onode:hover { border-color: var(--c); }
.onode .t { font-weight: 650; font-size: 12.5px; line-height: 1.3; }
.onode .d { font-size: 11px; color: var(--muted); margin-top: 2px; }
.onode .ppl { margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.onode .ppl .vac { color: var(--err); font-style: italic; }
/* one small name card per person, hanging under their position */
.staff { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding-top: 12px; }
.ecard { position: relative; z-index: 1; display: flex; gap: 9px; align-items: flex-start; width: 150px; padding: 5px 7px; text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line-2); border-left: 3px solid var(--c, var(--brand)); border-radius: 10px; box-shadow: var(--shadow); }
.ecard:hover, .ecard:focus-visible { border-color: var(--c, var(--brand)); outline: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--c, var(--brand)) 25%, transparent); }
.ecard::before { content: ''; position: absolute; left: 50%; top: -7px; height: 6px; border-left: 1.5px solid var(--line-2); }
.staff > .ecard:first-child::before { top: -13px; height: 12px; }
.ec-av { position: relative; flex: none; margin-top: 1px; line-height: 0; }
.ec-body { flex: 1; min-width: 0; }
.ec-name { font-size: 12px; font-weight: 650; line-height: 1.3; color: var(--ink); overflow-wrap: anywhere; }
/* open-task count sits on the photo's corner so the name keeps the full width */
.ec-task { position: absolute; top: -5px; right: -7px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px; border: 1.5px solid var(--panel);
  background: var(--brand); color: #fff; font-size: 10px; font-weight: 700; line-height: 14px; text-align: center; }
.ec-task.legend-task { position: static; display: inline-block; }
.ec-tags { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-top: 4px; }
.ec-tags .tag { display: block; max-width: 100%; font-size: 10.5px; padding: 1px 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag.proc { background: transparent; color: var(--ink-2); border: 1px solid var(--line-2); }
.tag.sub { background: var(--brand-soft); color: var(--accent-text); border-color: color-mix(in srgb, var(--brand) 30%, transparent); }
.ec-more { font-size: 10.5px; color: var(--muted); padding-left: 2px; }
.ecard.kiem { align-items: center; width: 140px; padding: 4px 8px; border-style: dashed; border-left-style: solid; background: var(--panel-2); box-shadow: none; }
.ecard.kiem .ec-name { font-weight: 600; font-size: 11.5px; }
.ec-kiem { font-size: 10.5px; color: var(--muted); font-style: italic; }
.org-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; margin-bottom: 10px; }
.org-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.org-legend .legend-kiem { display: inline-block; width: auto; padding: 1px 8px; font-size: 11px; cursor: default; }
.org-legend .legend-kiem::before { display: none; }
.onode .cnt { position: absolute; top: -10px; right: -8px; background: var(--c); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 7px; }

/* ── matrix */
table.mx { border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.mx th, table.mx td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 6px 8px; background: var(--panel); }
table.mx thead th { position: sticky; top: 0; background: var(--panel-2); z-index: 2; font-size: 12px; text-align: center; vertical-align: bottom; }
table.mx th.fn, table.mx td.fn { position: sticky; left: 0; z-index: 1; min-width: 260px; max-width: 320px; text-align: left; }
table.mx thead th.fn { z-index: 3; }
table.mx tr.grp td { background: var(--brand-soft); font-weight: 650; color: var(--accent-text); }
table.mx td.cell { text-align: center; min-width: 74px; cursor: default; }
table.mx td.cell.edit { cursor: pointer; }
table.mx td.cell.edit:hover { background: var(--row-hover); }
table.mx .dim td.cell:not(.focus) { opacity: .35; }
.r { display: inline-block; min-width: 30px; padding: 2px 6px; border-radius: 6px; font-weight: 700; font-size: 12px; }
.r-C { background: #dbeafe; color: #1e40af; }
.r-CQ { background: #1e40af; color: #fff; }
.r-Q { background: #fde68a; color: #92400e; }
.r-T { background: #e2e8f0; color: #334155; }
.r-B { background: #f1f5f9; color: #64748b; border: 1px dashed #cbd5e1; }

/* ── process map */
.band { border-radius: var(--radius); padding: 12px 14px; border: 1px solid var(--line); }
.band h4 { margin-bottom: 10px; }
.band.mg { background: #f9eeee; border-color: #ecc9cb; }
.band.core { background: #fdf5e3; border-color: #f1d9a0; }
.band.sup { background: #f6f2ec; border-color: #e3d9ca; }
.chain { display: flex; gap: 0; overflow-x: auto; padding-bottom: 4px; }
.chev { position: relative; flex: 1 0 150px; min-height: 76px; background: var(--brand); color: #fff; padding: 10px 26px 10px 30px; clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 50%, calc(100% - 16px) 100%, 0 100%, 16px 50%); margin-right: -8px; cursor: pointer; display: flex; flex-direction: column; justify-content: center; }
.chev:first-child { clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 50%, calc(100% - 16px) 100%, 0 100%); padding-left: 16px; }
.chev:nth-child(even) { background: linear-gradient(135deg, #e8ae34, #f3c55e); color: #3b1d02; }
.chev:hover { filter: brightness(1.1); }
.chev .c { font-size: 11px; opacity: .85; font-family: ui-monospace, Consolas, monospace; }
.chev .n { font-size: 12.5px; font-weight: 600; line-height: 1.3; }
.chev .alt { font-size: 11px; opacity: .9; margin-top: 3px; }
.pchips { display: flex; flex-wrap: wrap; gap: 8px; }
.pchip { background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; display: flex; gap: 8px; align-items: center; }
.pchip:hover { border-color: var(--brand-2); }

/* ── flowchart */
.flow-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); max-height: 78vh; }
.flow-wrap svg { display: block; }
.flow-wrap .step { cursor: pointer; }
.flow-wrap .step:hover rect, .flow-wrap .step:hover polygon { stroke-width: 2.4; }

/* ── kanban */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 12px; overflow-x: auto; align-items: start; }
.kcol { background: var(--kcol); border-radius: 10px; padding: 10px; min-height: 200px; }
.kcol.drop { outline: 2px dashed var(--brand-2); }
.kcol h3 { font-size: 13px; display: flex; justify-content: space-between; margin: 2px 4px 10px; }
.kcard { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow); }
.kcard:hover { border-color: var(--brand-2); }
.kcard .tt { font-weight: 600; font-size: 13.5px; line-height: 1.35; }
.kcard .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; font-size: 12px; color: var(--muted); }
.pri-Cao { border-left: 3px solid var(--err); }
.pri-Trung { border-left: 3px solid var(--warn); }
.pri-Thấp { border-left: 3px solid #94a3b8; }

/* ── library */
.lib { display: grid; grid-template-columns: 300px 1fr; gap: 16px; }
@media (max-width: 900px) { .lib { grid-template-columns: 1fr; } }
.ftree { max-height: 70vh; overflow: auto; font-size: 13px; }
.ftree div.fd { padding: 4px 8px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.ftree div.fd:hover { background: var(--panel-2); }
.ftree div.fd.on { background: var(--brand-soft); color: var(--accent-text); font-weight: 600; }
.ext { font-size: 10.5px; font-weight: 700; padding: 1px 5px; border-radius: 4px; background: #e2e8f0; color: #334155; text-transform: uppercase; }
.ext-doc, .ext-docx { background: #dbeafe; color: #1e40af; }
.ext-xls, .ext-xlsx, .ext-xlsm { background: #dcfce7; color: #166534; }
.ext-pdf { background: #fee2e2; color: #991b1b; }
.ext-vsdx, .ext-vsd, .ext-drawio { background: #ede9fe; color: #5b21b6; }
.ext-pptx, .ext-ppt { background: #ffedd5; color: #9a3412; }

/* ── printable document */
.doc { background: #fff; color: #000; max-width: 210mm; margin: 0 auto; padding: 14mm 14mm; font-size: 13px; box-shadow: var(--shadow); }
.doc table { width: 100%; border-collapse: collapse; }
.doc th, .doc td { border: 1px solid #555; padding: 5px 7px; vertical-align: top; }
.doc th { background: #f7efe2; }
.doc .doc-logo { height: 46px; width: auto; display: block; margin: 0 auto 4px; }
.doc .dh td { vertical-align: middle; }
.doc h2 { font-size: 15px; margin: 16px 0 6px; text-transform: uppercase; }
.doc .title { font-size: 18px; font-weight: 800; text-align: center; text-transform: uppercase; }
.page-break { break-before: page; }
@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; }
  .side, .topbar, .no-print, .toast { display: none !important; }
  .shell { display: block; }
  .page { padding: 0; max-width: none; }
  .doc { box-shadow: none; padding: 0; max-width: none; }
  .card { box-shadow: none; }
  .flow-wrap { max-height: none; overflow: visible; border: 0; }
}

/* ── sub-area tags under each work area */
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; line-height: 1.35; padding: 2px 8px; border-radius: 99px;
  background: var(--gold-soft); color: var(--gold-ink); border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent); white-space: nowrap; }
.tag.pick { cursor: pointer; background: var(--panel-2); color: var(--muted); border: 1px dashed var(--line-2); user-select: none; }
.tag.pick:hover { border-color: var(--gold); color: var(--ink); }
.tag.pick.on { background: var(--brand); color: #fff; border: 1px solid var(--brand); }
.tag .x { cursor: pointer; opacity: .7; margin-left: 2px; }
.tag .x:hover { opacity: 1; }
.tags.compact .tag { font-size: 11px; padding: 1px 7px; }
.tags .tag { max-width: 100%; white-space: normal; }
.tag-who { display: inline-flex; align-items: center; gap: 3px; margin-left: 3px; padding-left: 5px; font-weight: 650; white-space: nowrap;
  border-left: 1px solid color-mix(in srgb, currentColor 30%, transparent); }

/* ── staff list reorder mode */
.t.reorder tbody tr { cursor: grab; }
.t.reorder tbody tr:active { cursor: grabbing; }
.t.reorder .grip { color: var(--muted); font-weight: 700; letter-spacing: -2px; user-select: none; text-align: center; }
.t.reorder tr:hover .grip { color: var(--gold); }
.t.reorder tr.dragging { opacity: .4; }
.t.reorder tr.drop-before td { box-shadow: inset 0 3px 0 var(--gold); }
.t.reorder tr.drop-after td { box-shadow: inset 0 -3px 0 var(--gold); }
.t.reorder .btn.sm { min-width: 30px; justify-content: center; }

/* ── "Trang của tôi": large photo hero in brand colours */
.me-hero { position: relative; overflow: hidden; border-radius: 16px; margin-bottom: 18px; color: #fff;
  background: radial-gradient(circle at 88% -30%, rgba(246, 210, 122, .45), transparent 42%),
              linear-gradient(115deg, var(--side) 0%, var(--brand-ink) 45%, var(--brand) 78%, #a8452c 100%);
  box-shadow: 0 6px 24px rgba(80, 15, 20, .22); }
.me-hero::before { content: ""; position: absolute; right: -60px; bottom: -90px; width: 280px; height: 280px; border-radius: 50%; border: 26px solid rgba(232, 174, 52, .14); }
.me-hero::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: linear-gradient(90deg, var(--gold), var(--dept), var(--gold-2)); }
.me-hero-in { position: relative; display: flex; align-items: center; gap: 26px; padding: 26px 30px 28px; flex-wrap: wrap; }
.me-av { flex: none; filter: drop-shadow(0 6px 16px rgba(0, 0, 0, .35)); }
.me-av .av-ring > .av-in { border-color: #fff; }
.me-av.av-edit .cam { width: 38px; height: 38px; right: 6px; bottom: 8px; background: var(--gold); color: #3a1a05; border-color: #fff; }
.me-av.av-edit:hover .cam { background: var(--gold-2); }
.me-id { flex: 1; min-width: 240px; }
.me-hello { font-size: 13px; color: var(--gold-2); letter-spacing: .02em; }
.me-id h1 { color: #fff; font-size: 30px; font-weight: 750; margin-top: 2px; letter-spacing: .01em; }
.me-role { font-size: 15.5px; margin-top: 4px; color: #fbe9d6; }
.me-role b { color: #fff; }
.me-code { margin-left: 8px; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .22); }
.me-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 13px; color: #f3dcc4; }
.me-meta a { color: var(--gold-2); font-weight: 600; }
.me-stats { display: grid; grid-template-columns: repeat(2, minmax(118px, 1fr)); gap: 10px; }
.me-stat { display: block; padding: 10px 14px; border-radius: 12px; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18); color: #fff; backdrop-filter: blur(4px); }
a.me-stat:hover { background: rgba(255, 255, 255, .18); text-decoration: none; }
.me-stat b { display: block; font-size: 26px; line-height: 1.1; }
.me-stat span { font-size: 12px; color: #f3dcc4; }
.me-stat.bad b { color: #ffb4a8; }
.me-stat.good b { color: #a7f3c0; }
.me-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(360px, 1fr); gap: 16px; align-items: start; }
.me-side { position: sticky; top: 72px; }
.me-add { display: flex; gap: 8px; margin-bottom: 10px; }
.me-add input:first-child { flex: 1; min-width: 0; }
.me-add input[type="date"] { width: 150px; }
.me-task { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-top: 1px solid var(--line); }
.me-task:first-of-type { border-top: 0; }
.me-task-main { flex: 1; min-width: 0; }
.me-task-title { color: var(--ink); font-weight: 600; }
.me-task.done .me-task-title { color: var(--muted); text-decoration: line-through; }
.me-task.late { box-shadow: inset 3px 0 0 var(--err); padding-left: 10px; }
.me-check { flex: none; width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line-2); background: var(--field); color: #fff; cursor: pointer; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.me-check:hover { border-color: var(--ok); }
.me-task.done .me-check { background: var(--ok); border-color: var(--ok); }
.me-status { width: auto; flex: none; font-size: 12.5px; padding: 4px 8px; border-radius: 99px; font-weight: 600; }
/* one column: flatten the left stack so the AI panel can sit right after "Việc của tôi" */
@media (max-width: 1100px) {
  .me-grid { grid-template-columns: minmax(0, 1fr); }
  .me-grid > .stack { display: contents; }
  .me-grid > .stack > * { margin-top: 0; }
  .me-c-tasks { order: 1; } .me-side { order: 2; position: static; } .me-c-given { order: 3; } .me-c-income { order: 4; } .me-c-resp { order: 5; }
}
@media (max-width: 700px) {
  .me-hero-in { padding: 22px 18px; gap: 16px; justify-content: center; text-align: center; }
  .me-meta { justify-content: center; }
  .me-stats { width: 100%; }
  .me-id h1 { font-size: 24px; }
  .me-add { flex-wrap: wrap; }
  .me-add input:first-child { flex-basis: 100%; }
  .me-add input[type="date"] { flex: 1; width: auto; }
}

/* ── AI co-worker panel */
/* sized so the message box is visible below the hero without scrolling */
.ai-panel { display: flex; flex-direction: column; height: clamp(480px, calc(100vh - 330px), 780px); overflow: hidden; }
.ai-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, var(--gold-soft), var(--panel) 70%); }
.ai-av { width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; background: var(--ring); box-shadow: 0 0 0 3px var(--panel), 0 2px 8px rgba(139, 26, 31, .3); }
.ai-av svg { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .3)); }
.ai-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-live { color: var(--ok); }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 8px; }
.icon-btn:disabled { opacity: .45; cursor: default; }
.ai-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; background: var(--panel-2); }
.ai-msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 92%; }
.ai-msg.me { align-self: flex-end; align-items: flex-end; }
.ai-msg .bubble { padding: 9px 13px; border-radius: 14px; border-top-left-radius: 4px; background: var(--panel); border: 1px solid var(--line); line-height: 1.55; overflow-wrap: anywhere; }
.ai-msg.me .bubble { background: var(--brand); color: #fff; border-color: var(--brand); border-radius: 14px; border-top-right-radius: 4px; white-space: pre-wrap; }
.bubble.md p { margin: 0 0 6px; } .bubble.md p:last-child { margin-bottom: 0; }
.bubble.md ul, .bubble.md ol { margin: 4px 0 6px; padding-left: 20px; }
.bubble.md li { margin: 2px 0; }
.bubble.md .md-h { font-weight: 700; color: var(--accent-text); margin: 8px 0 4px; }
.bubble.md code { background: var(--gray-soft); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.bubble.md hr { border: 0; border-top: 1px solid var(--line); margin: 8px 0; }
.bubble.md .md-table { overflow-x: auto; margin: 6px 0; }
.bubble.md table { border-collapse: collapse; font-size: 12.5px; }
.bubble.md th, .bubble.md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.bubble.md th { background: var(--gold-soft); }
.ai-copy { display: inline-flex; align-items: center; gap: 4px; margin-top: 3px; border: 0; background: none; color: var(--muted); font: inherit; font-size: 11.5px; cursor: pointer; padding: 2px 4px; }
.ai-copy:hover { color: var(--accent-text); }
.bubble.typing { display: flex; gap: 4px; padding: 12px 14px; }
.bubble.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); animation: ai-dot 1s infinite ease-in-out; }
.bubble.typing i:nth-child(2) { animation-delay: .15s; } .bubble.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ai-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }
.ai-setup { font-size: 13px; }
.ai-quick { display: flex; gap: 6px; padding: 8px 12px 0; overflow-x: auto; scrollbar-width: thin; }
.ai-quick .tag { font: inherit; font-size: 12px; white-space: nowrap; }
.ai-quick .tag:disabled { opacity: .5; cursor: default; }
.ai-err { margin: 8px 12px 0; }
.ai-input { display: flex; gap: 8px; padding: 10px 12px; align-items: flex-end; }
.ai-input textarea { flex: 1; resize: none; min-height: 44px; max-height: 140px; }
.ai-input .btn { height: 44px; padding: 0 14px; }
.ai-foot { padding: 0 12px 10px; font-size: 11px; color: var(--muted); line-height: 1.4; }
.ai-steps li { margin-bottom: 8px; }
@media (max-width: 1100px) { .ai-panel { height: 72vh; } }
@media (prefers-reduced-motion: reduce) { .bubble.typing i { animation: none; opacity: .7; } }

/* ── dark theme (chosen per account with the icon in the top-right corner) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14100f; --panel: #1f1918; --panel-2: #27201e; --ink: #f2ebe6; --ink-2: #dacec6; --muted: #a8988f;
  --line: #3a302c; --line-2: #4d403a;
  --brand: #b3262e; --brand-ink: #c9343c; --brand-soft: #36181b; --brand-2: #d69a3a;
  --gold: #e8ae34; --gold-2: #f6d27a; --gold-soft: #33280f; --gold-ink: #f3cf7a;
  --side: #0f0506; --side-active: #2b0e11;
  --ok: #4ade80; --ok-soft: #123522; --warn: #fbbf24; --warn-soft: #3a2a0b; --err: #f87171; --err-soft: #3d1416;
  --info: #93c5fd; --info-soft: #172a4d; --gray-soft: #2e2826;
  --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 2px 10px rgba(0, 0, 0, .3);
  --accent-text: #f29aa0; --field: #1a1514; --row-hover: #2a2220; --row-hl: #3a2d14; --kcol: #1a1514; --overlay: rgba(0, 0, 0, .62);
}
:root[data-theme="dark"] .side .brand, :root[data-theme="dark"] .side .me { border-color: #2b0e11; }
:root[data-theme="dark"] .btn.danger { border-color: #6b2a2d; }
:root[data-theme="dark"] .st-draft { color: #cbd5e1; }
:root[data-theme="dark"] .st-doing { background: #2e1f5e; color: #c4b5fd; }
:root[data-theme="dark"] .b-sample { background: #3a2410; color: #fdba74; border-color: #7c4a1d; }
:root[data-theme="dark"] .warnbox { border-color: #6b4d12; color: #fde68a; }
:root[data-theme="dark"] .note { border-color: #5a4718; }
:root[data-theme="dark"] .r-C { background: #1e3a8a; color: #dbeafe; }
:root[data-theme="dark"] .r-CQ { background: #3b82f6; color: #fff; }
:root[data-theme="dark"] .r-Q { background: #78350f; color: #fde68a; }
:root[data-theme="dark"] .r-T { background: #334155; color: #e2e8f0; }
:root[data-theme="dark"] .r-B { background: transparent; color: #94a3b8; border-color: #475569; }
:root[data-theme="dark"] .band.mg { background: #2a1618; border-color: #4a2427; }
:root[data-theme="dark"] .band.core { background: #2b2310; border-color: #4d3d17; }
:root[data-theme="dark"] .band.sup { background: #221d1a; border-color: #3a302c; }
:root[data-theme="dark"] .ext { background: #334155; color: #e2e8f0; }
:root[data-theme="dark"] .ext-doc, :root[data-theme="dark"] .ext-docx { background: #1e3a8a; color: #dbeafe; }
:root[data-theme="dark"] .ext-xls, :root[data-theme="dark"] .ext-xlsx, :root[data-theme="dark"] .ext-xlsm { background: #14532d; color: #bbf7d0; }
:root[data-theme="dark"] .ext-pdf { background: #7f1d1d; color: #fecaca; }
:root[data-theme="dark"] .ext-vsdx, :root[data-theme="dark"] .ext-vsd, :root[data-theme="dark"] .ext-drawio { background: #4c1d95; color: #ddd6fe; }
:root[data-theme="dark"] .ext-pptx, :root[data-theme="dark"] .ext-ppt { background: #7c2d12; color: #fed7aa; }
:root[data-theme="dark"] .login .card { border-top-color: var(--gold); }
:root[data-theme="dark"] .doc { box-shadow: 0 0 0 1px #3a302c; }
/* printing always uses the light palette */
@media print {
  :root[data-theme="dark"] {
    color-scheme: light;
    --bg: #fff; --panel: #fff; --panel-2: #fcf9f4; --ink: #1f1a1a; --ink-2: #3d3434; --muted: #6f6461; --line: #ece2d4; --line-2: #dccdb8;
    --brand: #8b1a1f; --brand-soft: #f8ebe9; --gold-soft: #fdf4df; --gold-ink: #7a5208; --accent-text: #8b1a1f; --field: #fff; --gray-soft: #eef0f2;
  }
}