/* ===== Bộ token: màu, chữ, bo góc, đổ bóng (tông navy – vàng của logo DTV) ===== */
:root {
  color-scheme: light;
  --brand: #1b2d72; --brand-600: #24399a; --brand-50: #eef1fb; --brand-100: #dfe5f8;
  --gold: #c9962f; --gold-50: #fbf3df;
  --bg: #f5f7fc; --surface: #ffffff; --surface-2: #f9fafd;
  --text: #141b34; --muted: #5a6380; --line: #e2e6f0; --line-2: #cfd5e3;
  --danger: #c0262d; --danger-50: #fdecec; --ok: #137a4c;
  --grid: #b9bfcc; --head: #e4e6ec; --red: #e00000;
  --r-sm: 10px; --r: 14px; --r-lg: 20px; --r-pill: 999px;
  --sh-1: 0 1px 2px rgba(16, 24, 64, .06), 0 6px 18px -10px rgba(16, 24, 64, .22);
  --sh-2: 0 2px 6px rgba(16, 24, 64, .08), 0 24px 60px -20px rgba(16, 24, 64, .35);
  --sans: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --ease: cubic-bezier(.2, .8, .2, 1);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  min-height: 100vh; min-height: 100dvh;
  background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased;
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .45; }
[hidden] { display: none !important; }
.sr-only, .skip:not(:focus) { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip:focus { position: fixed; z-index: 200; top: 8px; left: 8px; background: var(--surface); padding: 10px 14px; border-radius: var(--r-sm); box-shadow: var(--sh-2); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand-600) 60%, transparent); outline-offset: 2px; }
.ic { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ic.big { width: 44px; height: 44px; stroke-width: 1.5; color: var(--brand); }

/* ===== Nút ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: var(--r-pill); border: 1px solid var(--line-2); background: var(--surface); color: var(--text); font-weight: 600; font-size: .94rem; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
.btn:hover:not(:disabled) { border-color: var(--brand-600); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 6px 14px -8px var(--brand); }
.btn.primary:hover:not(:disabled) { background: var(--brand-600); }
.btn .ic { width: 20px; height: 20px; }
.iconbtn { display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none; border: 0; border-radius: var(--r-pill); background: transparent; color: var(--text); padding: 0; transition: background .15s; }
.iconbtn:hover:not(:disabled) { background: var(--brand-50); }
.iconbtn.sm { width: 36px; height: 36px; }
.iconbtn.danger { color: var(--danger); }
.iconbtn.danger:hover { background: var(--danger-50); }
.link { border: 0; background: none; padding: 6px 2px; min-height: 36px; color: var(--brand-600); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.admin-only { display: none !important; }
body.admin .admin-only { display: revert !important; }
body.admin .btn.admin-only, body.admin .tabbar .admin-only { display: inline-flex !important; }
body.admin .menu-list .admin-only { display: flex !important; }
body.admin .menu-sep.admin-only { display: block !important; }

/* ===== Màn hình khởi động (chỉ hiện đến khi tải xong dữ liệu, không chờ giả) ===== */
.plan-loading { width: fit-content; margin: 0 auto; padding: 8px 14px; border-radius: var(--r-pill); background: var(--surface); color: var(--muted); font-size: .9rem; }

/* ===== Thanh trên (header) ===== */
.appbar {
  position: sticky; top: 0; z-index: 40;
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "brand tools" "month month";
  align-items: center; gap: 2px 8px;
  padding: calc(6px + var(--safe-t)) 8px 6px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { grid-area: brand; display: flex; align-items: center; gap: 10px; min-width: 0; text-decoration: none; color: inherit; min-height: 44px; }
.brand-logo { width: 40px; height: 40px; display: block; border-radius: 11px; box-shadow: 0 4px 10px -4px rgba(22, 41, 122, .5); }
.brand-t { display: grid; line-height: 1.15; min-width: 0; }
.brand-t b { font-size: 1.05rem; font-weight: 800; color: var(--brand); white-space: nowrap; }
.brand-t small { font-size: .72rem; font-weight: 600; color: var(--muted); }
.monthnav { grid-area: month; display: flex; align-items: center; justify-content: center; gap: 4px; }
.monthpick { position: relative; display: flex; align-items: center; justify-content: center; min-width: 168px; min-height: 44px; padding: 0 14px; border-radius: var(--r-pill); font-weight: 800; font-size: 1.12rem; color: var(--text); white-space: nowrap; cursor: pointer; }
.monthpick:hover { background: var(--brand-50); }
.monthpick input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.monthpick input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: auto; height: auto; cursor: pointer; }
.appbar-tools { grid-area: tools; display: flex; align-items: center; gap: 6px; }
.desk-only { display: none !important; }

/* Ô tìm kiếm thu gọn: chỉ là nút kính lúp, bấm mới mở ra */
.search { display: flex; align-items: center; }
.search input, #searchClose { display: none; }
body.searching .search { position: absolute; z-index: 2; left: 8px; right: 8px; top: calc(6px + var(--safe-t)); height: 48px; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-pill); box-shadow: var(--sh-1); padding: 0 2px; }
body.searching .search input { display: block; flex: 1; min-width: 0; border: 0; background: none; padding: 0 4px; font-size: 16px; height: 44px; outline: none; }
body.searching #searchClose { display: inline-grid; }
input[type=search]::-webkit-search-cancel-button { display: none; }

/* Dải thông báo */
.banner { display: flex; align-items: center; gap: 10px; padding: 8px 14px; font-size: .86rem; border-bottom: 1px solid var(--line); }
.banner .ic { width: 18px; height: 18px; }
.banner.admin { background: var(--gold-50); color: #5f4508; justify-content: space-between; }
.banner.cached { background: var(--gold-50); color: #5f4508; }
body.admin .banner.admin { display: flex !important; }
.banner .link { color: #5f4508; padding: 0 4px; min-height: 44px; min-width: 44px; }
.desk-inline { display: none; }

/* ===== Nội dung chính ===== */
.main { padding: 12px 10px 16px; outline: none; }
body { padding-bottom: calc(var(--tab-h) + var(--safe-b)); }
body.has-sel { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 72px); }

/* ===== Bảng tháng (giống tờ kế hoạch Excel) ===== */
.swipe-hint { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 0 0 8px; font-size: .8rem; color: var(--muted); }
.swipe-hint .ic { width: 18px; height: 18px; }
.sheet-wrap { position: relative; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; border-radius: var(--r); background: var(--surface); box-shadow: var(--sh-1); scroll-snap-type: x proximity; }
.sheet-wrap:focus-visible { outline-offset: 4px; }
.sheet { container-type: inline-size; min-width: 860px; padding: 12px; --hh: 28px; --rh: 48px; --gw: 0px; --fs: clamp(10.5px, 1.02cqw, 16px); }
.sheet.edit { --gw: 38px; }
.sheet-head { display: flex; align-items: center; justify-content: center; border: 1px solid var(--grid); border-bottom: 0; padding: 8px 10px; margin-left: var(--gw); }
.sheet-title { margin: 0; font-size: var(--title-size, clamp(1.15rem, 2.3cqw, 2.2rem)); font-weight: 800; letter-spacing: .01em; line-height: 1.2; text-align: center; overflow-wrap: anywhere; }
.title-line { position: relative; width: 100%; min-width: 0; }
.title-line.editable { padding-inline: 48px; }
.title-edit { position: absolute; inset-inline-end: 0; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; background: var(--surface); border: 1px solid var(--line); color: var(--brand); }
.title-arial { font-family: Arial, sans-serif; }
.title-segoe { font-family: "Segoe UI", system-ui, sans-serif; }
.title-georgia { font-family: Georgia, serif; }
.title-times { font-family: "Times New Roman", serif; }
.sheet-title.title-regular, .list-title.title-regular { font-weight: 400; }
.title-italic { font-style: italic; }
.title-fields { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) max-content; gap: 8px; }
.title-fields input[type=color] { min-width: 54px; padding: 5px; }
.title-toggles { display: flex; gap: 20px; }
.title-preview { container-type: inline-size; margin-top: 8px; padding: 14px 10px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.dow, .wk { display: grid; grid-template-columns: var(--gw) repeat(7, minmax(0, 1fr)); }
.dow > div:not(.gut) { padding: 5px 2px; text-align: center; font-weight: 700; color: #1f2d8a; border: 1px solid var(--grid); border-left: 0; font-size: calc(var(--fs) * 1.02); }
.dow > div:first-child { border-left: 1px solid var(--grid); }
.sat { --weekend-head: #225c89; --weekend-ink: #17476e; --weekend-date: #e5f2fc; --weekend-slot: #f5faff; }
.sun { --weekend-head: #a7233f; --weekend-ink: #822038; --weekend-date: #fce7eb; --weekend-slot: #fff7f8; }
.slot:is(.sat, .sun) { background: var(--weekend-slot); }
.wk .c1 { border-left: 1px solid var(--grid); }
.dh { display: grid; grid-template-columns: 1fr minmax(28px, 26%); align-items: center; background: var(--head); border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); font-weight: 700; color: #000; font-size: calc(var(--fs) * 1.02); line-height: 1; }
.dh .sd { text-align: center; }
.dh .ld { align-self: stretch; display: grid; place-items: center; border-left: 1px solid var(--grid); font-weight: 500; font-size: .9em; }
.dh .ld.first { color: var(--red); font-weight: 800; }
.dh.out { color: #737b8c; }
.dh.today { background: #ffe680; box-shadow: inset 0 0 0 2px #d9a400; }
.slot { border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); min-height: var(--rh); }
.gut { display: none; }
.sheet.edit .gut { display: grid; place-items: center; }
.rowh { width: calc(100% - 4px); height: calc(100% - 4px); margin: 2px 4px 2px 0; border: 1px solid var(--brand-100); background: var(--brand-50); color: var(--brand); font-size: .8rem; font-weight: 800; padding: 0; border-radius: 8px; display: grid; place-content: center; gap: 0; line-height: 1; }
.rowh .rowh-ic { width: 16px; height: 16px; transform: rotate(90deg); opacity: .7; }
.rowh:hover, .rowh:focus-visible { background: var(--brand); color: #fff; border-color: var(--brand); }

.blk { position: relative; z-index: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 1px; padding: 3px 6px; margin: 0 1px 1px 0; overflow: hidden; line-height: 1.22; font-weight: 500; color: #1f2d8a; font-size: calc(var(--fs) * var(--k, 1)); overflow-wrap: anywhere; outline-offset: -2px; }
.blk .t, .blk .s { display: block; }
.blk.plain { background: #fff; box-shadow: inset 0 0 0 1px var(--line-2); }
.blk.sz-s { --k: .86; } .blk.sz-m { --k: 1; } .blk.sz-l { --k: 1.32; }
.blk.b { font-weight: 800; } .blk.i { font-style: italic; }
.blk .s { font-size: .82em; }
.blk.cl { border-left: 4px dotted rgba(0, 0, 0, .35); }
.blk.cr { border-right: 4px dotted rgba(0, 0, 0, .35); }
.wk .blk { cursor: pointer; transition: filter .15s, box-shadow .15s; }
.wk .blk:hover { filter: brightness(1.06); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .25); }
.blk.dim { opacity: .15; }
.selbox { z-index: 2; pointer-events: none; background: rgba(36, 57, 154, .14); box-shadow: inset 0 0 0 2px var(--brand-600); border-radius: 2px; }

body.admin .slot { cursor: cell; position: relative; }
body.admin .slot:hover { background: var(--brand-50); }
body.admin .slot:hover::after { content: "+"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--brand); font-size: 1.3rem; font-weight: 300; pointer-events: none; }
body.admin .wk .blk[draggable] { cursor: grab; }
body.dragging .wk .blk { pointer-events: none; opacity: .5; }
.slot.over { background: #cfdcff !important; box-shadow: inset 0 0 0 2px var(--brand-600); }

/* ===== Danh sách: thẻ theo ngày ===== */
.list { max-width: 760px; margin: 0 auto; display: grid; gap: 10px; }
.list-title { margin: 2px 4px 6px; font-size: var(--title-size, 1.05rem); font-weight: 800; line-height: 1.2; text-align: center; overflow-wrap: anywhere; }
.day { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; align-items: start; background: var(--surface); border-radius: var(--r-lg); padding: 12px; box-shadow: var(--sh-1); }
.day.today { box-shadow: 0 0 0 2px #d9a400, var(--sh-1); }
.day.out { opacity: .85; }
.day-badge { display: grid; justify-items: center; gap: 1px; padding: 8px 0; border-radius: var(--r); background: var(--brand-50); color: var(--brand); line-height: 1.1; }
.day-badge small { font-size: .72rem; font-weight: 700; letter-spacing: .04em; }
.day-badge b { font-size: 1.6rem; font-weight: 800; }
.day-badge span { font-size: .66rem; color: var(--muted); font-weight: 600; }
.day:is(.sat, .sun) .day-badge { background: var(--weekend-date); color: var(--weekend-ink); }
.day.today .day-badge { background: #ffe680; color: #3d2f00; }
.day-items { display: grid; gap: 8px; }
.blk.li { width: 100%; border: 0; border-radius: var(--r-sm); padding: 12px 14px; min-height: 52px; margin: 0; --fs: 15px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); transition: transform .1s; }
.blk.li:active { transform: scale(.985); }
.blk .range { display: block; font-size: .76em; font-style: normal; font-weight: 600; opacity: .8; margin-top: 3px; }

/* ===== Thẻ trạng thái: trống / lỗi ===== */
.state-card { max-width: 520px; margin: 28px auto; padding: 28px 22px; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-1); text-align: center; display: grid; justify-items: center; gap: 6px; }
.state-card h2 { margin: 6px 0 0; font-size: 1.15rem; }
.state-card p { margin: 0 0 8px; color: var(--muted); }
.state-card.error .ic.big { color: var(--danger); }
.row.center { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ===== Dải nhận dạng "Designed by" (logo DTV) ===== */
.credit { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 14px 0 8px; background: linear-gradient(180deg, #1167cf, #0a52ae); color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18); }
.credit-logo { height: 28px; width: auto; display: block; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .35)); }
.credit i { font-weight: 800; font-size: .86rem; letter-spacing: .01em; }
.credit .ver { margin-left: auto; font-size: .82rem; font-weight: 600; opacity: .95; }
.menu-credit { margin: 10px 0 0; padding: 10px 12px 0; height: auto; background: none; box-shadow: none; color: var(--muted); border-top: 1px solid var(--line); }
.menu-credit .credit-logo { filter: none; }

/* ===== Thanh chọn vùng (trộn ô) ===== */
.selbar { position: fixed; z-index: 45; left: 10px; right: 10px; bottom: calc(var(--tab-h) + var(--safe-b) + 10px); display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px; background: var(--text); color: #fff; border-radius: var(--r-lg); box-shadow: var(--sh-2); font-size: .9rem; animation: up .2s var(--ease); }
.selbar #selInfo { flex: 1; min-width: 0; }
.selbar .iconbtn { color: #fff; }
.selbar .iconbtn:hover { background: rgba(255, 255, 255, .12); }
.selbar .btn.primary { background: var(--gold); border-color: var(--gold); color: #1d1500; box-shadow: none; }
.selbar .btn:not(.primary) { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .25); color: #fff; padding: 0 12px; }

/* ===== Thanh điều hướng dưới (điện thoại) ===== */
.tabbar { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; align-items: stretch; height: calc(var(--tab-h) + var(--safe-b)); padding: 0 6px var(--safe-b); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px); border-top: 1px solid var(--line); }
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 56px; border: 0; background: none; color: var(--muted); font-size: .7rem; font-weight: 600; padding: 6px 0; white-space: nowrap; }
.tabbar button .ic { width: 24px; height: 24px; padding: 3px 14px; box-sizing: content-box; border-radius: var(--r-pill); transition: background .2s var(--ease), color .2s; }
.tabbar button.on { color: var(--brand); }
.tabbar button.on .ic { background: var(--brand-100); }

/* ===== Hộp thoại: bottom sheet trên điện thoại ===== */
dialog { color: var(--text); border: 0; padding: 0; background: transparent; max-width: 100vw; max-height: 100dvh; }
dialog::backdrop { background: rgba(10, 16, 40, .45); backdrop-filter: blur(2px); }
.sheet-dlg { width: 100%; margin: auto 0 0; max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border-radius: 24px 24px 0 0; padding: 10px 18px calc(18px + var(--safe-b)); box-shadow: var(--sh-2); }
.sheet-dlg[open] { animation: up .25s var(--ease); }
.sheet-dlg::before { content: ""; display: block; width: 40px; height: 4px; margin: 0 auto 10px; border-radius: 4px; background: var(--line-2); }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
dialog h3 { margin: 4px 0 12px; font-size: 1.25rem; font-weight: 800; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dlg-head h3 { margin: 0; }
label, .label { display: block; margin: 12px 0 5px; font-size: .82rem; color: var(--muted); font-weight: 600; }
label small { font-weight: 400; }
input, textarea, select { font: inherit; font-size: 16px; width: 100%; min-height: 46px; padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s; }
textarea { resize: vertical; min-height: 0; line-height: 1.4; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand-600); box-shadow: 0 0 0 3px var(--brand-100); }
[aria-invalid="true"] { border-color: var(--danger) !important; box-shadow: 0 0 0 3px var(--danger-50) !important; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.two > * { min-width: 0; }
input[type=date], input[type=month] { min-width: 0; max-width: 100%; -webkit-appearance: none; appearance: none; }
.actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.actions.sticky { position: sticky; bottom: calc(-18px - var(--safe-b)); margin: 12px -18px calc(-18px - var(--safe-b)); padding: 10px 18px calc(10px + var(--safe-b)); background: var(--surface); border-top: 1px solid var(--line); }
.grow { flex: 1; }
.err { color: var(--danger); min-height: 1.3em; margin: 8px 0 0; font-size: .9rem; font-weight: 500; }
.err:empty { min-height: 0; margin: 0; }
.hint { color: var(--muted); font-size: .88rem; margin: 0 0 8px; }
.chk { display: inline-flex; align-items: center; gap: 8px; margin: 0; min-height: 44px; font-size: .95rem; color: var(--text); font-weight: 500; }
.chk input { width: 20px; height: 20px; min-height: 0; margin: 0; accent-color: var(--brand); }
.ed-grid { display: grid; gap: 0 22px; }
.fmt-row { display: flex; align-items: center; gap: 4px 16px; margin: 8px 0 0; flex-wrap: wrap; }
.sizesel { width: auto; min-height: 44px; padding: 6px 10px; }
.sw { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 38px; height: 38px; border-radius: 10px; padding: 0; border: 1px solid rgba(0, 0, 0, .18); }
.swatch.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--brand); }
.swatch.none { background: linear-gradient(135deg, #fff 44%, var(--danger) 44% 56%, #fff 56%); }
input[type=color].cpick { -webkit-appearance: none; appearance: none; width: 38px; height: 38px; min-height: 0; padding: 0; border: 1px solid rgba(0, 0, 0, .18); border-radius: 10px; background: conic-gradient(#ef4444, #eab308, #22c55e, #06b6d4, #3b82f6, #a855f7, #ef4444); cursor: pointer; }
input[type=color].cpick::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color].cpick::-webkit-color-swatch { border: 0; opacity: 0; }
input[type=color].cpick::-moz-color-swatch { border: 0; opacity: 0; }
.preview { border: 1px solid var(--grid); display: grid; width: 220px; max-width: 100%; min-height: 96px; border-radius: 4px; overflow: hidden; }
.preview .blk { margin: 0; --fs: 15px; }
.tpls { margin: 0 -18px 4px; padding: 0 18px 12px; border-bottom: 1px solid var(--line); }
.tpls .label { margin-top: 4px; }
.tpl-scroll { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scroll-snap-type: x proximity; }
.blk.tpl { flex: none; display: inline-flex; min-height: 40px; border: 1px solid rgba(0, 0, 0, .12); border-radius: 10px; padding: 6px 12px; margin: 0; --fs: 13px; white-space: nowrap; scroll-snap-align: start; }
.tpllist { display: grid; gap: 6px; }
.tplrow { display: flex; align-items: center; gap: 4px; }
.tplrow .blk { flex: 1; display: flex; min-height: 40px; padding: 6px 10px; border-radius: 10px; margin: 0; --fs: 13.5px; border: 1px solid rgba(0, 0, 0, .1); }
.tplrow [data-up] .ic { transform: rotate(90deg); }
.detail .blk.big { min-height: 100px; border-radius: var(--r); padding: 16px; margin: 4px 0 0; --fs: 17px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }
.detail dl { display: grid; grid-template-columns: 92px 1fr; gap: 10px 14px; margin: 16px 0 4px; }
.detail dt { color: var(--muted); font-size: .84rem; font-weight: 600; }
.detail dd { margin: 0; white-space: pre-wrap; }

/* Menu "Khác" */
.menu-icon { border-radius: 11px; }
.menu-head { display: flex; align-items: center; gap: 12px; padding: 0 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-head div { flex: 1; display: grid; line-height: 1.25; }
.menu-head b { color: var(--brand); }
.menu-head small { color: var(--muted); }
.menu-list { display: grid; gap: 2px; }
.menu-list button { display: flex; align-items: center; gap: 14px; min-height: 50px; padding: 0 12px; border: 0; border-radius: var(--r-sm); background: none; text-align: left; font-size: .98rem; font-weight: 500; }
.menu-list button:hover:not(:disabled) { background: var(--brand-50); }
.menu-list button .ic { color: var(--brand); }
.menu-list .accent { color: var(--brand); font-weight: 700; border-top: 1px solid var(--line); border-radius: 0 0 var(--r-sm) var(--r-sm); margin-top: 6px; }
.menu-list .danger, .menu-list .danger .ic { color: var(--danger); }
.menu-sep { margin: 10px 12px 2px; font-size: .74rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); }

/* Hướng dẫn */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 8px -18px 4px; padding: 0 18px; }
.tabs button { flex: none; min-height: 44px; border: 0; background: none; padding: 0 12px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
.help h4 { margin: 18px 0 6px; color: var(--brand); font-size: 1rem; }
.help ul, .help ol { margin: 0; padding-left: 22px; }
.help li { margin: 5px 0; }

.pwwrap { position: relative; display: block; }
.pwwrap input { padding-right: 52px; }
.pwtoggle { position: absolute; top: 1px; bottom: 1px; right: 2px; width: 46px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); border-radius: var(--r-sm); }

/* Thông báo ngắn */
.toast { position: fixed; z-index: 250; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 14px); translate: -50% 0; display: flex; align-items: center; gap: 14px; width: max-content; max-width: calc(100vw - 24px); padding: 12px 14px 12px 18px; background: #151b33; color: #fff; border-radius: var(--r); box-shadow: var(--sh-2); font-size: .92rem; animation: up .2s var(--ease); }
.toast.error { background: #8f1a20; }
.toast button { flex: none; min-height: 36px; border: 0; border-radius: var(--r-pill); padding: 0 14px; background: rgba(255, 255, 255, .16); color: #fff; font-weight: 700; }
body.has-sel .toast { bottom: calc(var(--tab-h) + var(--safe-b) + 84px); }

/* ===== Điện thoại: ẩn thanh cuộn (vẫn cuộn bình thường) ===== */
@media (max-width: 899px) {
  html, body, .sheet-wrap, .tpl-scroll, .tabs, dialog, .sheet-dlg { scrollbar-width: none; }
  html::-webkit-scrollbar, body::-webkit-scrollbar, .sheet-wrap::-webkit-scrollbar, .tpl-scroll::-webkit-scrollbar, .tabs::-webkit-scrollbar, .sheet-dlg::-webkit-scrollbar { display: none; }
  /* Dấu hiệu còn nội dung bên phải khi vuốt ngang bảng */
  .sheet-wrap { background: linear-gradient(90deg, var(--surface) 30%, transparent) left / 24px 100% no-repeat local, linear-gradient(270deg, var(--surface) 30%, transparent) right / 24px 100% no-repeat local, radial-gradient(farthest-side at 0 50%, rgba(16, 24, 64, .18), transparent) left / 10px 100% no-repeat scroll, radial-gradient(farthest-side at 100% 50%, rgba(16, 24, 64, .18), transparent) right / 10px 100% no-repeat scroll, var(--surface); }
  .mob-inline { display: inline; }
  body.admin .desk-only, body.admin .btn.desk-only.admin-only { display: none !important; }
}

/* ===== Máy tính bảng / máy tính ===== */
@media (min-width: 900px) {
  .appbar { grid-template-columns: auto 1fr auto; grid-template-areas: "brand month tools"; padding: calc(10px + var(--safe-t)) 20px 10px; gap: 16px; }
  .desk-only { display: inline-flex !important; }
  body.admin .desk-only.admin-only { display: inline-flex !important; }
  .tabbar, .swipe-hint, .mob-inline { display: none !important; }
  .desk-inline { display: inline; }
  .seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--brand-50); border-radius: var(--r-pill); }
  .seg button { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px; border: 0; border-radius: var(--r-pill); background: none; color: var(--muted); font-weight: 700; font-size: .9rem; white-space: nowrap; }
  .seg button .ic { width: 18px; height: 18px; }
  .seg button[aria-pressed="true"] { background: var(--surface); color: var(--brand); box-shadow: var(--sh-1); }
  body.searching .search { position: static; width: 300px; height: 44px; }
  .main { padding: 18px 22px 20px; }
  body, body.has-sel { padding-bottom: 0; }
  .banner { padding: 8px 22px; }
  .selbar { left: 50%; right: auto; translate: -50% 0; bottom: 22px; min-width: 520px; }
  .toast { bottom: 24px; }
  body.has-sel .toast { bottom: 96px; }
  .sheet-dlg { margin: auto; width: min(560px, calc(100vw - 32px)); max-height: 88vh; border-radius: 24px; padding: 22px 24px 22px; }
  .sheet-dlg::before { display: none; }
  .sheet-dlg.wide { width: min(980px, calc(100vw - 32px)); }
  .sheet-dlg.small { width: min(420px, calc(100vw - 32px)); }
  .sheet-dlg.menu { margin: 70px 18px auto auto; width: 320px; padding: 14px; }
  .actions.sticky { bottom: -22px; margin: 14px -24px -22px; padding: 12px 24px; }
  .tpls { margin: 0 -24px 4px; padding: 0 24px 12px; }
  .tabs { margin: 8px -24px 4px; padding: 0 24px; }
  .ed-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
  .tpl-scroll { flex-wrap: wrap; overflow: visible; }
  .swatch, input[type=color].cpick { width: 30px; height: 30px; border-radius: 8px; }
  input, select { min-height: 42px; font-size: 15px; }
  .sheet { min-width: 900px; }
}
@media (min-width: 900px) and (max-width: 1199px) {
  .brand-t { display: none; }
  .seg button { padding: 0 10px; }
  .monthpick { min-width: 150px; }
}
@media (min-width: 1300px) { .main { padding: 20px 32px 20px; } }

/* Thiết bị cảm ứng: vùng chạm đủ lớn ngay cả trên màn hình rộng (máy tính bảng ngang) */
@media (pointer: coarse) {
  .swatch, input[type=color].cpick { width: 40px; height: 40px; }
  .seg button { min-height: 44px; }
}

/* =====================================================================
   GIAO DIỆN CHUYÊN NGHIỆP: thanh trên navy, dải nền, thẻ tóm tắt, bảng tinh gọn
   ===================================================================== */
:root { --navy-900: #0d1b4f; --navy-700: #16307f; --navy-600: #1d3fa6; --navy-500: #2b5bd7; --bg: #f2f5fb; }
.appbar {
  background: linear-gradient(115deg, var(--navy-900) 0%, var(--navy-700) 55%, var(--navy-500) 100%);
  color: #fff; border-bottom: 0; backdrop-filter: none; -webkit-backdrop-filter: none;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset;
}
.appbar .brand-t b { color: #fff; }
.appbar .brand-t small { color: rgba(255, 255, 255, .72); }
.appbar .brand-logo { box-shadow: 0 6px 14px -6px rgba(0, 0, 0, .55), 0 0 0 2px rgba(255, 255, 255, .18); }
.appbar .iconbtn { color: #fff; }
.appbar .iconbtn:hover:not(:disabled) { background: rgba(255, 255, 255, .14); }
.appbar .monthpick { color: #fff; }
.appbar .monthpick:hover { background: rgba(255, 255, 255, .12); }
.appbar .btn { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .28); color: #fff; }
.appbar .btn:hover:not(:disabled) { background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .5); }
body.searching .search { border-color: transparent; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .5); }
body.searching .search .iconbtn { color: var(--text); }
body.searching .search .iconbtn:hover { background: var(--brand-50); }

/* Dải nền navy nối tiếp thanh trên, nội dung nổi lên như thẻ */
.main { position: relative; isolation: isolate; }
.main::before { content: ""; position: absolute; z-index: -1; left: 0; right: 0; top: 0; height: 150px; background: linear-gradient(180deg, var(--navy-700) 0%, #2a4fb8 45%, var(--bg) 100%); }
.banner.admin { background: #102768; color: #ffe39a; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.banner.admin b { color: #ffd060; }
.banner.admin .link { color: #ffe39a; }
.swipe-hint { color: var(--muted); }

/* Thẻ tóm tắt */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 2px 0 14px; }
.stat { display: flex; align-items: center; gap: 12px; min-height: 76px; padding: 12px 14px; overflow: hidden; text-align: left; border: 0; border-radius: 16px; background: var(--surface); box-shadow: 0 1px 2px rgba(13, 27, 79, .06), 0 10px 24px -14px rgba(13, 27, 79, .45); transition: transform .15s var(--ease), box-shadow .15s; min-width: 0; }
.stat:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(13, 27, 79, .08), 0 16px 30px -14px rgba(13, 27, 79, .5); }
.stat:disabled { opacity: 1; cursor: default; }
.stat-ic { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px; color: #fff; }
.stat-ic .ic { width: 22px; height: 22px; }
.s1 .stat-ic { background: linear-gradient(135deg, #3b6cf0, #1d3fa6); }
.s2 .stat-ic { background: linear-gradient(135deg, #f6b73c, #e08a12); }
.s3 .stat-ic { background: linear-gradient(135deg, #22c38e, #0f8f66); }
.s4 .stat-ic { background: linear-gradient(135deg, #a66cf5, #6d3ad6); }
.stat-b { display: grid; min-width: 0; line-height: 1.2; }
.stat-b small { font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-b b { font-size: 1.35rem; font-weight: 800; color: var(--text); margin: 2px 0 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-b b small { font-size: .8rem; text-transform: none; letter-spacing: 0; color: var(--muted); }
.stat-b > span { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Bảng tháng tinh gọn trên màn hình (bản in vẫn kiểu Excel, xem phần @media print) */
.sheet-wrap { border-radius: 18px; box-shadow: 0 1px 2px rgba(13, 27, 79, .06), 0 18px 40px -22px rgba(13, 27, 79, .55); }
.sheet { --grid: #d7dde9; padding: 14px; }
.sheet-head { border: 0; padding: 4px 10px 12px; }
.sheet-title { color: var(--title-color, var(--navy-900)); letter-spacing: .02em; }
.dow > div:not(.gut) { border-color: transparent; background: var(--navy-700); color: #fff; font-weight: 700; letter-spacing: .02em; }
.dow > div:first-child { border-radius: 10px 0 0 0; border-left-color: transparent; }
.dow > div:last-child { border-radius: 0 10px 0 0; }
.dow > div:is(.sat, .sun) { background: var(--weekend-head); color: #fff; }
.dh { background: #eef2fa; color: #1e2a55; }
.dh .ld { color: #6a7392; }
.dh.out { color: #9aa2b8; background: #f6f7fb; }
.dh:is(.sat, .sun):not(.today) { background: var(--weekend-date); color: var(--weekend-ink); }
.dh.out:is(.sat, .sun):not(.today) { color: #59657d; }
.dh.today { background: linear-gradient(180deg, #ffe48a, #ffd352); box-shadow: inset 0 -2px 0 #e0a800; color: #3a2b00; }
.blk { margin: 2px; border-radius: 6px; box-shadow: 0 1px 2px rgba(0, 0, 0, .14); }
.blk.cl { border-left-width: 3px; } .blk.cr { border-right-width: 3px; }
.wk .blk:hover { filter: brightness(1.04); box-shadow: 0 6px 14px -6px rgba(0, 0, 0, .45); transform: translateY(-1px); }
.blk.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px #ffd352, 0 0 0 8px rgba(255, 211, 82, .4); } 100% { box-shadow: 0 1px 2px rgba(0, 0, 0, .14); } }
.blk.plain { box-shadow: inset 0 0 0 1px var(--line-2); }

/* Cột bút chì (chỉ quản trị) */
.sheet.edit { --gw: 34px; }
.sheet:not(.edit) .gut { display: none !important; }
.rowh { width: 28px; height: 28px; margin: 0 6px 0 0; justify-self: center; align-self: center; border-radius: 9px; border: 1px solid var(--brand-100); background: var(--surface); color: var(--navy-600); box-shadow: 0 1px 2px rgba(13, 27, 79, .08); }
.rowh .ic { width: 16px; height: 16px; }
@media (pointer: coarse) { .rowh { width: 32px; height: 32px; } .rowh .ic { width: 18px; height: 18px; } }

/* Danh sách */
.list-title { color: var(--title-color, #fff); text-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.title-surface { padding-block: 8px; border-radius: var(--r); background: var(--surface); }
.title-surface .list-title { text-shadow: none; }
.day { border-radius: 18px; box-shadow: 0 1px 2px rgba(13, 27, 79, .06), 0 10px 24px -16px rgba(13, 27, 79, .45); }
.blk.li { border-radius: 10px; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

/* Thanh dưới */
.tabbar button.on .ic { background: var(--brand-100); color: var(--navy-600); }
.tabbar button.on { color: var(--navy-600); }

@media (max-width: 899px) {
  .stat { gap: 10px; min-height: 66px; padding: 10px; border-radius: 14px; }
  .stat-ic { width: 36px; height: 36px; border-radius: 11px; }
  .stat-ic .ic { width: 19px; height: 19px; }
  .stat-b small { font-size: .66rem; letter-spacing: .02em; }
  .stat-b b { font-size: 1.12rem; }
  .stat-b > span { font-size: .74rem; }
}
@media (min-width: 900px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
  .main::before { height: 190px; }
  .seg { background: rgba(255, 255, 255, .12); }
  .seg button { color: rgba(255, 255, 255, .85); }
  .seg button[aria-pressed="true"] { background: #fff; color: var(--navy-700); }
}

/* Giảm chuyển động theo cài đặt hệ thống */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ===== In: A4 ngang, giữ đúng màu ===== */
@media print {
  @page { size: A4 landscape; margin: 7mm; }
  body { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; padding: 0; }
  .appbar, .tabbar, .banner, .toast, .selbar, .plan-loading, .title-edit, .swipe-hint, dialog, .skip { display: none !important; }
  .main { padding: 0 !important; }
  .sheet-wrap { overflow: visible; box-shadow: none; border-radius: 0; background: none; }
  .sheet { min-width: 0; padding: 0; --rh: 40px; --gw: 0px !important; }
  .gut { display: none !important; }
  .dh.today { background: var(--head); box-shadow: none; }
  .blk.plain { box-shadow: none; }
  .selbox { display: none; }
  .main::before, .stats { display: none !important; }
  .sheet { --grid: #b9bfcc; }
  .sheet-head { border: 1px solid var(--grid); border-bottom: 0; }
  .sheet-title { color: var(--title-color, #000); }
  .dow > div:not(.gut) { background: #fff; color: #1f2d8a; border-color: var(--grid); border-radius: 0 !important; }
  .dow > div:first-child { border-left-color: var(--grid); }
  .dow > div:is(.sat, .sun) { background: var(--weekend-date); color: var(--weekend-ink); }
  .dh, .dh.out { background: var(--head); color: #000; }
  .dh .ld { color: #000; }
  .blk { margin: 0 1px 1px 0; border-radius: 0; box-shadow: none !important; transform: none !important; }
}
