/* styles.css — Editor chrome only.
   The page styling (1920x1080 frames, themes) lives in templates/_base/.
   This file styles the surrounding SPA: input form, grid view, modal, toolbar.

   Anything inside .editor-chrome must hide in `body.printing` and `@media print`
   so the export PDF only shows the page frames.
*/

/* ---------------- Base ---------------- */

:root {
  --bg:          #fafaf9;
  --surface:     #ffffff;
  --surface-2:   #f3f4f6;
  --line:        #e5e7eb;
  --line-2:      #d1d5db;
  --ink:         #0f172a;
  --ink-soft:    #475569;
  --ink-mute:    #94a3b8;
  --primary:     #2962ff;
  --primary-ink: #ffffff;
  --danger:      #dc2626;
  --warn:        #b45309;
  --ok:          #15803d;
  --shadow-sm:   0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md:   0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg:   0 24px 64px rgba(15, 23, 42, 0.18);
  --radius:      10px;
  --radius-sm:   6px;
  --font:        -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  --mono:        ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme:  light;
}

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; }
[x-cloak] { display: none !important; }

/* ---------------- Top bar ---------------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; gap: 14px; align-items: center;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand {
  font-weight: 700; letter-spacing: -0.01em; font-size: 15px;
}
.topbar .crumbs {
  display: flex; gap: 4px; align-items: center;
  color: var(--ink-mute); font-size: 13px;
}
.topbar .crumbs .step { padding: 4px 10px; border-radius: 999px; }
.topbar .crumbs .step.active {
  background: var(--ink); color: #fff;
}
.topbar .crumbs .sep { color: var(--ink-mute); }
.topbar .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.topbar .saved {
  font-size: 12px; color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
}

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 60ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: var(--primary); border-color: var(--primary);
  color: var(--primary-ink);
}
.btn.primary:hover { background: #1e4dd8; border-color: #1e4dd8; }
.btn.primary:disabled { background: #93b0ff; border-color: #93b0ff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn.danger:hover { background: rgba(220, 38, 38, 0.08); }

/* ---------------- Inputs ---------------- */

label.field {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--ink-soft); letter-spacing: 0.02em;
  text-transform: uppercase; margin-bottom: 6px;
}
input[type=text], input[type=file], textarea, select {
  width: 100%; box-sizing: border-box;
  padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-family: inherit; font-size: 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input[type=text]:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(41, 98, 255, 0.18);
}
textarea { resize: vertical; min-height: 120px; line-height: 1.55; }

/* ---------------- Page 1 — Input view ---------------- */

.view-input {
  max-width: 760px; margin: 32px auto; padding: 0 24px;
}
.view-input h1 {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 6px;
}
.view-input .lede { color: var(--ink-soft); margin: 0 0 28px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm); margin-bottom: 18px;
}

.dropzone {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  width: 100%; box-sizing: border-box;
  min-height: 92px;
  border: 2px dashed var(--line-2); border-radius: var(--radius);
  padding: 24px; text-align: center; color: var(--ink-soft);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--primary); background: rgba(41, 98, 255, 0.06);
  color: var(--ink);
}
.dropzone .filename { font-weight: 600; color: var(--ink); }
.dropzone .or {
  display: block; margin-top: 8px; font-size: 12px; color: var(--ink-mute);
}
.dropzone .or a { color: var(--primary); text-decoration: none; }
.dropzone .or a:hover { text-decoration: underline; }
.scan-warning {
  margin-top: 8px; padding: 8px 12px; border-radius: var(--radius-sm);
  background: #fef3c7; color: #92400e; font-size: 12px;
}

.theme-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
}
.theme-card {
  position: relative;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 12px 10px; cursor: pointer;
  background: var(--surface);
  transition: border-color 120ms ease, transform 80ms ease, box-shadow 120ms ease;
  text-align: center;
}
.theme-card:hover { border-color: var(--line-2); transform: translateY(-1px); }
.theme-card.active {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(41, 98, 255, 0.15);
}
.theme-card .swatch {
  height: 40px; border-radius: 4px; margin-bottom: 8px;
  border: 1px solid var(--line);
}
.theme-card .name { font-weight: 600; font-size: 13px; }

.swatch-neutral { background: linear-gradient(135deg, #dee6ff, #fff4e6); }
.swatch-notion  { background: linear-gradient(135deg, #f7f7f5, #ffffff); border-left: 4px solid #000; }
.swatch-clickup { background: linear-gradient(135deg, #f3f0ff, #fff5f3); border-left: 4px solid #7b68ee; }
.swatch-monday  { background: linear-gradient(135deg, #e6f1ff, #fff0f6); border-left: 4px solid #0073ea; }

.input-actions {
  display: flex; align-items: center; gap: 12px; margin-top: 8px;
}
.input-actions .progress {
  font-size: 13px; color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.error-banner {
  margin-top: 12px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: #fef2f2; color: #991b1b; border: 1px solid #fecaca;
  font-size: 13px;
}

/* ---------------- Page 2 — Grid view ---------------- */

.view-grid {
  padding: 0 24px 64px;
}
.gridbar {
  position: sticky; top: 49px; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; margin-bottom: 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.gridbar .meta {
  margin-left: auto; color: var(--ink-mute); font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.gridbar .meta + .meta { margin-left: 12px; }

.warn-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(180, 83, 9, 0.08);
  color: var(--warn);
  border: 1px solid rgba(180, 83, 9, 0.25);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease;
}
.warn-toggle:hover { background: rgba(180, 83, 9, 0.14); }
.warn-toggle .warn-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--warn);
}
.warn-toggle .caret { font-size: 10px; }

.warnings-panel {
  margin: -4px 0 12px;
  background: #fff8ed;
  border: 1px solid rgba(180, 83, 9, 0.25);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.warnings-panel__head {
  display: flex; flex-direction: column; gap: 2px;
  margin-bottom: 8px;
}
.warnings-panel__head strong { color: var(--warn); font-size: 13px; }
.warnings-panel__head .hint { font-size: 11px; color: var(--ink-mute); }
.warnings-panel__list {
  margin: 0; padding-left: 22px;
  font-size: 13px; color: var(--ink);
  display: grid; gap: 4px;
}
.warnings-panel__list li { line-height: 1.5; }
.warnings-panel__foot {
  margin-top: 8px; display: flex; justify-content: flex-end;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

/* Each card is a 16:9 frame containing a scaled-down clone of the rendered page. */
.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 80ms ease, box-shadow 120ms ease, border-color 120ms ease;
}
.tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--line-2);
}
.tile .frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #f1f1f1;
}
/* The scaled .page lives inside .frame at 1920x1080 and is shrunk via transform. */
.tile .frame .page {
  transform-origin: top left;
  /* JS sets --tile-scale based on the frame's measured width. */
  transform: scale(var(--tile-scale, 0.18));
}
.tile .badge {
  position: absolute; left: 8px; top: 8px;
  background: rgba(15, 23, 42, 0.85); color: #fff;
  font-size: 11px; font-weight: 600; padding: 3px 7px;
  border-radius: 4px; letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  z-index: 2;
}
.tile .typebadge {
  position: absolute; right: 8px; top: 8px;
  background: rgba(255, 255, 255, 0.92); color: var(--ink-soft);
  font-size: 10px; font-weight: 600; padding: 3px 7px;
  border-radius: 4px; letter-spacing: 0.06em; text-transform: uppercase;
  z-index: 2;
}
.tile .footer {
  padding: 8px 12px; border-top: 1px solid var(--line);
  background: var(--surface);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px;
}
.tile .footer .title {
  font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.tile .footer .actions {
  display: flex; gap: 4px;
  opacity: 0; transition: opacity 120ms ease;
}
.tile:hover .footer .actions { opacity: 1; }
.tile .icon-btn {
  border: none; background: transparent;
  width: 24px; height: 24px; border-radius: 4px;
  cursor: pointer; color: var(--ink-soft);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.tile .icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.tile .incomplete {
  position: absolute; right: 8px; bottom: 38px;
  background: var(--warn); color: #fff;
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  z-index: 2;
}
.tile .img-badge {
  position: absolute; left: 8px; bottom: 38px;
  background: var(--ok); color: #fff;
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  font-weight: 600; letter-spacing: 0.02em;
  z-index: 2;
}

/* ---------------- Image picker (solution_detail modal) ---------------- */

.image-picker__drop-wrap {
  display: flex; flex-direction: column; gap: 8px;
}
.image-picker__drop-wrap .paste-btn { align-self: flex-start; }
.image-picker__drop kbd {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 1px;
  font-family: var(--mono);
  font-size: 11px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink-soft);
  vertical-align: baseline;
}

.image-picker__drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  border: 1.5px dashed var(--line-2);
  border-radius: var(--radius-sm);
  padding: 22px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--ink-soft);
  text-align: center;
  transition: border-color 120ms ease, background 120ms ease;
}
.image-picker__drop:hover {
  border-color: var(--primary); background: rgba(41, 98, 255, 0.04);
}
.image-picker__drop strong { color: var(--ink); font-weight: 600; }
.image-picker__drop .hint { font-size: 12px; color: var(--ink-mute); }
.image-picker__preview {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--surface);
}
.image-picker__preview img {
  width: 180px; max-height: 110px; object-fit: cover;
  border-radius: 4px; background: #000;
}
.image-picker__actions {
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
.pill {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-soft);
  letter-spacing: 0.02em;
}
.pill.ok { background: rgba(21, 128, 61, 0.12); color: var(--ok); }

/* ---------------- Modal (expand-on-click) ---------------- */

.modal-bg {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 32px;
}
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: min(960px, 100%); max-height: calc(100vh - 64px);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.modal header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal header .typebadge { position: static; }
.modal header .right { margin-left: auto; display: flex; gap: 8px; }
.modal .body {
  padding: 20px; overflow-y: auto;
  display: grid; grid-template-columns: 1fr; gap: 16px;
}
.modal .preview {
  background: #1a1a1a; border-radius: var(--radius-sm);
  padding: 16px; display: flex; justify-content: center;
  overflow: hidden;
}
.modal .preview .page {
  transform-origin: top left;
  transform: scale(var(--modal-scale, 0.36));
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  border-radius: 4px;
}
.modal .preview .frame {
  width: calc(1920px * var(--modal-scale, 0.36));
  height: calc(1080px * var(--modal-scale, 0.36));
  position: relative;
  overflow: hidden;
}
.fields { display: grid; gap: 12px; }
.fields .row { display: grid; gap: 6px; }
.fields .wc {
  font-size: 11px; color: var(--ink-mute);
  font-variant-numeric: tabular-nums; text-align: right;
}
.fields .wc.over { color: var(--danger); }

.regen-row {
  display: flex; gap: 8px; align-items: center;
  padding-top: 12px; border-top: 1px solid var(--line);
}
.regen-row input[type=text] { flex: 1; }

/* ---------------- Page 3 — Export view ---------------- */

.view-export {
  padding: 32px 0 120px;
}
.export-stage {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  padding: 0 24px;
}
.export-stage .page {
  /* JS sets --export-scale on .export-stage based on viewport width. */
  transform: scale(var(--export-scale, 0.5));
  transform-origin: top center;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
  border-radius: 6px;
  margin-bottom:
    calc(1080px * var(--export-scale, 0.5) - 1080px + 20px);
}

.export-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; gap: 12px; align-items: center;
  padding: 14px 24px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: saturate(180%) blur(8px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.06);
}
.export-bar .label {
  font-size: 12px; color: var(--ink-mute);
}

/* ---------------- Generation overlay ---------------- */

.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
}
.overlay-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 32px; min-width: 340px;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.overlay-card h3 {
  margin: 0 0 6px; font-size: 16px; font-weight: 600;
}
.overlay-card .stage {
  color: var(--ink-soft); font-size: 13px; margin-bottom: 12px;
  min-height: 18px;
}
.overlay-card .bar {
  height: 6px; background: var(--surface-2); border-radius: 999px;
  overflow: hidden;
}
.overlay-card .bar > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--primary), #5da6ff);
  width: 0%; transition: width 240ms ease;
}
.overlay-card .hint {
  color: var(--ink-mute); font-size: 12px; margin-top: 14px;
}

/* ---------------- Print mode ---------------- */

/* When printing, hide every editor surface and let layout.css/print.css drive
   the page geometry. body.printing is set by print.js right before
   window.print() so onscreen flicker is brief but tidy. */
@media print {
  .topbar, .gridbar, .export-bar, .overlay,
  .view-input, .view-grid, .modal-bg,
  .editor-only { display: none !important; }
  body, html { background: #fff; }
  .view-export { padding: 0; }
  .export-stage { gap: 0; padding: 0; }
  .export-stage .page {
    transform: none !important;
    margin: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }
}

body.printing .topbar,
body.printing .gridbar,
body.printing .export-bar,
body.printing .overlay,
body.printing .view-input,
body.printing .view-grid,
body.printing .modal-bg,
body.printing .editor-only { display: none !important; }
body.printing .export-stage { gap: 0; padding: 0; }
body.printing .export-stage .page {
  transform: none !important;
  margin: 0 !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}
