:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #d7dbe0;
  --text: #1b1e24;
  --muted: #6b7280;
  --accent: #1f6feb;
  --accent-dark: #144fb8;
  --good: #1a7f37;
  --bad: #c62828;
  --header-bg: #1b1e24;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 60px;
}

.topbar {
  background: var(--header-bg);
  color: #fff;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.topbar input[type="date"] {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #2a2e37;
  color: #fff;
}

.btn {
  border: 1px solid #444;
  background: #2a2e37;
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-ghost:hover { background: #3a3f4a; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
}
.btn-primary:hover { filter: brightness(1.08); }

.totals-strip {
  margin-top: 8px;
  gap: 10px;
}
.pill {
  background: #2a2e37;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  white-space: nowrap;
}
.pill span { font-weight: 700; }
#strip-overshort-pill.over { background: #1a3d24; }
#strip-overshort-pill.short { background: #4a1f1f; }

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (min-width: 1050px) {
  .layout {
    grid-template-columns: 2fr 1fr;
    align-items: start;
  }
}

.side-panels {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.panel-header h2 {
  font-size: 1rem;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.hint {
  color: var(--muted);
  font-size: 0.78rem;
}

.lottery-tables {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 700px) {
  .lottery-tables { grid-template-columns: 1fr 1fr; }
}

.lottery-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table.lottery-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

table.lottery-table th {
  background: #eef0f3;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}

table.lottery-table td {
  border-bottom: 1px solid #eef0f3;
  padding: 3px 4px;
  text-align: center;
  vertical-align: middle;
}

table.lottery-table td.slot-num {
  font-weight: 700;
  background: #f7f8fa;
  width: 28px;
}

table.lottery-table input[type="text"].game-input {
  width: 56px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 0.78rem;
  text-align: center;
}
table.lottery-table input.price-input {
  width: 44px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 0.78rem;
  text-align: center;
}
table.lottery-table input.game-input:focus,
table.lottery-table input.price-input:focus {
  border-color: var(--border);
  background: #fff;
}

table.lottery-table td.game-readonly {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
}

.oc-cell {
  display: flex;
  align-items: center;
  gap: 2px;
  justify-content: center;
}

.oc-cell input {
  width: 42px;
  padding: 3px 2px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
  font-size: 0.8rem;
}

.search-results {
  margin-top: 6px;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.search-result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.search-result-row:last-child { border-bottom: none; }
.search-result-row.empty { justify-content: center; color: var(--muted); }
.search-result-row .stock-count { font-weight: 600; white-space: nowrap; }

.report-photo-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.report-zoom { font-size: 0.8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.report-canvas-wrap { overflow: auto; max-height: 55vh; border: 1px solid var(--border); border-radius: 6px; background: #222; }
#reportCanvas { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: none; }
.report-badge { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 10px; color: #fff; font-size: 0.75rem; font-weight: 700; text-align: center; }
.report-actions { white-space: nowrap; }
#reportTable select, #reportTable input[type=text], #reportTable input[type=number] { min-width: 140px; }
input.report-warn { border-color: var(--bad) !important; background: #fff5f5; }
.report-file-btn { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
table.vendor-table select {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.85rem;
  background: #fff;
}
.qty-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-cell input {
  width: 70px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
  font-size: 1rem;
}

.scan-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 2px;
  line-height: 1;
}
.scan-btn:active { transform: scale(0.9); }

td.sold-cell, td.total-cell {
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

.lottery-footer {
  margin-top: 10px;
  font-size: 0.9rem;
  text-align: right;
}

table.cat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
table.cat-table td {
  padding: 5px 4px;
  border-bottom: 1px solid #eef0f3;
}
.cat-label {
  color: var(--text);
  white-space: nowrap;
}
table.cat-table input[type="number"] {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  text-align: right;
  font-size: 0.88rem;
}
.auto-tag {
  font-size: 0.65rem;
  color: var(--muted);
  background: #eef0f3;
  border-radius: 4px;
  padding: 1px 4px;
  margin-left: 4px;
}

.total-row td {
  font-weight: 700;
  border-top: 2px solid var(--text);
  border-bottom: none;
  padding-top: 8px;
}
.total-row-2 td {
  border-top: 1px dashed var(--border);
  padding-top: 6px;
}
.total-row span, .total-row-2 span {
  display: block;
  text-align: right;
}

table.vendor-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
table.vendor-table th {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 4px;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
}
table.vendor-table td {
  padding: 4px;
  border-bottom: 1px solid #eef0f3;
}
table.vendor-table input[type="text"] {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
}
table.vendor-table input[type="number"] {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  text-align: right;
}
.row-remove {
  border: none;
  background: none;
  color: var(--bad);
  cursor: pointer;
  font-size: 1rem;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 10px;
  padding: 18px;
  max-width: 380px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-wide { max-width: 560px; }
.modal h3 { margin-top: 0; }
.modal-sub { color: var(--muted); margin-top: -8px; }
.modal-row { margin-bottom: 12px; }
.modal-row label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.modal-row input {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}
.raw-text {
  font-family: monospace;
  background: #f4f5f7;
  padding: 8px;
  border-radius: 6px;
  word-break: break-all;
  font-size: 0.85rem;
}
.modal-error { color: var(--bad); font-size: 0.85rem; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 6px;
}
.modal-actions .btn {
  color: #fff;
}
.modal-actions .btn-ghost { background: #6b7280; border-color: #6b7280; }

.continuous-badge {
  background: #eaf2ff;
  color: var(--accent);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 10px;
  text-align: center;
}
.modal-row-inline {
  display: flex;
  gap: 14px;
}
.modal-row-inline > div { flex: 1; }
.modal-row-inline-3 {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.modal-row-inline-3 > div { flex: 1; min-width: 90px; }
.games-table-wrap {
  max-height: 340px;
  overflow-y: auto;
  margin-bottom: 4px;
}
.game-info-badge {
  background: #eaf7ea;
  color: var(--good);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-weight: 600;
}
.game-info-badge.unknown {
  background: #fff6e0;
  color: #8a6100;
}
.roll-change-icon-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 2px;
  line-height: 1;
  opacity: 0.55;
}
.roll-change-icon-btn:hover { opacity: 1; }
.roll-change-btn {
  border: none;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0;
  margin-left: 4px;
}
.slot-input-big {
  font-size: 1.4rem !important;
  font-weight: 700;
  text-align: center;
}
.field-badge {
  padding: 8px;
  border-radius: 6px;
  background: #f4f5f7;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
}
.choice-row {
  display: flex;
  gap: 10px;
}
.btn-choice {
  flex: 1;
  padding: 16px 10px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 8px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  line-height: 1.6;
}
.btn-choice span {
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.85;
}
.btn-danger {
  background: var(--bad) !important;
  border-color: var(--bad) !important;
}
.slot-config-grid {
  display: grid;
  grid-template-columns: 40px 1fr 80px;
  gap: 4px 8px;
  max-height: 260px;
  overflow-y: auto;
  margin-top: 6px;
  font-size: 0.85rem;
}
.slot-config-grid .sc-num {
  font-weight: 700;
  align-self: center;
}
.slot-config-grid input {
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  width: 100%;
}

.modal-live {
  max-width: 480px;
  padding: 14px;
}
.live-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}
.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.viewfinder {
  position: absolute;
  top: 30%;
  left: 8%;
  right: 8%;
  bottom: 30%;
  border: 3px solid rgba(255,255,255,0.85);
  border-radius: 8px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,0.25);
  pointer-events: none;
}
.live-hint {
  text-align: center;
  margin-top: 10px;
}
.live-fallback {
  text-align: center;
  margin-top: 10px;
  display: flex;
  justify-content: center;
  gap: 10px;
}

.lock-overlay {
  position: fixed;
  inset: 0;
  background: var(--header-bg);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.lock-overlay .modal { max-width: 320px; }

.app-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}
.app-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media print {
  @page { size: portrait; margin: 6mm; }

  html, body { padding: 0 !important; margin: 0 !important; background: #fff !important; font-size: 10px; }

  .topbar-actions, .scan-btn, .row-remove, #addVendorBtn, .hint, #continuousScanBtn,
  table.lottery-table th:last-child, table.lottery-table td:last-child,
  table.lottery-table th:nth-child(2), table.lottery-table td:nth-child(2),
  .search-results { display: none !important; }

  .topbar { position: static; background: #fff; color: #000; padding: 0 0 3px; }
  .topbar-row.totals-strip { gap: 5px; }
  h1#businessNameDisplay { font-size: 15px; }
  .pill { background: none; color: #000; border: 1px solid #000; padding: 1px 5px; font-size: 9px; }

  main.layout {
    display: grid !important;
    grid-template-columns: 2fr 1fr !important;
    gap: 5px !important;
    padding: 0 !important;
    max-width: none !important;
    margin: 0 !important;
  }

  .lottery-tables {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 4px !important;
  }

  .side-panels { display: flex !important; flex-direction: column; gap: 4px !important; }

  .panel {
    padding: 3px !important;
    border-radius: 0 !important;
    border-color: #000 !important;
    break-inside: avoid;
  }
  .panel-header { margin-bottom: 2px !important; }
  .panel-header h2 { font-size: 9px !important; }

  .lottery-table-wrap { overflow: visible !important; border-color: #000 !important; }

  /* Fixed layout + explicit column widths so long content (or a printer's
     own scaling) can never push the table wider than its column — it just
     truncates instead of blowing out the one-page layout. */
  table.lottery-table { table-layout: fixed !important; width: 100% !important; }
  table.lottery-table th:nth-child(1), table.lottery-table td:nth-child(1) { width: 8% !important; }
  table.lottery-table th:nth-child(3), table.lottery-table td:nth-child(3) { width: 16% !important; }
  table.lottery-table th:nth-child(4), table.lottery-table td:nth-child(4) { width: 18% !important; }
  table.lottery-table th:nth-child(5), table.lottery-table td:nth-child(5) { width: 18% !important; }
  table.lottery-table th:nth-child(6), table.lottery-table td:nth-child(6) { width: 16% !important; }
  table.lottery-table th:nth-child(7), table.lottery-table td:nth-child(7) { width: 24% !important; }

  table.lottery-table, table.cat-table, table.vendor-table { font-size: 9px !important; }
  table.lottery-table th, table.lottery-table td,
  table.cat-table td, table.vendor-table td { padding: 1.5px 3px !important; }
  table.lottery-table th { position: static !important; background: #eee !important; }
  table.lottery-table td.slot-num { width: auto !important; }

  .lottery-footer { margin-top: 3px !important; font-size: 8.5px !important; }

  /* Inputs should read like plain filled-in values on paper, not form controls */
  input, select, textarea {
    border: none !important;
    background: transparent !important;
    border-radius: 0 !important;
    padding: 0 !important;
    font-size: inherit !important;
    color: #000 !important;
    -webkit-appearance: none;
  }
  table.lottery-table input.price-input,
  .oc-cell input {
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .oc-cell { display: block !important; }
  table.cat-table input[type="number"] { text-align: right !important; }
}
