@import url("./design.css");

:root {
  --template-bg: oklch(0.955 0.006 92);
  --template-panel: rgba(252, 250, 244, 0.9);
  --template-panel-strong: rgba(255, 253, 248, 0.96);
  --template-ink: oklch(0.28 0.018 92);
  --template-muted: oklch(0.48 0.018 92);
  --template-line: rgba(77, 68, 50, 0.16);
  --template-accent: oklch(0.5 0.075 54);
  --template-danger: oklch(0.48 0.12 28);
  --sheet-preview-w: 560px;
  --sheet-preview-h: 795px;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--template-ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(234, 230, 218, 0.9)),
    repeating-linear-gradient(90deg, transparent 0 92px, rgba(77, 68, 50, 0.045) 92px 93px),
    var(--template-bg);
  font-family: var(--ui-font);
}

.template-lab {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(270px, 320px) minmax(0, 1fr) minmax(330px, 390px);
}

.template-rail,
.template-editor-panel {
  min-height: 100vh;
  display: grid;
  background: var(--template-panel);
  backdrop-filter: blur(12px);
}

.template-rail {
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 18px;
  padding: clamp(18px, 2.4vw, 30px);
  border-right: 1px solid var(--template-line);
}

.brand-link {
  width: max-content;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--template-ink);
  text-decoration: none;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.76rem;
}

.brand-link img {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.template-head {
  display: grid;
  gap: 6px;
}

.template-head p,
.template-kicker {
  margin: 0;
  color: var(--template-accent);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.template-head h1,
.preview-topbar h2 {
  margin: 0;
  font-weight: 520;
  letter-spacing: 0;
}

.template-head h1 {
  font-size: clamp(1.45rem, 2.4vw, 2.15rem);
  line-height: 1.08;
}

.template-tools {
  display: grid;
  gap: 12px;
}

.search-box {
  display: grid;
  gap: 7px;
  color: var(--template-muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.search-box input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--template-line);
  border-radius: 4px;
  padding: 10px 12px;
  color: var(--template-ink);
  background: rgba(255, 253, 248, 0.8);
  outline: none;
}

.search-box input:focus {
  border-color: color-mix(in oklch, var(--template-accent) 54%, var(--template-line));
  box-shadow: 0 0 0 4px color-mix(in oklch, var(--template-accent) 14%, transparent);
}

.filter-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.filter-chip,
.template-card,
.text-btn,
.danger-btn,
.solid-btn {
  border: 1px solid var(--template-line);
  background: rgba(255, 253, 248, 0.72);
  color: var(--template-ink);
}

.filter-chip {
  min-height: 32px;
  padding: 7px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.76rem;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.filter-chip:hover {
  border-color: color-mix(in oklch, var(--template-accent) 36%, var(--template-line));
}

.filter-chip.is-active {
  background: var(--template-ink);
  border-color: var(--template-ink);
  color: oklch(0.96 0.006 92);
}

.template-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 9px;
  overflow: auto;
  padding-right: 4px;
}

.template-card {
  width: 100%;
  display: grid;
  gap: 7px;
  padding: 12px;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.template-card:hover,
.template-card.is-active {
  transform: translateX(3px);
  border-color: color-mix(in oklch, var(--template-accent) 42%, var(--template-line));
  background: var(--template-panel-strong);
}

.template-card strong {
  font-size: 0.92rem;
  font-weight: 560;
  line-height: 1.32;
}

.template-card span {
  color: var(--template-muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.template-card.is-dirty strong::after {
  content: " *";
  color: var(--template-accent);
}

.template-card-meta,
.template-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.template-card-meta i,
.template-meta span {
  font-style: normal;
  padding: 3px 7px;
  border: 1px solid rgba(77, 68, 50, 0.14);
  border-radius: 999px;
  color: var(--template-muted);
  background: rgba(255, 255, 255, 0.42);
  font-size: 0.68rem;
  line-height: 1.2;
}

.preview-stage {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(16px, 2.4vw, 26px);
  padding: clamp(18px, 3.2vw, 40px);
}

.preview-topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
}

.preview-topbar h2 {
  max-width: 680px;
  font-size: clamp(1.35rem, 2.6vw, 2.35rem);
  line-height: 1.08;
}

.template-meta {
  justify-content: flex-end;
}

.template-preview {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 8px;
}

.sheet-shell {
  display: grid;
  gap: 12px;
  justify-items: center;
  width: min(100%, calc(var(--sheet-preview-w) + 44px));
}

.preview-sheet-frame {
  width: min(var(--sheet-preview-w), calc(100vw - 420px));
  aspect-ratio: 148 / 210;
  min-width: 320px;
  background: transparent;
}

.preview-sheet-frame .mook-sheet {
  --type-size-min: 7.8pt;
  --type-size-base: 11.2pt;
  --type-size-max: 20pt;
  box-shadow: 0 26px 70px rgba(53, 43, 31, 0.24);
}

.preview-sheet-frame .sheet-title {
  letter-spacing: 0;
}

.preview-sheet-frame .cover-part-title {
  letter-spacing: 0;
}

.preview-sheet-frame .sheet-media-slot,
.preview-sheet-frame .cover-part-media {
  cursor: default;
}

.preview-sheet-frame .sheet-media-slot.is-active,
.preview-sheet-frame .cover-part-media.is-active,
.preview-sheet-frame .sheet-freeblock.is-active {
  box-shadow: none;
}

.preview-sheet-frame .sheet-freeblock {
  pointer-events: none;
}

.sheet-caption {
  max-width: min(var(--sheet-preview-w), calc(100vw - 420px));
  color: var(--template-muted);
  font-size: 0.78rem;
  line-height: 1.5;
  text-align: center;
}

.empty-state,
.error-state {
  max-width: 520px;
  padding: 24px;
  border: 1px solid var(--template-line);
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.72);
}

.empty-state strong,
.error-state strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1rem;
  font-weight: 560;
}

.empty-state span,
.error-state span {
  color: var(--template-muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.template-editor-panel {
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: clamp(18px, 2.2vw, 26px);
  border-left: 1px solid var(--template-line);
}

.editor-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.editor-head p {
  margin: 0 0 5px;
  color: var(--template-accent);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.editor-head h2 {
  margin: 0;
  font-size: clamp(1.12rem, 1.4vw, 1.45rem);
  font-weight: 520;
  line-height: 1.1;
}

.editor-status {
  min-height: 24px;
  max-width: 140px;
  color: var(--template-muted);
  font-size: 0.72rem;
  line-height: 1.35;
  text-align: right;
}

.editor-status.is-error {
  color: var(--template-danger);
}

.editor-summary {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--template-line);
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.62);
}

.editor-summary strong {
  font-size: 0.92rem;
  font-weight: 560;
  line-height: 1.25;
}

.editor-summary span {
  color: var(--template-muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.editor-actions,
.editor-footer {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.editor-actions {
  justify-content: space-between;
}

.editor-footer {
  justify-content: end;
}

.text-btn,
.danger-btn,
.solid-btn {
  min-height: 34px;
  border-radius: 5px;
  padding: 7px 11px;
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, opacity 160ms ease;
}

.text-btn:hover,
.danger-btn:hover {
  border-color: color-mix(in oklch, var(--template-accent) 42%, var(--template-line));
  background: rgba(255, 253, 248, 0.94);
}

.danger-btn {
  color: var(--template-danger);
}

.solid-btn {
  background: var(--template-ink);
  border-color: var(--template-ink);
  color: oklch(0.96 0.006 92);
}

.solid-btn:hover {
  background: color-mix(in oklch, var(--template-ink) 88%, var(--template-accent));
}

.text-btn:disabled,
.danger-btn:disabled,
.solid-btn:disabled {
  cursor: default;
  opacity: 0.48;
}

.json-editor {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  color: var(--template-muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.json-editor textarea {
  width: 100%;
  min-width: 0;
  min-height: 340px;
  height: 100%;
  resize: none;
  border: 1px solid var(--template-line);
  border-radius: 6px;
  padding: 12px;
  color: var(--template-ink);
  background: rgba(255, 253, 248, 0.78);
  outline: none;
  font: 12px/1.55 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  letter-spacing: 0;
  text-transform: none;
  tab-size: 2;
}

.json-editor textarea:focus {
  border-color: color-mix(in oklch, var(--template-accent) 54%, var(--template-line));
  box-shadow: 0 0 0 4px color-mix(in oklch, var(--template-accent) 14%, transparent);
}

.json-editor textarea.is-invalid {
  border-color: color-mix(in oklch, var(--template-danger) 70%, var(--template-line));
  box-shadow: 0 0 0 4px color-mix(in oklch, var(--template-danger) 12%, transparent);
}

@media (max-width: 1240px) {
  .template-lab {
    grid-template-columns: minmax(260px, 310px) minmax(0, 1fr);
  }

  .template-editor-panel {
    grid-column: 1 / -1;
    min-height: 560px;
    border-left: 0;
    border-top: 1px solid var(--template-line);
  }
}

@media (max-width: 980px) {
  .template-lab {
    grid-template-columns: 1fr;
  }

  .template-rail {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--template-line);
  }

  .template-list {
    max-height: 280px;
  }

  .preview-topbar {
    align-items: start;
    flex-direction: column;
  }

  .template-meta {
    justify-content: flex-start;
  }

  .preview-sheet-frame {
    width: min(92vw, var(--sheet-preview-w));
    min-width: 0;
  }

  .sheet-caption {
    max-width: min(92vw, var(--sheet-preview-w));
  }

  .template-editor-panel {
    min-height: 620px;
  }
}
