html[data-form-theme="novel"] {
  --bg: #f2eee5;
  --surface: #fffdf8;
  --surface-2: #e9e3d7;
  --ink: #191d32;
  --muted: #6d7183;
  --line: #ddd7cb;
  --accent: #315ff0;
  --accent-strong: #2045bf;
  --accent-soft: #e7edff;
  --teal: #27786e;
  --teal-soft: #e2f1ec;
  --shadow: 0 18px 48px rgb(23 32 76 / 10%);
  color-scheme: light;
}

html[data-form-theme="dark"] {
  --bg: #090b13;
  --surface: #111522;
  --surface-2: #1a2132;
  --ink: #f4f5fc;
  --muted: #a3acc1;
  --line: #2b354b;
  --accent: #6f91ff;
  --accent-strong: #9bb0ff;
  --accent-soft: #1b2a53;
  --teal: #6fd2c3;
  --teal-soft: #173632;
  --shadow: 0 20px 60px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
}

body {
  background: var(--bg);
  color: var(--ink);
}

#root.pdfw-locale-loading {
  visibility: hidden;
}

.templates-page {
  min-height: 100vh;
  padding: 0 0 max(64px, env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse at 50% 0, color-mix(in srgb, var(--accent) 7%, transparent), transparent 40rem),
    var(--bg);
  color: var(--ink);
  transition: background-color .25s, color .25s;
}

.templates-header {
  position: sticky;
  z-index: 50;
  top: 0;
  width: min(1240px, calc(100% - 48px));
  height: 76px;
  border-color: color-mix(in srgb, var(--line) 76%, transparent);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.templates-header > a {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  transition: color .18s, transform .18s;
}

.templates-header > a:hover {
  color: var(--accent-strong);
  transform: translateX(-2px);
}

.templates-header > strong {
  margin-left: auto;
  padding-left: 18px;
  font-size: 17px;
}

.pdfw-controls {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-left: 18px;
}

.pdfw-locale-control {
  display: inline-flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
}

.pdfw-locale-control button {
  min-width: 39px;
  min-height: 32px;
  padding: 0 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.pdfw-locale-control button.active {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: 0 2px 8px rgb(13 21 54 / 10%);
}

.pdfw-theme-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.pdfw-theme-control select {
  min-height: 40px;
  padding: 0 30px 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}

.templates-page .templates-hero {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(310px, .96fr);
  align-items: center;
  gap: clamp(28px, 5vw, 68px);
  width: min(1240px, calc(100% - 48px));
  min-height: 422px;
  margin: 28px auto 58px;
  padding: clamp(30px, 4.5vw, 58px);
  overflow: hidden;
  border: 1px solid rgb(142 163 255 / 24%);
  border-radius: 32px;
  background:
    radial-gradient(ellipse at 78% 20%, rgb(49 95 240 / 38%), transparent 23rem),
    radial-gradient(ellipse at 6% 100%, rgb(24 152 204 / 18%), transparent 27rem),
    linear-gradient(125deg, #080a16 0%, #10152c 56%, #101d42 100%);
  box-shadow: 0 28px 72px rgb(16 26 71 / 20%);
  color: #f5f7ff;
  text-align: left;
}

.templates-page .templates-hero::after {
  position: absolute;
  z-index: -1;
  top: -140px;
  right: 18%;
  width: 330px;
  height: 330px;
  border: 1px solid rgb(129 154 255 / 18%);
  border-radius: 50%;
  box-shadow: 0 0 0 32px rgb(121 149 255 / 5%), 0 0 0 72px rgb(121 149 255 / 4%);
  content: "";
  pointer-events: none;
}

.pdfw-hero-eyebrow {
  grid-column: 1;
  grid-row: 1;
  width: fit-content;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgb(134 157 255 / 25%);
  border-radius: 999px;
  background: rgb(97 124 255 / 12%);
  color: #c9d4ff;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .15em;
}

.templates-page .templates-hero h1,
.pdfw-hero-title {
  grid-column: 1;
  grid-row: 2;
  max-width: 640px;
  margin: 17px 0 0;
  color: #fbfcff;
  font-size: clamp(38px, 5.2vw, 62px);
  font-weight: 820;
  letter-spacing: -.055em;
  line-height: 1.1;
}

.templates-page .templates-hero p,
.pdfw-hero-summary {
  grid-column: 1;
  grid-row: 3;
  max-width: 590px;
  margin: 15px 0 0;
  color: #bac4df;
  font-size: 14px;
  line-height: 1.9;
}

.templates-page .template-search,
.pdfw-hero-search {
  grid-column: 1;
  grid-row: 4;
  width: 100%;
  max-width: 570px;
  height: 62px;
  margin: 25px 0 0;
  border: 1px solid #d5ddf5;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 14px 34px rgb(0 0 0 / 16%);
}

.template-search:focus-within {
  border-color: #8fa7ff;
  box-shadow: 0 0 0 4px rgb(111 145 255 / 20%), 0 14px 34px rgb(0 0 0 / 16%);
}

.template-search > svg {
  color: #315ff0;
}

.template-search input {
  color: #19233f;
  font-size: 14px;
}

.template-search input::placeholder {
  color: #7b849b;
}

.pdfw-hero-card {
  grid-column: 2;
  grid-row: 1 / 5;
  align-self: stretch;
  min-width: 0;
  padding: 24px;
  border: 1px solid rgb(163 181 255 / 24%);
  border-radius: 24px;
  background: linear-gradient(145deg, rgb(25 34 69 / 92%), rgb(13 20 43 / 95%));
  box-shadow: inset 0 1px rgb(255 255 255 / 7%), 0 20px 48px rgb(0 0 0 / 24%);
  color: #f5f7ff;
}

.pdfw-panel-top {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #b3c1ec;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .13em;
}

.pdfw-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6ddfc5;
  box-shadow: 0 0 15px rgb(109 223 197 / 75%);
}

.pdfw-local-badge {
  margin-left: auto;
  padding: 7px 9px;
  border: 1px solid rgb(109 223 197 / 24%);
  border-radius: 999px;
  background: rgb(109 223 197 / 9%);
  color: #92ead6;
  font-size: 8px;
  letter-spacing: .08em;
}

.pdfw-panel-title {
  margin-top: 22px;
  font-size: 20px;
  font-weight: 780;
  letter-spacing: -.03em;
}

.pdfw-panel-meta {
  margin-top: 5px;
  color: #a8b5d4;
  font-size: 11px;
}

.pdfw-stat-list {
  display: grid;
  gap: 16px;
  margin-top: 25px;
  padding: 18px 0 15px;
  border-top: 1px solid rgb(177 191 231 / 15%);
  border-bottom: 1px solid rgb(177 191 231 / 15%);
}

.pdfw-stat-row {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) minmax(70px, 1.2fr) 24px;
  align-items: center;
  gap: 11px;
  color: #d6def3;
  font-size: 10px;
}

.pdfw-stat-row > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdfw-stat-row > strong {
  color: #f7f8ff;
  font-size: 11px;
  text-align: right;
}

.pdfw-stat-track,
.pdfw-progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 99px;
  background: rgb(190 201 233 / 15%);
}

.pdfw-stat-track i,
.pdfw-progress-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3970ff, #79a6ff);
  box-shadow: 0 0 16px rgb(67 116 255 / 60%);
}

.pdfw-panel-foot {
  margin-top: 15px;
  color: #9eaed4;
  font-size: 10px;
}

.legal-notice {
  width: min(1240px, calc(100% - 48px));
  margin: 0 auto 20px;
  padding: 15px 18px;
  border-radius: 14px;
  font-size: 12px;
}

.pdfw-category-filters {
  position: sticky;
  z-index: 35;
  top: 76px;
  display: flex;
  gap: 8px;
  width: min(1240px, calc(100% - 48px));
  margin: 0 auto 38px;
  padding: 10px;
  overflow-x: auto;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 17px;
  background: color-mix(in srgb, var(--bg) 91%, transparent);
  box-shadow: 0 10px 26px rgb(19 29 71 / 7%);
  scrollbar-width: none;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.pdfw-category-filters::-webkit-scrollbar {
  display: none;
}

.pdfw-category-filters button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
  transition: background .18s, color .18s, border-color .18s, transform .18s;
}

.pdfw-category-filters button:hover {
  border-color: var(--line);
  background: var(--surface);
  color: var(--accent-strong);
  transform: translateY(-1px);
}

.pdfw-category-filters button.active {
  border-color: #315ff0;
  background: #315ff0;
  color: #fff;
  box-shadow: 0 6px 16px rgb(49 95 240 / 24%);
}

.templates-page .template-group {
  width: min(1240px, calc(100% - 48px));
  margin: 0 auto 56px;
  scroll-margin-top: 145px;
}

.templates-page .template-group h2 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 18px;
  color: var(--ink);
  font-size: clamp(22px, 2.8vw, 29px);
  font-weight: 780;
  letter-spacing: -.04em;
}

.templates-page .template-group h2::before {
  width: 4px;
  height: 25px;
  border-radius: 4px;
  background: linear-gradient(#315ff0, #64c7e9);
  content: "";
}

.template-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.template-grid article {
  display: flex;
  min-height: 208px;
  flex-direction: column;
  align-items: flex-start;
  padding: 21px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 5px 18px rgb(22 35 83 / 4%);
  transition: transform .2s, border-color .2s, box-shadow .2s, background .2s;
}

.template-grid article:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  box-shadow: 0 18px 38px rgb(22 35 83 / 10%);
}

.template-grid article small {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 0 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 14%, transparent);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 9px;
  font-weight: 800;
}

.template-grid article h3 {
  margin: 16px 0 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}

.template-grid article p {
  flex: 1;
  margin: 7px 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.75;
}

.template-grid article button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid #315ff0;
  border-radius: 10px;
  background: #315ff0;
  color: #fff;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  transition: transform .18s, box-shadow .18s, background .18s;
}

.template-grid article button:hover {
  transform: translateY(-1px);
  background: #244bd0;
  box-shadow: 0 8px 20px rgb(49 95 240 / 26%);
}

.template-grid article button:focus-visible,
.pdfw-controls button:focus-visible,
.pdfw-controls select:focus-visible,
.pdfw-category-filters button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 42%, transparent);
  outline-offset: 3px;
}

.dialog-backdrop {
  z-index: 90;
  padding: 20px;
  background: rgb(5 8 22 / 72%);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.template-editor {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  grid-template-rows: auto auto auto minmax(160px, 1fr) auto;
  gap: 12px 22px;
  width: min(1160px, 100%);
  max-height: calc(100dvh - 40px);
  padding: 25px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 32px 90px rgb(0 0 0 / 38%);
  color: var(--ink);
}

.template-editor > .dialog-header,
.template-editor > .draft-note {
  grid-column: 1 / -1;
}

.template-editor > .dialog-header {
  min-width: 0;
  margin-bottom: 0;
}

.dialog-header > div:nth-child(2) {
  min-width: 0;
}

.dialog-header h2 {
  color: var(--ink);
  font-size: clamp(19px, 2vw, 25px);
  line-height: 1.35;
}

.dialog-header > div:nth-child(2) > span {
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 800;
}

.template-editor > .draft-note {
  margin: 0;
  padding: 11px 14px;
  border: 1px solid color-mix(in srgb, var(--teal) 22%, var(--line));
  border-radius: 12px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 11px;
}

.pdfw-form-progress {
  grid-column: 1;
  min-width: 0;
  padding: 5px 0 3px;
}

.pdfw-progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
}

.pdfw-progress-copy strong {
  color: var(--ink);
  font-size: 11px;
}

.pdfw-form-progress .pdfw-progress-track {
  height: 6px;
  background: var(--surface-2);
}

.pdfw-form-progress .pdfw-progress-track i {
  transition: width .2s;
}

.template-form {
  grid-column: 1;
  grid-row: 4;
  min-height: 0;
  align-content: start;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 2px 7px 5px 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.template-form label {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
  color: var(--ink);
  font-size: 10px;
  font-weight: 750;
}

.template-form label.wide {
  grid-column: 1 / -1;
}

.template-form input,
.template-form textarea,
.template-form select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.55;
}

.template-form textarea {
  min-height: 90px;
  resize: vertical;
}

.template-form input:focus,
.template-form textarea:focus,
.template-form select:focus {
  border-color: var(--accent);
  outline: 3px solid color-mix(in srgb, var(--accent) 14%, transparent);
}

.document-preview {
  grid-column: 2;
  grid-row: 3 / 5;
  min-height: 0;
  margin: 0;
  padding: 20px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-2);
  overscroll-behavior: contain;
}

.document-preview > strong {
  display: block;
  margin-bottom: 12px;
  color: var(--accent-strong);
  font-size: 11px;
}

.document-preview pre {
  margin: 0;
  padding: 22px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-family: "Noto Serif Thai", "Noto Serif", Georgia, serif;
  font-size: 12px;
  line-height: 1.9;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.pdfw-output-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}

.template-editor > .template-actions {
  grid-column: 1;
  grid-row: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.template-actions button {
  min-height: 42px;
  flex: 1 1 130px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.template-actions button:first-child {
  border: 1px solid #315ff0;
  background: #315ff0;
  color: #fff;
}

.template-actions button:nth-child(2) {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.template-actions button:last-child {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
}

.template-actions button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

html[data-form-theme="dark"] .templates-page .legal-notice {
  border-color: #594923;
  border-left-color: #e0ad43;
  background: #282315;
  color: #e9d59a;
}

html[data-form-theme="dark"] .template-grid article:hover {
  box-shadow: 0 18px 40px rgb(0 0 0 / 32%);
}

@media (max-width: 980px) {
  .templates-page .templates-hero {
    grid-template-columns: minmax(0, 1fr) minmax(275px, .86fr);
    gap: 26px;
    min-height: 390px;
  }

  .pdfw-hero-card {
    padding: 20px;
  }

  .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .template-editor {
    gap: 10px 16px;
    padding: 20px;
  }
}

@media (max-width: 760px) {
  html {
    scroll-padding-top: 72px;
  }

  .templates-header {
    width: calc(100% - 28px);
    height: 68px;
  }

  .templates-header > strong {
    display: none;
  }

  .pdfw-controls {
    gap: 7px;
    margin-left: auto;
  }

  .pdfw-theme-control > span {
    display: none;
  }

  .templates-page .templates-hero {
    grid-template-columns: minmax(0, 1fr);
    width: calc(100% - 28px);
    min-height: 0;
    gap: 24px;
    margin: 18px auto 38px;
    padding: 28px 23px;
    border-radius: 24px;
  }

  .pdfw-hero-eyebrow,
  .templates-page .templates-hero h1,
  .templates-page .templates-hero p,
  .templates-page .template-search,
  .pdfw-hero-card {
    grid-column: 1;
    grid-row: auto;
  }

  .templates-page .templates-hero h1 {
    margin-top: -12px;
    font-size: clamp(36px, 9.3vw, 55px);
  }

  .templates-page .templates-hero p {
    margin-top: -13px;
    font-size: 13px;
  }

  .templates-page .template-search {
    margin-top: -8px;
  }

  .pdfw-hero-card {
    padding: 19px;
    border-radius: 18px;
  }

  .pdfw-stat-list {
    gap: 13px;
    margin-top: 18px;
  }

  .legal-notice,
  .pdfw-category-filters,
  .templates-page .template-group {
    width: calc(100% - 28px);
  }

  .pdfw-category-filters {
    top: 68px;
    gap: 5px;
    margin-bottom: 30px;
    padding: 7px;
  }

  .pdfw-category-filters button {
    min-height: 37px;
    padding: 0 12px;
    font-size: 10px;
  }

  .template-editor {
    display: flex;
    width: 100%;
    max-height: calc(100dvh - 12px);
    flex-direction: column;
    gap: 12px;
    padding: 17px 15px calc(15px + env(safe-area-inset-bottom));
    border-radius: 19px;
    overflow-y: auto;
  }

  .template-editor > .dialog-header {
    padding-right: 1px;
  }

  .pdfw-form-progress {
    flex: 0 0 auto;
  }

  .template-form {
    display: grid;
    flex: 0 0 auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }

  .document-preview {
    min-height: 260px;
    max-height: 42vh;
    flex: 0 0 auto;
  }

  .template-editor > .template-actions {
    position: sticky;
    z-index: 2;
    bottom: -15px;
    flex: 0 0 auto;
    margin: 0 -15px calc(-15px - env(safe-area-inset-bottom));
    padding: 10px 15px calc(12px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
}

@media (max-width: 520px) {
  .templates-header > a {
    max-width: 125px;
    font-size: 11px;
  }

  .pdfw-controls {
    gap: 5px;
  }

  .pdfw-theme-control select {
    min-height: 38px;
    padding-left: 9px;
    font-size: 10px;
  }

  .template-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .template-grid article {
    min-height: 175px;
    padding: 17px;
  }

  .template-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .template-form label.wide {
    grid-column: 1;
  }

  .pdfw-progress-copy {
    align-items: baseline;
  }

  .pdfw-progress-copy span {
    text-align: right;
  }

  .template-actions button {
    flex-basis: 100%;
  }
}

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