/* Shared by index.html and share.html: page chrome, formatting toolbar and
   receipt preview. The look follows phib.vercel.app (bankosegger.me style). */
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("/static/fonts/PlusJakartaSans-Variable.woff2") format("woff2-variations");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #1c1c1c;
  --surface: #242424;
  --surface-line: #303030;
  --hover: #25221f;
  --fg: #f5f3f0;
  --muted: #ada59c;
  --line: #312c28;
  --accent: #f2884b;
  --success: #6cc788;
  --danger: #ff6b5e;
  --radius: 8px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --hairline: inset 0 0 0 1px var(--line);
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scrollbar-width: thin; scrollbar-color: #3d3732 transparent; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.55;
  background: var(--bg);
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
::selection { background: #f2884b33; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
:focus-visible { outline: 1.5px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 960px; margin: 0 auto; padding: 56px 24px 64px; }

/* ---- Header ------------------------------------------------------------ */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 1.5rem;
}
h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.25; margin: 0; }
.sub { color: var(--muted); font-size: 0.875rem; margin-top: 0.4rem; }
.pill {
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  padding-bottom: 0.3rem;
}
.pill.ok { color: var(--success); }
.pill.bad { color: var(--danger); }
/* Main page: the printer status doubles as the page heading. */
h1.headline { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.006em; }
.headline .ok { color: var(--success); }
.headline .bad { color: var(--danger); }

/* ---- Layout: editor + actions left, preview right ------------------------ */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "composer" "actions" "preview";
  gap: 16px;
}
@media (min-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "composer preview" "actions preview";
    grid-template-rows: auto 1fr;
    column-gap: 24px;
  }
  .preview-col { position: sticky; top: 24px; align-self: start; }
}
.composer { grid-area: composer; }
.actions { grid-area: actions; }
.preview-col { grid-area: preview; }

/* ---- Composer ---------------------------------------------------------- */
.composer {
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--surface-line);
  transition: box-shadow 0.16s ease;
}
.composer:focus-within { box-shadow: inset 0 0 0 1px var(--accent); }
.composer textarea {
  display: block;
  width: 100%;
  min-height: 200px;
  padding: 14px 16px;
  border: 0;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  font-weight: 400;
  resize: vertical;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--muted); }

.composer-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 8px 12px;
  border-top: 1px solid var(--surface-line);
  font-size: 12px;
  color: var(--muted);
}
.charcount { margin-left: auto; font-variant-numeric: tabular-nums; }
.charcount.warn { color: var(--danger); }
.tokencost { font-variant-numeric: tabular-nums; }
.tokencost.warn { color: var(--danger); }

/* ---- Toolbar ----------------------------------------------------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--surface-line);
}
.toolbar .sep { width: 1px; height: 16px; background: var(--surface-line); margin: 0 6px; }
.toolbar button {
  min-width: 30px;
  height: 28px;
  padding: 0 7px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  transition: background 0.16s ease, color 0.16s ease;
}
.toolbar button:hover { background: #2e2e2e; color: var(--fg); }
.toolbar .tb-bold { font-weight: 800; }
.toolbar .tb-underline { text-decoration: underline; }
.toolbar .tb-invert span { background: var(--muted); color: var(--surface); padding: 0 3px; border-radius: 2px; }
.toolbar .tb-invert:hover span { background: var(--fg); }
.toolbar .tb-mini { font-size: 0.75em; }

/* ---- Actions + status ---------------------------------------------------- */
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
/* Admin page: one row (options left, copies + print right); status and the
   ticket download only take a line of their own while they have content. */
.actions.stacked { flex-wrap: wrap; justify-content: space-between; gap: 10px 12px; }
.actions .opts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.actions .go { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.actions .go button { white-space: nowrap; flex-shrink: 0; }
.actions .go button.primary { height: 32px; padding: 0 18px; }
.actions .notes { flex-basis: 100%; display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.actions .notes:has(#status:empty):has(#ticketsBtn[hidden]) { display: none; }
.status { font-size: 0.8125rem; color: var(--muted); min-width: 0; }
.status.ok { color: var(--success); }
.status.err { color: var(--danger); }
.actions > .status,
.actions .notes .status { margin-right: auto; }
/* Options are toggle pills: the checkbox stays for keyboard + screen readers
   but is invisible, the pill turns orange while it is on. */
.actions .opt {
  position: relative;
  display: inline-flex; align-items: center;
  height: 32px; padding: 0 12px;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  white-space: nowrap; cursor: pointer; user-select: none;
  background: var(--surface);
  border-radius: 9999px;
  box-shadow: inset 0 0 0 1px var(--surface-line);
  transition: color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}
.actions .opt:hover { color: var(--fg); box-shadow: inset 0 0 0 1px #45403b; }
.actions .opt:has(input:checked) {
  color: var(--accent);
  background: #f2884b1a;
  box-shadow: inset 0 0 0 1px #f2884b80;
}
.actions .opt:has(input:disabled) { opacity: 0.5; cursor: progress; }
.actions .opt:has(input:focus-visible) { outline: 1.5px solid var(--accent); outline-offset: 2px; }
.actions .opt input[type="checkbox"] {
  position: absolute; inset: 0;
  width: 100%; height: 100%; margin: 0;
  opacity: 0; cursor: inherit;
}
/* Copies: − / + are round buttons inset in the pill, so their hover
   background never touches the pill's border. The border only turns
   orange while the number itself is being edited. */
.stepper {
  display: inline-flex; align-items: center; gap: 0;
  height: 32px; padding: 0 2px;
  border: 1px solid var(--surface-line);
  border-radius: 9999px;
  background: var(--surface);
  transition: border-color 0.16s ease;
}
.stepper:hover { border-color: #45403b; }
.stepper:has(input:focus) { border-color: var(--accent); }
.stepper button {
  display: grid; place-items: center;
  width: 26px; height: 26px; padding: 0; border: 0;
  border-radius: 50%;
  background: transparent; color: var(--muted);
  font-size: 15px; line-height: 1; font-weight: 600;
  transition: background 0.16s ease, color 0.16s ease, transform 0.14s var(--ease);
}
.stepper button:hover { background: #2e2e2e; color: var(--fg); }
.stepper button:active { transform: scale(0.9); }
.stepper button:focus-visible { border-radius: 50%; outline-offset: 0; }
.stepper input {
  width: 28px; padding: 0; border: 0; background: transparent;
  text-align: center; font-weight: 700; font-size: 13px;
  -moz-appearance: textfield; appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: none; }
kbd {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 8px;
}

button.primary,
button.ghost {
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg);
  border: 0;
  box-shadow: var(--hairline);
  color: var(--fg);
  font-size: 0.91rem;
  font-weight: 700;
  line-height: 1.2;
  padding: 9px 18px;
  border-radius: 9999px;
  transition: transform 0.14s var(--ease), background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}
button.primary {
  background: var(--accent);
  color: #1c1c1c;
  box-shadow: none;
}
button.primary:hover:not(:disabled) { background: #f79a63; }
button.primary kbd { color: #1c1c1c99; }
button.primary:active:not(:disabled),
button.ghost:active:not(:disabled) { transform: scale(0.96); }
button.ghost {
  padding: 4px 12px;
  color: var(--muted);
  font-size: 0.75rem;
}
button.ghost:hover:not(:disabled) { background: var(--hover); color: var(--fg); }
button.ghost.danger:hover { color: var(--danger); }

/* ---- Preview ----------------------------------------------------------- */
/* Paper is always white with black ink, regardless of color scheme. */
.preview {
  /* 48 columns ≈ 28.8em of monospace; shrink to fit narrow screens. */
  --pv-font: min(12px, calc((100vw - 72px) / 29.5));
  width: calc(48ch + 24px);
  max-width: 100%;
  min-height: 120px;
  margin: 0 auto;
  padding: 16px 12px 24px;
  background: #fff;
  color: #111;
  font-family: var(--font-mono);
  font-size: var(--pv-font);
  font-weight: 400;
  line-height: 1.35;
  border-radius: 4px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.preview-label { font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-bottom: 8px; text-align: center; }
.pv-line { min-height: 1.35em; }
/* Mini text (font B): 9x17 dots vs. font A's 12x24, so 0.75 of the width. */
.pv-mini { font-size: 0.75em; }
.pv-mini-row { min-height: 1.01em; font-size: 0.75em; }
/* Font B: 9x17 dots vs. font A's 12x24. */
.pv-author { min-height: 0; margin-top: 0.5em; font-size: 0.75em; line-height: 1.35; text-align: center; }
.pv-h1 { font-size: 2em; }
.pv-h2 { padding: 0.35em 0; }
.pv-h2 .pv-heading-inner { display: inline-block; transform: scaleY(2); }
.pv-bold { font-weight: 700; }
.pv-underline { text-decoration: underline; }
.pv-invert { background: #111; color: #fff; }
.pv-qr {
  display: inline-block;
  max-width: 100%;
  margin: 0.25em 0;
  image-rendering: pixelated;
  vertical-align: top;
}
/* Grayscale approximates the printer; the server dithers to 1-bit. */
.pv-img {
  display: inline-block;
  max-width: 100%;
  margin: 0.25em 0;
  filter: grayscale(1) contrast(1.15);
  vertical-align: top;
}
.pv-img-missing {
  display: inline-block;
  padding: 0.4em 0.6em;
  border: 0.15em dashed #b00;
  color: #b00;
}

/* ---- Share links (index.html) -------------------------------------------- */
.shares { margin-top: 40px; padding-top: 28px; border-top: 1px solid var(--surface-line); }
.shares summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  font-size: 1.125rem;
  font-weight: 700;
  user-select: none;
}
.shares summary::-webkit-details-marker { display: none; }
.shares summary::before {
  content: "›";
  display: inline-block;
  width: 10px;
  color: var(--muted);
  transition: transform 0.15s ease;
}
.shares[open] summary::before { transform: rotate(90deg); }
.shares summary .count { color: var(--muted); font-weight: 500; font-size: 0.8125rem; }
.shares-body { padding: 16px 0 0; }
.share-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.share-form input {
  min-height: 34px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font-size: 0.875rem;
  transition: border-color 0.16s ease;
}
.share-form input:focus { outline: none; border-color: var(--accent); }
.share-form input::placeholder { color: var(--muted); opacity: 0.7; }
.share-form input[type="text"] { flex: 1 1 180px; min-width: 0; }
.share-form input[type="number"] { width: 76px; }
.share-form .unit { font-size: 13px; color: var(--muted); }
.share-form button.primary { padding: 8px 16px; }
.shares-body > .status { margin-top: 8px; }
.shares-body > .status:empty { display: none; }

.share-list { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.share-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--surface-line);
  font-size: 0.875rem;
}
.share-row .info { flex: 1; min-width: 0; }
.share-row .label { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-row .label.none { color: var(--muted); font-weight: 500; }
.share-row .link {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-row .remaining { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.share-row .remaining.empty { color: var(--danger); }
.share-row .remaining { min-width: 130px; text-align: right; }
.share-row .bar { height: 3px; margin-top: 6px; border-radius: 9999px; background: var(--surface-line); overflow: hidden; }
.share-row .bar i { display: block; height: 100%; border-radius: inherit; background: var(--success); transition: width 0.3s var(--ease); }
.share-row .remaining.empty .bar i { background: var(--danger); }
.share-row { transition: box-shadow 0.16s ease; }
.share-row:hover { box-shadow: inset 0 0 0 1px #45403b; }
@media (max-width: 640px) {
  .share-row { flex-wrap: wrap; }
  .share-row .info { flex-basis: 100%; }
  .share-row .remaining { text-align: left; flex: 1; }
}
.share-row .row-actions { display: flex; gap: 2px; flex-shrink: 0; }
.share-row .failed { color: var(--danger); font-size: 12px; font-weight: 500; margin-left: 6px; }
#history { margin-top: 24px; padding-top: 20px; }
.history-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.history-bar .unit { font-size: 13px; color: var(--muted); }
#historyMoreBtn { margin-top: 8px; }
.empty-note { color: var(--muted); font-size: 0.8125rem; padding: 8px 0; }

/* ---- Share page --------------------------------------------------------- */
.gone { text-align: center; color: var(--muted); padding: 64px 0; font-size: 0.875rem; }
