:root {
  --bg: #f6f4f1;
  --card: #ffffff;
  --text: #1d1b19;
  --muted: #6f6a64;
  --line: #e6e1db;
  --accent: #f26b1d;
  --accent-ink: #ffffff;
  --accent-soft: #fdebdf;
  --ok: #1f8a4c;
  --ok-soft: #e1f3e8;
  --danger: #c73a2b;
  --danger-soft: #fbe5e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151312;
    --card: #1f1c1a;
    --text: #f2eee9;
    --muted: #a39d96;
    --line: #34302c;
    --accent: #ff7d33;
    --accent-ink: #1a0d04;
    --accent-soft: #3a2416;
    --ok: #4cc27f;
    --ok-soft: #173325;
    --danger: #ff6b5c;
    --danger-soft: #3a1c18;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }

.wrap { max-width: 720px; margin: 0 auto; padding: 16px; }

/* ---------- Encabezado ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top .wrap { display: flex; align-items: center; gap: 10px; padding-top: 12px; padding-bottom: 12px; }
.top h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { font-weight: 800; letter-spacing: -.01em; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600;
  text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.icon-btn { min-width: 44px; padding: 0; }

/* ---------- Tarjetas y listas ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px;
}
.stack > * + * { margin-top: 12px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 4px 8px; font-weight: 700; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap-row { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small-text { font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.strong { font-weight: 700; }
.big { font-size: 22px; font-weight: 800; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.round-item { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.round-item + .round-item { margin-top: 10px; }

.chip {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.gray { background: var(--line); color: var(--muted); }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }

/* ---------- Carrito en la ronda ---------- */
.cart-card .name { font-weight: 700; font-size: 17px; }
.cart-card .share { font-size: 20px; font-weight: 800; color: var(--accent); }
.cart-card.paid { border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.paid-toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; font-size: 14px; user-select: none; min-height: 36px; }
.paid-toggle input { width: 20px; height: 20px; accent-color: var(--ok); }

.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
.totals .label { color: var(--muted); }

/* ---------- Formularios ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 110px; resize: vertical; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; text-align: center; padding: 28px 22px; }
.login h1 { margin: 0 0 4px; font-size: 26px; }
.code-input {
  width: 100%; text-align: center; font-size: 32px; letter-spacing: .5em; padding-left: .5em;
  font-variant-numeric: tabular-nums; font-weight: 700; margin: 20px 0 12px;
}
.error { color: var(--danger); font-size: 14px; min-height: 20px; }

/* ---------- Editor de carrito (hoja) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px; max-height: 94dvh; overflow: auto;
  border-radius: 18px 18px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 760px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-head { position: sticky; top: 0; background: var(--bg); z-index: 2; border-bottom: 1px solid var(--line); }
.sheet-head .wrap { display: flex; align-items: center; gap: 8px; padding-top: 10px; padding-bottom: 10px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; }

.tabs { display: flex; gap: 6px; background: var(--line); padding: 4px; border-radius: 12px; }
.tabs button { flex: 1; border: 0; background: transparent; min-height: 38px; border-radius: 9px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.items { width: 100%; border-collapse: collapse; }
.item-row { display: grid; grid-template-columns: 1fr 64px 96px 36px; gap: 6px; align-items: center; }
.item-row + .item-row { margin-top: 6px; }
.item-row .input { min-height: 40px; padding: 8px 10px; font-size: 15px; }
.item-head { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
@media (max-width: 520px) {
  .item-head { display: none; }
  .item-row { grid-template-columns: 1fr 1.4fr 44px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
  .item-row + .item-row { margin-top: 8px; }
  .item-row [data-f="title"] { grid-column: 1 / -1; }
  .item-row [data-f="qty"]::placeholder, .item-row [data-f="unit_price"]::placeholder { color: var(--muted); }
}

.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; cursor: pointer;
  color: var(--muted); display: block;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); color: var(--accent); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

.notice { background: var(--accent-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.notice.warn { background: var(--danger-soft); }

/* ---------- Reparto ---------- */
.split-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.split-row:last-child { border-bottom: 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Miniaturas de productos ---------- */
.thumb-strip { display: flex; gap: 6px; margin-top: 10px; align-items: center; overflow: hidden; }
.thumb-strip img { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--line); flex: none; }
.thumb-strip .more { flex: none; font-size: 13px; color: var(--muted); font-weight: 700; padding-left: 2px; }
