:root {
  color-scheme: light;
  --ink: #181818;
  --muted: #6a6a6a;
  --paper: #f8f5ec;
  --panel: #fffdf7;
  --line: #d9d2c2;
  --button: #202020;
  --danger: #9e2b25;
  --shadow: 0 18px 60px rgba(0, 0, 0, .10);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(255,255,255,.58), rgba(255,255,255,.58)),
    repeating-linear-gradient(0deg, #ece8dd 0, #ece8dd 1px, transparent 1px, transparent 4px),
    var(--paper);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
.shell { width: min(920px, calc(100% - 32px)); margin: 0 auto; padding: 48px 0; }
.printer-card, .admin-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: clamp(24px, 5vw, 48px); position: relative;
}
.printer-card { max-width: 760px; margin: 0 auto; }
.printer-card::after {
  content: ""; position: absolute; left: 18px; right: 18px; bottom: -9px; height: 18px;
  background: linear-gradient(135deg, transparent 8px, var(--panel) 0) 0 0/18px 18px repeat-x;
  filter: drop-shadow(0 5px 2px rgba(0,0,0,.05));
}
.eyebrow { letter-spacing: .12em; color: var(--muted); font-size: .78rem; margin-bottom: 10px; text-transform: uppercase; }
h1 { margin: 0 0 12px; font-size: clamp(2rem, 7vw, 4rem); letter-spacing: -.06em; line-height: .98; }
h2 { margin: 0; font-size: 1.45rem; }
.lead { color: var(--muted); line-height: 1.65; margin: 0 0 26px; }
.message-form, .message-fieldset { display: grid; gap: 14px; }
.message-fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.message-fieldset:disabled { opacity: .55; }
label, .field-label { font-weight: 700; }
.optional { color: var(--muted); font-weight: 400; }
.required-mark { color: #7d2b25; font-size: .72rem; font-weight: 700; text-transform: uppercase; margin-left: 5px; }
textarea, input[type="text"] {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  color: var(--ink); font: inherit; font-size: 1rem; padding: 14px 15px; outline: none;
}
textarea { resize: vertical; min-height: 170px; line-height: 1.5; }
textarea:focus, input[type="text"]:focus { border-color: #888; box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
.field-meta, .status-row, .job-top, .roll-meta { display: flex; justify-content: space-between; gap: 16px; color: var(--muted); font-size: .8rem; }
.field-group { display: grid; gap: 9px; margin-top: 5px; }
.helper { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.55; }
button, .secondary-button {
  appearance: none; border: 0; border-radius: 10px; background: var(--button); color: #fff;
  font: inherit; font-weight: 700; text-decoration: none; text-align: center; padding: 15px 18px; cursor: pointer;
}
button:hover, .secondary-button:hover { opacity: .86; }
.secondary-button { display: inline-block; background: transparent; color: var(--ink); border: 1px solid var(--line); }
.compact { padding: 9px 11px; font-size: .82rem; }
.message-form > fieldset > button[type="submit"] { margin-top: 8px; }
.status-row { border-top: 1px dashed var(--line); padding-top: 22px; margin-top: 28px; flex-wrap: wrap; }
.alert, .error-box { border: 1px solid #e1b1ad; background: #fff3f2; color: #78231f; border-radius: 9px; padding: 12px 14px; margin: 0 0 20px; }
.honeypot { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip: rect(1px, 1px, 1px, 1px) !important; }
.thank-you { text-align: center; }
.receipt-icon { width: 58px; height: 58px; margin: 0 auto 20px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 50%; font-size: 1.7rem; }
.tiny-stat { color: var(--muted); font-size: .85rem; }

.printer-notice, .printer-status-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin: 0 0 22px; text-align: left; display: grid; gap: 6px; }
.printer-notice span { color: var(--muted); line-height: 1.5; }
.printer-notice.warning, .printer-status-card.status-paper_out, .printer-status-card.status-near_end { background: #fff7df; border-color: #e1c76d; }
.printer-status-card.status-ready, .printer-status-card.status-unknown { background: #edf7ee; border-color: #b9d8bd; }
.printer-notice.offline, .printer-status-card.status-offline, .printer-status-card.status-error { background: #fff3f2; border-color: #e1b1ad; }

.public-stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 0 0 26px; background: #fff; }
.public-stats div { padding: 13px 10px; text-align: center; border-right: 1px solid var(--line); }
.public-stats div:last-child { border-right: 0; }
.public-stats strong { display: block; font-size: 1.25rem; }
.public-stats span { display: block; color: var(--muted); font-size: .68rem; margin-top: 3px; }

.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.theme-choice { cursor: pointer; }
.theme-choice input { position: absolute; opacity: 0; pointer-events: none; }
.theme-preview { display: grid; gap: 5px; min-height: 86px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: #fff; transition: .15s ease; }
.theme-preview small { color: var(--muted); line-height: 1.35; }
.theme-choice input:checked + .theme-preview { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.theme-retro .theme-preview { border-radius: 0; background: #f6f6f2; }
.theme-postcard .theme-preview { border-style: double; border-width: 3px; }
.theme-party .theme-preview strong::before, .theme-party .theme-preview strong::after { content: "★"; margin: 0 5px; }

.photo-booth { display: grid; gap: 10px; border: 1px dashed var(--line); border-radius: 12px; padding: 14px; margin-top: 4px; }
.camera-stage { min-height: 190px; border-radius: 10px; overflow: hidden; background: #eeece5; display: grid; place-items: center; border: 1px solid var(--line); }
.camera-stage video, .camera-stage img { display: block; width: 100%; max-height: 360px; object-fit: cover; }
.camera-placeholder { color: var(--muted); font-size: .85rem; }
.camera-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.file-button { cursor: pointer; }
.camera-status { color: var(--muted); font-size: .78rem; line-height: 1.45; min-height: 1em; }

.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 24px; }
.admin-head h1 { font-size: clamp(1.8rem, 5vw, 3rem); }
.printer-status-card { grid-template-columns: 1fr auto; gap: 24px; align-items: start; }
.printer-status-card p { margin: 7px 0; color: var(--muted); line-height: 1.5; }
.printer-status-card code { font-size: .8rem; }
.printer-status-title { font-size: 1.05rem; }
.printer-status-meta { display: grid; gap: 6px; color: var(--muted); font-size: .78rem; text-align: right; }
.dashboard-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.metric { background: #fff; border: 1px solid var(--line); border-radius: 11px; padding: 16px; }
.metric strong { display: block; font-size: 1.7rem; }
.metric span { color: var(--muted); font-size: .76rem; }
.roll-card, .theme-stats { border: 1px solid var(--line); border-radius: 12px; padding: 18px; background: #fff; margin-bottom: 18px; }
.roll-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.roll-head p { color: var(--muted); margin: 6px 0 0; font-size: .82rem; }
.roll-meter { height: 18px; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin: 16px 0 8px; background: #eee; }
.roll-meter span { display: block; height: 100%; background: repeating-linear-gradient(90deg, #222 0, #222 8px, #444 8px, #444 10px); }
.theme-stat-row { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-stat-row span { border: 1px solid var(--line); border-radius: 999px; padding: 6px 9px; font-size: .75rem; }
.admin-section-head { margin: 28px 0 12px; }
.jobs { display: grid; gap: 14px; }
.job { border: 1px solid var(--line); border-radius: 12px; padding: 18px; background: #fff; }
.job-message { white-space: pre-wrap; line-height: 1.55; font-size: 1rem; }
.job-sender, .job-meta { color: var(--muted); font-size: .82rem; }
.job-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { display: inline-block; padding: 4px 8px; border-radius: 999px; background: #eee; color: #333; font-weight: 700; }
.status-printed { background: #e7f4e9; }
.status-failed, .status-rejected { background: #fbe5e3; }
.status-printing, .status-queued { background: #e5eef9; }
.status-pending_review { background: #fff1c9; }
.theme-badge { background: #eee9fa; }
.photo-badge { background: #e8f4f5; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 15px; }
.actions form { margin: 0; }
.small-button { padding: 9px 11px; font-size: .82rem; }
.small-button.danger { background: var(--danger); }
.error-box { white-space: pre-wrap; overflow-x: auto; font-size: .75rem; }
.message-fieldset:disabled textarea, .message-fieldset:disabled input, .message-fieldset:disabled button, .message-fieldset:disabled label { cursor: not-allowed; }
.message-fieldset:disabled button { background: #777; }

@media (max-width: 700px) {
  .public-stats { grid-template-columns: repeat(2, 1fr); }
  .public-stats div:nth-child(2) { border-right: 0; }
  .public-stats div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .theme-grid { grid-template-columns: 1fr; }
  .dashboard-metrics { grid-template-columns: repeat(2, 1fr); }
  .roll-head { flex-direction: column; }
}
@media (max-width: 560px) {
  .shell { width: min(100% - 20px, 920px); padding: 20px 0 34px; }
  .printer-card, .admin-card { border-radius: 14px; padding: 24px 18px; }
  .field-meta, .status-row, .job-top, .roll-meta { align-items: flex-start; flex-direction: column; gap: 6px; }
  .admin-head { flex-direction: column; }
  .printer-status-card { grid-template-columns: 1fr; gap: 12px; }
  .printer-status-meta { text-align: left; }
  .dashboard-metrics { grid-template-columns: 1fr 1fr; }
}

/* --------------------------------------------------------------------------
   v4.1 public-page polish + robust hidden handling
   -------------------------------------------------------------------------- */
[hidden] { display: none !important; }

.hero { margin-bottom: 24px; }
.hero .lead { max-width: 62ch; margin-bottom: 0; }

.public-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  border: 0;
  overflow: visible;
  background: transparent;
  margin: 0 0 22px;
}
.public-stats .stat-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 14px 12px;
  text-align: left;
  min-width: 0;
}
.public-stats .stat-card strong {
  display: block;
  font-size: 1.5rem;
  line-height: 1;
  margin-bottom: 7px;
}
.public-stats .stat-card span {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.25;
  margin: 0;
}

.message-fieldset { gap: 16px; }
.form-section {
  display: grid;
  gap: 16px;
  background: rgba(255, 255, 255, .74);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 13px;
  border-bottom: 1px dashed var(--line);
}
.section-heading > div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.section-heading h2 {
  font-size: 1.05rem;
  line-height: 1.25;
  margin: 0;
}
.section-step {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: .78rem;
  font-weight: 800;
}
.section-hint {
  color: var(--muted);
  font-size: .73rem;
  white-space: nowrap;
}
.field-stack { display: grid; gap: 8px; }
.required-mark {
  display: inline-block;
  color: #7d2b25;
  background: #fff0ee;
  border: 1px solid #edc9c4;
  border-radius: 999px;
  padding: 2px 6px;
  font-size: .62rem;
  letter-spacing: .03em;
  vertical-align: 2px;
}
textarea { min-height: 150px; }

.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.theme-choice { display: block; cursor: pointer; min-width: 0; }
.theme-choice input { position: absolute; opacity: 0; pointer-events: none; }
.theme-preview {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  min-height: 98px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.theme-choice:hover .theme-preview { transform: translateY(-1px); border-color: #aaa393; }
.theme-radio {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border: 2px solid #aaa393;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 4px #fff;
}
.theme-copy { display: grid; gap: 6px; min-width: 0; }
.theme-copy strong { line-height: 1.2; }
.theme-copy small { color: var(--muted); line-height: 1.4; font-weight: 400; }
.theme-choice input:checked + .theme-preview {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--ink);
}
.theme-choice input:checked + .theme-preview .theme-radio { background: var(--ink); border-color: var(--ink); }
.theme-retro .theme-preview { border-radius: 4px; background: #f7f7f3; }
.theme-postcard .theme-preview { border-style: double; border-width: 3px; }
.theme-party .theme-preview strong::before,
.theme-party .theme-preview strong::after { content: "★"; margin: 0 4px; }

.photo-section .helper { margin-top: -4px; }
.photo-booth {
  display: grid;
  gap: 12px;
  border: 0;
  border-radius: 0;
  padding: 0;
  margin: 0;
}
.camera-stage {
  min-height: 210px;
  border-radius: 12px;
  overflow: hidden;
  background: #efede5;
  display: grid;
  place-items: center;
  border: 1px dashed #c7c0b0;
}
.camera-stage video,
.camera-stage img {
  width: 100%;
  height: 100%;
  min-height: 210px;
  max-height: 390px;
  object-fit: cover;
  background: #111;
}
.camera-placeholder {
  display: grid;
  justify-items: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
  padding: 30px 20px;
}
.camera-placeholder strong { color: var(--ink); font-size: .9rem; }
.camera-placeholder small { font-size: .73rem; line-height: 1.4; }
.camera-icon {
  width: 44px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 2px solid #9e9788;
  border-radius: 6px;
  color: #80796c;
  font-size: 1.2rem;
  margin-bottom: 3px;
}
.camera-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.primary-small {
  appearance: none;
  border: 1px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.camera-status {
  min-height: 1.3em;
  padding: 0 2px;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.45;
}
.camera-status.is-error { color: #8a211b; font-weight: 700; }
.camera-status.is-ok { color: #37653c; }
.camera-debug {
  border-top: 1px dashed var(--line);
  padding-top: 10px;
  color: var(--muted);
  font-size: .76rem;
}
.camera-debug summary { cursor: pointer; color: var(--muted); }
.camera-debug-grid {
  display: grid;
  grid-template-columns: minmax(130px, .8fr) minmax(0, 1.4fr);
  gap: 7px 12px;
  margin: 12px 0;
}
.camera-debug-grid code {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: .74rem;
}

.submit-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  border-radius: 14px;
  padding: 18px 20px;
  background: var(--ink);
  color: #fff;
}
.submit-panel > div { display: grid; gap: 4px; }
.submit-panel > div span { color: #d7d7d7; font-size: .76rem; line-height: 1.35; }
.submit-button {
  flex: 0 0 auto;
  background: #fff;
  color: var(--ink);
  border: 1px solid #fff;
  padding: 13px 17px;
}
.submit-button:hover { opacity: .9; }

.status-row { margin-top: 22px; padding-top: 18px; }
.app-version { opacity: .7; }

@media (max-width: 700px) {
  .public-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .public-stats .stat-card { border: 1px solid var(--line); }
  .theme-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; }
  .section-hint { white-space: normal; text-align: right; }
}

@media (max-width: 560px) {
  .form-section { padding: 16px; }
  .section-heading { flex-direction: column; gap: 8px; }
  .section-hint { padding-left: 38px; text-align: left; }
  .submit-panel { align-items: stretch; flex-direction: column; }
  .submit-button { width: 100%; }
  .camera-actions > * { flex: 1 1 auto; }
  .camera-debug-grid { grid-template-columns: 1fr; gap: 3px; }
  .camera-debug-grid code { margin-bottom: 6px; }
}

/* --------------------------------------------------------------------------
   v4.2 live printpreview
   -------------------------------------------------------------------------- */
.preview-section .helper { margin-top: -4px; }
.receipt-live-preview {
  position: relative;
  min-height: 260px;
  display: grid;
  place-items: center;
  padding: 22px;
  border: 1px dashed #c7c0b0;
  border-radius: 14px;
  background:
    linear-gradient(rgba(255,255,255,.56), rgba(255,255,255,.56)),
    repeating-linear-gradient(0deg, #ebe7dc 0, #ebe7dc 1px, transparent 1px, transparent 4px),
    #efede5;
  overflow: auto;
}
.receipt-live-preview img {
  display: block;
  width: min(100%, 384px);
  height: auto;
  max-height: 640px;
  object-fit: contain;
  object-position: top center;
  background: #fff;
  border: 1px solid #d0cbc0;
  box-shadow: 0 14px 34px rgba(0,0,0,.16);
}
.receipt-preview-placeholder {
  display: grid;
  justify-items: center;
  gap: 7px;
  max-width: 330px;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}
.receipt-preview-placeholder strong { color: var(--ink); font-size: .9rem; }
.receipt-preview-placeholder small { font-size: .75rem; }
.receipt-preview-icon {
  width: 50px;
  height: 62px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  background: #fff;
  border: 1px solid #aaa393;
  box-shadow: 4px 5px 0 #d8d3c7;
  font-size: 1.35rem;
}
.receipt-preview-loading {
  color: var(--muted);
  font-size: .8rem;
}
.receipt-preview-loading::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 8px;
  border: 2px solid #bbb5a7;
  border-top-color: var(--ink);
  border-radius: 50%;
  vertical-align: -2px;
  animation: receipt-spin .75s linear infinite;
}
@keyframes receipt-spin { to { transform: rotate(360deg); } }
.receipt-preview-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  color: var(--muted);
  font-size: .74rem;
}

@media (max-width: 560px) {
  .receipt-live-preview { min-height: 220px; padding: 14px; }
  .receipt-live-preview img { max-height: 520px; }
}
