:root {
  --navy: #18243a;
  --navy-2: #22304a;
  --accent: #1877f2;
  --accent-soft: #e8f1ff;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #111827;
  --muted: #64748b;
  --border: #dbe3ee;
  --border-strong: #c7d2e1;
  --danger: #c0392b;
  --success: #15803d;
  --shadow: 0 12px 32px rgba(24, 36, 58, 0.08);
  --radius: 8px;
  --header-h: 56px;
  --toolbar-h: 42px;
  --editor-font-size: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --surface: #111827;
    --surface-2: #172033;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #2a3850;
    --border-strong: #3a4b68;
    --accent-soft: #14294b;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #111827;
  --surface-2: #172033;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #2a3850;
  --border-strong: #3a4b68;
  --accent-soft: #14294b;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Pretendard, "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.skip-link {
  position: fixed; left: 12px; top: -60px; z-index: 9999;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 8px;
}
.skip-link:focus { top: 12px; }

.app-shell { height: 100dvh; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.app-header {
  height: var(--header-h); flex: 0 0 var(--header-h);
  padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--navy); color: white; border-bottom: 1px solid rgba(255,255,255,.05);
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center;
  width: 21px; height: 21px; border: 1.5px solid #fff; border-radius: 2px;
  font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: -.02em; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 7px; }
.mobile-more-button { display: none; }
.header-button, .header-icon {
  border: 1px solid rgba(255,255,255,.7); background: transparent; color: #fff;
  min-height: 30px; border-radius: 5px; padding: 4px 9px; font-size: 13px;
}
.header-button:hover, .header-icon:hover { background: rgba(255,255,255,.09); }

.workspace { flex: 1; min-height: 0; padding: 16px 24px 18px; display: flex; flex-direction: column; gap: 12px; overflow: hidden; }
.editor-card {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
}
.document-bar {
  min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 10px 6px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.doc-title {
  width: min(520px, 50vw); border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--text);
  font-size: 14px; font-weight: 700; padding: 6px 8px;
}
.doc-title:hover, .doc-title:focus { border-color: var(--border-strong); background: var(--surface); }
.document-actions { display: flex; align-items: center; gap: 6px; }
.compact-action { min-height: 31px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); color: var(--text); padding: 0 9px; font-size: 11px; font-weight: 750; white-space: nowrap; }
.compact-action:hover { background: var(--surface-2); border-color: var(--border-strong); }
.compact-action.save-action { background: var(--accent); border-color: var(--accent); color: #fff; }
.compact-action.save-action:hover { filter: brightness(.96); }
.save-state { color: var(--muted); font-size: 12px; margin-right: 4px; }
.save-state.dirty { color: #b45309; }
.save-state.saving { color: var(--accent); }
.save-state.saved { color: var(--success); }
.icon-button {
  width: 31px; height: 31px; display: inline-grid; place-items: center;
  border: 1px solid var(--border); border-radius: 5px; background: var(--surface); color: var(--text); padding: 0;
}
.icon-button:hover { background: var(--surface-2); border-color: var(--border-strong); }
.danger-soft:hover { background: #fff0ee; color: var(--danger); border-color: #f0b8b0; }

.format-toolbar {
  min-height: var(--toolbar-h); display: flex; align-items: stretch; overflow-x: auto; overflow-y: hidden;
  border-bottom: 1px solid var(--border); background: var(--surface); scrollbar-width: thin;
}
.tool-group { display: flex; align-items: center; padding: 4px 5px; border-right: 1px solid var(--border); flex: 0 0 auto; }
.tool-button {
  min-width: 30px; height: 31px; padding: 0 7px; border: 1px solid transparent; border-radius: 4px;
  background: transparent; color: #315078; font-size: 12px; font-weight: 650;
}
:root[data-theme="dark"] .tool-button { color: #b8c7df; }
.tool-button:hover { background: var(--surface-2); border-color: var(--border); }
.tool-button.strong { font-weight: 900; }
.tool-button.italic { font-style: italic; }
.tool-button.underline { text-decoration: underline; }
.tool-button.strike { text-decoration: line-through; }

.find-panel {
  display: flex; align-items: end; gap: 7px; padding: 8px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.find-panel[hidden] { display: none; }
.find-panel label { display: grid; gap: 3px; color: var(--muted); font-size: 11px; }
.find-panel input { width: 180px; height: 31px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); color: var(--text); padding: 0 8px; }
.small-button, .secondary-button, .primary-button, .danger-button {
  min-height: 32px; border-radius: 6px; border: 1px solid var(--border); padding: 6px 10px; background: var(--surface); color: var(--text);
}
.small-button:hover, .secondary-button:hover { background: var(--surface-2); }
.primary-button { background: var(--accent); color: white; border-color: var(--accent); font-weight: 700; }
.primary-button:hover { filter: brightness(.96); }
.danger-button { background: var(--danger); color: white; border-color: var(--danger); font-weight: 700; }

.mobile-mode-switch { display: none; padding: 6px; background: var(--surface-2); border-bottom: 1px solid var(--border); gap: 4px; }
.mode-button { flex: 1; min-height: 34px; border: 1px solid transparent; background: transparent; border-radius: 6px; color: var(--muted); font-weight: 700; }
.mode-button.active { background: var(--surface); color: var(--accent); border-color: var(--border); }

.split-pane { flex: 1; min-height: 0; display: flex; overflow: hidden; background: var(--surface); }
.pane { min-width: 0; min-height: 0; }
.editor-pane { flex: 0 0 var(--editor-width, 50%); display: flex; flex-direction: column; }
.preview-pane { flex: 1 1 auto; display: flex; flex-direction: column; border-left: 0; }
.splitter {
  position: relative; z-index: 2; flex: 0 0 9px; cursor: col-resize; background: var(--surface-2); border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}
.splitter::before { content: ""; position: absolute; width: 2px; height: 36px; border-left: 1px solid var(--border-strong); border-right: 1px solid var(--border-strong); top: 50%; left: 50%; transform: translate(-50%, -50%); }
.splitter:hover, .splitter.dragging { background: var(--accent-soft); }

.code-editor-wrap { position: relative; flex: 1; min-height: 0; display: flex; overflow: hidden; background: #fff; }
:root[data-theme="dark"] .code-editor-wrap { background: #0d1422; }
.line-numbers {
  margin: 0; padding: 10px 8px 32px; min-width: 52px; overflow: hidden; user-select: none; text-align: right;
  border-right: 1px solid var(--border); background: var(--surface-2); color: #94a3b8;
  font: 400 var(--editor-font-size)/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.code-editor {
  flex: 1; min-width: 0; min-height: 0; resize: none; border: 0; outline: 0; padding: 10px 14px 32px;
  background: #fff; color: #0f172a; tab-size: 2; white-space: pre; overflow: auto;
  font: 400 var(--editor-font-size)/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  letter-spacing: -.01em;
}
:root[data-theme="dark"] .code-editor { background: #0d1422; color: #e7eef9; }
.code-editor.wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.status-bar {
  min-height: 35px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; padding: 4px 10px; background: var(--surface-2); color: var(--muted); font-size: 11px;
}
.status-chip { background: var(--accent); color: white; border-radius: 11px; padding: 2px 8px; font-weight: 700; }
.status-spacer { flex: 1; }
.status-button { border: 0; background: transparent; color: var(--muted); padding: 3px 5px; border-radius: 4px; }
.status-button:hover { color: var(--text); background: var(--surface); }
.font-size-control { display: flex; align-items: center; gap: 3px; }
.font-size-control select { border: 0; background: transparent; color: var(--muted); }

.preview-toolbar {
  min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 5px 9px 5px 12px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.preview-title { color: var(--muted); font-size: 13px; }
.preview-tools { display: flex; align-items: center; gap: 4px; }
.device-toggle { display: flex; gap: 2px; padding-right: 4px; border-right: 1px solid var(--border); }
.preview-button {
  min-width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); color: var(--muted); padding: 0 7px; font-size: 11px;
}
.preview-button:hover { color: var(--text); border-color: var(--border-strong); }
.preview-button.active { color: var(--accent); background: var(--accent-soft); border-color: #9bc2ff; }
.preview-stage { flex: 1; min-height: 0; overflow: auto; background: #eef2f7; padding: 0; display: flex; align-items: flex-start; justify-content: center; }
:root[data-theme="dark"] .preview-stage { background: #0b1220; }
.device-frame { width: 100%; height: 100%; min-height: 0; background: white; transition: width .18s ease, margin .18s ease, border-radius .18s ease; overflow: hidden; }
.preview-stage[data-device="tablet"] { padding: 14px; }
.preview-stage[data-device="tablet"] .device-frame { width: min(768px, 100%); border: 1px solid #cbd5e1; border-radius: 10px; box-shadow: 0 6px 20px rgba(15,23,42,.08); }
.preview-stage[data-device="mobile"] { padding: 14px; }
.preview-stage[data-device="mobile"] .device-frame { width: min(390px, 100%); border: 1px solid #cbd5e1; border-radius: 14px; box-shadow: 0 6px 20px rgba(15,23,42,.08); }
.preview-frame, #previewFrame { width: 100%; height: 100%; border: 0; background: white; display: block; }

.ad-slot { min-height: 90px; border: 1px dashed var(--border-strong); border-radius: 8px; display: grid; place-items: center; background: var(--surface); color: var(--muted); font-size: 10px; letter-spacing: .12em; }
.ad-slot[hidden] { display: none; }

.popover-menu {
  position: fixed; z-index: 1000; width: 210px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: 0 12px 32px rgba(15,23,42,.18);
}
.popover-menu[hidden] { display: none; }
.popover-menu button { display: block; width: 100%; border: 0; background: transparent; color: var(--text); text-align: left; border-radius: 5px; padding: 9px 10px; font-size: 13px; }
.popover-menu button:hover { background: var(--surface-2); }
.popover-menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 2000; display: grid; gap: 8px; pointer-events: none; }
.toast { min-width: 240px; max-width: 380px; background: #111827; color: white; border-radius: 8px; padding: 11px 14px; box-shadow: 0 10px 28px rgba(0,0,0,.22); font-size: 13px; animation: toast-in .18s ease-out; }
.toast.error { background: #8b1e18; }
.toast.success { background: #166534; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.dialog { width: min(720px, calc(100vw - 28px)); max-height: min(82vh, 760px); padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: 0 22px 60px rgba(0,0,0,.22); }
.dialog::backdrop { background: rgba(8,15,28,.52); backdrop-filter: blur(2px); }
.large-dialog { width: min(900px, calc(100vw - 28px)); }
.small-dialog { width: min(440px, calc(100vw - 28px)); }
.dialog-shell { display: flex; flex-direction: column; max-height: inherit; }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 0; font-size: 20px; }
.dialog-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.dialog-body { padding: 18px 20px; overflow: auto; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.dialog-toolbar { display: flex; gap: 8px; margin-bottom: 14px; }
.dialog-toolbar input[type="search"] { margin-left: auto; width: min(280px, 35vw); border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); padding: 7px 10px; }
.storage-info { align-self: center; color: var(--muted); font-size: 11px; white-space: nowrap; }
.document-list { display: grid; gap: 7px; }
.document-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px; align-items: center; border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.document-row.active { border-color: #8ab7f8; background: var(--accent-soft); }
.document-main { min-width: 0; }
.document-title { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.document-meta { margin-top: 3px; color: var(--muted); font-size: 11px; }
.document-actions-row { display: flex; gap: 5px; }
.empty-state { padding: 36px 18px; text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: 8px; }
.help-content section + section { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 18px; }
.help-content h3 { margin: 0 0 8px; font-size: 15px; }
.help-content p, .help-content li { color: var(--muted); line-height: 1.7; font-size: 13px; }
.shortcut-grid { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; align-items: center; font-size: 13px; }
kbd { padding: 4px 7px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); color: var(--text); font-family: ui-monospace, monospace; }

.drop-active::after {
  content: "HTML 파일을 놓아 불러오기"; position: fixed; inset: 72px 40px 34px; z-index: 1500; display: grid; place-items: center;
  border: 3px dashed var(--accent); border-radius: 16px; background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--accent); font-size: 24px; font-weight: 800;
}

@media (max-width: 900px) {
  .app-header { padding-inline: 14px; }
  .header-actions .header-button:not(#helpButton) { padding-inline: 7px; }
  .workspace { padding: 10px 12px 12px; }
  .preview-button { min-width: 28px; }
}

@media (max-width: 700px) {
  body { overflow: hidden; }
  .app-shell { height: 100dvh; min-height: 0; }
  .app-header { position: sticky; top: 0; z-index: 30; }
  .brand-name { font-size: 17px; }
  .header-actions { gap: 4px; }
  .header-actions #docsButton, .header-actions #templatesButton, .header-actions #importButton, .header-actions #exportMenuButton, .header-actions #themeButton { display: none; }
  .mobile-more-button { display: inline-grid; }
  .header-button { font-size: 12px; }
  .workspace { min-height: 0; overflow: hidden; }
  .editor-card { min-height: 0; }
  .document-bar { min-height: 44px; }
  .doc-title { width: 58vw; }
  .format-toolbar { min-height: 45px; }
  .mobile-mode-switch { display: flex; }
  .split-pane { min-height: 0; }
  .split-pane[data-mobile-mode="editor"] .editor-pane { display: flex; flex: 1 1 auto; }
  .split-pane[data-mobile-mode="editor"] .preview-pane, .split-pane[data-mobile-mode="editor"] .splitter { display: none; }
  .split-pane[data-mobile-mode="preview"] .preview-pane { display: flex; flex: 1 1 auto; }
  .split-pane[data-mobile-mode="preview"] .editor-pane, .split-pane[data-mobile-mode="preview"] .splitter { display: none; }
  .split-pane[data-mobile-mode="split"] { flex-direction: column; overflow: auto; }
  .split-pane[data-mobile-mode="split"] .editor-pane, .split-pane[data-mobile-mode="split"] .preview-pane { display: flex; flex: 0 0 auto; width: 100%; min-height: 380px; }
  .split-pane[data-mobile-mode="split"] .preview-pane { min-height: 420px; border-top: 1px solid var(--border); }
  .split-pane[data-mobile-mode="split"] .splitter { display: none; }
  .find-panel { flex-wrap: wrap; align-items: end; }
  .find-panel input { width: min(42vw, 180px); }
  .preview-title { display: none; }
  .preview-toolbar { justify-content: flex-end; }
  .preview-tools { overflow-x: auto; }
  .dialog-toolbar { flex-wrap: wrap; }
  .dialog-toolbar input[type="search"] { margin-left: 0; width: 100%; }
  .document-row { grid-template-columns: 1fr; }
  .document-actions-row { justify-content: flex-end; }
  .toast-region { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: none; width: 100%; }
}

@media (max-width: 430px) {
  .app-header { padding-inline: 10px; }
  .brand-mark { width: 20px; height: 20px; }
  .header-actions #helpButton { padding-inline: 7px; }
  .workspace { padding: 8px; }
  .document-actions .icon-button:nth-of-type(2) { display: none; }
  .save-state { display: none; }
  .status-bar { gap: 6px; overflow-x: auto; }
  #cursorPosition { display: none; }
}

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


/* V2 service refinements */
.document-bar { flex: 0 0 auto; }
.format-toolbar { flex: 0 0 auto; }
.split-pane { height: 100%; }
.editor-pane, .preview-pane { overflow: hidden; }
.code-editor { scrollbar-gutter: stable; }
.line-numbers { scrollbar-gutter: stable; }
.preview-stage { scrollbar-gutter: stable; }
.preview-pane:fullscreen { background: var(--surface); }
.preview-pane:fullscreen .preview-stage { min-height: 0; }
.preview-pane:fullscreen .device-frame { min-height: calc(100vh - 42px); }

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.template-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 16px;
  text-align: left;
  color: var(--text);
  min-height: 150px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.template-card:hover { border-color: #8ab7f8; box-shadow: 0 8px 22px rgba(24, 119, 242, .08); }
.template-card h3 { margin: 0; font-size: 15px; }
.template-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.template-card .template-meta { margin-top: auto; color: var(--accent); font-size: 11px; font-weight: 800; }

.settings-list { display: grid; gap: 0; padding-block: 4px; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 2px;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row span { display: grid; gap: 4px; min-width: 0; }
.setting-row strong { font-size: 13px; }
.setting-row small { color: var(--muted); font-size: 11px; line-height: 1.55; }
.setting-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex: 0 0 auto; }

.quality-summary {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.quality-score { width: 78px; height: 78px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 22px; font-weight: 900; }
.quality-summary h3 { margin: 0 0 5px; font-size: 16px; }
.quality-summary p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.quality-list { display: grid; gap: 8px; }
.quality-item { display: grid; grid-template-columns: 26px minmax(0,1fr); gap: 10px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; }
.quality-item.ok { background: color-mix(in srgb, #dcfce7 44%, var(--surface)); }
.quality-item.warn { background: color-mix(in srgb, #fef3c7 48%, var(--surface)); }
.quality-item.error { background: color-mix(in srgb, #fee2e2 45%, var(--surface)); }
.quality-item strong { display: block; font-size: 12px; margin-bottom: 2px; }
.quality-item span { color: var(--muted); font-size: 11px; line-height: 1.55; }

.version-row .document-title { display: flex; align-items: center; gap: 6px; }
.version-badge { display: inline-block; padding: 2px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 10px; font-weight: 800; }

@media (max-width: 900px) {
  .document-actions .compact-action { padding-inline: 7px; }
  #snapshotButton { display: none; }
  .template-grid { grid-template-columns: 1fr; }
  .storage-info { width: 100%; }
}

@media (max-width: 700px) {
  .workspace { padding: 8px; }
  .editor-card { height: 100%; }
  .document-bar { padding-inline: 8px; }
  .doc-title { width: min(44vw, 260px); }
  #saveHtmlDataButton { padding-inline: 8px; }
  .format-toolbar { scrollbar-width: none; }
  .format-toolbar::-webkit-scrollbar { display: none; }
  .preview-stage[data-device="tablet"], .preview-stage[data-device="mobile"] { padding: 8px; }
  .setting-row { align-items: flex-start; }
}

@media (max-width: 430px) {
  .brand-name { max-width: 128px; overflow: hidden; text-overflow: ellipsis; }
  .doc-title { width: 40vw; }
  #saveHtmlDataButton { font-size: 10px; }
  #editorBottomButton, #byteCount { display: none; }
  .preview-button { padding-inline: 6px; }
}

.mobile-menu { width: 230px; }

/* V3 template library + direct preview editing */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
#templatesDialog.large-dialog { width: min(1160px, calc(100vw - 28px)); max-height: min(90vh, 860px); }
.template-browser { padding-top: 14px; }
.template-toolbar {
  position: sticky;
  top: -18px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 0 12px;
  background: var(--surface);
}
.template-search { flex: 1 1 auto; min-width: 0; }
.template-search input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  font-size: 13px;
  outline: none;
}
.template-search input:focus { border-color: #6da8fa; box-shadow: 0 0 0 3px rgba(24,119,242,.12); }
.template-count { flex: 0 0 auto; color: var(--muted); font-size: 12px; font-weight: 800; }
.template-edit-guide {
  margin: 0 0 12px;
  padding: 11px 13px;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--border));
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
}
.template-categories {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.template-category {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
.template-category:hover { border-color: var(--border-strong); color: var(--text); }
.template-category.active { border-color: #8ab7f8; background: var(--accent-soft); color: var(--accent); }
.template-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.template-card { min-height: 170px; padding: 14px; cursor: pointer; position: relative; overflow: hidden; }
.template-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent); opacity: .72; }
.template-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.template-card-icon {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 15px;
  font-weight: 900;
}
.template-category-name { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 800; }
.template-card h3 { font-size: 14px; line-height: 1.35; }
.template-card p { font-size: 11px; line-height: 1.55; }
.template-card-actions { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.template-direct-badge { color: #15803d; font-size: 10px; font-weight: 800; }
.template-use { color: var(--accent); font-size: 11px; font-weight: 900; }
.template-empty { grid-column: 1 / -1; padding: 48px 20px; text-align: center; border: 1px dashed var(--border-strong); border-radius: 10px; color: var(--muted); }
.direct-edit-button.active { color: #166534; background: #dcfce7; border-color: #86efac; }
html[data-theme="dark"] .direct-edit-button.active { color: #86efac; background: rgba(22,101,52,.32); border-color: #166534; }
.preview-stage.direct-edit-mode { box-shadow: inset 0 0 0 2px rgba(22,163,74,.22); }

@media (max-width: 980px) {
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  #templatesDialog.large-dialog { width: calc(100vw - 14px); max-height: 94dvh; }
  .template-browser { padding-inline: 12px; }
  .template-toolbar { top: -18px; flex-wrap: wrap; }
  .template-search { flex-basis: 100%; }
  .template-grid { grid-template-columns: 1fr; }
  .template-card { min-height: 142px; }
  .direct-edit-button { white-space: nowrap; }
}
