/* ── Fonts tự host (gộp từ fonts/*.css — giảm render-blocking request) ── */
@font-face {
  font-family: 'Material Symbols Outlined';
  font-style: normal;
  font-weight: 100 700;
  font-display: block;
  src: url(/fonts/ms-subset.woff2) format('woff2');
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/Inter-400-9df17551da.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/Inter-400-1ad231aac0.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/Inter-400-260c81a475.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/fonts/Inter-400-9df17551da.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/fonts/Inter-400-1ad231aac0.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/fonts/Inter-400-260c81a475.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/fonts/Inter-400-9df17551da.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/fonts/Inter-400-1ad231aac0.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/fonts/Inter-400-260c81a475.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/fonts/Inter-400-9df17551da.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/fonts/Inter-400-1ad231aac0.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/fonts/Inter-400-260c81a475.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/JetBrainsMono-400-ffcfa7a246.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/JetBrainsMono-400-bd4781a31b.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/JetBrainsMono-400-b636a65da4.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/fonts/JetBrainsMono-400-ffcfa7a246.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/fonts/JetBrainsMono-400-bd4781a31b.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/fonts/JetBrainsMono-400-b636a65da4.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/fonts/JetBrainsMono-400-ffcfa7a246.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/fonts/JetBrainsMono-400-bd4781a31b.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/fonts/JetBrainsMono-400-b636a65da4.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ── Header (fixed, glass) ──────────────────────── */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100; height: 64px;
  background: color-mix(in srgb, var(--bg-deep) 78%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1200px; margin: 0 auto; height: 100%;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 0 20px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-tile {
  width: 32px; height: 32px; border-radius: var(--r-md); flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
}
.logo-tile .msym { font-size: 18px; color: var(--on-accent); }
.brand-name { font-weight: 700; font-size: 17px; color: var(--accent); letter-spacing: -.01em; }
.note-chip {
  display: inline-flex; align-items: center;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--subtle); background: transparent;
  border: none; border-radius: 6px; padding: 2px 4px;
  white-space: nowrap;
}
.chip-lock {
  display: none; align-items: center; gap: 5px;
  color: var(--warn); border: 1px solid rgba(255,159,10,.3); background: rgba(255,159,10,.08);
  border-radius: 999px; padding: 2px 9px;
}
.chip-lock.show { display: inline-flex; }
.header-nav { display: flex; align-items: center; gap: 4px; }
.nav-link {
  font-family: var(--font-mono); font-size: 12px; text-decoration: none;
  color: var(--subtle); padding: 6px 12px; border-radius: 8px;
  border-bottom: 2px solid transparent; cursor: pointer; transition: all .15s ease;
}
.nav-link:hover { background: rgba(255,255,255,.05); color: var(--text); }
body.light .nav-link:hover { background: rgba(0,0,0,.05); }
.nav-link.active { color: var(--accent); border-bottom-color: var(--accent); border-radius: 8px 8px 0 0; }

.actions { display: flex; align-items: center; gap: 6px; }

/* ── Buttons ────────────────────────────────────── */
.icon-btn, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: transparent; border: none; color: var(--text);
  cursor: pointer; border-radius: var(--r-md);
  transition: background .15s ease, transform .1s ease, opacity .15s ease;
  position: relative; text-decoration: none;
}
.icon-btn { width: 36px; height: 36px; }
.icon-btn .msym { font-size: 20px; color: var(--subtle); transition: color .15s ease; }
.icon-btn:hover .msym { color: var(--text); }
.btn { padding: 8px 14px; font-size: 13px; font-weight: 550; font-family: inherit; }
.btn:hover { background: rgba(255,255,255,.05); }
body.light .btn:hover { background: rgba(0,0,0,.05); }
.icon-btn:hover { background: rgba(255,255,255,.05); }
body.light .icon-btn:hover { background: rgba(0,0,0,.05); }
.icon-btn:active, .btn:active { transform: scale(.96); }
.divider-v { width: 1px; height: 22px; background: var(--border-strong); margin: 0 6px; }
.btn-primary {
  background: var(--accent-deep); color: var(--on-accent);
  font-family: var(--font-mono); font-size: 12px; font-weight: 600; letter-spacing: .03em;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.btn-primary:hover { filter: brightness(1.08); background: var(--accent-deep); opacity: 1; }
.btn-danger-solid { background: var(--error-solid); color: #ffdad6; }
.btn-danger-solid:hover { background: var(--error-solid); opacity: .9; }
.menu-item-danger:hover { color: var(--error); }

/* Tooltip */
[data-tip]::after {
  content: attr(data-tip); position: absolute; top: calc(100% + 8px); left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: var(--surface-3); border: 1px solid var(--border); color: var(--text);
  font-family: var(--font-mono); font-size: 11px; padding: 4px 9px; border-radius: 7px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .15s ease, transform .15s ease; z-index: 160;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
[data-tip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Dropdown menu ⋯ ────────────────────────────── */
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 150;
  min-width: 240px; background: var(--surface-2); border: 1px solid var(--glass-border);
  border-radius: var(--r-md); padding: 5px; box-shadow: var(--shadow-menu);
  opacity: 0; pointer-events: none;
  /* Chỉ translateY, KHÔNG scale() (sửa 2026-09-13): scale buộc Chrome
     raster lại layer + bóng đổ ở 2 tỉ lệ khác nhau trong lúc transition.
     Dùng --shadow-menu hẹp thay --shadow-lg để bounding box layer nhỏ lại. */
  transform: translateY(-4px); transform-origin: top right;
  transition: opacity .15s ease, transform .15s ease;
}
.menu.open { opacity: 1; pointer-events: auto; transform: none; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text); background: none; border: none; border-radius: 8px;
  cursor: pointer; text-align: left; transition: background .12s ease;
}
.menu-item:hover { background: var(--surface-3); }
.menu-item .msym { font-size: 18px; color: var(--subtle); }
.menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }
#miPermanentUnlock { display: none; }

/* ── Editor card (solid — bỏ blur 20px để mượt trên Windows) ─ */
.editor-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden;
  display: flex; flex-direction: column; min-height: 0;
  transition: border-color .2s ease, box-shadow .2s ease;
  contain: content;
}
.editor-card:focus-within { border-color: rgba(10,132,255,.35); box-shadow: 0 0 0 3px rgba(10,132,255,.08); }

.editor-body { display: flex; align-items: stretch; flex: 1; min-height: 0; overflow: hidden; }
.gutter {
  min-width: 3.4ch; padding: 20px 10px 12px; text-align: right;
  font-family: var(--font-mono); font-size: 13px; line-height: 24px;
  color: color-mix(in srgb, var(--subtle) 55%, transparent);
  user-select: none; overflow: hidden; flex-shrink: 0;
  border-right: 1px solid var(--border);
}
.gutter div { transition: color .1s ease; }
.gutter div.active { color: var(--accent); font-weight: 600; }
textarea {
  display: block; flex: 1; width: 100%; min-width: 0; height: 100%; resize: none;
  overflow-y: auto; overflow-x: auto; white-space: pre;
  background: transparent; border: none; outline: none; color: var(--text);
  caret-color: var(--accent);
  font-family: var(--font-mono); font-size: 13.5px; line-height: 24px;
  padding: 20px 20px 12px;
}
textarea::placeholder { color: var(--subtle); opacity: .65; }

/* Statusbar nhúng trong card */
.statusbar {
  display: flex; justify-content: flex-end; align-items: center;
  padding: 7px 14px; font-size: 11.5px; color: var(--subtle);
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-deep) 55%, transparent);
  flex-shrink: 0; gap: 10px;
}
#lnCol {
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--ok); font-weight: 600; margin-right: auto;
}
.statusbar-spacer { margin-right: auto; display: none; }
.sep-v { opacity: .35; }
.icon-btn.mini { width: auto; height: auto; padding: 4px 8px; border-radius: 7px; font-size: 11.5px; color: var(--subtle); }
.icon-btn.mini .msym { font-size: 15px; }
.icon-btn.mini:hover { color: var(--text); background: var(--surface-2); }

/* ── Cột phải: files panel + info card ──────────── */
.right-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.files-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden;
  position: sticky; top: 84px; align-self: start;
  contain: content;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px 10px;
}
.panel-title {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  letter-spacing: .12em; text-transform: uppercase; color: var(--subtle);
}
.add-file-btn {
  all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-mono); font-size: 12px; color: var(--accent-deep);
  padding: 3px 8px; border-radius: 7px; transition: color .15s ease, background .15s ease;
}
body.light .add-file-btn { color: var(--accent); }
.add-file-btn .msym { font-size: 16px; }
.add-file-btn:hover { color: var(--accent); background: rgba(255,255,255,.05); }
body.light .add-file-btn:hover { background: rgba(0,0,0,.05); }
.panel-body { display: flex; flex-direction: column; padding: 0 14px 14px; gap: 10px; }
.drop-zone {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  border: 2px dashed var(--border); border-radius: var(--r-md);
  padding: 26px 14px; color: var(--subtle); font-size: 12.5px; cursor: pointer;
  text-align: center; flex-direction: column; gap: 8px;
  transition: border-color .2s ease, background .2s ease, color .2s ease;
}
.dz-bubble {
  width: 44px; height: 44px; border-radius: 999px;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  transition: transform .2s ease;
}
.dz-bubble .msym { font-size: 22px; }
.drop-zone:hover, .drop-zone.drag-over {
  border-color: color-mix(in srgb, var(--accent-deep) 50%, transparent);
  background: var(--surface); color: var(--text);
}
.drop-zone:hover .dz-bubble, .drop-zone.drag-over .dz-bubble { transform: scale(1.1); }

.upload-box {
  display: none; flex-direction: column; gap: 5px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2);
}
.upload-box.show { display: flex; }
.upload-info { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--subtle); gap: 8px; }
.upload-info b {
  color: var(--text); font-weight: 550; font-family: var(--font-mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.upload-track { height: 4px; border-radius: 99px; background: var(--bg-deep); overflow: hidden; }
.upload-fill { height: 100%; width: 0; background: var(--accent-deep); transition: width .15s ease; }

.file-list {
  display: flex; flex-direction: column; gap: 7px;
  max-height: calc(100vh - 300px); overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent;
}
.file-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border);
  transition: border-color .15s ease;
}
.file-item:hover { border-color: var(--border-strong); }
.file-icon-chip {
  width: 34px; height: 34px; border-radius: var(--r-sm); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.file-icon-chip .msym { font-size: 18px; }
.fi-pdf { background: rgba(239,68,68,.1);  color: #f87171; }
.fi-img { background: rgba(56,189,248,.1); color: #38bdf8; }
.fi-media { background: rgba(168,85,247,.12); color: #c084fc; }
.fi-zip { background: rgba(255,159,10,.12); color: var(--warn); }
.fi-doc { background: rgba(71,226,102,.1); color: var(--ok); }
.file-info { flex: 1; min-width: 0; }
.file-name {
  font-weight: 550; font-size: 12.5px; font-family: var(--font-mono); display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-decoration: none; color: var(--text); cursor: pointer;
}
.file-name:hover { text-decoration: underline; color: var(--accent-deep); }
body.light .file-name:hover { color: var(--accent); }
.file-meta { font-size: 10.5px; color: var(--subtle); margin-top: 1px; }
.file-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s ease; flex-shrink: 0; }
.file-item:hover .file-actions { opacity: 1; }
@media (hover: none) { .file-actions { opacity: 1; } }
.file-actions .icon-btn { width: 28px; height: 28px; border-radius: 7px; }
.file-actions .icon-btn .msym { font-size: 16px; }
.file-actions .danger:hover .msym { color: var(--error); }

/* ── Overlay / Modal ────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none; transition: opacity .22s ease;
}
.overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  width: 90%; max-width: 340px; background: var(--surface);
  border: 1px solid var(--glass-border); border-radius: var(--r-lg); padding: 26px 24px 22px;
  /* --shadow-modal (blur 32px) thay --shadow-lg (blur 60px): layer lúc animate
     184k → 116k px. Giữ nguyên hiệu ứng nảy bên dưới — đo cho thấy bỏ scale()
     không giảm thêm, nên không đánh đổi thiết kế. */
  box-shadow: var(--shadow-modal); position: relative;
  transform: translateY(10px) scale(.96); opacity: 0;
  transition: transform .25s cubic-bezier(.2,.9,.3,1.2), opacity .2s ease;
}
.overlay.open .modal { transform: translateY(0) scale(1); opacity: 1; }
.modal-icon {
  width: 42px; height: 42px; border-radius: 12px; margin-bottom: 14px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10,132,255,.12); color: var(--accent);
}
.modal-icon.blue { background: rgba(121,184,254,.12); color: var(--info); }
.modal-icon.red { background: rgba(255,180,171,.1); color: var(--error); }
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.modal p { margin: 0 0 18px; font-size: 13px; color: var(--subtle); }
.modal input {
  width: 100%; padding: 11px 14px; font-family: inherit; font-size: 13.5px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--input-bg); color: var(--text); outline: none;
  transition: border-color .15s ease, box-shadow .15s ease; margin-bottom: 14px;
}
.modal input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10,132,255,.12); }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; }
/* .modal .modal-x (không phải .modal-x): cần độ ưu tiên cao hơn .icon-btn trong rule
   ripple ở cuối file — nếu không, position:relative của ripple sẽ ghi đè position:absolute
   và đẩy nút X lệch ra ngoài panel. */
.modal .modal-x { position: absolute; top: 12px; right: 12px; color: var(--subtle); width: 30px; height: 30px; }
.modal-x .msym { font-size: 19px; }

/* Sheet (admin / history) */
.overlay.sheet { align-items: flex-start; padding: 9vh 16px 16px; overflow-y: auto; }
.sheet-panel { width: 90%; max-width: 640px; padding: 0; transform-origin: top center; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 0; }
.sheet-head h3 { margin: 0; display: flex; align-items: center; gap: 8px; }
.count-pill {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600; color: var(--subtle);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px;
}
.sheet-sub { padding: 6px 20px 0; font-size: 12.5px; color: var(--subtle); margin: 0; }
.sheet-body { padding: 14px 20px 20px; }
.sheet-search {
  width: 100%; padding: 10px 12px; font-family: var(--font-mono); font-size: 12.5px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--input-bg); color: var(--text); outline: none;
  transition: border-color .15s ease, box-shadow .15s ease; margin-bottom: 12px;
}
.sheet-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10,132,255,.1); }
.sheet-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 54vh; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent;
}
.empty-state { text-align: center; color: var(--subtle); font-size: 13px; padding: 26px 0; }

.admin-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-md);
  cursor: pointer; background: var(--surface);
  transition: border-color .15s ease, background .15s ease;
}
.admin-row:hover { background: var(--surface-2); border-color: var(--border-strong); }
.admin-row .rid {
  font-family: var(--font-mono); font-size: 12.5px; white-space: nowrap;
  min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis;
}
.admin-file {
  display: inline-flex; align-items: center; gap: 3px; flex-shrink: 0;
  font-family: var(--font-mono); font-size: 11px; color: var(--subtle);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px;
}
.admin-file .msym { font-size: 13px !important; }
.admin-days { font-family: var(--font-mono); font-size: 11px; color: var(--subtle); white-space: nowrap; flex-shrink: 0; }
.admin-days.danger { color: var(--error); font-weight: 500; }
.admin-date { font-size: 11px; color: var(--subtle); white-space: nowrap; flex-shrink: 0; }
.lock-badge { color: var(--warn); font-size: 14px !important; flex-shrink: 0; }
.chev { color: var(--subtle); opacity: .6; flex-shrink: 0; font-size: 16px !important; }
.empty-state { text-align: center; color: var(--subtle); font-size: 13px; padding: 26px 0; }

.version-item {
  padding: 13px 16px; border: 1px solid var(--border); border-radius: var(--r-md);
  display: flex; flex-direction: column; gap: 10px; background: var(--surface);
}
.version-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.version-label { font-weight: 600; font-size: 13.5px; }
.version-date { font-size: 11px; color: var(--subtle); margin-top: 2px; }
.btn-rollback {
  background: var(--accent-deep); color: var(--on-accent); border: none; cursor: pointer;
  padding: 6px 12px; font-size: 12px; font-weight: 600; font-family: var(--font-mono);
  border-radius: 8px; transition: filter .15s ease; flex-shrink: 0;
}
.btn-rollback:hover { filter: brightness(1.08); }
.btn-rollback:disabled { opacity: .5; cursor: default; }
.version-preview { border-top: 1px dashed var(--border); padding-top: 8px; cursor: pointer; }
.version-preview summary { font-size: 12px; color: var(--subtle); outline: none; user-select: none; }
.version-preview pre {
  margin: 8px 0 0; font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
  background: var(--input-bg); padding: 10px; border-radius: 8px;
  max-height: 140px; overflow-y: auto; color: var(--text); font-family: var(--font-mono);
  border: 1px solid var(--border);
}

/* ── Toast (Apple pill · fixed peek + hide) ───── */
#toast {
  position: fixed; top: 72px; left: 50%; z-index: 500;
  display: flex; align-items: center; gap: 6px;
  transform: translate(-50%, -150px);
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 7px 14px; border-radius: 999px; font-size: 12px; font-weight: 500; letter-spacing: -0.01em;
  box-shadow: 0 8px 24px rgba(0,0,0,.35), 0 1px 0 rgba(255,255,255,.06) inset;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: transform .45s cubic-bezier(.19,1,.22,1);
  max-width: 90vw; white-space: nowrap;
}
#toast.show { transform: translate(-50%, 0); }
#toast .msym { font-size: 15px; color: var(--accent); flex-shrink: 0; }
#toast.error { background: var(--error-solid); color: #ffdad6; border-color: rgba(255,255,255,.12); }
#toast.error .msym { color: #ffdad6; }

/* ── Ripple (fx.js chèn span vào .btn khi bấm) ─── */
.btn, .btn-rollback, .icon-btn {
  position: relative; overflow: hidden; contain: layout paint; -webkit-tap-highlight-color: transparent;
}
.ripple {
  position: absolute; width: 2px; height: 2px; border-radius: 50%; pointer-events: none;
  background: currentColor; transform: translate(-50%, -50%) scale(0);
  animation: ripple-spread .45s ease-out forwards;
}
@keyframes ripple-spread {
  0% { transform: translate(-50%, -50%) scale(0); opacity: .22; }
  100% { transform: translate(-50%, -50%) scale(var(--r-scale, 100)); opacity: 0; }
}

/* ── Mobile layout (đặt CUỐI để thắng cascade) ──── */
@media (max-width: 920px) {
  body { height: auto; overflow: auto; }
  .main-grid { grid-template-columns: 1fr; }

  /* Mobile: bỏ số dòng — dành hết chiều ngang cho nội dung */
  .gutter { display: none; }

  /* Height theo vh để trang khít màn hình khi panel đóng → không scrollbar */
  .editor-body { flex: none; height: calc(100vh - 228px); min-height: 300px; }
  .files-panel { position: static; align-self: auto; }

  /* Panel đính kèm collapse mặc định trên mobile — bấm head để mở/đóng */
  .panel-head { cursor: pointer; user-select: none; }
  .files-panel:not(.open) .panel-body { display: none; }
}

@media (max-width: 600px) {
  /* Header: thu gọn — ẩn nav + nhãn nút, chỉ còn brand | history | menu */
  .header-nav, .btn span.lbl, .header-actions-hide-sm, #btnSaveHeader { display: none !important; }
  .header-inner { gap: 8px; padding: 0 12px; }
  .brand-name { font-size: 15px; }
  .note-chip { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
  .btn { padding: 8px 10px; }

  /* Statusbar: không wrap, co chữ đếm từ */
  .statusbar { gap: 6px; padding: 7px 10px; }

  /* Modal buttons xếp dọc */
  .modal-btns { flex-direction: column-reverse; }
  .modal-btns .btn { justify-content: center; width: 100%; }
  #lnCol { white-space: nowrap; }

  /* Admin row: tên note xuống dòng riêng, badge nằm dưới — tránh chen chúc */
  .admin-row { flex-wrap: wrap; row-gap: 6px; }
  .admin-row .rid { flex: 1 1 100%; }
  .chev { display: none; }
}
