:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-strong: #f0f3f8;
  --text: #172033;
  --muted: #667085;
  --line: #d9dee8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --shadow: 0 16px 40px rgba(22, 32, 51, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.7;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
button, input { font: inherit; }
button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
button:hover:not(:disabled) { transform: translateY(-1px); border-color: #aab4c5; }
button:disabled { cursor: not-allowed; opacity: 0.42; }
button.primary { border-color: var(--primary); color: #ffffff; background: var(--primary); }
button.primary:hover:not(:disabled) { border-color: var(--primary-dark); background: var(--primary-dark); }
button.danger { border-color: #fecaca; color: var(--danger); background: #fff5f5; }
button.danger:hover:not(:disabled) { border-color: var(--danger); color: #ffffff; background: var(--danger); }

.site-header, .site-footer { width: min(1320px, calc(100% - 32px)); margin: 0 auto; }
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.1rem 0; }
.brand { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; }
.site-nav { display: flex; gap: 1rem; color: var(--muted); font-size: 0.94rem; }
main { width: min(1320px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 3rem; }
.hero { padding: 3.2rem 0 1.25rem; }
.compact-hero { padding-top: 2rem; }
.eyebrow { margin: 0 0 0.5rem; color: var(--primary); font-weight: 700; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 900px; margin-bottom: 1rem; font-size: clamp(2rem, 4vw, 4.2rem); line-height: 1.08; letter-spacing: -0.05em; }
h2 { margin-bottom: 0.35rem; font-size: 1.05rem; letter-spacing: -0.02em; }
h3 { margin-bottom: 0.35rem; font-size: 1rem; }
.lead { max-width: 920px; color: var(--muted); font-size: 1.05rem; }
.card, .privacy-note { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.privacy-note { margin-bottom: 1rem; padding: 0.9rem 1.05rem; }
.app-shell { display: grid; gap: 1rem; }

.app-topbar {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
}
.drop-zone {
  display: flex;
  align-items: center;
  gap: 1rem;
  border: 2px dashed var(--line);
  border-radius: 18px;
  padding: 1rem;
  background: #fbfcff;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.compact-drop-zone { min-height: 96px; }
.drop-zone:hover, .drop-zone:focus-visible { border-color: #9db7f9; background: #f4f7ff; }
.drop-zone.is-drag-over { border-color: var(--primary); background: #eff6ff; transform: translateY(-1px); }
.drop-zone-icon { display: grid; place-items: center; width: 62px; height: 62px; flex: 0 0 auto; border-radius: 16px; color: var(--primary); background: #eaf1ff; font-weight: 900; letter-spacing: -0.04em; }
.drop-zone-copy { min-width: 0; }
.file-label { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: 44px; border-radius: 999px; padding: 0.55rem 1rem; color: #ffffff; background: var(--text); font-weight: 800; cursor: pointer; }
.drop-zone-text { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.93rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.top-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.65rem; }

.editor-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 310px;
  gap: 1rem;
  align-items: start;
}
.page-list, .preview, .side-panel { padding: 1rem; }
.page-list, .side-panel { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.panel-heading h2, .panel-heading p { margin-bottom: 0; }
.panel-caption { color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.muted, .status { color: var(--muted); font-size: 0.9rem; }
.page-pill { flex: 0 0 auto; border-radius: 999px; padding: 0.25rem 0.7rem; color: var(--muted); background: var(--surface-strong); font-size: 0.9rem; font-weight: 800; }
.preview-heading { min-height: 62px; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-weight: 800;
}
.icon-button > span:first-child { font-size: 1.08rem; line-height: 1; }
.icon-button.mini { min-height: 36px; padding: 0.35rem 0.6rem; font-size: 0.86rem; }
.save-button { min-width: 128px; box-shadow: 0 10px 24px rgba(37, 99, 235, 0.22); }
.small-action-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.45rem; margin-bottom: 0.8rem; }
#prev-page, #next-page { display: none; }

.pages-empty, .empty-preview { color: var(--muted); font-size: 0.95rem; }
.page-items { display: grid; gap: 0; }
.drop-slot {
  display: none !important;
  align-items: center;
  justify-content: center;
  height: 34px !important;
  margin: 0 !important;
  border-radius: 999px;
  pointer-events: none !important;
}
.drop-slot span {
  display: block;
  width: 100%;
  height: 3px !important;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.22) !important;
  box-shadow: none !important;
}
.page-items.is-page-dragging .drop-slot {
  display: flex !important;
  pointer-events: auto !important;
}
.page-items.is-page-dragging .drop-slot.active {
  height: 42px !important;
}
.page-items.is-page-dragging .drop-slot.active span {
  height: 10px !important;
  background: var(--primary) !important;
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.2) !important;
}
.page-items.is-page-dragging .page-item.drop-target,
.page-items.is-page-dragging .page-item.drop-before,
.page-items.is-page-dragging .page-item.drop-after,
.page-items.is-page-dragging .page-item.current {
  border-color: var(--line) !important;
  background: #ffffff !important;
}
.page-item { display: grid; grid-template-columns: auto 58px minmax(0, 1fr) auto; gap: 0.55rem; align-items: center; border: 1px solid var(--line); border-radius: 14px; padding: 0.55rem; background: #ffffff; }
.page-item.current { border-color: var(--primary); background: #eff6ff; }
.page-item.dragging { opacity: 0.5; }
.page-item.drop-target { border-color: var(--primary); }
.page-thumb { display: grid; place-items: center; width: 58px; height: 76px; min-height: 76px; border-radius: 10px; padding: 0.25rem; overflow: hidden; background: #f4f6fa; box-shadow: inset 0 0 0 1px #e4e8f0; }
.page-thumb:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--primary); }
.page-thumb img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; background: #ffffff; box-shadow: 0 2px 8px rgba(22, 32, 51, 0.16); }
.thumb-loading { display: grid; place-items: center; width: 100%; height: 100%; color: var(--muted); font-weight: 900; }
.page-select { display: grid; gap: 0.1rem; min-height: auto; border: 0; padding: 0.2rem; text-align: left; background: transparent; border-radius: 8px; font-weight: 800; }
.page-select small { color: var(--muted); font-size: 0.72rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-actions { display: flex; align-items: center; gap: 0.35rem; }
.page-actions button { min-height: 32px; padding: 0.25rem 0.48rem; font-size: 0.82rem; }
.drag-hint { color: var(--muted); cursor: grab; font-weight: 900; }

.canvas-wrap { position: relative; display: grid; place-items: center; min-height: 620px; overflow: auto; border-radius: 14px; padding: 1rem; background: repeating-linear-gradient(45deg, #f5f7fb, #f5f7fb 12px, #eef2f8 12px, #eef2f8 24px); }
#pdf-canvas { display: none; max-width: 100%; height: auto; background: #ffffff; box-shadow: 0 10px 30px rgba(22, 32, 51, 0.22); }
#pdf-canvas.editable-canvas { cursor: crosshair; }
.empty-preview { display: grid; place-items: center; min-height: 240px; text-align: center; }

.side-panel { display: grid; gap: 1rem; }
.panel-section { display: grid; gap: 0.75rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; padding-bottom: 0; }
.section-heading h2 { margin: 0; }
.section-heading p { margin: 0.1rem 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.tool-grid, .icon-tool-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; }
.page-tool-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.icon-tile {
  display: grid;
  place-items: center;
  gap: 0.25rem;
  min-height: 76px;
  border-radius: 16px;
  padding: 0.55rem;
  text-align: center;
  font-size: 0.86rem;
  font-weight: 800;
}
.icon-tile span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; color: var(--primary); background: #eaf1ff; font-size: 1.1rem; line-height: 1; }
.icon-tile strong { font-size: 0.82rem; }
.icon-tile.active, .tool-buttons button.active { border-color: var(--primary); color: #ffffff; background: var(--primary); }
.icon-tile.active span, .tool-buttons button.active span { color: #ffffff; background: rgba(255, 255, 255, 0.2); }
.icon-tile.danger span { color: var(--danger); background: #fff1f2; }
.stacked-actions { display: grid; gap: 0.55rem; }
.stacked-actions .icon-button { justify-content: flex-start; border-radius: 14px; }

.edit-fields { display: grid; gap: 0.7rem; align-items: end; }
.edit-fields label { display: grid; gap: 0.3rem; color: var(--muted); font-size: 0.84rem; font-weight: 800; }
.edit-fields input[type="text"], .edit-fields input[type="number"], .edit-fields input[type="file"] { width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 12px; padding: 0.45rem 0.65rem; color: var(--text); background: #ffffff; }
.edit-fields input[type="color"] { width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 12px; padding: 0.2rem; background: #ffffff; }
.field-row { display: grid; grid-template-columns: 1fr 74px 74px; gap: 0.55rem; }
.edit-help { margin: 0; color: var(--muted); font-size: 0.86rem; line-height: 1.55; }

.feature-grid { display: none; }
.feature-card p { margin-bottom: 0; color: var(--muted); }
.site-footer { padding: 2rem 0; color: var(--muted); font-size: 0.9rem; }
.document-page { max-width: 860px; padding-top: 2rem; }
.document-page .card { padding: clamp(1.25rem, 4vw, 2.25rem); }
.document-page li + li { margin-top: 0.5rem; }
.help-page { display: grid; gap: 1rem; }
.guide-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem; margin-top: 1.5rem; }
.guide-card { display: flex; align-items: center; gap: 0.75rem; border: 1px solid var(--line); border-radius: 16px; padding: 0.85rem; background: #fbfcff; }
.guide-card span { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 auto; border-radius: 10px; color: var(--primary); background: #eaf1ff; font-weight: 900; }
.guide-section { scroll-margin-top: 1rem; }
.guide-section p:last-child, .guide-section ul:last-child, .guide-section ol:last-child { margin-bottom: 0; }
.guide-two-column { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.note-box { border-left: 4px solid var(--primary); border-radius: 12px; padding: 0.85rem 1rem; color: var(--muted); background: #f4f7ff; }
.shortcut-table { display: grid; gap: 0.45rem; }
.shortcut-table div { display: grid; grid-template-columns: minmax(180px, auto) 1fr; gap: 1rem; align-items: center; border-bottom: 1px solid var(--line); padding: 0.45rem 0; }
kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; min-height: 28px; border: 1px solid #c7cfdd; border-bottom-width: 2px; border-radius: 7px; padding: 0.1rem 0.45rem; color: var(--text); background: #ffffff; font-size: 0.84rem; font-weight: 800; }
.back-link { display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; padding: 0.65rem 1rem; color: #ffffff; background: var(--primary); font-weight: 800; }
.back-link:hover { text-decoration: none; background: var(--primary-dark); }
.noscript { position: fixed; inset: auto 1rem 1rem 1rem; border-radius: 12px; padding: 1rem; color: #ffffff; background: var(--danger); z-index: 10; }
body.is-busy { cursor: progress; }

@media (max-width: 1180px) {
  .editor-layout { grid-template-columns: 320px minmax(0, 1fr); }
  .side-panel { position: static; grid-column: 1 / -1; max-height: none; overflow: visible; }
  .side-panel { grid-template-columns: repeat(3, 1fr); }
  .panel-section { border-bottom: 0; border-right: 1px solid var(--line); padding-right: 1rem; padding-bottom: 0; }
  .panel-section:last-child { border-right: 0; padding-right: 0; }
}

@media (max-width: 900px) {
  .app-topbar, .editor-layout { grid-template-columns: 1fr; }
  .top-actions { justify-content: flex-start; }
  .page-list { position: static; order: 2; max-height: none; overflow: visible; }
  .side-panel { grid-template-columns: 1fr; }
  .panel-section { border-right: 0; border-bottom: 1px solid var(--line); padding-right: 0; padding-bottom: 1rem; }
  .panel-section:last-child { border-bottom: 0; padding-bottom: 0; }
  .canvas-wrap { min-height: 500px; }
  .guide-grid, .guide-two-column { grid-template-columns: 1fr; }
  .shortcut-table div { grid-template-columns: 1fr; gap: 0.35rem; }
}

@media (max-width: 640px) {
  .site-header { align-items: flex-start; flex-direction: column; }
  .site-nav { flex-wrap: wrap; }
  .compact-hero { padding-top: 1.5rem; }
  .drop-zone { align-items: flex-start; flex-direction: column; }
  .file-label, .top-actions button, .stacked-actions button { width: 100%; }
  .top-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .top-actions .save-button { grid-column: span 2; }
  .tool-grid, .icon-tool-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .canvas-wrap { min-height: 360px; padding: 0.75rem; }
  .page-item { grid-template-columns: auto 54px 1fr; }
  .page-thumb { width: 54px; height: 70px; min-height: 70px; }
  .page-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .field-row { grid-template-columns: 1fr; }
}
