/* ════════════════════════════════════════════════════════════
   Paper Templates — styles.css
   ════════════════════════════════════════════════════════════ */

/* ── Reset / Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* [hidden] must beat everything including display:flex on components */
[hidden] { display: none !important; }

/* Exclude checkboxes/radios from appearance reset */
input:not([type="checkbox"]):not([type="radio"]),
button,
select {
  appearance: none;
  -webkit-appearance: none;
}
input[type="checkbox"] { accent-color: var(--accent); }

/* ── CSS Variables ────────────────────────────────────────── */
:root {
  --accent:       #2563EB;
  --accent-light: #EFF6FF;
  --green:        #16A34A;
  --green-light:  #F0FDF4;
  --bg:           #F6F7F9;
  --surface:      #FFFFFF;
  --border:       #E1E4E8;
  --text:         #111827;
  --text-2:       #4B5563;
  --text-3:       #9CA3AF;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow-card:  0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-paper: 0 4px 24px rgba(0,0,0,.16);
  --font:         'Inter', system-ui, sans-serif;
  --toolbar-h:    52px;
  --preset-bar-h: 48px;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ════════════════════════════════════════════════════════════
   MAIN LISTING PAGE
   ════════════════════════════════════════════════════════════ */

/* ── Site Header ──────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 40px 24px 36px;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
}

.site-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  margin-bottom: 6px;
}

.site-sub {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
}

/* ── Cards Grid ───────────────────────────────────────────── */
.main-grid-wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

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

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow .15s, transform .15s;
}

.card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.1), 0 8px 28px rgba(0,0,0,.1);
  transform: translateY(-2px);
}

.card-preview-link { display: block; }

.card-preview {
  height: 160px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.card-preview svg {
  display: block;
  width: 100%;
  height: 100%;
}

.card-body {
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
  position: relative;
}

.card-title-link { display: block; }

.card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.card-desc {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  flex: 1;
  margin-bottom: 14px;
}

.card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Primary button ───────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background .12s;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary:hover { background: #1d4ed8; }

/* ── Preset toggle ────────────────────────────────────────── */
.btn-presets-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 12px;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: border-color .12s, color .12s;
}
.btn-presets-toggle:hover { border-color: var(--accent); color: var(--accent); }
.btn-presets-toggle .caret { font-size: 10px; }
.btn-presets-toggle[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }

/* ── Preset dropdown (main page card) ────────────────────── */
.presets-menu {
  list-style: none;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
  overflow: hidden;
}

.presets-menu li a {
  display: block;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.presets-menu li:last-child a { border-bottom: none; }
.presets-menu li a:hover { background: var(--accent-light); color: var(--accent); }

/* ════════════════════════════════════════════════════════════
   VIEW PAGE
   ════════════════════════════════════════════════════════════ */

.page-view body,
body.page-view {
  overflow: hidden;
}

/* Critical layout: flex column that fills 100vh */
.view-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── View Toolbar ─────────────────────────────────────────── */
.view-toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--toolbar-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border);
  z-index: 10;
}

.toolbar-back {
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius-sm);
  transition: color .12s;
}
.toolbar-back:hover { color: var(--accent); }

.toolbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

/* ── Print button ─────────────────────────────────────────── */
.btn-print {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
}
.btn-print:hover { background: #15803d; }

/* ── Download split button ────────────────────────────────── */
.dl-split {
  display: flex;
  align-items: stretch;
  position: relative;
  border-radius: var(--radius-sm);
  overflow: visible;
}

.btn-dl {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-right: 1px solid rgba(255,255,255,.25);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
}
.btn-dl:hover { background: #1d4ed8; }

.btn-dl-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 34px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 11px;
  cursor: pointer;
  transition: background .12s;
}
.btn-dl-caret:hover { background: #1d4ed8; }
.btn-dl-caret[aria-expanded="true"] { background: #1d4ed8; }

/* ── Download format dropdown ─────────────────────────────── */
.dl-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0,0,0,.14);
  list-style: none;
  z-index: 100;
  overflow: hidden;
}

.dl-menu li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background .1s;
  border-bottom: 1px solid var(--border);
}
.dl-menu li:last-child { border-bottom: none; }
.dl-menu li:hover { background: var(--accent-light); color: var(--accent); }
.dl-menu li.active { font-weight: 600; color: var(--accent); }

.fmt-note {
  color: var(--text-3);
  font-size: 11px;
  margin-left: auto;
}

/* ── Preset Bar ───────────────────────────────────────────── */
.preset-bar {
  flex: none;
  height: var(--preset-bar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.preset-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.preset-strip::-webkit-scrollbar { display: none; }

/* ── Preset Chip ──────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: all .12s;
  font-family: var(--font);
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip-custom { border-style: dashed; }
.chip-custom.active { background: var(--accent); border-style: solid; }

/* ── Custom Panel ─────────────────────────────────────────── */
.custom-panel {
  flex: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.custom-panel::-webkit-scrollbar { display: none; }

.custom-inner {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  padding: 12px 16px;
  min-width: max-content;
}

/* ── Control group ────────────────────────────────────────── */
.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 80px;
}

.ctrl-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-check-label {
  flex-direction: row;
  font-size: 12px;
  cursor: pointer;
}
.ctrl-check-label input[type="checkbox"] { width: 14px; height: 14px; }

.ctrl-val {
  color: var(--accent);
  font-weight: 600;
}

/* ── Toggle group ─────────────────────────────────────────── */
.toggle-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.tg-btn {
  flex: 1;
  height: 28px;
  padding: 0 10px;
  background: var(--surface);
  border: none;
  border-right: 1px solid var(--border);
  font-size: 12px;
  font-family: var(--font);
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background .1s, color .1s;
}
.tg-btn:last-child { border-right: none; }
.tg-btn:hover { background: var(--accent-light); color: var(--accent); }
.tg-btn.active { background: var(--accent); color: #fff; font-weight: 500; }

/* ── Range sliders ────────────────────────────────────────── */
input[type="range"] {
  width: 120px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* ── Color picker ─────────────────────────────────────────── */
input[type="color"] {
  width: 40px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
  background: var(--surface);
}

.minor-sub {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
}

/* ── View Canvas ──────────────────────────────────────────── */
.view-canvas {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(circle, #c9cdd4 1px, transparent 1px);
  background-size: 20px 20px;
}

/* ── Paper Shadow ─────────────────────────────────────────── */
.paper-shadow {
  background: #ffffff;
  box-shadow: var(--shadow-paper);
  transition: width .15s, height .15s;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  overflow: hidden;
  border-radius: 1px;
}

#svg-out {
  display: flex;
  width: 100%;
  height: 100%;
}

#svg-out svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Loading state ────────────────────────────────────────── */
.preview-loading {
  position: relative;
}
.preview-loading::after {
  content: 'Generating…';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-3);
  background: rgba(255,255,255,.8);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .toolbar-title { display: none; }
  .btn-print { padding: 0 10px; font-size: 12px; }
  .main-grid-wrap { padding: 16px 12px 40px; }
  .header-inner { padding: 0; }
  .site-header { padding: 24px 16px 20px; }
}

/* ── Print styles ─────────────────────────────────────────── */
@media print {
  .view-toolbar, .preset-bar, .custom-panel { display: none !important; }
  .view-canvas {
    height: 100vh;
    background: none;
  }
}