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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #e8e4dc;
  min-height: 100vh;
  color: #222;
}

/* ── Public page ─────────────────────────────────────────── */
.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem 4rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: .25rem;
  color: #1a1a1a;
}

.page-subtitle {
  font-size: .9rem;
  color: #666;
  margin-bottom: 1.5rem;
}

/*
 * receipt-container sets the Courier New font context so that
 * all ch units inside refer to the same character width.
 * --receipt-chars is injected from the template.
 */
.receipt-container {
  font-family: 'Courier New', 'Courier', monospace;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Printer body ─────────────────────────────────────────── */
.printer-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.printer-body {
  background: #2c2c2c;
  border-radius: 12px 12px 0 0;
  width: calc(var(--receipt-chars, 42) * 1ch + 40px);
  padding: 16px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 -4px 12px rgba(0,0,0,.3);
  position: relative;
  z-index: 2;
}

.printer-label {
  font-size: .55rem;
  letter-spacing: .15em;
  color: #888;
  text-align: center;
}

.printer-lights {
  display: flex;
  justify-content: flex-end;
  padding-right: 4px;
}

.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
}
.led--green  { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.led--orange { background: #f97316; box-shadow: 0 0 6px #f97316; }

.printer-slot {
  background: #111;
  height: 10px;
  border-radius: 2px;
  margin: 0 -4px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.6);
}

/* ── Paper ─────────────────────────────────────────────────── */
.paper {
  background: #fff;
  width: calc(var(--receipt-chars, 42) * 1ch + 40px);
  min-height: 80px;
  padding: 16px 20px 4px;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 4px 12px rgba(0,0,0,.18);
  position: relative;
  z-index: 1;
}

/* Perforated edge at bottom */
.receipt-tear {
  width: calc(100% + 40px);
  margin: 8px -20px 0;
  height: 14px;
  background:
    radial-gradient(circle at 7px 14px, #e8e4dc 7px, transparent 7px),
    radial-gradient(circle at 21px 14px, #e8e4dc 7px, transparent 7px);
  background-size: 28px 14px;
  background-repeat: repeat-x;
  background-position: 0 0;
}

/* ── Receipt content ───────────────────────────────────────── */
.receipt-header,
.receipt-footer {
  font-weight: bold;
  color: #555;
  line-height: 1.4;
  padding: 4px 0;
}

.receipt-align-center { text-align: center; }
.receipt-align-left   { text-align: left; }
.receipt-align-right  { text-align: right; }

.receipt-sep {
  font-size: 11px;
  color: #bbb;
  overflow: hidden;
  white-space: nowrap;
  padding: 3px 0;
}

.receipt-textarea {
  line-height: 1.5;
  width: calc(var(--receipt-chars, 42) * 1ch);
  border: none;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: #111;
  padding: 4px 0;
  caret-color: #333;
}

.receipt-textarea::placeholder {
  color: #bbb;
  font-style: italic;
}

.receipt-image-preview {
  padding: 6px 0;
  text-align: center;
}

.receipt-image-preview img {
  max-width: 100%;
  max-height: 200px;
  display: block;
  margin: 0 auto;
  filter: grayscale(80%) contrast(1.1);
}

/* ── Controls ──────────────────────────────────────────────── */
.controls {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  margin-top: 1.25rem;
  width: calc(var(--receipt-chars, 42) * 1ch + 40px);
}

.line-count {
  font-size: .8rem;
  color: #888;
  align-self: flex-end;
}
.line-count--warn { color: #f97316; }
.line-count--over { color: #ef4444; font-weight: 600; }

.upload-label {
  font-size: .85rem;
  color: #555;
  cursor: pointer;
  border: 1px dashed #bbb;
  border-radius: 6px;
  padding: .4rem .9rem;
  transition: border-color .15s, color .15s;
  width: 100%;
  text-align: center;
}
.upload-label:hover { border-color: #888; color: #222; }

.upload-name {
  font-size: .75rem;
  color: #888;
  text-align: center;
}

.rate-status {
  background: #fef9c3;
  border: 1px solid #fde047;
  border-radius: 6px;
  padding: .5rem .9rem;
  font-size: .85rem;
  color: #713f12;
  width: 100%;
  text-align: center;
}

.btn-print {
  width: 100%;
  padding: .7rem 1.5rem;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn-print:hover:not(:disabled) { background: #333; }
.btn-print:active:not(:disabled) { transform: scale(.98); }
.btn-print:disabled { background: #aaa; cursor: not-allowed; }

.result-msg {
  font-size: .875rem;
  text-align: center;
  min-height: 1.2em;
}
.result-msg--ok    { color: #16a34a; }
.result-msg--error { color: #dc2626; }

/* ── Admin ─────────────────────────────────────────────────── */
.admin-body { background: #f3f4f6; }

.admin-wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.admin-title {
  font-size: 1.6rem;
  font-weight: 700;
}

.admin-card {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

.admin-card h2 {
  font-size: 1.1rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: .5rem;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.field-row label {
  font-size: .85rem;
  font-weight: 600;
  color: #374151;
}

.field-row input,
.field-row select,
.field-row textarea {
  padding: .45rem .75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: .9rem;
  font-family: inherit;
  width: 100%;
  max-width: 400px;
}

.field-row textarea {
  font-family: 'Courier New', monospace;
  font-size: .85rem;
  resize: vertical;
  max-width: 100%;
}

.fieldset {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1rem;
}

.fieldset legend {
  font-weight: 600;
  font-size: .9rem;
  padding: 0 .4rem;
  color: #374151;
}

.btn-save {
  align-self: flex-start;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: .55rem 1.5rem;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-save:hover { background: #333; }

/* Messages table */
.table-wrap { overflow-x: auto; }

.msg-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

.msg-table th {
  text-align: left;
  padding: .5rem .75rem;
  background: #f9fafb;
  border-bottom: 2px solid #e5e7eb;
  font-weight: 600;
  color: #374151;
  white-space: nowrap;
}

.msg-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: top;
}

.msg-table tr:hover td { background: #fafafa; }

.td-time { white-space: nowrap; color: #6b7280; font-size: .8rem; }
.td-ip   { font-family: monospace; font-size: .8rem; color: #6b7280; white-space: nowrap; }
.td-text { max-width: 400px; word-break: break-word; }

.thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #e5e7eb;
}

.empty { color: #9ca3af; font-style: italic; }

/* ── Printing animation ────────────────────────────────────── */
@keyframes feed-in {
  from { transform: translateY(-8px); opacity: .6; }
  to   { transform: translateY(0);   opacity: 1; }
}

.paper--printing {
  animation: feed-in .4s ease-out;
}
