:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --hover: #ebe6dc;
  --ink: #1d1b18;
  --muted: #6b655b; /* đủ tương phản 4.5:1 trên --bg, --card và --hover */
  --line: #ddd6c8;
  --accent: #c2410c;
  --ok: #1f6f4a;
  --warn: #b42318;
  --t-str: #1f6f4a;
  --t-num: #b45309;
  --t-lit: #6d4fb3;
  color-scheme: light;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

/* Chế độ tối: theo máy khi chọn "Tự động", hoặc bật tay bằng nút Sáng/Tối */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513;
    --card: #1f1d1a;
    --hover: #2a2723;
    --ink: #ece7dc;
    --muted: #9a9385;
    --line: #36332d;
    --accent: #f08a4b;
    --ok: #5fc08f;
    --warn: #f07a6e;
    --t-str: #7cc79f;
    --t-num: #f0a35e;
    --t-lit: #b9a3e8;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #161513;
  --card: #1f1d1a;
  --hover: #2a2723;
  --ink: #ece7dc;
  --muted: #9a9385;
  --line: #36332d;
  --accent: #f08a4b;
  --ok: #5fc08f;
  --warn: #f07a6e;
  --t-str: #7cc79f;
  --t-num: #f0a35e;
  --t-lit: #b9a3e8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

code, .mono { font-family: var(--mono); font-size: .92em; }

/* Khung trang */

.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 32px 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  border-right: 1px solid var(--line);
}

.side::-webkit-scrollbar { width: 6px; }
.side::-webkit-scrollbar-thumb { border-radius: 3px; background: var(--line); }
.side::-webkit-scrollbar-track { background: transparent; }

.side-top { display: flex; align-items: center; gap: 8px; margin-bottom: 24px; }

.theme-btn {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  margin-left: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}

.theme-btn:hover { color: var(--ink); border-color: var(--muted); }
.theme-btn svg { display: none; }
.theme-btn[data-mode="auto"] .i-auto,
.theme-btn[data-mode="light"] .i-light,
.theme-btn[data-mode="dark"] .i-dark { display: block; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  text-decoration: none;
}

.nav { display: flex; flex: 1 0 auto; flex-direction: column; gap: 2px; }

.nav a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}

.nav a:hover { color: var(--ink); background: var(--hover); }

.nav a.active {
  color: var(--ink);
  font-weight: 600;
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--line);
}

.nav small, .sheet-head, .sheet-search, .menu-btn, .backdrop { display: none; }

.side-note {
  margin: 12px 0 0;
  padding: 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.main { padding: 56px 48px 80px; min-width: 0; }

.tool { max-width: none; }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

/* Cột tuỳ chọn hẹp bên trái, kết quả rộng bên phải */
.split-side { grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); }
/* Ô soạn chính rộng bên trái, cột thao tác hẹp bên phải */
.split-main { grid-template-columns: minmax(0, 1fr) minmax(240px, 300px); }

.col { min-width: 0; }

/* Công cụ có ô nhập: hai cột cao hết phần màn hình còn lại, ô nhập tự giãn theo */
.split.fill {
  height: max(360px, calc(100vh - 232px - var(--above, 0px)));
  align-items: stretch;
}

.fill > .col { display: flex; flex-direction: column; min-height: 0; }
.fill > .col > textarea { flex: 1 1 auto; min-height: 140px; resize: none; }
.fill .list { flex: 0 1 auto; min-height: 0; overflow-y: auto; }

.col-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  margin-bottom: 8px;
}

.col-head .field-label { margin: 0; }
.col-note { margin: 8px 0 0; }
.col .opts { margin-bottom: 0; }

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.panel .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.stack { display: flex; flex-direction: column; gap: 10px; }

.op-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.op-grid .btn { padding: 11px 10px; }

.opts-top { margin: 0 0 20px; }

.tool-head h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.tool-head p { margin: 0 0 28px; color: var(--muted); }

/* Menu theo nhóm, nút tìm */

.search-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 18px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.search-btn:hover { border-color: var(--muted); color: var(--ink); }
.search-btn span { flex: 1; min-width: 0; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--muted);
  font: 11px var(--mono);
  white-space: nowrap;
}

/* Nhóm trong menu: tiêu đề là nút thu gọn, chấm màu theo nhóm */
.nav-group { margin-bottom: 6px; }
.nav-group + .nav-group { padding-top: 6px; border-top: 1px solid var(--line); }

.nav-h {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 6px 7px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.nav-h:hover { background: var(--hover); }
.nav-dot { flex-shrink: 0; align-self: flex-start; width: 8px; height: 8px; margin-top: 4px; border-radius: 3px; background: var(--gc); }
.nav-hn { flex: 1; min-width: 0; line-height: 1.3; }
.nav-count {
  flex-shrink: 0;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--hover);
  color: var(--muted);
  font: 600 11px/18px var(--mono);
}
.nav-h:hover .nav-count { background: var(--card); }
.nav-h svg { flex-shrink: 0; color: var(--muted); transition: transform .2s; }
.nav-group.closed .nav-h svg { transform: rotate(-90deg); }

/* Thu gọn bằng cách co hàng lưới về 0, có chuyển động trượt */
.nav-items { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .22s ease; }
.nav-group.closed .nav-items { grid-template-rows: 0fr; }
.nav-items-in { display: flex; flex-direction: column; gap: 1px; min-height: 0; overflow: hidden; padding: 2px 0 4px; }
.nav-group.closed .nav-items-in { padding: 0; }
.nav-group a { padding: 6px 10px 6px 22px; }

/* Trang chủ */

.home-head { max-width: 760px; padding-top: 8px; }
.home-head h1 { margin: 0 0 8px; font-size: 34px; letter-spacing: -0.02em; }
.home-head p { margin: 0; font-size: 16px; color: var(--muted); }

.home-search {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(560px, 100%);
  margin-top: 22px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}

.home-search:hover { border-color: var(--ink); }
.home-search span { flex: 1; text-align: left; }

.home-group { margin-top: 36px; }

/* Đủ rộng thì các nhóm xếp thành nhiều cột kiểu báo, mỗi nhóm 2 thẻ một hàng,
   trình duyệt tự cân chiều cao các cột để không trống một bên */
.home-main { container-type: inline-size; }
@container (min-width: 1100px) {
  .home-groups-in { columns: 540px; column-gap: 28px; margin-top: 14px; }
  .home-group { break-inside: avoid; margin: 0 0 26px; padding-top: 8px; }
  .home-group .home-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.home-group h2 { margin: 0 0 12px; font-size: 17px; }


.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(max(240px, calc((100% - 30px) / 4)), 1fr));
  gap: 10px;
}

.hcard {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
}

.hcard:hover { border-color: var(--ink); }
.hcard-t { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hcard-t strong { font-size: 15px; }
.hcard-t span { font-size: 13px; color: var(--muted); }

/* Ô ký hiệu, màu theo nhóm */
.glyph {
  --gc: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--gc) 13%, transparent);
  color: var(--gc);
  font: 700 13px var(--mono);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.g-tai-khoan { --gc: var(--accent); }
.g-van-ban { --gc: var(--t-lit); }
.g-du-lieu { --gc: var(--t-str); }
.g-web { --gc: var(--t-num); }
.g-media { --gc: #0e7490; }
:root[data-theme="dark"] .g-media { --gc: #5cc3d6; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .g-media { --gc: #5cc3d6; } }
.hcard:hover .glyph { background: var(--gc); color: var(--card); }

.pal-list .glyph { width: 30px; height: 30px; border-radius: 7px; font-size: 10.5px; }

/* Trang chủ: cột phải có lời ngỏ, tác giả */

.tool.home { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); gap: 40px; align-items: start; }
.home-main { min-width: 0; }
.home-side { position: sticky; top: 24px; display: flex; flex-direction: column; gap: 14px; padding-top: 8px; }

.hs-card { padding: 18px 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.hs-card h2 { margin: 0 0 10px; font-size: 15px; }
.hs-card p { margin: 0; font-size: 14px; line-height: 1.65; color: var(--ink); }
.hs-card p + p { margin-top: 10px; }

.hs-who { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.hs-avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .02em;
}
.hs-who > div { display: flex; flex-direction: column; }
.hs-label { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.hs-who strong { font-size: 17px; }

.hs-contact { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.hs-contact li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.hs-contact li:last-child { border-bottom: 0; padding-bottom: 0; }
.hs-contact span { color: var(--muted); }
.hs-contact a { color: var(--ink); font-weight: 600; text-decoration: none; overflow-wrap: anywhere; text-align: right; }
.hs-contact a:hover { color: var(--accent); text-decoration: underline; }

.hs-points { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.hs-points li { position: relative; padding-left: 18px; font-size: 13.5px; line-height: 1.55; color: var(--muted); }
.hs-points li::before { content: ""; position: absolute; left: 2px; top: 8px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.hs-points strong { color: var(--ink); }

.hs-new { display: flex; flex-direction: column; gap: 4px; }
.hs-new a { display: flex; align-items: center; gap: 10px; padding: 6px; margin: 0 -6px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.hs-new a:hover { background: var(--hover); }
.hs-new .glyph { width: 32px; height: 32px; border-radius: 8px; font-size: 11px; }
.hs-new a > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.hs-new strong { font-size: 13.5px; }
.hs-new small { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1300px) {
  .tool.home { grid-template-columns: minmax(0, 1fr); }
  .home-side { position: static; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-top: 32px; }
}

/* Câu hỏi chung ở trang chủ */

.home-faq { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--line); }
.home-faq h2 { margin: 0 0 12px; font-size: 17px; }
/* Hai cột cố định: mở một câu chỉ đẩy các câu cùng cột xuống, câu không chạy sang cột kia */
.home-faq-grid { display: grid; grid-template-columns: minmax(0, 1fr); column-gap: 32px; align-items: start; border-top: 1px solid var(--line); }
.home-faq details { border-top: 0; }
@container (min-width: 1100px) {
  .home-faq-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.home-faq details p { font-size: 14px; line-height: 1.6; }

/* Đường dẫn vị trí và phần giới thiệu */

.crumb { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--ink); text-decoration: underline; }

.about {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px 48px;
  max-width: 1200px;
  margin-top: 56px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.about h2 { margin: 0 0 10px; font-size: 17px; }
.about h2 ~ h2 { margin-top: 28px; }
.about p, .about li { font-size: 14.5px; line-height: 1.65; }
.about p { margin: 0; }
.about ol { margin: 0; padding-left: 1.3em; }
.about li + li { margin-top: 6px; }
.about code, .about b code { padding: 1px 5px; border-radius: 4px; background: var(--hover); font: .88em var(--mono); }

.faq details { padding: 11px 0; border-bottom: 1px solid var(--line); }
.faq details:first-child { border-top: 1px solid var(--line); }
.faq summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14.5px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--muted); font-weight: 400; }
.faq details[open] summary::after { content: "−"; }
.faq details p { margin-top: 8px; color: var(--muted); }

.about-side h3 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

.about-side a {
  display: block;
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
}

.about-side a:hover { border-color: var(--ink); }
.about-side strong { display: block; font-size: 14px; }
.about-side span { display: block; font-size: 12px; color: var(--muted); }

/* Ô tìm nhanh */

.palette {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh 16px 16px;
  background: rgba(20, 18, 15, .45);
}

.pal-box {
  display: flex;
  flex-direction: column;
  width: min(620px, 100%);
  max-height: 70vh;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}

.pal-in { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--muted); }
.pal-in input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--ink); font: inherit; font-size: 16px; }
.pal-list { margin: 0; padding: 6px; list-style: none; overflow-y: auto; }

.pal-list li {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.pal-list li.on { background: var(--hover); }
.pal-list strong { font-size: 14px; white-space: nowrap; }
.pal-list span { overflow: hidden; font-size: 13px; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.pal-list em { font-size: 11px; font-style: normal; color: var(--muted); white-space: nowrap; }
.pal-list .pal-none { display: block; color: var(--muted); cursor: default; }
.pal-foot { display: flex; gap: 16px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.pal-foot kbd { margin-right: 2px; }

/* Ô nhập */

.field { display: block; }

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

textarea {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: 14px/1.6 var(--mono);
  resize: vertical;
  outline: none;
}

textarea:focus { border-color: var(--ink); }
textarea[readonly] { background: transparent; }
/* Khung soạn thảo không viền riêng cho ô nhập: viền cả khung khi đang gõ */
.ed:has(.ed-body textarea:focus) { border-color: var(--ink); }
.rx-test:focus-within .rx-hl { border-color: var(--ink); }

/* Viền khi dùng bàn phím (Tab) cho nút, link, ô chọn; ô chữ đã đổi màu viền khi focus */
:where(a, button, summary, select, label, [tabindex]:not([tabindex="-1"]), input[type="checkbox"], input[type="radio"], input[type="color"], input[type="range"], input[type="file"]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Máy đặt giảm chuyển động: bỏ hiệu ứng trượt, mờ dần */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

#tx-in { font-family: inherit; font-size: 15px; }

select, input[type="number"] {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

input[type="number"] { width: 76px; }
input[type="range"], input[type="checkbox"] { accent-color: var(--ink); }
input[type="range"] { width: 160px; }

.opts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
  margin: 16px 0;
}

.check, .inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.hint { margin: 16px 0 8px; font-size: 13px; color: var(--muted); }

/* Nút */

.btns { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: .4; cursor: default; border-color: var(--line); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { opacity: .88; }

.seg {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
}

.seg button {
  padding: 6px 12px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.seg button.on { background: var(--ink); color: var(--bg); }

.stats { font-size: 13px; color: var(--muted); }
.error { color: var(--warn); }

/* Tách cột */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 240px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.chip:hover { border-color: var(--ink); }
.chip.on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.chip .idx { font: 600 12px var(--mono); color: var(--muted); }
.chip.on .idx { color: var(--accent); }
.chip .val {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  color: var(--muted);
}

/* ---- Mã QR: tạo mã, kiểu dáng, đọc mã ---- */

.qr-types { display: flex; flex-wrap: wrap; gap: 2px; width: fit-content; max-width: 100%; margin-bottom: 20px; }

/* Khung nhập của từng loại mã: lưới hai cột, điện thoại một cột */
.qr-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px 16px; align-items: end; }
.qr-fields .full { grid-column: 1 / -1; }
.qr-fields .hint { margin: 0; }
.qr-f { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.qr-f .field-label { margin: 0; }
.qr-f .field-label small { font-weight: 400; }
.qr-fields .text { max-width: none; padding: 8px 10px; font-family: inherit; font-size: 14px; }
.qr-fields .text.mono { font-family: var(--mono); }
.qr-fields textarea { font-family: inherit; }
.qr-fields select { width: 100%; padding: 8px 10px; }
.qr-fields .text:disabled { opacity: .5; }
.qr-f-check { padding-bottom: 9px; }
.qr-unit { display: flex; align-items: center; gap: 8px; }
.qr-unit .text { flex: 1; min-width: 0; }
.qr-unit > span { font-size: 14px; color: var(--muted); }
.qr-adv summary { font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.qr-adv .opts { margin: 12px 0 0; }
.qr-adv .hint { margin: 10px 0 0; }

/* Ô chọn ngân hàng có danh sách gợi ý thả xuống */
.qb-combo { position: relative; }
.qb-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 290px;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
}
.qb-list li { display: flex; flex-direction: column; gap: 1px; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.qb-list li.on { background: var(--hover); }
.qb-list strong { font-size: 14px; }
.qb-list span { overflow: hidden; font-size: 12px; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.qb-list .qb-none { color: var(--muted); font-size: 13px; cursor: default; }

.qr-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.qr-stage .stats { margin: 0; text-align: center; }
.qr-stage .btns { justify-content: center; }
.qr-cap { margin: -4px 0 0; font-size: 14px; font-weight: 600; text-align: center; overflow-wrap: anywhere; }
.qr-cap:empty, .qr-warn:empty { display: none; }

/* Nền khung theo màu nền của mã (JS đặt), mặc định trắng kể cả ở chế độ tối */
.qr-box {
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

#qr-canvas {
  display: block;
  width: 280px;
  height: 280px;
}

#qr-canvas.sq { image-rendering: pixelated; }

.qr-ph { display: none; }

/* Chưa có nội dung: ô nét đứt giữ chỗ, cùng cỡ với mã thật */
.qr-box.empty {
  display: grid;
  place-items: center;
  width: 310px;
  height: 310px;
  background: none;
  border: 1.5px dashed var(--line);
}

.qr-box.empty #qr-canvas { display: none; }
.qr-box.empty .qr-ph { display: block; font-size: 13px; color: var(--muted); }

.qr-style .seg { flex-shrink: 0; }
.qr-logo-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#qr-ecl:disabled { opacity: .6; }

/* Đọc mã */
.pdf-drop.qd-drop { min-height: 280px; }
.qd-drop canvas { max-width: 100%; max-height: 360px; border-radius: 6px; }
.qd-drop.has-img > svg, .qd-drop.has-img > span { display: none; }
.qd-drop.has-img strong { font-size: 14px; font-weight: 500; color: var(--muted); }
.qd-cam { margin-top: 12px; }
/* Máy tính không có máy ảnh sau: nút chụp chỉ hiện trên điện thoại, máy tính bảng */
@media (hover: hover) and (pointer: fine) { .qd-cam { display: none; } }
.qd-out .kv { margin: 0; align-items: baseline; gap: 6px 16px; }
.qd-out dd { overflow-wrap: anywhere; white-space: pre-wrap; }
.qd-out .pw { white-space: pre-wrap; }
.qd-out .hint { margin: 14px 0 0; }
.qd-acts { margin-top: 16px; }
.qd-ok { color: var(--ok); font-weight: 600; }
.qd-accs { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.qd-acc { display: grid; gap: 3px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.qd-acc-h strong { font-size: 15px; }
.qd-acc-h span { margin-left: 8px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.qd-acc small { font-size: 12px; color: var(--muted); }
.qd-acc em { font-style: normal; color: var(--warn); }
.qd-acc .pw { justify-self: start; font-size: 14px; }

@media (max-width: 760px) {
  #qr-canvas { width: 220px; height: 220px; }
  .qr-box.empty { width: 250px; height: 250px; }
  .qr-fields { grid-template-columns: minmax(0, 1fr); }
  .qr-f-check { padding-bottom: 0; }
  .qr-stage { padding: 20px 14px; }
  /* Ô nhỏ giữ chiều cao theo số dòng, không theo cỡ chung 180px của ô nhập trên điện thoại */
  .split #qr-payload, .split .qr-fields textarea { height: auto; }
}
/* ---- Hết phần Mã QR ---- */

/* Thời gian */

.now {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 40px;
  margin-bottom: 28px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.now .pw { display: block; font-size: 22px; font-weight: 600; }

.kv-label { display: block; font-size: 13px; color: var(--muted); }

input.text {
  width: 100%;
  max-width: 320px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: 15px var(--mono);
  outline: none;
}

input.text:focus { border-color: var(--ink); }


.kv {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 2px 16px;
  margin: 10px 0 0;
}

.kv:empty { display: none; }
.kv dt { font-size: 13px; color: var(--muted); }
.kv dd { margin: 0; }
.kv .pw { font-size: 15px; }

/* JSON: hai khung soạn thảo, cột thao tác ở giữa */

.tool.wide { max-width: none; }
.tool.wide .tool-head p { margin-bottom: 20px; }

.ed-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.ed {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  overflow: hidden;
}

.ed-bar, .ed-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px 0 12px;
  background: var(--hover);
}

.ed-bar { min-height: 40px; border-bottom: 1px solid var(--line); }
.ed-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.ed-tools { display: flex; gap: 2px; }

.ed-btn {
  padding: 5px 8px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.ed-btn:hover { background: var(--line); }

.seg-sm button { padding: 4px 10px; }

.ed-body {
  position: relative;
  display: flex;
  height: max(320px, calc(100vh - 296px));
}

.gutter {
  flex-shrink: 0;
  min-width: 44px;
  margin: 0;
  padding: 12px 8px 60px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font: 13px/1.6 var(--mono);
  text-align: right;
  user-select: none;
}

.gutter .err { margin-right: -4px; padding: 0 4px; color: var(--bg); background: var(--warn); border-radius: 3px; font-weight: 400; }

.ed-body textarea {
  flex: 1;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: none;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  resize: none;
}

.ed-status {
  min-height: 30px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.ed-status span:last-child { text-align: right; }

.ed.full {
  position: fixed;
  inset: 0;
  z-index: 40;
  border: 0;
  border-radius: 0;
}

.ed.full .ed-body { flex: 1; height: auto; min-height: 0; }
body.noscroll { overflow: hidden; }

.ed-mid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ed-mid .btn, .ed-mid select, .ed-mid input.text {
  width: 100%;
  max-width: none;
  text-align: center;
}

.ed-mid select { padding: 8px 6px; font-size: 13px; }
.ed-mid input.text { font-size: 13px; padding: 8px; text-align: left; }
.ed-mid .check { font-size: 13px; padding: 4px 2px; }
.ed-mid .btn.on, .ed-mid select.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.ed-mid #js-validate { margin-bottom: 8px; }
.ed-mid #js-dl { margin-top: 8px; }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.tree {
  position: absolute;
  inset: 0;
  padding: 12px 14px;
  overflow: auto;
  font: 13px/1.7 var(--mono);
}

.tree summary { list-style: none; cursor: pointer; white-space: nowrap; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary::before {
  content: "▸";
  display: inline-block;
  width: 14px;
  color: var(--muted);
}
.tree details[open] > summary::before { content: "▾"; }

.tree .kids {
  margin-left: 5px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.tree .leaf { padding-left: 14px; word-break: break-all; }
.tree .t { margin-left: 6px; color: var(--muted); }
.tree .leaf .k + .t { margin-left: 0; }

.tree .k, .tree .v { border-radius: 3px; cursor: pointer; }
.tree .k:hover, .tree .v:hover { background: var(--hover); }
.tree .k.root { color: var(--muted); cursor: default; }
.tree .k.root:hover { background: none; }
.tree .copied { background: var(--hover); }

.v-string { color: var(--t-str); }
.v-number { color: var(--t-num); }
.v-boolean, .v-null { color: var(--t-lit); }

/* Markdown: hai khung, không có cột giữa */

.ed-grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.ed-check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* Khung soạn: lớp tô màu (pre) nằm dưới ô nhập trong suốt, hai lớp phải cùng cỡ chữ, cùng lề */
.md-editor { --gut: 44px; }

.md-editor .md-hl,
.md-editor textarea {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 12px 14px 40px calc(var(--gut) + 14px);
  border: 0;
  font: 13px/1.6 var(--mono);
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  overflow-y: scroll;
}

.md-hl {
  counter-reset: ln;
  overflow: hidden;
  color: var(--ink);
  pointer-events: none;
  background: linear-gradient(to right, var(--hover) 0 var(--gut), var(--line) var(--gut) calc(var(--gut) + 1px), transparent 0);
}

.md-hl .ln { display: block; position: relative; }
.md-hl .ln::before {
  counter-increment: ln;
  content: counter(ln);
  position: absolute;
  left: calc(-1 * var(--gut) - 14px);
  width: calc(var(--gut) - 8px);
  text-align: right;
  color: var(--muted);
}

.md-editor textarea {
  height: 100%;
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
  resize: none;
}

.md-editor textarea::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); color: transparent; }

.h-head { color: var(--accent); font-weight: 700; }
.h-strong { font-weight: 700; }
.h-em { font-style: italic; }
.h-del { text-decoration: line-through; color: var(--muted); }
.h-code, .h-fence { color: var(--t-str); }
.h-link { color: var(--t-lit); }
.h-url { color: var(--muted); text-decoration: underline; }
.h-punc, .h-list { color: var(--t-num); }
.h-quote { color: var(--t-num); }
.h-quote-text { color: var(--muted); font-style: italic; }

/* Phần xem trước */

.md-body {
  flex: 1;
  min-width: 0;
  padding: 20px 28px 48px;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.65;
  overflow-wrap: break-word;
}

.md-body > :first-child { margin-top: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 {
  margin: 1.4em 0 .6em;
  line-height: 1.25;
  font-weight: 700;
}
.md-body h1 { font-size: 1.9em; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.md-body h2 { font-size: 1.45em; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.md-body h3 { font-size: 1.2em; }
.md-body h4 { font-size: 1.05em; }
.md-body h5 { font-size: .95em; }
.md-body h6 { font-size: .85em; color: var(--muted); }
.md-body p, .md-body ul, .md-body ol, .md-body blockquote, .md-body pre, .md-body table { margin: 0 0 1em; }
.md-body ul, .md-body ol { padding-left: 1.7em; }
.md-body li + li { margin-top: .25em; }
.md-body li > ul, .md-body li > ol { margin: .25em 0 0; }
.md-body li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.4em; }
.md-body li > input[type="checkbox"] { margin: 0 .5em 0 0; vertical-align: middle; }
.md-body a { color: var(--accent); }
.md-body blockquote { padding: .1em 1em; border-left: 4px solid var(--line); color: var(--muted); }
.md-body blockquote > :last-child { margin-bottom: 0; }
.md-body code {
  padding: .15em .4em;
  border-radius: 4px;
  background: var(--hover);
  font: .88em var(--mono);
}
.md-body pre {
  padding: 14px 16px;
  overflow-x: auto;
  border-radius: 8px;
  background: var(--hover);
  line-height: 1.5;
}
.md-body pre code { padding: 0; background: none; font-size: 13px; }
.md-body table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.md-body th, .md-body td { padding: 6px 13px; border: 1px solid var(--line); }
.md-body th { font-weight: 700; background: var(--hover); }
.md-body tr:nth-child(even) td { background: color-mix(in srgb, var(--hover) 45%, transparent); }
.md-body img { max-width: 100%; height: auto; }
.md-body hr { height: 0; margin: 1.6em 0; border: 0; border-top: 2px solid var(--line); }
.md-empty { color: var(--muted); }

/* Xuất PDF: chỉ in phần xem trước, luôn nền trắng chữ đen */
@media print {
  /* Chế độ tối làm trình duyệt tô cả lề giấy màu tối, nên khi in luôn về nền sáng */
  :root:has(body.print-md) { color-scheme: light; background: #fff; }
  body.print-md {
    --bg: #fff; --card: #fff; --hover: #f2f2f2; --ink: #111; --muted: #555; --line: #ccc; --accent: #b4370a;
    background: #fff;
  }
  body.print-md .side, body.print-md .backdrop, body.print-md .toast,
  body.print-md .tool:not(#t-markdown), body.print-md #t-markdown .tool-head,
  body.print-md #md-left, body.print-md #md-right .ed-bar, body.print-md #md-right .ed-status { display: none !important; }
  body.print-md .app, body.print-md .ed-grid { display: block; }
  body.print-md .main { padding: 0; }
  body.print-md .ed { border: 0; background: none; overflow: visible; }
  body.print-md .ed-body { height: auto; display: block; }
  body.print-md .md-body { padding: 0; overflow: visible; color: #111; }
}

/* PDF */

.pdf-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: max(360px, calc(100vh - 250px));
  padding: 24px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s;
}

.pdf-drop:hover, .dropping .pdf-drop { border-color: var(--accent); }
.pdf-drop svg { color: var(--accent); margin-bottom: 6px; }
.pdf-drop strong { font-size: 18px; color: var(--ink); }
.pdf-drop span { font-size: 14px; }
.pdf-drop small { margin-top: 14px; font-size: 12px; }

.dropping .pdf-work { outline: 2px dashed var(--accent); outline-offset: 8px; border-radius: 8px; }

.pdf-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.pdf-bar .btns { align-items: center; }
.pdf-range { width: 180px; padding: 7px 10px; font-size: 13px; }

.pdf-sources { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.psrc {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 4px 4px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
  font-size: 13px;
}

.psrc b {
  padding: 1px 7px;
  border-radius: 4px;
  background: var(--c);
  color: #fff;
  font: 600 12px var(--mono);
}

.psrc button {
  padding: 2px 6px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.psrc button:hover { background: var(--hover); color: var(--ink); }

.pdf-grid {
  --tw: 168px;
  --th: 210px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tw), 1fr));
  gap: 14px;
  align-items: start;
}

.pcard {
  position: relative;
  padding: 10px 10px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  user-select: none;
}

.pcard:hover { border-color: var(--muted); }
.pcard.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pcard.dragging { opacity: .35; }

.pcard.drop-before::before, .pcard.drop-after::after {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.pcard.drop-before::before { left: -9px; }
.pcard.drop-after::after { right: -9px; }

.pcheck {
  position: absolute;
  top: -8px;
  left: -8px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: transparent;
  font-size: 12px;
  font-weight: 700;
}

.pcard.sel .pcheck { border-color: var(--accent); background: var(--accent); color: #fff; }

.pdf-grid[data-size="s"] { --tw: 128px; --th: 160px; }
.pdf-grid[data-size="l"] { --tw: 250px; --th: 330px; }

.pthumb {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--th);
  overflow: hidden;
  border-radius: 6px;
  background: var(--hover);
}

.pthumb canvas {
  display: block;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
  transition: transform .2s;
}

.pload { font-size: 12px; color: var(--muted); }

.pact {
  position: absolute;
  left: 50%;
  bottom: 42px;
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity .12s;
}

.pcard:hover .pact, .pcard:focus-within .pact { opacity: 1; }
@media (hover: none) { .pact { opacity: 1; } }

.pact button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
}

.pact button:hover { background: var(--hover); }

.pmeta { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; }
.pnum { font: 600 13px var(--mono); }
.ptag {
  padding: 1px 6px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: var(--c);
  font: 600 11px var(--mono);
}
.pedit { margin-left: auto; color: var(--ok); }

.pdf-foot {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
  padding: 12px 0 16px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.pdf-foot .btns { align-items: center; gap: 8px 10px; }

/* Xem trang lớn */

.pview {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  background: rgba(20, 18, 15, .88);
}

.pview-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.pview-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pview-bar .btns { align-items: center; }
.pv-zoom { display: inline-flex; align-items: center; gap: 6px; }
.pv-zoom .btn { width: 34px; padding: 8px 0; font-size: 15px; }
#pv-zv { min-width: 46px; text-align: center; font: 600 13px var(--mono); }

.pview-stage {
  flex: 1;
  display: flex;
  overflow: auto;
  padding: 24px;
}

#pv-canvas {
  display: block;
  margin: auto;
  background: #fff;
  box-shadow: 0 4px 30px rgba(0, 0, 0, .5);
}

/* Sửa trang */

.ped-title { font-size: 14px; font-weight: 600; margin-left: 4px; }
.ped-props { align-items: center; }
#ped-size { width: 64px; }
#ped-color {
  width: 38px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer;
}
#ped-bold.on, .sign-dlg .btn.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
#ped-hint { margin: 0 0 10px; }

.ped-stage {
  height: max(420px, calc(100vh - 290px));
  padding: 16px;
  overflow: auto;
  border-radius: 10px;
  background: var(--hover);
}

.ped-page {
  position: relative;
  width: fit-content;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .2);
}

#ped-canvas { display: block; }
.ped-layer { position: absolute; inset: 0; }

.ov { position: absolute; cursor: move; touch-action: none; }
.ov.on { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.ov-text {
  white-space: pre;
  line-height: 1.25;
  font-family: "Noto Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-left: .1em;
}
.ov-text.editing { min-width: 2em; cursor: text; outline: 1.5px solid var(--accent); background: rgba(255, 255, 255, .7); }
.ov-img { background: no-repeat center / 100% 100%; }
.ov-white { background: #fff; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }

.ov-h {
  position: absolute;
  right: -7px;
  bottom: -7px;
  display: none;
  width: 13px;
  height: 13px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  cursor: nwse-resize;
}
.ov.on .ov-h { display: block; }

/* Khung ký tên */

.sign-dlg {
  width: min(640px, calc(100vw - 32px));
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
}

.sign-dlg::backdrop { background: rgba(20, 18, 15, .45); }

#sign-pad {
  display: block;
  width: 100%;
  height: 220px;
  margin: 4px 0 14px;
  border: 1px dashed var(--muted);
  border-radius: 8px;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
}

.sign-actions { display: flex; justify-content: space-between; gap: 8px; }

/* Đang xử lý */

.busy {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(20, 18, 15, .3);
}

.busy span {
  padding: 14px 22px;
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
}

/* Âm thanh */

.au-drop { min-height: max(320px, calc(100vh - 330px)); }
.dropping .au-work, .dropping #au-jwork { outline: 2px dashed var(--accent); outline-offset: 8px; border-radius: 8px; }

.au-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.au-head > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.au-name { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wave {
  position: relative;
  height: 180px;
  margin-top: 30px; /* chỗ cho nhãn giờ trên hai tay kéo */
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.wave canvas { display: block; width: 100%; height: 100%; }

.wave-sel {
  position: absolute;
  top: 0;
  bottom: 0;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  cursor: grab;
}

/* Chế độ "Bỏ đoạn chọn": vùng chọn gạch chéo, nghĩa là phần này sẽ bị bỏ đi */
.wave-sel.drop {
  background: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--warn) 22%, transparent) 0 6px, transparent 6px 12px);
}

.wave-h {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 16px;
  margin-left: -8px;
  cursor: ew-resize;
  z-index: 2;
}

.wave-h::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 7px;
  width: 2px;
  background: var(--accent);
}

.wave-h::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  width: 12px;
  height: 28px;
  margin-top: -14px;
  border-radius: 4px;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

.wave-h span {
  position: absolute;
  top: -22px;
  left: 50%;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font: 600 11px var(--mono);
  white-space: nowrap;
  /* --p (0..1) là vị trí tay cầm: ở mép trái nhãn lệch sang phải, ở mép phải lệch sang trái, nên không tràn khỏi dải */
  transform: translateX(calc(var(--p, .5) * -100%));
}

.wave-play {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
  pointer-events: none;
  z-index: 1;
}

.wave-ruler {
  position: relative;
  height: 22px;
  margin: 4px 0 0;
  font: 11px var(--mono);
  color: var(--muted);
}

.wave-ruler span { position: absolute; top: 4px; transform: translateX(-50%); white-space: nowrap; }
.wave-ruler span:first-child { transform: none; }

.au-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.au-controls .btns { align-items: center; gap: 10px 14px; }
input.text.au-time { width: 92px; padding: 7px 10px; font-size: 14px; }
#au-xfv { white-space: nowrap; }
.au-play { min-width: 160px; }

.au-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }

.au-item {
  position: relative;
  display: grid;
  grid-template-columns: auto auto auto minmax(140px, 1.2fr) minmax(120px, 2fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.au-item.dragging { opacity: .35; }
.au-item.drop-before::before, .au-item.drop-after::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.au-item.drop-before::before { top: -6px; }
.au-item.drop-after::after { bottom: -6px; }

.au-grip { color: var(--muted); cursor: grab; letter-spacing: -2px; }
.au-idx { font: 600 13px var(--mono); color: var(--muted); min-width: 1.5em; }
.au-meta { display: flex; flex-direction: column; min-width: 0; }
.au-meta strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.au-meta span { font-size: 12px; color: var(--muted); }
.au-mini { width: 100%; height: 36px; display: block; }

.au-pbtn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}

.au-pbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.au-acts { display: flex; gap: 2px; }
.au-acts button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  cursor: pointer;
}
.au-acts button:hover { background: var(--hover); }

.au-foot { margin-top: 20px; }

/* ==== Video (js/video.js) ==== */

.dropping .vd-work { outline: 2px dashed var(--accent); outline-offset: 8px; border-radius: 8px; }
.vd-warn {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  color: var(--warn);
  font-size: 13px;
}
.vd-warn .vd-retry { margin-left: 4px; padding: 4px 12px; font-size: 13px; }

.vd-stage { position: relative; border-radius: 10px; overflow: hidden; background: #000; }
.vd-stage video { display: block; width: 100%; height: min(56vh, 520px); background: #000; }
.vd-noplay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 16px;
  color: #ddd;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}

.wave.vd-tl { height: 64px; overflow: visible; }
.vd-tl canvas { border-radius: 9px; }
.vd-tl .wave-sel { background: none; box-shadow: inset 0 0 0 2px var(--accent); border-radius: 2px; }
.vd-tl .wave-h::after { height: 24px; margin-top: -12px; }
/* Nhãn giờ cuối thước nằm lọt trong khung, không tràn ra phải */
#vd-ruler span:last-child:not(:first-child) { transform: translateX(-100%); }

.vd-controls { justify-content: flex-start; gap: 12px 24px; }
.vd-times .btn { padding: 7px 10px; }

.vd-panel { margin-top: 20px; }
.vd-panel .opts, .vd-panel .hint { margin: 0; }
.vd-panel.vd-off .opts, .vd-panel.vd-off .hint, .vd-panel.vd-off .vd-act { opacity: .45; pointer-events: none; }
.vd-panel .vd-warn { margin: 0; }
/* Tên lựa chọn dài ("OGG (giữ nguyên chất lượng, nhanh)") không đẩy trang rộng ra trên điện thoại */
.vd-panel .inline { max-width: 100%; }
.vd-panel .inline select { min-width: 0; max-width: 100%; }
.vd-act { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.vd-act .btn.primary { min-width: 140px; }
.vd-bad { color: var(--warn); font-weight: 600; }
.vd-done { margin: 0; font-size: 14px; color: var(--ok); }
.vd-h { margin: 0; font-size: 15px; }
.vd-h2 { padding-top: 16px; border-top: 1px solid var(--line); }
.vd-result { display: flex; flex-direction: column; gap: 10px; }
.vd-result img {
  display: block;
  max-width: 100%;
  max-height: 360px;
  margin-right: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
#vd-every { width: 72px; }

.vd-prog {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 12px 0 16px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.vd-bar { flex: 1; height: 8px; border-radius: 4px; background: var(--hover); overflow: hidden; }
.vd-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.vd-prog .stats { min-width: 150px; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .vd-stage video { height: auto; max-height: 50vh; aspect-ratio: 16 / 9; }
  .vd-controls .btns { width: 100%; }
  .vd-times { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px 10px; }
  .vd-times .inline { display: contents; }
  .vd-times input.text.au-time { width: 100%; max-width: none; }
  .vd-prog { flex-wrap: wrap; }
  .vd-prog .vd-bar { flex-basis: 100%; }
  .vd-prog .stats { flex: 1; min-width: 0; }
}

/* ==== Hết phần Video ==== */

/* So sánh văn bản */

.df-sum { margin-left: auto; font-weight: 600; }
.d-add { color: var(--ok); }
.d-del { color: var(--warn); }
.d-same { color: var(--muted); }

.diff { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.diff .empty { margin: 0; padding: 18px; }

.dtab { width: 100%; border-collapse: collapse; table-layout: fixed; font: 13px/1.6 var(--mono); }
.dtab td { padding: 0 10px; vertical-align: top; white-space: pre-wrap; overflow-wrap: anywhere; }
.dtab col.dn { width: 52px; }
.dtab col.ds { width: 22px; }
.dtab td.dn { color: var(--muted); text-align: right; user-select: none; border-right: 1px solid var(--line); }
.dtab td.ds { padding: 0; text-align: center; user-select: none; }
.dtab td.d-del { background: color-mix(in srgb, var(--warn) 11%, transparent); }
.dtab td.d-add { background: color-mix(in srgb, var(--ok) 13%, transparent); }
.dtab td.d-empty { background: repeating-linear-gradient(-45deg, transparent 0 5px, color-mix(in srgb, var(--line) 60%, transparent) 5px 6px); }
.dtab del { background: color-mix(in srgb, var(--warn) 30%, transparent); text-decoration: none; border-radius: 2px; }
.dtab ins { background: color-mix(in srgb, var(--ok) 32%, transparent); text-decoration: none; border-radius: 2px; }
.dtab tr.d-fold td { padding: 2px; background: var(--hover); text-align: center; }
.d-fold button { border: 0; background: none; color: var(--muted); font: 12px inherit; font-family: inherit; cursor: pointer; padding: 3px 8px; }
.d-fold button:hover { color: var(--ink); }

/* Regex */

.rx-pattern {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font: 16px var(--mono);
  color: var(--muted);
}
.rx-pattern:focus-within { border-color: var(--ink); }
.rx-pattern input { min-width: 0; border: 0; outline: 0; background: none; color: var(--ink); font: inherit; padding: 11px 0; }
#rx-src { flex: 1; }
#rx-flags { width: 64px; }
.rx-flags { margin: 10px 0 18px; gap: 6px 16px; }
.rx-flags .check { font-size: 13px; }
.rx-gap { margin-top: 18px; }

.rx-test { position: relative; height: 190px; }
.rx-test .rx-hl, .rx-test textarea {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: 14px/1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow-y: scroll;
}
.rx-test .rx-hl { overflow: hidden; color: transparent; background: var(--card); border-color: var(--line); pointer-events: none; }
.rx-test textarea { height: 100%; background: transparent; resize: none; caret-color: var(--ink); }
.rx-hl mark { color: transparent; background: color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 2px; box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 50%, transparent); }
.rx-hl mark.alt { background: color-mix(in srgb, var(--t-lit) 28%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--t-lit) 50%, transparent); }
.rx-hl mark.zero { display: inline-block; width: 2px; height: 1.2em; vertical-align: text-bottom; background: var(--accent); }
.rx-rep { max-width: none; margin-bottom: 8px; }

.cheat { width: 100%; border-collapse: collapse; font-size: 13px; }
.cheat td, .cheat th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.cheat th { font-size: 12px; color: var(--muted); font-weight: 600; }
.cheat code { font: 12.5px var(--mono); color: var(--accent); white-space: pre; }
.cheat em { color: var(--muted); font-size: 12px; }
.rx-res code { color: var(--ink); background: var(--hover); padding: 1px 5px; border-radius: 4px; cursor: pointer; white-space: pre-wrap; }
.rx-table { max-height: 320px; overflow: auto; }

/* JWT */

.jw-colored { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--hover); font: 12.5px/1.6 var(--mono); overflow-wrap: anywhere; }
.jw-colored:empty { display: none; }
.jw-p0 { color: var(--warn); }
.jw-p1 { color: var(--t-lit); }
.jw-p2 { color: var(--t-str); }
.jw-dot { color: var(--ink); font-weight: 700; }
.jw-badge { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.jw-badge:empty { display: none; }
.jw-badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.jw-badge.bad { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.jw-badge:not(.ok):not(.bad) { background: var(--hover); color: var(--muted); }
.jw-claims { margin-top: 14px; grid-template-columns: 130px 1fr; gap: 8px 16px; }
.jw-claims dd { display: flex; flex-direction: column; font-size: 14px; }
.jw-claims small { font-size: 12px; }
.jw-ok { color: var(--ok); }
.jw-bad { color: var(--warn); }
.jw-note { color: var(--muted); }
#jw-key { min-height: 0; }

/* Mã băm */

.hs-hmac { margin-top: 14px; }
.hs-hmac .text { max-width: none; }
.hs-drop { min-height: 220px; }
.hs-out { grid-template-columns: 110px minmax(0, 1fr); gap: 6px 14px; margin: 0; }
.hs-out .pw { font-size: 13.5px; word-break: break-all; text-align: left; }
.hs-out .pw.hs-hit { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.hs-cmp { margin-top: 20px; }
.hs-cmp .text { max-width: none; font-size: 13px; }
.hs-ok { color: var(--ok); font-weight: 600; }

/* Nén ảnh */

.im-drop { min-height: max(300px, calc(100vh - 330px)); }
.im-dim { opacity: .45; }
.im-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.im-card { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; background: var(--card); overflow: hidden; }
.im-thumb {
  height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-conic-gradient(var(--hover) 0 25%, transparent 0 50%) 0 0 / 16px 16px;
}
.im-thumb img { max-width: 100%; max-height: 100%; display: block; }
.im-meta { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px 0; font-size: 12.5px; color: var(--muted); }
.im-meta strong { font-size: 13.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-ok { color: var(--ok); font-weight: 600; }
.im-bad { color: var(--warn); font-weight: 600; }
.im-acts { display: flex; gap: 6px; padding: 10px 12px 12px; }
.im-acts .btn:first-child { flex: 1; }

/* Scan tài liệu */

.sc-drop { min-height: max(320px, calc(100vh - 330px)); }
.sc-pick { justify-content: center; margin-top: 10px; }
.sc-pick .btn { min-width: 130px; padding: 11px 18px; font-size: 14px; }
.sc-snap { font-size: 13px; color: var(--muted); }
.sc-hint { margin: 0 0 14px; }
.sc-card .pthumb img { display: block; max-width: 100%; max-height: 100%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .18); }
.sc-tag { color: var(--muted); }
.sc-warn {
  margin-left: auto;
  padding: 1px 6px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  color: var(--warn);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.sc-opt { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.sc-row { align-items: center; margin-bottom: 10px; }
#sc-ehint { margin: 4px 0 10px; }
#sc-ehint.sc-bad { color: var(--warn); font-weight: 600; }

.sc-stage {
  --pad: 28px;
  position: relative;
  display: grid;
  place-items: center;
  height: max(420px, calc(100vh - 330px));
  padding: var(--pad);
  overflow: hidden;
  border-radius: 10px;
  background: var(--hover);
  user-select: none;
  -webkit-user-select: none;
}

.sc-frame { position: relative; }
#sc-canvas { display: block; width: 100%; height: 100%; box-shadow: 0 2px 14px rgba(0, 0, 0, .2); }
.sc-quad { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#sc-dim { fill: rgba(20, 18, 15, .5); fill-rule: evenodd; }
#sc-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }

/* Chấm góc: vùng bấm 44 px cho ngón tay, phần nhìn thấy nhỏ hơn */
.sc-h {
  position: absolute;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: grab;
  touch-action: none;
}

.sc-h::after {
  content: "";
  position: absolute;
  inset: 11px;
  border: 2.5px solid #fff;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 70%, transparent);
  box-shadow: 0 1px 5px rgba(0, 0, 0, .45);
}

.sc-h:focus-visible { outline: none; }
.sc-h:focus-visible::after { box-shadow: 0 0 0 3px var(--ink); }
/* Đang kéo: chấm thành vòng rỗng để thấy góc giấy bên dưới */
.sc-h.on { cursor: grabbing; }
.sc-h.on::after { inset: 6px; background: none; }

.sc-loupe {
  position: absolute;
  z-index: 2;
  width: 120px;
  height: 120px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
  pointer-events: none;
}

/* Ảnh kết quả vừa khung, giữ tỉ lệ */
.sc-result {
  position: absolute;
  inset: 0;
  max-width: calc(100% - 2 * var(--pad));
  max-height: calc(100% - 2 * var(--pad));
  margin: auto;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .2);
  transition: opacity .15s;
}
.sc-result.sc-old { opacity: .45; }

.sc-wait {
  position: absolute;
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .15);
}

/* Đổi màu */

.mc-main { display: flex; gap: 18px; align-items: flex-start; }
.mc-swatch {
  position: relative;
  flex-shrink: 0;
  width: 140px;
  height: 140px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  overflow: hidden;
}
.mc-swatch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.mc-vals { flex: 1; min-width: 0; margin: 0; grid-template-columns: 72px minmax(0, 1fr); gap: 0 10px; }
.mc-vals .pw { font-size: 14px; }
.mc-in { max-width: none; margin-top: 14px; }
.mc-scale { display: grid; grid-template-columns: repeat(10, 1fr); border-radius: 8px; overflow: hidden; }
.mc-step { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; height: 72px; padding: 6px 2px; border: 0; font: 10px var(--mono); cursor: pointer; }
.mc-step:hover { outline: 2px solid var(--ink); outline-offset: -2px; }
.mc-step span:first-child { opacity: .75; }
.ct-hex { width: 110px; padding: 6px 9px; font-size: 13px; }
.panel input[type="color"] { width: 38px; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); cursor: pointer; }
.ct-preview { margin-top: 14px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 10px; }
.ct-preview p { margin: 0; font-size: 16px; }
.ct-preview .ct-big { margin-bottom: 6px; font-size: 24px; font-weight: 700; }
.ct-ratio { display: flex; align-items: baseline; gap: 10px; margin: 16px 0 10px; }
.ct-ratio strong { font: 700 30px var(--mono); }
.ct-ratio span { color: var(--muted); font-size: 13px; }
.ct-grades { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ct-g { display: flex; flex-direction: column; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-size: 13px; }
.ct-g strong { font-size: 15px; }
.ct-g small { color: var(--muted); font-size: 11.5px; }
.ct-g.pass strong { color: var(--ok); }
.ct-g.fail strong { color: var(--warn); }

/* Cron */

input.text.cr-in { max-width: none; font-size: 22px; padding: 12px 14px; letter-spacing: .04em; }
.cr-say { margin: 14px 0 4px; font-size: 18px; font-weight: 600; line-height: 1.45; }
.cr-fields { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.cr-f { display: flex; flex-direction: column; gap: 4px; }
.cr-f .field-label { margin: 0; }
.cr-f .text { max-width: none; padding: 8px 10px; font-size: 14px; }
.cr-f small { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
#cr-presets .chip { flex-direction: column; align-items: flex-start; gap: 0; max-width: none; }
.cr-next { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); counter-reset: run; }
.cr-next li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 14px; counter-increment: run; }
.cr-next li span::before { content: counter(run) ". "; color: var(--muted); font: 12px var(--mono); }
.cr-next small { color: var(--muted); white-space: nowrap; }

/* Đổi hệ số */

.nb-list { display: flex; flex-direction: column; gap: 10px; max-width: 900px; }
.nb-row { display: grid; grid-template-columns: 170px minmax(0, 1fr) auto; align-items: center; gap: 12px; }
.nb-name { font-weight: 600; font-size: 14px; display: flex; align-items: baseline; gap: 6px; }
.nb-name small { color: var(--muted); font-weight: 400; font-size: 12px; }
.nb-row .text { max-width: none; font-size: 15px; }
.nb-custom { width: 58px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); font: inherit; }

/* Đợt 2 */

input.text.jc-name { width: 150px; padding: 6px 10px; font-size: 14px; }
.tx-sub { margin: 16px 0 8px; }
#lo-out { font-family: inherit; font-size: 15px; line-height: 1.7; }

/* Danh sách tra cứu (mã HTTP, MIME) */
input.text.ref-search { max-width: 460px; flex: 1 1 280px; font-family: inherit; }
.ref-list { display: flex; flex-direction: column; max-width: 980px; border-top: 1px solid var(--line); }
.ref-item { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 14px; align-items: start; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.ref-item strong { font-size: 15px; }
.ref-item p { margin: 3px 0 0; font-size: 14px; color: var(--muted); line-height: 1.5; }
.ref-en { margin-left: 6px; font: 400 12.5px var(--mono); color: var(--muted); }
.ref-code { padding: 6px 0; border: 0; border-radius: 6px; font: 700 18px var(--mono); cursor: pointer; text-align: center; }
.ref-code.c1 { background: var(--hover); color: var(--muted); }
.ref-code.c2 { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.ref-code.c3 { background: color-mix(in srgb, var(--t-lit) 16%, transparent); color: var(--t-lit); }
.ref-code.c4 { background: color-mix(in srgb, var(--t-num) 16%, transparent); color: var(--t-num); }
.ref-code.c5 { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.ref-ext { padding-top: 4px; font: 600 13px var(--mono); color: var(--accent); word-break: break-word; }
.ref-item .mm-type { margin-left: -8px; font-size: 14px; word-break: break-all; }
.mm-drop { min-height: 0; flex-direction: row; padding: 10px 16px; font-size: 13px; }

/* User-Agent */
.ua-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 16px; }
.ua-card { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.ua-card span { font-size: 12px; color: var(--muted); }
.ua-card strong { font-size: 17px; }
.ua-card small { font-size: 12.5px; color: var(--muted); }
#ua-samples .chip { max-width: none; }

/* Ảnh sang Base64 */
.ib-drop { min-height: 220px; }
.ib-drop img { max-width: 100%; max-height: 180px; border-radius: 6px; background: repeating-conic-gradient(var(--hover) 0 25%, transparent 0 50%) 0 0 / 14px 14px; }
.ib-view { margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; text-align: center; background: repeating-conic-gradient(var(--hover) 0 25%, transparent 0 50%) 0 0 / 16px 16px; }
.ib-view:empty { display: none; }
.ib-view img { max-width: 100%; max-height: 360px; }

/* Favicon */
input.text.fv-text { width: 90px; text-align: center; font: 700 18px inherit; font-family: inherit; }
.fv-drop { min-height: 120px; margin-bottom: 10px; font-size: 13px; }
.fv-prev { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 18px; padding: 20px; border: 1px solid var(--line); border-radius: 10px; background: repeating-conic-gradient(var(--hover) 0 25%, transparent 0 50%) 0 0 / 16px 16px; }
.fv-item { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.fv-item canvas { display: block; image-rendering: pixelated; }
.fv-item span { font: 11px var(--mono); color: var(--muted); }
.fv-tab { margin-top: 14px; max-width: 360px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--hover); }
.fv-tab-bar { display: flex; gap: 6px; padding: 8px 10px 0; }
.fv-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.fv-tab-row { display: flex; align-items: center; gap: 8px; width: 230px; margin: 8px 0 0 10px; padding: 8px 12px; border-radius: 8px 8px 0 0; background: var(--card); font-size: 13px; }
.fv-tab-row canvas { width: 16px; height: 16px; }
.fv-x { margin-left: auto; color: var(--muted); font-size: 11px; }

/* .gitignore */
input.text.gi-search { max-width: none; font-family: inherit; }
#gi-list .chip.on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
#gi-list .chip.on .idx { color: var(--ok); }
#gi-list .chip .val { color: var(--ink); font-family: inherit; }

/* Màn hình vừa: khung soạn thảo xếp chồng, cột thao tác nằm ngang */
@media (max-width: 1180px) {
  .ed-grid { grid-template-columns: minmax(0, 1fr); }
  .ed-body { height: 420px; }
  .ed-mid { flex-direction: row; flex-wrap: wrap; }
  .ed-mid > * { width: auto !important; flex: 1 1 140px; }
  .ed-mid #js-validate, .ed-mid #js-dl { margin: 0; }
}

/* Danh sách kết quả (2FA, mật khẩu) */

.timer {
  height: 3px;
  margin-bottom: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  background: var(--ink);
  transform-origin: left;
  transition: transform 1s linear;
}

.timer-bar.low { background: var(--accent); }

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.item-name {
  min-width: 0;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item.bad .item-name { color: var(--warn); }

.code, .pw {
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  cursor: pointer;
}

.code {
  flex-shrink: 0;
  margin-right: -8px;
  font: 600 28px/1 var(--mono);
  letter-spacing: 0.08em;
}

.pw {
  margin-left: -8px;
  text-align: left;
  font: 500 16px/1.4 var(--mono);
  word-break: break-all;
}

.code:hover, .pw:hover { background: var(--hover); }
.code.copied, .pw.copied { color: var(--ok); }

.empty { margin: 20px 0 0; color: var(--muted); font-size: 14px; }

/* Danh sách dạng thẻ xếp lưới: màn rộng nhiều cột, điện thoại một cột */
.list.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  align-content: start;
  gap: 10px;
  border-top: 0;
}

.cards .item {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.cards .pw { width: 100%; margin: -4px -8px; }

/* Thẻ mã 2FA: tên ở trên, mã to ở dưới */
#tf-list .item { flex-direction: column; align-items: flex-start; gap: 6px; }
#tf-list .item-name { max-width: 100%; }
#tf-list .code { margin: 0 0 0 -8px; }
#tf-list { margin-top: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity .15s, transform .15s;
  pointer-events: none;
  z-index: 200; /* nằm trên mọi lớp phủ: ô tìm nhanh, hộp xác nhận, màn chờ */
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Hộp xác nhận ask() trong core.js */
.ask {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(0 0 0 / .45);
}

.ask-box {
  width: min(380px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 12px 40px rgb(0 0 0 / .25);
}

.ask-box p { margin: 0 0 18px; font-size: 15px; line-height: 1.5; }
.ask-btns { display: flex; justify-content: flex-end; gap: 8px; }
.ask-btns .btn { min-width: 88px; min-height: 40px; }
.ask-btns .btn.danger { background: var(--warn); border-color: var(--warn); color: var(--bg); } /* chữ trắng trên --warn tối chỉ 2.7:1 */

/* Màn hình vừa: hai cột xếp chồng */

@media (max-width: 1000px) {
  .about { grid-template-columns: minmax(0, 1fr); }
  .split, .split-side, .split-main { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  /* Xếp chồng thì để chiều cao tự nhiên */
  .split.fill { height: auto; }
  .fill > .col > textarea { flex: none; resize: vertical; }
}

/* Điện thoại: thanh trên cùng + bảng chọn công cụ trượt từ dưới lên */

@media (max-width: 760px) {
  .app { display: block; }

  .side {
    position: sticky;
    top: 0;
    z-index: 30;
    height: auto;
    padding: 10px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
  }

  .side-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0;
  }

  .brand { padding: 0; font-size: 16px; }

  .menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }

  .menu-btn #menu-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .menu-btn svg { flex-shrink: 0; color: var(--muted); transition: transform .2s; }
  .menu-open .menu-btn svg { transform: rotate(180deg); }

  .search-btn { display: none; }
  input.sheet-search { display: block; width: 100%; max-width: none; font-family: inherit; }
  .home-search kbd { display: none; }
  .nav-list { display: flex; flex-direction: column; gap: 14px; }
  .nav-group { margin: 0; }
  .nav-group + .nav-group { padding-top: 0; border-top: 0; }
  .nav-h { padding: 0 2px 8px; pointer-events: none; }
  .nav-h svg { display: none; }
  .nav-group.closed .nav-items { grid-template-rows: 1fr; }
  .nav-items-in, .nav-group.closed .nav-items-in { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0; overflow: visible; }
  .nav-group a { padding: 12px; }
  .home-head h1 { font-size: 28px; }
  /* Trang chủ: danh sách một cột cho đủ chỗ cho tên và mô tả */
  .home-grid { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .hcard { padding: 11px 12px; gap: 12px; }
  .hcard .glyph { width: 38px; height: 38px; font-size: 12px; }
  .home-group { margin-top: 26px; }
  /* Nhóm nút chọn nhiều lựa chọn: xuống hàng thay vì bóp chữ */
  .seg { flex-wrap: wrap; max-width: 100%; }
  .seg button { white-space: nowrap; }
  /* Bảng nhãn và giá trị: nhãn hẹp lại, giá trị ngắt ở dấu cách chứ không ngắt giữa số */
  .kv { grid-template-columns: 96px minmax(0, 1fr); }
  .kv .pw { word-break: normal; overflow-wrap: anywhere; }
  /* Thanh công cụ của khung soạn thảo: xuống hàng khi chật, chữ không gãy */
  .ed-bar { flex-wrap: wrap; padding: 6px 6px 6px 12px; row-gap: 4px; }
  .ed-bar .ed-title, .ed-btn, .ed-check { white-space: nowrap; }
  .ed-tools { flex-wrap: wrap; justify-content: flex-end; }
  .pal-list span { display: none; }
  /* iOS tự phóng to trang khi chạm vào ô chữ nhỏ hơn 16px: trên điện thoại mọi ô nhập đều 16px.
     Lớp tô màu và cột số dòng nằm sau ô nhập phải cùng cỡ chữ để khớp dòng */
  textarea, select, input.text, input:not([type]), input[type="text"], input[type="search"], input[type="number"], input[type="email"],
  input[type="tel"], input[type="url"], input[type="password"], input[type="date"], input[type="time"], input[type="datetime-local"],
  .gutter, .md-editor .md-hl, .rx-test .rx-hl { font-size: 16px !important; }
  /* Nút đủ lớn để chạm (khoảng 40px) */
  .btn, .seg button, .chip, .menu-btn, .sheet-close { min-height: 40px; }
  label.btn { display: inline-flex; align-items: center; }

  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 82vh;
    padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    background: var(--card);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, .18);
    transform: translateY(105%);
    transition: transform .25s ease;
  }

  .menu-open .nav { transform: none; }
  .menu-open { overflow: hidden; }
  /* Thanh trên cùng chứa bảng chọn, phải nằm trên lớp nền tối */
  .menu-open .side { z-index: 60; }

  .sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0 6px;
    font-size: 15px;
    font-weight: 700;
  }

  /* Vạch nhỏ ở mép trên, gợi ý đây là bảng trượt */
  .sheet-head::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    width: 36px;
    height: 4px;
    margin-left: -18px;
    border-radius: 2px;
    background: var(--line);
  }

  .sheet-close {
    padding: 6px 10px;
    border: 0;
    border-radius: 6px;
    background: var(--hover);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
  }

  .nav a {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
    color: var(--ink);
    white-space: normal;
  }

  .nav a .nm { font-weight: 600; }

  .nav small {
    display: block;
    grid-column: 1 / -1;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.4;
    color: var(--muted);
  }

  .nav a.active { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: var(--card); }

  .theme-btn { width: 40px; height: 40px; }

  .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(20, 18, 15, .45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
  }

  .menu-open .backdrop { opacity: 1; pointer-events: auto; }

  .side-note { display: none; }
  .main { padding: 24px 16px 64px; }
  .tool-head h1 { font-size: 24px; }
  .tool-head p { margin-bottom: 20px; }
  .code { font-size: 24px; }
  input[type="range"] { width: 120px; }
  /* Ô nhập thấp lại để thấy được kết quả mà không phải cuộn xa */
  .split textarea { height: 180px; }
  .split #tx-in { height: 240px; }
  .pdf-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .pthumb { height: 170px; }
  .pdf-range { width: 100%; }
  /* Trên điện thoại các nút xuống nhiều hàng, nếu dính đáy sẽ che lưới trang */
  .pdf-foot { position: static; }
  .ref-item { grid-template-columns: 64px minmax(0, 1fr); }
  .ref-code { font-size: 15px; }
  .cr-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .nb-row { grid-template-columns: minmax(0, 1fr) auto; }
  .nb-row .nb-name { grid-column: 1 / -1; }
  .mc-main { flex-direction: column; }
  .mc-swatch { width: 100%; height: 90px; }
  .mc-scale { grid-template-columns: repeat(5, 1fr); }
  .dtab { font-size: 12px; }
  .dtab col.dn { width: 34px; }
  .pdf-grid[data-size="l"] { --tw: 100%; }
  .pview-stage { padding: 10px; }
  .pview-bar { padding: 8px 10px; }
  .wave { height: 140px; }
  .au-item { grid-template-columns: auto auto minmax(0, 1fr) auto; }
  .au-item .au-grip, .au-item .au-mini { display: none; }
  .au-controls .btns { width: 100%; }
  .ped-stage { height: 65vh; padding: 8px; }
  .sc-drop { min-height: 300px; }
  .sc-pick { width: 100%; }
  .sc-pick .btn { flex: 1; min-width: 0; }
  .sc-stage { --pad: 24px; height: max(320px, 62vh); }
  /* Nút xoay chỉ còn biểu tượng để cả hàng nút vừa một dòng */
  .sc-lbl { display: none; }
  .sc-row .btn { padding: 8px 11px; }
  #sc-rl, #sc-rr { min-width: 40px; font-size: 15px; line-height: 1.3; }
  .sc-dl { width: 100%; }
  .sc-dl .btn { flex: 1; }
  .sc-h { width: 48px; height: 48px; margin: -24px 0 0 -24px; }
  .sc-h::after { inset: 12px; }
}
