/* tally — one small stylesheet, mobile-first, dark. */

:root {
  --bg: #0b0f10;
  --panel: #14191b;
  --panel-2: #1b2224;
  --line: #263033;
  --text: #e7eeef;
  --muted: #9fb0b3;
  --accent: #14b8a6;
  --accent-strong: #0f766e;
  --danger: #ef6b6b;
  --radius: 14px;
  --pad: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 12px) var(--pad) 48px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Header */
.masthead h1 {
  margin: 6px 0 0;
  font-size: 30px;
  letter-spacing: -0.02em;
}
.masthead h1::before { content: "🧾 "; }
.tagline { margin: 4px 0 0; color: var(--muted); }

/* Intake / buttons */
.intake { display: flex; flex-direction: column; gap: 10px; }
.photo-input { display: flex; gap: 10px; flex-wrap: wrap; }
.blurb { color: var(--muted); margin: 2px 0 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; padding: 8px 12px; font-weight: 500; }

/* Status */
.status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
}
.status.busy { color: var(--text); }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Image viewer + region selection */
.viewer { display: flex; flex-direction: column; gap: 10px; }
.image-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  touch-action: none; /* let us draw without the page scrolling */
  background: #000;
  line-height: 0;
}
.receipt { width: 100%; height: auto; display: block; -webkit-user-drag: none; }
.selection {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(20, 184, 166, 0.18);
  pointer-events: none;
}
.viewer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

/* Items */
.items { display: flex; flex-direction: column; gap: 10px; }
.items-head { display: flex; align-items: center; justify-content: space-between; }
.items-head h2 { margin: 0; font-size: 18px; }
.items-bulk { display: flex; gap: 4px; }

.item-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.item.is-selected { border-color: var(--accent-strong); background: var(--panel-2); }
.item-check { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.item-fields { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.item-name {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 2px 0;
}
.item-name:focus { outline: none; border-bottom-color: var(--accent); }
.item-numbers { display: flex; gap: 10px; }
.mini { display: flex; flex-direction: column; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.item-numbers input {
  width: 64px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 5px 7px;
}
.item-qty { width: 46px !important; }
.item-value { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.item-remove {
  background: transparent; border: none; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 4px;
}
.item-remove:hover { color: var(--danger); }
.add-item { align-self: flex-start; }
.empty { color: var(--muted); }

/* Totals */
.totals {
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.total-line { display: flex; align-items: baseline; justify-content: space-between; }
.total-line .num { font-variant-numeric: tabular-nums; font-weight: 700; }
.total-line.sub { color: var(--muted); font-size: 14px; }
.total-line.grand { border-top: 1px solid var(--line); padding-top: 10px; font-size: 20px; }
.total-line.grand .num { color: var(--accent); font-size: 24px; }
.tip-block { display: flex; flex-direction: column; gap: 4px; }

.final-bill summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.final-grid { display: flex; gap: 10px; margin: 10px 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; }
.field input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); font-size: 16px; padding: 9px 10px;
}
input:focus { outline: 2px solid var(--accent-strong); outline-offset: 0; }

/* Raw text + footer */
.raw summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.raw pre {
  white-space: pre-wrap; word-break: break-word;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; font-size: 12px; color: var(--muted); max-height: 240px; overflow: auto;
}
.foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 8px; }

@media (max-width: 380px) {
  .item { grid-template-columns: auto 1fr auto; }
  .item-remove { grid-column: 3; }
}
