:root {
  --paper-width: 58mm;
  --ink: #171717;
  --muted: #696969;
  --line: #d8d8d3;
  --panel: #ffffff;
  --page: #f1f1ed;
  --soft: #fbfbf7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 460px) minmax(300px, 1fr);
  gap: 32px;
  width: min(1240px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 32px 0;
  align-items: start;
}

.panel {
  display: grid;
  gap: 18px;
  max-height: calc(100vh - 64px);
  overflow: auto;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.08);
}

.panel__header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  background: #eeeeea;
  border-radius: 8px;
}

.tab {
  min-height: 38px;
  color: var(--ink);
  background: transparent;
  border-color: transparent;
}

.tab.is-active {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

.mode-panel {
  display: none;
  gap: 16px;
}

.mode-panel.is-active {
  display: grid;
}

.field {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

textarea,
input[type="text"],
input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--soft);
  outline: none;
}

textarea {
  min-height: 140px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

textarea:focus,
input:focus,
.upload-card:focus-within {
  border-color: #171717;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

button {
  min-height: 42px;
  border: 1px solid #171717;
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: #171717;
  cursor: pointer;
}

button:hover {
  filter: contrast(1.15);
}

button.secondary {
  color: var(--ink);
  background: #fff;
}

.button-row,
.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.full-width {
  width: 100%;
}

.upload-card {
  display: grid;
  gap: 8px;
  min-height: 78px;
  padding: 12px;
  border: 1px dashed #999;
  border-radius: 8px;
  background: var(--soft);
  cursor: pointer;
}

.upload-card span {
  font-weight: 700;
}

.upload-card input,
.field input[type="file"] {
  width: 100%;
  font-size: 12px;
}

.prompt-box {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.prompt-box summary {
  cursor: pointer;
  font-weight: 700;
}

.prompt-box textarea {
  margin-top: 10px;
  min-height: 180px;
}

.template-meta,
.validation-report {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.template-meta strong {
  color: var(--ink);
  font-size: 15px;
}

.validation-report p,
.template-meta p {
  margin: 0;
}

.is-ok {
  border-color: #8eb88a;
  background: #f5faf3;
}

.is-warn {
  border-color: #d9bd72;
  background: #fffaf0;
}

.is-error {
  border-color: #cc7d7d;
  background: #fff4f4;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.preview-wrap {
  display: grid;
  justify-content: center;
  align-content: start;
  min-height: calc(100vh - 64px);
  padding: 52px 28px 28px;
  background: #deded9;
  border-radius: 8px;
  overflow: auto;
}

.receipt {
  width: 384px;
  background: #fff;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.22);
}

.receipt img {
  display: block;
  width: 100%;
  height: auto;
}

.receipt-middle,
.receipt-middle .middle {
  width: 384px;
}

.measure-host {
  position: fixed;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100vw - 24px, 660px);
    gap: 18px;
    padding: 12px 0 24px;
  }

  .panel {
    max-height: none;
  }

  .preview-wrap {
    min-height: auto;
    padding: 36px 12px 20px;
  }
}

@page {
  size: 58mm auto;
  margin: 0;
}

@media print {
  html,
  body {
    width: var(--paper-width);
    min-height: auto;
    margin: 0;
    padding: 0;
    background: #fff;
  }

  .panel {
    display: none !important;
  }

  .app-shell,
  .preview-wrap {
    display: block;
    width: var(--paper-width);
    min-height: auto;
    margin: 0;
    padding: 0;
    background: #fff;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }

  .receipt {
    width: var(--paper-width) !important;
    margin: 0;
    box-shadow: none;
  }

  .receipt-middle,
  .receipt-middle .middle {
    width: var(--paper-width) !important;
  }
}
