/* =========================================================
   ManhTool — Xem trước Markdown có trợ lý AI
   Màu theo logo: xanh rừng đậm → xanh ngọc → xanh chanh
   ========================================================= */

:root {
  --ink: #0f2620;
  --brand-800: #0a5c44;
  --brand-700: #0e7c5a;
  --brand-500: #12b886;
  --leaf: #4cb944;
  --lime: #c4e43a;
  --grad: linear-gradient(115deg, #0e7c5a 0%, #12b886 50%, #7ccf3e 85%, #c4e43a 100%);

  --bg: #f5f8f6;
  --surface: #ffffff;
  --surface-2: #f3f7f4;
  --tint: #e9f6ef;           /* nền xanh rất nhạt khi rê chuột / chọn */
  --raised: #ffffff;         /* tab, nút đang chọn nổi trên nền xám */
  --border: #e1ebe5;
  --border-strong: #cddcd3;
  --text: #13241f;
  --text-2: #4a5a55;
  --text-3: #6f7f79;
  --primary: #0e7c5a;
  --primary-hover: #0a5c44;
  --on-primary: #ffffff;
  --accent-text: #0e7c5a;
  --warn: #b45309;
  --warn-bg: #fff7e8;
  --danger: #c2410c;
  --danger-bg: #fff4ee;
  --ok: #237a3b;
  --ok-bg: #edf8ee;
  /* Màu cú pháp: khóa xanh thương hiệu, chuỗi nâu cam, số xanh dương, true/false tím */
  --syn-key: #0b6b4f;
  --syn-str: #a2541a;
  --syn-num: #1f5fbf;
  --syn-bool: #8b3fb8;
  --syn-null: #7a8a84;
  --syn-punc: #8a9a94;
  --code-bg: #fbfdfc;
  --gutter: #f1f6f3;
  --shadow: 0 1px 2px rgba(15,38,32,.04), 0 4px 16px rgba(15,38,32,.06);
  --shadow-lg: 0 24px 60px rgba(15,38,32,.2);

  --r-lg: 18px;
  --r: 12px;
  --r-sm: 9px;
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1613; --surface: #121e1a; --surface-2: #17251f; --tint: #173328; --raised: #23392f;
    --border: #213530; --border-strong: #2d463d;
    --text: #e7f1ec; --text-2: #a8bab2; --text-3: #85988f;
    --primary: #12b886; --primary-hover: #34cf98; --on-primary: #04241a; --accent-text: #3dd598;
    --warn: #facc15; --warn-bg: #2a2410; --danger: #fb923c; --danger-bg: #2a1a10;
    --ok: #6fd88a; --ok-bg: #132b1c;
    --syn-key: #4fd6a2; --syn-str: #f2b47a; --syn-num: #82b4ff; --syn-bool: #d6a1f7; --syn-null: #8a9c95; --syn-punc: #6f827b;
    --code-bg: #0f1a16; --gutter: #131f1b;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
    --shadow-lg: 0 24px 60px rgba(0,0,0,.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1613; --surface: #121e1a; --surface-2: #17251f; --tint: #173328; --raised: #23392f;
  --border: #213530; --border-strong: #2d463d;
  --text: #e7f1ec; --text-2: #a8bab2; --text-3: #85988f;
  --primary: #12b886; --primary-hover: #34cf98; --on-primary: #04241a; --accent-text: #3dd598;
  --warn: #facc15; --warn-bg: #2a2410; --danger: #fb923c; --danger-bg: #2a1a10;
  --ok: #6fd88a; --ok-bg: #132b1c;
  --syn-key: #4fd6a2; --syn-str: #f2b47a; --syn-num: #82b4ff; --syn-bool: #d6a1f7; --syn-null: #8a9c95; --syn-punc: #6f827b;
  --code-bg: #0f1a16; --gutter: #131f1b;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
  --shadow-lg: 0 24px 60px rgba(0,0,0,.55);
  color-scheme: dark;
}

/* ---------- Nền tảng ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column; overflow-x: hidden;
  font-family: var(--font); font-size: 16px; line-height: 1.55; color: var(--text);
  background: var(--bg);
}
body::before {
  /* vệt sáng xanh nhẹ phía trên, lấy cảm hứng từ dải màu logo */
  content: ""; position: absolute; inset: 0 0 auto 0; height: 420px; z-index: -1; pointer-events: none;
  background:
    radial-gradient(600px 300px at 85% -60px, rgba(196,228,58,.22), transparent 70%),
    radial-gradient(700px 320px at 10% -80px, rgba(18,184,134,.18), transparent 70%);
}
main { flex: 1; }
img { max-width: 100%; display: block; }
a { color: var(--accent-text); }
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

.ic { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.container { width: 100%; max-width: 1360px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 768px) { .container { padding: 0 24px; } }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 16px; top: -48px; z-index: 100; background: var(--primary); color: var(--on-primary); padding: 8px 14px; border-radius: 8px; text-decoration: none; }
.skip-link:focus { top: 12px; }
:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
[hidden] { display: none !important; }

.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: #fff; box-shadow: 0 0 0 1px var(--border); }
.brand-name { font-weight: 800; font-size: 1.15rem; letter-spacing: -.01em; }
.brand-accent { color: var(--primary); }
.header-actions { display: flex; align-items: center; gap: 6px; }
.header-link {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px;
  border-radius: 999px; text-decoration: none; color: var(--text-2); font-weight: 500; font-size: .9rem;
}
.header-link:hover { background: var(--tint); color: var(--accent-text); }
@media (max-width: 479px) { .header-link span { display: none; } .header-link { padding: 0; width: 38px; justify-content: center; } }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { color: var(--accent-text); border-color: var(--border-strong); }
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

/* ---------- Hero ---------- */
.hero { text-align: center; padding-top: 40px; padding-bottom: 28px; }
.hero h1 { font-size: clamp(1.7rem, 3.6vw + .6rem, 2.75rem); font-weight: 800; letter-spacing: -.025em; line-height: 1.15; text-wrap: balance; }
.hero p { margin-top: 10px; color: var(--text-2); font-size: clamp(.98rem, .6vw + .8rem, 1.1rem); text-wrap: balance; }
@media (max-width: 559px) { .hero { padding-top: 24px; padding-bottom: 18px; } }

/* ---------- Bố cục ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
@media (min-width: 1024px) { .layout { grid-template-columns: minmax(0, 1fr) 288px; gap: 24px; } }
.main-col { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); }

/* ---------- Công cụ ---------- */
.tool { padding: 14px; container-type: inline-size; scroll-margin-top: 76px; }
.tool:focus { outline: none; }
@media (min-width: 768px) { .tool { padding: 20px; } }

/* Tab chính: Văn bản | Hình ảnh & file */
.tabs {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 4px; margin-bottom: 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
}
.tab {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 0;
  height: 44px; padding: 0 12px; border: 0; border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--text-2); font-size: .95rem; font-weight: 600; white-space: nowrap;
  transition: background .15s, color .15s, box-shadow .15s;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--raised); color: var(--accent-text); box-shadow: 0 1px 3px rgba(15,38,32,.12), 0 0 0 1px var(--border); }

/* Hàng chọn chiều */
.mode-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 13px; border-radius: 999px;
  font-size: .82rem; font-weight: 600; color: var(--text-2); white-space: nowrap; transition: background .15s, color .15s;
}
.seg span .ic { width: 15px; height: 15px; }
.seg label:hover span { color: var(--text); }
.seg input:checked + span { background: var(--primary); color: var(--on-primary); box-shadow: 0 1px 3px rgba(15,38,32,.18); }
.seg input:focus-visible + span { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.seg-lg span { padding: 8px 16px; font-size: .9rem; }
@media (max-width: 479px) {
  .mode-row .seg { flex: 1; }
  .mode-row .seg label { flex: 1; }
  .mode-row .seg span { justify-content: center; width: 100%; padding: 8px 6px; font-size: .84rem; }
}

/* Hai ô: vào | ra */
.panes { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@container (min-width: 760px) { .panes { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pane { display: flex; flex-direction: column; min-width: 0; }
.pane-head { display: flex; align-items: center; gap: 10px; min-height: 30px; margin-bottom: 6px; }
.pane-head label, .pane-title { font-size: .92rem; font-weight: 700; }
.pane-head .pane-meta { margin-left: auto; }
.pane-head .link-btn { margin-left: auto; }
.pane-head .pane-meta:not(:empty) + .link-btn { margin-left: 0; }
.pane-meta { font-size: .8rem; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pane-meta b { color: var(--text-2); font-weight: 600; }
.pane-meta .up { color: var(--warn); font-weight: 600; }

.editor-box {
  position: relative; border: 1.5px solid var(--border-strong); border-radius: var(--r); background: var(--surface);
  overflow: hidden; transition: border-color .2s, box-shadow .2s;
}
.editor-box:focus-within { border-color: var(--brand-500); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-500) 15%, transparent); }
.editor-box.dragover { border-color: var(--brand-500); border-style: dashed; }
.editor-box.dragover::after {
  content: "Thả file vào đây"; position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 700; color: var(--accent-text); background: color-mix(in srgb, var(--tint) 90%, transparent);
  pointer-events: none;
}
.editor-box textarea {
  display: block; width: 100%; height: 34vh; min-height: 200px; max-height: 70vh; resize: vertical;
  padding: 12px 14px; border: 0; outline: none; background: transparent; color: var(--text);
  font: inherit; font-size: .98rem; line-height: 1.65;
}
@media (max-width: 559px) { .panes .editor-box textarea { height: 26vh; min-height: 160px; } }
@media (min-width: 1024px) { .panes .editor-box textarea { height: clamp(260px, calc(100vh - 470px), 440px); } }
.editor-box textarea::placeholder { color: var(--text-3); }
.editor-box textarea.mono { font-family: var(--mono); font-size: .86rem; line-height: 1.6; word-break: break-all; }
.editor-box textarea.out-short { height: 150px; min-height: 110px; }
.out-box { background: var(--surface-2); border-color: var(--border); }
.out-box textarea { color: var(--text); }

/* Thanh trạng thái dưới ô */
.status {
  display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap;
  padding: 9px 12px; font-size: .84rem; line-height: 1.45; border-top: 1px solid var(--border);
}
.status > .ic { width: 16px; height: 16px; margin-top: 1px; }
.status > span { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.status .link-btn { margin: -4px 0; padding: 4px 10px; background: var(--surface); box-shadow: 0 0 0 1px currentColor inset; color: inherit; }
.status .link-btn:hover { background: var(--surface); filter: brightness(.95); }
.status.is-error { color: var(--danger); background: var(--danger-bg); }
.status.is-warn { color: var(--warn); background: var(--warn-bg); }
.status.is-info { color: var(--accent-text); background: var(--tint); }

/* Nút thao tác */
.pane-actions { display: flex; align-items: center; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.pane-actions .btn-primary { margin-left: auto; }
.pane-actions > .pane-meta { margin-right: auto; }
.act {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 12px; cursor: pointer;
  font-size: .88rem; font-weight: 500; color: var(--text-2); white-space: nowrap;
  background: transparent; border: 1px solid transparent; border-radius: var(--r-sm);
  transition: background .15s, color .15s;
}
.act:hover:not(:disabled) { background: var(--tint); color: var(--accent-text); }
.act:disabled { opacity: .4; cursor: default; }
.act-danger:hover:not(:disabled) { background: var(--danger-bg); color: var(--danger); }
.act-icon { width: 40px; padding: 0; }
.act-sep { width: 1px; align-self: center; height: 22px; background: var(--border); margin: 0 4px; }
.mode-row .act { border-color: var(--border); }

.btn-primary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 20px; border-radius: var(--r-sm); cursor: pointer;
  font-size: .92rem; font-weight: 600; text-decoration: none; white-space: nowrap;
  transition: background .15s, transform .1s, border-color .15s, color .15s;
}
.btn-primary { color: var(--on-primary); background: var(--primary); border: 0; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active, .btn-ghost:active { transform: scale(.97); }
.btn-ghost { color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); }
.btn-ghost:hover { border-color: var(--brand-500); color: var(--accent-text); }
.btn-sm { height: 38px; padding: 0 14px; font-size: .86rem; }
.btn-copy { min-width: 128px; }
.btn-copy .ic-check { display: none; }
.btn-copy.is-done .ic-copy { display: none; }
.btn-copy.is-done .ic-check { display: block; }
.btn-primary.is-done { background: var(--leaf); }
.btn-ghost.is-done { color: var(--accent-text); border-color: var(--brand-500); }

.link-btn { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border: 0; border-radius: 7px; background: none; color: var(--accent-text); font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.link-btn:hover { background: var(--tint); }

@media (max-width: 559px) {
  .pane-actions { gap: 0; justify-content: space-between; }
  .pane-actions .act { width: 44px; height: 44px; padding: 0; }
  .pane-actions .act span, .mode-row .act span { display: none; }
  .pane-actions .act-sep { display: none; }
  .pane-actions .btn-primary { flex: 1; height: 46px; margin-left: 8px; }
  .pane-actions > .pane-meta { flex-basis: 100%; margin: 0 0 6px; }
  .mode-row .act { width: 44px; height: 44px; padding: 0; }
}

/* Tùy chọn */
.options {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px;
  margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border-strong);
}
.check-line { position: relative; display: inline-flex; align-items: center; gap: 8px; font-size: .86rem; color: var(--text-2); cursor: pointer; user-select: none; }
.check-line input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { position: relative; width: 34px; height: 20px; flex-shrink: 0; background: var(--border-strong); border-radius: 999px; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .2s; }
.check-line input:checked + .switch { background: var(--brand-500); }
.check-line input:checked + .switch::after { transform: translateX(14px); }
.check-line input:focus-visible + .switch { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.select-line { display: inline-flex; align-items: center; gap: 8px; font-size: .86rem; color: var(--text-2); }
.select, .input {
  height: 36px; padding: 0 10px; font: inherit; font-size: .88rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
}
.select:focus, .input:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 18%, transparent); }
.opt-note { display: flex; align-items: flex-start; gap: 8px; font-size: .84rem; color: var(--text-3); }
.opt-note .ic { width: 16px; height: 16px; margin-top: 2px; color: var(--accent-text); }
@media (max-width: 479px) {
  .options { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .select-line { justify-content: space-between; }
}


/* ---------- Thanh bên ---------- */
.side { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) and (max-width: 1023px) and (hover: hover) { .side { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (hover: none) { .shortcuts-card { display: none; } }

.side-card { padding: 16px; }
.side-head { display: flex; align-items: center; gap: 12px; }
.side-head h2 { font-size: .98rem; font-weight: 700; line-height: 1.3; }
.side-head p { font-size: .82rem; color: var(--text-3); }
.side-icon {
  display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0;
  border-radius: 10px; background: var(--tint); color: var(--accent-text);
}
.donate .side-icon { background: var(--grad); color: #fff; }
.side-note { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 10px; font-size: .8rem; color: var(--text-3); }
.side-note .ic { width: 15px; height: 15px; }

.qr-frame {
  position: relative; display: block; width: 100%; margin-top: 14px; padding: 12px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--r); cursor: zoom-in; overflow: hidden;
}
.qr-frame img { width: 100%; max-width: 190px; height: auto; margin: 0 auto; }
.qr-zoom {
  position: absolute; left: 50%; bottom: 10px; transform: translate(-50%, 6px);
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  font-size: .78rem; font-weight: 600; color: #fff; background: rgba(15,38,32,.85);
  border-radius: 999px; opacity: 0; transition: opacity .2s, transform .2s;
}
.qr-zoom .ic { width: 14px; height: 14px; }
.qr-frame:hover .qr-zoom, .qr-frame:focus-visible .qr-zoom { opacity: 1; transform: translate(-50%, 0); }

.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; margin: 14px 0 0; font-size: .82rem; align-items: center; }
.shortcuts dt { display: flex; align-items: center; gap: 3px; color: var(--text-3); }
.shortcuts dd { margin: 0; color: var(--text-2); text-align: right; }
kbd {
  font-family: var(--mono); font-size: .72rem; font-weight: 600; line-height: 1;
  padding: 4px 6px; border-radius: 5px; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px;
}

/* ---------- Hướng dẫn ---------- */
.guide { padding-top: 56px; padding-bottom: 48px; }
.guide h2 { text-align: center; font-size: clamp(1.25rem, 1.5vw + .9rem, 1.6rem); font-weight: 800; letter-spacing: -.015em; margin-bottom: 20px; }
.guide-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 600px) { .guide-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .guide-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.guide-item { padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); }
.guide-ic { display: grid; place-items: center; width: 38px; height: 38px; margin-bottom: 12px; border-radius: 10px; background: var(--tint); color: var(--accent-text); }
.guide-item h3 { font-size: .98rem; font-weight: 700; }
.guide-item p { margin-top: 4px; font-size: .87rem; color: var(--text-2); }
.guide-item b { color: var(--text); font-weight: 600; }

.faq { max-width: 780px; margin: 48px auto 0; }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); }
.faq details + details { margin-top: 8px; }
.faq summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; font-weight: 600; cursor: pointer; list-style: none;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary:hover { color: var(--accent-text); }
.faq .chev { color: var(--text-3); transition: transform .2s; }
.faq details[open] .chev { transform: rotate(180deg); }
.faq details p { padding: 0 16px 16px; font-size: .92rem; color: var(--text-2); }

.privacy { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 24px; font-size: .85rem; color: var(--text-3); text-align: center; }
.privacy .ic { width: 16px; height: 16px; color: var(--accent-text); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); padding: 18px 0 calc(18px + env(safe-area-inset-bottom)); }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 10px 20px; flex-wrap: wrap; font-size: .85rem; color: var(--text-3); }
.footer-brand { display: flex; align-items: center; gap: 10px; color: var(--text-2); text-decoration: none; }
.footer-brand img { border-radius: 7px; background: #fff; box-shadow: 0 0 0 1px var(--border); }
.footer-brand strong { color: var(--text); }

/* ---------- Hộp QR phóng to ---------- */
.qr-dialog {
  width: min(92vw, 360px); padding: 22px; border: 0; border-radius: 20px; text-align: center;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.qr-dialog::backdrop { background: rgba(6,20,16,.55); backdrop-filter: blur(3px); }
.qr-dialog h2 { font-size: 1.05rem; margin-bottom: 14px; }
.qr-dialog img { width: 100%; height: auto; padding: 10px; background: #fff; border-radius: var(--r); border: 1px solid var(--border); }
.qr-dialog p { margin-top: 12px; font-size: .88rem; color: var(--text-2); }
.qr-dialog form { position: absolute; top: 12px; right: 12px; margin: 0; }
.qr-close { width: 32px; height: 32px; }
.qr-close .ic { width: 16px; height: 16px; }

/* ---------- Thông báo ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 50;
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 999px;
  background: var(--ink); color: #fff; font-size: .88rem; font-weight: 500; box-shadow: var(--shadow-lg);
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
:root[data-theme="dark"] .toast { background: #e7f1ec; color: #0f2620; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast { background: #e7f1ec; color: #0f2620; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* =========================================================
   Khối "Về ManhTool" + "Hợp tác" — dùng chung cho mọi công cụ
   ========================================================= */
.brand-section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; padding-bottom: 48px; }
@media (min-width: 1024px) { .brand-section { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: stretch; } }

.brand-card {
  display: flex; align-items: center; gap: 28px; padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.brand-logo {
  width: 150px; height: 150px; flex: none; object-fit: contain;
  border-radius: 24px; background: #fff; border: 1px solid #e8ece9;
  box-shadow: 0 12px 30px -12px rgba(14,124,90,.45);
}
.eyebrow { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 700; color: var(--accent-text); margin-bottom: 8px; }
.eyebrow .ic { width: 15px; height: 15px; }
.brand-body h2 { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.25; margin-bottom: 6px; }
.brand-slogan { font-weight: 700; font-size: 1.02rem; margin-bottom: 10px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-body p:not(.brand-slogan) { color: var(--text-2); margin-bottom: 16px; }
.brand-body b { color: var(--text); }

.hire-card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 12px; padding: 26px;
  border-radius: var(--r-lg); color: #fff;
  background:
    radial-gradient(420px 220px at 100% 0%, rgba(101,199,40,.28), transparent 70%),
    radial-gradient(360px 200px at 0% 100%, rgba(15,159,110,.3), transparent 70%),
    linear-gradient(160deg, #10241c, #0c1712);
  border: 1px solid rgba(255,255,255,.06);
}
.hire-label { align-self: flex-start; padding: 4px 11px; border-radius: 999px; background: rgba(101,199,40,.16); color: #a6e77a; font-size: .75rem; font-weight: 700; letter-spacing: .02em; }
.hire-card h2 { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.3; }
.hire-card > p { color: rgba(255,255,255,.75); }
.hire-services { list-style: none; margin: 2px 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.hire-services li { display: flex; align-items: center; gap: 10px; font-size: .9rem; font-weight: 500; }
.hire-services .ic { width: 16px; height: 16px; color: #7ddc4a; }
.hire-phone {
  display: flex; align-items: center; gap: 14px; margin-top: 4px; padding: 14px 16px;
  border-radius: 14px; color: #fff; text-decoration: none;
  background: linear-gradient(135deg, #12b886, #4fb52a);
  box-shadow: 0 14px 30px -12px rgba(79,181,42,.65);
  transition: transform .15s, box-shadow .15s;
}
.hire-phone:hover { transform: translateY(-2px); box-shadow: 0 18px 34px -12px rgba(79,181,42,.8); }
.hp-ico { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.2); }
.hp-ico .ic { width: 20px; height: 20px; animation: ring 2.6s ease-in-out infinite; }
@keyframes ring { 0%, 70%, 100% { transform: rotate(0); } 75% { transform: rotate(-14deg); } 80% { transform: rotate(12deg); } 85% { transform: rotate(-8deg); } 90% { transform: rotate(6deg); } }
.hire-phone small { display: block; font-size: .75rem; opacity: .85; font-weight: 600; }
.hire-phone b { display: block; font-size: 1.45rem; font-weight: 800; letter-spacing: .02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.hire-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-ghost-light {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: var(--r-sm); cursor: pointer;
  font-size: .86rem; font-weight: 600; color: #fff; text-decoration: none;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.16);
  transition: background .15s;
}
.btn-ghost-light .ic { width: 16px; height: 16px; }
.btn-ghost-light:hover { background: rgba(255,255,255,.12); }
.hire-tags { font-size: .78rem; color: rgba(255,255,255,.55); margin-top: auto; padding-top: 4px; }

@media (max-width: 767px) {
  .brand-card, .hire-card { padding: 20px 16px; }
}
@media (max-width: 560px) {
  .brand-card { flex-direction: column; text-align: center; gap: 16px; }
  .brand-logo { width: 120px; height: 120px; }
  .hire-actions .btn-ghost-light { flex: 1 1 auto; }
}

/* ---------- Lời mời tư vấn (giống trang chủ) ---------- */
.nudge {
  position: fixed; left: 20px; bottom: 24px; z-index: 30; width: 320px; padding: 20px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: 0 20px 50px -12px rgba(15,38,32,.28), 0 2px 6px rgba(15,38,32,.06);
  animation: nudge-in .35s ease-out;
}
.nudge[hidden] { display: none; }
@keyframes nudge-in { from { opacity: 0; transform: translateY(12px); } }
.nudge-close {
  position: absolute; top: 10px; right: 10px; display: grid; place-items: center; width: 30px; height: 30px; padding: 0;
  background: none; border: 0; border-radius: 8px; color: var(--text-3); cursor: pointer;
}
.nudge-close:hover { background: var(--surface-2); color: var(--text); }
.nudge-close .ic { width: 16px; height: 16px; }
.nudge-head { display: flex; align-items: center; gap: 12px; padding-right: 24px; }
.nudge-head img { width: 50px; height: 30px; object-fit: contain; flex: none; }
.nudge-head p { font-size: .95rem; font-weight: 700; line-height: 1.35; margin: 0; }
.nudge-text { margin-top: 8px; font-size: .88rem; line-height: 1.55; color: var(--text-2); margin-bottom: 0; }
.nudge-actions { display: flex; gap: 8px; margin-top: 16px; }
.nudge-actions .btn-primary {
  flex: 1; height: 42px; padding: 0 12px;
  background: linear-gradient(135deg, var(--brand-700), var(--brand-500));
  border-radius: 10px; color: #fff; font-weight: 600; font-size: .88rem;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none; border: none;
}
.nudge-actions .btn-primary:hover { background: linear-gradient(135deg, var(--brand-800), var(--brand-700)); }
:root[data-theme="dark"] .nudge-actions .btn-primary { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .nudge-actions .btn-primary { color: #fff; } }
.nudge-actions .btn-ghost {
  height: 42px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border); color: var(--text);
  font-weight: 600; font-size: .88rem; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; background: transparent;
}
.nudge-actions .btn-ghost:hover { background: var(--surface-2); }
.nudge-actions .btn-ghost .ic { width: 16px; height: 16px; }
@media (max-width: 1023px) { .nudge { display: none !important; } }
@media (prefers-reduced-motion: reduce) { .nudge { animation: none; } }



/* =========================================================
   Riêng công cụ Xem trước Markdown
   ========================================================= */
:root {
  --md-text: var(--text); --md-muted: var(--text-2); --md-border: var(--border); --md-soft: var(--surface-2);
  --md-code-bg: var(--code-bg); --md-link: var(--accent-text); --md-mark: #fff1a8; --md-diagram-bg: #fff;
  --ins-bg: #d9f5e1; --ins-text: #0d5c2a; --del-bg: #fde2e1; --del-text: #9b1c1c;
  --ai-grad: linear-gradient(120deg, #0e7c5a, #12b886 55%, #7ccf3e);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --md-mark: rgba(250,204,21,.32); --md-diagram-bg: #0f1a16; --ins-bg: rgba(52,207,152,.18); --ins-text: #7ee2b4; --del-bg: rgba(248,113,113,.16); --del-text: #fca5a5; }
}
:root[data-theme="dark"] { --md-mark: rgba(250,204,21,.32); --md-diagram-bg: #0f1a16; --ins-bg: rgba(52,207,152,.18); --ins-text: #7ee2b4; --del-bg: rgba(248,113,113,.16); --del-text: #fca5a5; }

.hide-touch { }
@media (hover: none) { .hide-touch { display: none !important; } }
@media (max-width: 559px) { .hide-xs { display: none !important; } }
@media (max-width: 767px) { .hide-sm { display: none !important; } }

.md-tool { padding: 0; overflow: visible; display: flex; flex-direction: column; container-type: normal; }
.md-tool.is-compact .hide-md { display: none !important; }
.md-tool.is-compact .top-actions .act span { display: none; }
.md-tool.is-compact .top-actions .act { width: 40px; padding: 0; }
.md-tool.is-compact .doc-btn { max-width: 230px; }
.md-tool > * { min-width: 0; }

/* ---------- Hàng trên ---------- */
.top-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px 10px; }
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.menu-wrap { position: relative; display: inline-flex; }
.doc-btn {
  display: inline-flex; align-items: center; gap: 8px; max-width: 300px; height: 40px; padding: 0 10px 0 12px;
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .92rem;
}
.doc-btn:hover { border-color: var(--border-strong); background: var(--tint); }
.doc-btn .ic { color: var(--accent-text); }
.doc-btn .chev { color: var(--text-3); width: 16px; height: 16px; }
.doc-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.view-seg b { font-weight: 600; }
.act-bordered { border-color: var(--border); }
.act-bordered:hover:not(:disabled) { border-color: var(--border-strong); }
.btn-ai {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 40px; padding: 0 16px;
  border: 0; border-radius: 999px; cursor: pointer; color: #fff; font-weight: 700; font-size: .9rem; white-space: nowrap;
  background: var(--ai-grad); box-shadow: 0 6px 18px -8px rgba(14,124,90,.7); transition: filter .15s, transform .1s;
}
.btn-ai:hover { filter: brightness(1.07); }
.btn-ai:active { transform: scale(.97); }
.btn-ai-block { width: 100%; margin-top: 12px; border-radius: var(--r-sm); }
.md-tool.ai-off .btn-ai { filter: grayscale(.6); opacity: .7; }
.ic-xs { width: 14px; height: 14px; }
#btnFull .ic-min { display: none; }
.md-tool.is-full #btnFull .ic-max { display: none; }
.md-tool.is-full #btnFull .ic-min { display: block; }

/* ---------- Menu ---------- */
.menu {
  position: fixed; top: 0; left: 0; z-index: 80; min-width: 250px; max-width: min(340px, calc(100vw - 24px));
  max-height: min(70vh, 520px); overflow: auto; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-lg);
}
.menu-head { padding: 6px 10px 4px; font-size: .74rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--border); }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: none; cursor: pointer; text-align: left; font-size: .88rem; color: var(--text);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--tint); outline: none; }
.menu-item .ic { color: var(--text-3); width: 17px; height: 17px; }
.menu-item:hover .ic { color: var(--accent-text); }
.menu-item:disabled { opacity: .45; cursor: default; }
.menu-danger:hover { background: var(--danger-bg); color: var(--danger); }
.menu-danger:hover .ic { color: var(--danger); }
kbd.mk { margin-left: auto; padding: 2px 5px; font-size: .66rem; color: var(--text-3); background: none; border-bottom-width: 1px; white-space: nowrap; }
@media (hover: none) { kbd.mk { display: none; } }
.doc-list { max-height: 300px; overflow: auto; }
.doc-item.is-current { background: var(--tint); }
.doc-item.is-current .ic { color: var(--accent-text); }
.doc-item-body { display: flex; flex-direction: column; min-width: 0; }
.doc-item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item-time { font-size: .76rem; color: var(--text-3); }
.tpl-item { padding: 9px 12px; }
.h-item b { font-weight: 700; }

/* ---------- Thanh định dạng ---------- */
.fmt-bar {
  display: flex; align-items: center; gap: 2px; padding: 4px 10px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: var(--surface-2); overflow-x: auto; scrollbar-width: thin;
}
.fmt-bar .act { height: 36px; color: var(--text-2); flex-shrink: 0; }
.fmt-bar .act-icon { width: 36px; }
.fmt-bar .act-sep { height: 20px; margin: 0 4px; flex-shrink: 0; }
.fmt-bar .fmt-h { width: auto; padding: 0 6px; gap: 2px; }
.fmt-spacer { flex: 1; min-width: 8px; }
.dock-tabs-mini { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.dock-toggle { position: relative; }
.dock-toggle[aria-pressed="true"] { background: var(--raised); color: var(--accent-text); box-shadow: 0 0 0 1px var(--border); }
.dock-toggle[data-dock="ai"] { color: var(--accent-text); font-weight: 600; }
.badge { position: absolute; top: 3px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--warn); color: #fff; font-size: .62rem; font-weight: 700; line-height: 16px; text-align: center; }
:root[data-theme="dark"] .badge { color: #1a1300; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge { color: #1a1300; } }
.fmt-bar #headMenu { min-width: 210px; }

/* ---------- Thanh AI ---------- */
.ai-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, color-mix(in srgb, var(--brand-500) 7%, var(--surface)), var(--surface) 70%);
  transition: background .2s;
}
.ai-bar.has-sel { background: linear-gradient(90deg, color-mix(in srgb, var(--brand-500) 16%, var(--surface)), color-mix(in srgb, var(--lime) 8%, var(--surface)) 70%); }
.ai-bar-label { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 700; color: var(--accent-text); white-space: nowrap; flex-shrink: 0; }
.ai-bar-label .ic { width: 16px; height: 16px; }
.ai-chips { display: flex; align-items: center; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; flex: 1; padding: 2px 0; }
.ai-chips::-webkit-scrollbar { display: none; }
.ai-chips { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); padding-right: 22px; }
.ai-chips .menu-wrap { flex-shrink: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 11px; flex-shrink: 0;
  border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--text-2);
  font-size: .8rem; font-weight: 600; white-space: nowrap; cursor: pointer; transition: border-color .15s, color .15s, background .15s;
}
.chip .ic { width: 14px; height: 14px; }
.chip:hover:not(:disabled) { border-color: var(--brand-500); color: var(--accent-text); background: var(--tint); }
.chip:disabled { opacity: .45; cursor: default; }
.ai-ask { display: flex; align-items: center; gap: 4px; flex: 0 1 280px; min-width: 180px; }
.ai-ask .input { flex: 1; min-width: 0; height: 34px; border-radius: 999px; padding: 0 14px; font-size: .84rem; }
.ai-ask .act { width: 34px; height: 34px; color: var(--accent-text); }
.md-tool.ai-off .ai-chips, .md-tool.ai-off .ai-ask { opacity: .55; }
@media (max-width: 899px) {
  .ai-bar { flex-wrap: wrap; row-gap: 6px; }
  .ai-chips { order: 3; flex-basis: 100%; }
  .ai-ask { flex: 1 1 200px; }
}

/* ---------- Vùng làm việc ---------- */
.work {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  height: clamp(440px, calc(100vh - 330px), 980px); min-height: 0;
}
.md-tool[data-view="edit"] .work { grid-template-columns: minmax(0, 1fr); }
.md-tool[data-view="edit"] .pane-pv { display: none; }
.md-tool[data-view="preview"] .work { grid-template-columns: minmax(0, 1fr); }
.md-tool[data-view="preview"] .pane-ed { display: none; }
.md-tool.is-narrow .only-wide { display: none; }
@media (max-width: 559px) { .work { height: max(62vh, 380px); } }

.pane-ed, .pane-pv { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.md-tool[data-view="split"] .pane-ed { border-right: 1px solid var(--border); }
#editor {
  flex: 1; width: 100%; height: 100%; min-height: 0; resize: none; margin: 0; border: 0; outline: none;
  padding: 18px 20px 40vh; background: var(--surface); color: var(--text);
  font-family: var(--mono); font-size: .9rem; line-height: 1.75; tab-size: 2;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal; overflow-y: auto;
  font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0;
}
#editor::placeholder { color: var(--text-3); }
#editor:read-only { cursor: progress; }
.md-tool.ai-writing #editor { background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--brand-500) 5%, var(--surface))); }
.ed-mirror {
  position: absolute; top: 0; left: 0; visibility: hidden; pointer-events: none; box-sizing: border-box;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal; z-index: -1;
  font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0;
}
.pv-scroll { flex: 1; min-height: 0; overflow: auto; padding: 22px 28px 40vh; background: var(--surface); }
.pv-scroll:focus { outline: none; }
.md-tool[data-view="preview"] .pv-scroll { padding-left: max(28px, calc(50% - 420px)); padding-right: max(28px, calc(50% - 420px)); }
.pv-empty { color: var(--text-3); }
@media (max-width: 559px) { #editor { padding: 14px 14px 40vh; } .pv-scroll { padding: 16px 16px 40vh; } }

.work.dragover::after {
  content: "Thả file .md, .txt, .html hoặc ảnh vào đây"; position: absolute; inset: 6px; z-index: 5; display: grid; place-items: center;
  border: 2px dashed var(--brand-500); border-radius: var(--r); font-weight: 700; color: var(--accent-text);
  background: color-mix(in srgb, var(--tint) 92%, transparent); pointer-events: none;
}

/* Nút chép trên khối code */
.md-body .code-copy {
  position: absolute; top: 6px; right: 6px; display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text-2); font: 600 .74rem var(--font);
  cursor: pointer; opacity: 0; transition: opacity .15s;
}
.md-body .code-copy .ic { width: 14px; height: 14px; }
.md-body pre:hover .code-copy, .md-body .code-copy:focus-visible { opacity: 1; }
.md-body pre:hover[data-lang]::before { opacity: 0; }
.md-body .code-copy.is-done { color: var(--ok); border-color: var(--ok); }
@media (hover: none) { .md-body .code-copy { opacity: .85; } }

/* Đang viết bằng AI */
.stream-badge {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 6; display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 8px 6px 14px; border-radius: 999px; background: var(--ink); color: #fff; font-size: .82rem; font-weight: 600; box-shadow: var(--shadow-lg);
}
.stream-badge .link-btn { color: #fff; background: rgba(255,255,255,.12); }
.stream-badge .link-btn:hover { background: rgba(255,255,255,.22); }
.dot-pulse { display: inline-block; width: 8px; height: 8px; margin-right: 2px; border-radius: 50%; background: var(--brand-500); animation: pulse 1s ease-in-out infinite; vertical-align: middle; }
@keyframes pulse { 0%, 100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.15); } }

/* ---------- Bảng bên (AI, mục lục, kiểm tra) ---------- */
.dock {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 8; width: min(400px, 100%);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: -18px 0 40px -24px rgba(15,38,32,.35);
}
.md-tool.is-full .work { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 0; }
.md-tool.is-full[data-dock] .work { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 400px; }
.md-tool.is-full[data-dock][data-view="edit"] .work, .md-tool.is-full[data-dock][data-view="preview"] .work { grid-template-columns: minmax(0, 1fr) 400px; }
.md-tool.is-full[data-view="edit"]:not([data-dock]) .work, .md-tool.is-full[data-view="preview"]:not([data-dock]) .work { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .md-tool.is-full .dock { position: relative; width: auto; box-shadow: none; } }
.dock-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 0 10px; border-bottom: 1px solid var(--border); }
.dock-tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.dock-tab {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px; border: 0; border-bottom: 2px solid transparent;
  background: none; color: var(--text-3); font-size: .84rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.dock-tab .ic { width: 15px; height: 15px; }
.dock-tab[aria-selected="true"] { color: var(--accent-text); border-bottom-color: var(--brand-500); }
.act-sm { width: 32px; height: 32px; }
.dock-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.dock-panel[hidden] { display: none; }
.dock-panel[data-panel="toc"], .dock-panel[data-panel="lint"] { overflow: auto; padding: 12px; }
.dock-empty { color: var(--text-3); font-size: .86rem; padding: 6px 4px; }

/* Trò chuyện */
.chat { flex: 1; min-height: 0; overflow: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 12px; }
.chat-empty { margin: auto 0; text-align: center; padding: 10px 6px; color: var(--text-2); font-size: .88rem; }
.chat-empty[hidden] { display: none; }
.chat-empty-ic { display: inline-grid; place-items: center; width: 44px; height: 44px; margin-bottom: 10px; border-radius: 14px; background: var(--ai-grad); color: #fff; }
.chat-empty-ic .ic { width: 22px; height: 22px; }
.chat-empty b { color: var(--text); }
.suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 14px; }
.suggest .chip { height: auto; min-height: 30px; padding: 5px 11px; white-space: normal; text-align: left; }
.msg { max-width: 100%; }
.msg-user { align-self: flex-end; max-width: 88%; }
.msg-user .msg-body { padding: 8px 12px; border-radius: 14px 14px 4px 14px; background: var(--tint); color: var(--text); font-size: .88rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-assistant .msg-body { font-size: .9rem; line-height: 1.65; }
.msg-assistant .msg-body h1 { font-size: 1.3em; } .msg-assistant .msg-body h2 { font-size: 1.15em; } .msg-assistant .msg-body h3 { font-size: 1.02em; }
.msg-error .msg-body { color: var(--danger); background: var(--danger-bg); padding: 8px 12px; border-radius: 10px; font-size: .86rem; }
.msg-acts { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 6px; }
.msg-acts .ic { width: 14px; height: 14px; }
.ai-wait { color: var(--text-3); font-size: .86rem; display: flex; align-items: center; gap: 8px; }
.chat-form { display: flex; align-items: flex-end; gap: 8px; margin: 6px 12px 0; padding: 6px 6px 6px 12px; border: 1.5px solid var(--border-strong); border-radius: 16px; background: var(--surface); }
.chat-form:focus-within { border-color: var(--brand-500); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 15%, transparent); }
.chat-form[hidden] { display: none; }
.chat-form textarea { flex: 1; min-width: 0; max-height: 160px; padding: 6px 0; border: 0; outline: none; resize: none; background: none; color: var(--text); font: inherit; font-size: .9rem; line-height: 1.5; }
.send-btn { display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0; border: 0; border-radius: 12px; background: var(--ai-grad); color: #fff; cursor: pointer; }
.send-btn .ic { width: 17px; height: 17px; }
.send-btn .ic-stop { display: none; }
.send-btn.is-stop { background: var(--ink); }
.send-btn.is-stop .ic-send { display: none; }
.send-btn.is-stop .ic-stop { display: block; }
.chat-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px 10px; }
.chat-foot .ic { width: 14px; height: 14px; }
.chat-model { font-size: .72rem; color: var(--text-3); }
.ai-off { display: flex; gap: 10px; margin: 10px 12px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--warn-bg); color: var(--warn); font-size: .84rem; }
.ai-off .ic { width: 16px; height: 16px; margin-top: 2px; }
.ai-off[hidden] { display: none; }

/* Mục lục */
.toc-actions { margin-bottom: 8px; }
.toc-actions .ic { width: 15px; height: 15px; }
.toc { display: flex; flex-direction: column; }
.toc-item {
  display: block; width: 100%; padding: 6px 10px; border: 0; border-left: 2px solid var(--border); background: none; text-align: left;
  font-size: .86rem; color: var(--text-2); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toc-item:hover { color: var(--accent-text); background: var(--tint); }
.toc-item.is-active { color: var(--accent-text); border-left-color: var(--brand-500); font-weight: 600; background: color-mix(in srgb, var(--tint) 60%, transparent); }

/* Kiểm tra */
.lint-head { font-size: .84rem; color: var(--text-2); margin-bottom: 10px; }
.lint-ok { display: inline-flex; align-items: center; gap: 8px; color: var(--ok); font-weight: 600; }
.lint-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lint-item { display: flex; gap: 10px; align-items: flex-start; width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); text-align: left; font-size: .84rem; color: var(--text-2); cursor: pointer; }
.lint-item:hover { border-color: var(--border-strong); background: var(--tint); }
.lint-item .ic { width: 16px; height: 16px; margin-top: 2px; }
.lint-item b { color: var(--text); font-weight: 600; }
.lv-error .ic { color: var(--danger); }
.lv-warn .ic { color: var(--warn); }
.lv-info .ic { color: var(--text-3); }

/* ---------- Thanh trạng thái ---------- */
.status-bar {
  display: flex; align-items: center; gap: 6px 16px; flex-wrap: wrap; padding: 8px 14px; border-top: 1px solid var(--border);
  font-size: .78rem; color: var(--text-3); font-variant-numeric: tabular-nums; border-radius: 0 0 var(--r-lg) var(--r-lg); background: var(--surface-2);
}
.st-save { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; }
.st-save .ic { width: 14px; height: 14px; color: var(--ok); }
.st-save.is-saving .ic { opacity: .3; }
.st-save.is-error { color: var(--danger); }
.st-save.is-error .ic { color: var(--danger); }

/* ---------- Toàn màn hình ---------- */
html.md-full, html.md-full body { overflow: hidden; }
.md-tool.is-full { position: fixed; inset: 0; z-index: 70; border-radius: 0; border: 0; }
.md-tool.is-full .work { flex: 1; height: auto; }
.md-tool.is-full .status-bar { border-radius: 0; }
html.md-full .nudge, html.md-full .mp-chip, html.md-full [data-mp-chip] { display: none !important; }

/* ---------- Hộp thoại ---------- */
.dlg {
  width: min(94vw, 780px); max-height: min(90vh, 860px); padding: 0; border: 0; border-radius: 20px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); overflow: hidden;
}
.dlg[open] { display: flex; flex-direction: column; }
.dlg > form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.dlg::backdrop { background: rgba(6,20,16,.55); backdrop-filter: blur(3px); }
.dlg-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 18px 12px; }
.dlg-ic { display: grid; place-items: center; width: 38px; height: 38px; flex-shrink: 0; border-radius: 12px; background: var(--ai-grad); color: #fff; }
.dlg-title-wrap { flex: 1; min-width: 0; }
.dlg-head h2 { font-size: 1.05rem; font-weight: 700; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.dlg-sub { margin-top: 2px; font-size: .82rem; color: var(--text-3); }
.dlg-close { width: 34px; height: 34px; flex-shrink: 0; }
.dlg-body { flex: 1; min-height: 0; overflow: auto; padding: 4px 18px 14px; }
.dlg-foot { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; padding: 12px 18px 16px; border-top: 1px solid var(--border); }
.dlg-meta { margin-right: auto; font-size: .8rem; color: var(--text-3); display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.dlg-foot .btn-primary:disabled { opacity: .5; cursor: default; }
@media (max-width: 559px) {
  .dlg { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 20px 20px 0 0; }
  .dlg-foot .act span { display: none; }
  .dlg-foot .act { width: 44px; padding: 0; }
  .dlg-meta { flex-basis: 100%; margin-bottom: 4px; }
  .dlg-foot .btn-primary { flex: 1; }
}

/* Hộp kết quả AI */
.ai-views { margin: 0 18px 10px; align-self: flex-start; }
.ai-views label[hidden] { display: none; }
.ai-dlg .dlg-body { min-height: 180px; }
.ai-out { min-height: 160px; }
.ai-out.md-body { font-size: .95rem; }
.ai-diff { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .92rem; line-height: 1.75; }
.ai-diff ins { text-decoration: none; background: var(--ins-bg); color: var(--ins-text); border-radius: 3px; padding: 0 1px; }
.ai-diff del { background: var(--del-bg); color: var(--del-text); border-radius: 3px; padding: 0 1px; text-decoration-thickness: 1px; }
.ai-src { display: block; width: 100%; height: 100%; min-height: 300px; resize: vertical; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--code-bg); color: var(--text); font: .86rem/1.65 var(--mono); }
.ai-src:focus { outline: none; border-color: var(--brand-500); }
.ai-error { display: flex; gap: 10px; align-items: flex-start; margin-top: 10px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--danger-bg); color: var(--danger); font-size: .88rem; }
.ai-error .ic { width: 17px; height: 17px; margin-top: 2px; }
.dlg > form.ai-refine { display: flex; flex-direction: row; flex: 0 0 auto; gap: 6px; padding: 0 18px 12px; }
.ai-refine .input { flex: 1; min-width: 0; height: 40px; }
.ai-refine .act { width: 40px; height: 40px; color: var(--accent-text); }
.ai-dlg[data-state="streaming"] .ai-out { cursor: progress; }

/* Hộp AI viết */
.write-dlg { width: min(94vw, 640px); }
.write-kinds { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.write-kinds label { position: relative; cursor: pointer; }
.write-kinds input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.write-kinds span { display: inline-flex; align-items: center; height: 32px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 999px; font-size: .82rem; font-weight: 600; color: var(--text-2); }
.write-kinds input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.write-kinds input:focus-visible + span { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.write-prompt { display: block; width: 100%; padding: 12px 14px; border: 1.5px solid var(--border-strong); border-radius: var(--r); background: var(--surface); color: var(--text); font: inherit; font-size: .95rem; line-height: 1.6; resize: vertical; }
.write-prompt:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-500) 15%, transparent); }
.write-opts { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 18px; margin-top: 12px; }
.write-opts label[hidden] { display: none; }

/* Bảng lệnh */
.cmd-dlg { width: min(94vw, 620px); margin-top: 12vh; max-height: 70vh; }
.cmd-search { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.cmd-search .ic { color: var(--text-3); }
.cmd-search input { flex: 1; min-width: 0; height: 36px; border: 0; outline: none; background: none; color: var(--text); font: inherit; font-size: 1rem; }
.cmd-list { flex: 1; min-height: 0; overflow: auto; padding: 6px; }
.cmd-group { padding: 10px 10px 4px; font-size: .72rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.cmd-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: none; text-align: left; cursor: pointer; color: var(--text); font-size: .9rem; }
.cmd-item.is-sel { background: var(--tint); }
.cmd-item .ic { width: 16px; height: 16px; color: var(--accent-text); }
.cmd-item kbd { margin-left: auto; font-size: .68rem; }
.cmd-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-grp { margin-left: auto; font-size: .74rem; color: var(--text-3); white-space: nowrap; }
.cmd-item kbd + .cmd-grp { margin-left: 8px; }
.cmd-item.is-ask { color: var(--accent-text); font-weight: 600; }
.cmd-empty { padding: 18px; text-align: center; color: var(--text-3); font-size: .9rem; }

/* Hộp nhập nhanh */
.ask-dlg { width: min(94vw, 480px); }
#askFields { display: flex; flex-wrap: wrap; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; flex-basis: 100%; font-size: .84rem; font-weight: 600; color: var(--text-2); }
.field-inline { flex: 1 1 120px; }
.field .input { height: 40px; font-weight: 400; width: 100%; }
.field textarea.input { height: auto; padding: 10px 12px; line-height: 1.55; resize: vertical; font-family: inherit; }
.field-extra { align-self: flex-start; }
.ask-ai { margin-right: auto; color: var(--accent-text); }

/* Thông báo có nút */
.toast { display: inline-flex; align-items: center; gap: 12px; }
.toast.has-act { pointer-events: auto; padding-right: 8px; }
.toast-act { border: 0; background: rgba(255,255,255,.16); color: inherit; font: inherit; font-weight: 700; font-size: .84rem; padding: 5px 10px; border-radius: 999px; cursor: pointer; }
:root[data-theme="dark"] .toast-act { background: rgba(15,38,32,.12); }
.toast:not(.show) { pointer-events: none !important; }

/* ---------- Bảng cú pháp ---------- */
.cheat { margin-top: 48px; }
.cheat-grid { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 600px) { .cheat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .cheat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.ck { display: flex; flex-direction: column; gap: 8px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); }
.ck code { display: block; padding: 10px 12px; border-radius: var(--r-sm); background: var(--code-bg); border: 1px solid var(--border); font: .8rem/1.6 var(--mono); color: var(--syn-key); overflow-x: auto; white-space: nowrap; }
.ck span { font-size: .84rem; color: var(--text-2); }

/* ---------- Điện thoại ---------- */
@media (max-width: 559px) {
  .top-bar { padding: 10px 10px 8px; gap: 6px; }
  .top-bar > .menu-wrap:first-child { flex: 1 1 100%; }
  .doc-btn, .md-tool.is-compact .doc-btn { width: 100%; max-width: none; }
  .view-seg { flex: 1; }
  .view-seg label { flex: 1; }
  .view-seg span { justify-content: center; width: 100%; padding: 7px 6px; }
  .top-actions { margin-left: 0; gap: 4px; }
  .top-actions .act span { display: none; }
  .top-actions .act { width: 40px; padding: 0; }
  .btn-ai { padding: 0 12px; }
  .fmt-bar { padding: 2px 6px; }
  .fmt-bar .act[data-dock="ai"] span { display: none; }
  .fmt-bar .act[data-dock="ai"] { width: 36px; padding: 0; }
  .status-bar { padding: 7px 10px; gap: 4px 12px; }
}
@media (max-width: 380px) { .view-seg span .ic { display: none; } }

/* ---------- In ---------- */
#printArea { display: none; }
@media print {
  html.printing body > *:not(#printArea) { display: none !important; }
  html.printing #printArea { display: block; }
  html.printing body { background: #fff; }
  html.printing body::before { display: none; }
  #printArea .md-body { --md-text: #1d2a25; --md-muted: #5b6b65; --md-border: #dbe5df; --md-soft: #f3f7f5; --md-code-bg: #f4f7f5; --md-link: #0b7a57; --md-mark: #fff1a8; --md-diagram-bg: #fff; color: #1d2a25; }
  @page { margin: 16mm 14mm; }
}
