/* Reusable pieces. Each block is independent; sections combine them. */

/* ---------- Logo (4:3 frame, image set once in theme.css) ---------- */
.logo {
  aspect-ratio: 4 / 3;
  background: var(--logo-url) center / calc(100% * var(--logo-zoom, 1)) auto no-repeat;
  flex-shrink: 0;
}
.logo-sm { height: 60px; }
.logo-lg { width: 100%; }

/* The big login logo sits in a block of "ice" so the logo's white
   background reads as part of the design. */
.ice-block {
  width: min(340px, 86vw);
  margin: 0 auto;
  padding: .5rem;
  border: var(--outline) solid var(--line);
  border-radius: 22px;
  background: var(--surface-ice);
  box-shadow: var(--frost-edge), 0 var(--lift) 0 var(--line), 0 14px 30px rgba(31, 42, 110, .18);
}
.ice-block .logo { border-radius: 14px; background-color: #fff; }

/* ---------- Cards (frosted ice panels) ---------- */
.card {
  background: var(--surface-ice);
  border: var(--outline) solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--frost-edge), 0 var(--lift) 0 var(--line);
  padding: 1rem;
  margin-bottom: 1.25rem;
}
.card > :last-child { margin-bottom: 0; }
.card-title { display: flex; align-items: center; gap: .5rem; justify-content: space-between; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: var(--tap);
  padding: .5rem 1.25rem;
  border: var(--outline) solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-ice);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--frost-edge), 0 var(--lift) 0 var(--line);
  transition: transform .05s, box-shadow .05s;
  touch-action: manipulation;
  user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(var(--lift)); box-shadow: 0 0 0 var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 1.4em; height: 1.4em; flex-shrink: 0; }
.btn-primary { background: linear-gradient(180deg, #34449a 0%, var(--primary) 55%); color: var(--primary-text); box-shadow: inset 0 2px 0 rgba(255,255,255,.25), 0 var(--lift) 0 #0d1440; }
.btn-accent { background: linear-gradient(180deg, #5fa2e6 0%, var(--accent) 55%); color: #fff; box-shadow: inset 0 2px 0 rgba(255,255,255,.45), 0 var(--lift) 0 var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { box-shadow: none; border-color: transparent; background: transparent; text-decoration: underline; min-height: 48px; }
.btn-ghost:active:not(:disabled) { transform: none; }
.btn-block { width: 100%; }
.btn-xl { min-height: 76px; font-size: 1.25rem; }
.btn-sm { min-height: 48px; padding: .25rem .9rem; font-size: .95rem; }

.btn-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

/* ---------- Form fields ---------- */
.field { display: block; margin-bottom: 1rem; }
.field-label { display: block; font-weight: 800; margin-bottom: .35rem; }
.field-hint { display: block; font-size: .85rem; color: var(--text-muted); margin-top: .25rem; }

.input, .select, textarea.input {
  width: 100%;
  min-height: var(--tap);
  padding: .5rem .85rem;
  border: var(--outline) solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}
textarea.input { min-height: 110px; resize: vertical; }
.select {
  appearance: none;
  padding-right: 2.75rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--navy) 50%), linear-gradient(135deg, var(--navy) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 14px) 50%;
  background-size: 8px 8px;
  background-repeat: no-repeat;
}
.input:focus, .select:focus { outline: 4px solid var(--orange); outline-offset: 0; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .75rem; }
.grid-2 > * { min-width: 0; }
input[type="date"], input[type="datetime-local"] { min-width: 0; max-width: 100%; display: block; }
@media (max-width: 420px) { .grid-2.stack-sm { grid-template-columns: 1fr; } }

/* ---------- Choice tiles (product picker) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: .6rem; }
.tile {
  min-height: 92px;
  padding: .5rem;
  border: var(--outline) solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-ice);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1.15;
  box-shadow: var(--frost-edge), 0 var(--lift) 0 var(--line);
  cursor: pointer;
  touch-action: manipulation;
}
.tile[aria-pressed="true"] {
  background: linear-gradient(160deg, #6fb0ee 0%, var(--blue) 45%, #1f5fae 100%);
  color: #fff;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.5), 0 var(--lift) 0 var(--line);
}
.tile[aria-pressed="true"]::after { content: " ✓"; }
.tile:active { transform: translateY(var(--lift)); box-shadow: none; }

/* ---------- Quantity field ---------- */
.qty-input {
  display: block;
  width: 100%;
  min-height: 88px;
  text-align: center;
  font: inherit;
  font-size: 2.6rem;
  font-weight: 800;
  border: var(--outline) solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--surface);
  box-shadow: inset 0 3px 0 rgba(169, 212, 245, .5);
  -moz-appearance: textfield;
}
.qty-input:focus { outline: 4px solid var(--orange); outline-offset: 0; }
.qty-input::-webkit-outer-spin-button, .qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---------- Badges / chips / status ---------- */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.6em; height: 1.6em; padding: 0 .45em;
  border-radius: 999px;
  background: var(--red); color: #fff;
  font-size: .8rem; font-weight: 800;
}
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .6rem;
  border: 2px solid currentColor;
  border-radius: 999px;
  font-size: .8rem; font-weight: 800;
  white-space: nowrap;
}
.chip-ok { color: var(--ok); background: var(--ok-bg); }
.chip-warn { color: var(--warn-text); background: var(--warn-bg); }
.chip-danger { color: #fff; background: var(--red); border-color: var(--red); }
.chip-info { color: var(--navy); background: var(--ice); }

.status-pill {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .3rem .7rem;
  border-radius: 999px;
  border: 2px solid var(--line);
  font-weight: 800; font-size: .85rem;
}
.status-pill::before { content: ""; width: .75rem; height: .75rem; border-radius: 50%; background: currentColor; }
.status-pill.online { color: var(--ok); }
.status-pill.offline { color: var(--red); }
.status-pill > span { color: var(--text); }

/* ---------- Banners (top-of-page notices) ---------- */
.banner {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .75rem 1rem;
  margin-bottom: .75rem;
  background: var(--warn-bg); color: var(--warn-text);
  border: var(--outline) solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 var(--lift) 0 var(--line);
  font-weight: 700;
}
.banner > .grow { flex: 1 1 200px; }
.banner-info { background: var(--ice); color: var(--navy); }
.banner-danger { background: var(--red); color: #fff; }

/* ---------- Lists of records ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .25rem .75rem;
  padding: .85rem 0;
  border-bottom: 2px solid var(--ice);
}
.list-item:last-child { border-bottom: 0; }
.list-item .title { font-weight: 800; font-size: 1.05rem; }
.list-item .meta { color: var(--text-muted); font-size: .9rem; }
.list-item .chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .35rem; }
.list-item .actions { grid-column: 1 / -1; display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .4rem; }
.list-item .qty { font-size: 1.6rem; font-weight: 800; text-align: right; }
.list-item.error { background: #fff0f0; margin: 0 -1rem; padding-left: 1rem; padding-right: 1rem; }

.empty { text-align: center; color: var(--text-muted); padding: 1.5rem .5rem; font-weight: 600; }

/* ---------- Tables (admin screens, scroll sideways on phones) ---------- */
.table-wrap { overflow-x: auto; margin: 0 -1rem; padding: 0 1rem; }
table.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { text-align: left; padding: .6rem .5rem; border-bottom: 2px solid var(--ice); vertical-align: top; }
.table th { font-weight: 800; border-bottom-color: var(--line); white-space: nowrap; }
.table td.num, .table th.num { text-align: right; }

/* ---------- Toast ---------- */
#toasts {
  position: fixed; left: 0; right: 0;
  top: calc(88px + env(safe-area-inset-top, 0px));
  z-index: 50;
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  pointer-events: none;
  padding: 0 1rem;
}
.toast {
  max-width: 560px; width: 100%;
  padding: 1rem 1.25rem;
  border: var(--outline) solid var(--line);
  border-radius: var(--radius);
  background: var(--navy); color: #fff;
  font-weight: 800; font-size: 1.05rem;
  box-shadow: 0 var(--lift) 0 rgba(0, 0, 0, .35);
  animation: toast-in .15s ease-out;
}
.toast-ok { background: var(--ok); }
.toast-error { background: var(--red); }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(14, 20, 51, .6);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--surface-ice);
  border: var(--outline) solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.25rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
}
@media (min-width: 640px) { .modal { border-radius: var(--radius); } }
.modal h2 { margin-bottom: 1rem; }

.callout {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  border: 2px solid currentColor;
  margin-bottom: 1rem;
  font-weight: 700;
}
.callout-warn { background: var(--warn-bg); color: var(--warn-text); }
.callout-error { background: #ffe5e5; color: #8a0d14; }
.callout-ok { background: var(--ok-bg); color: var(--ok); }
.callout-info { background: var(--ice); color: var(--navy); }

/* ---------- Sticky action bar (Save button on the log screen) ---------- */
.sticky-actions {
  position: sticky;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  padding: .75rem 0;
}

/* ---------- Header pieces ---------- */
.user-btn { min-height: 48px; padding: .2rem .75rem; font-size: .9rem; box-shadow: none; }

/* ---------- Weekly sheet preview grid ---------- */
.sheet-grid td.num, .sheet-grid th.num { text-align: center; }
.sheet-grid td { font-variant-numeric: tabular-nums; font-weight: 700; }
.sheet-grid .cell-changed { background: #ffe7c7; box-shadow: inset 0 0 0 2px var(--orange); border-radius: 6px; }

/* ---------- Booth QR sheet ---------- */
.qr-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.qr-card {
  background: #fff;
  border: var(--outline) solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  break-inside: avoid;
}
.qr-card img { display: block; width: 100%; max-width: 240px; height: auto; margin: .25rem auto; }
.qr-brand { font-weight: 800; color: var(--blue); text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; }
.qr-booth { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.qr-store { color: var(--text-muted); font-weight: 700; }

/* ---------- Print (QR sheet) ---------- */
@media print {
  @page { margin: 12mm; }
  .qr-sheet { grid-template-columns: 1fr 1fr; gap: 10mm; }
  .qr-card { border-width: 2px; }
  .qr-card img { max-width: 80%; }
  .qr-booth { font-size: 2.6rem; }
  body { background: #fff !important; }
  .app-header, .app-nav, #banners, #toasts, .no-print { display: none !important; }
  body { background: #fff; padding: 0; }
  main#view { max-width: none; padding: 0; }
  .card { box-shadow: none; }
}
