:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --text: #1c2624;
  --muted: #5f6f6b;
  --border: #dde5e3;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --accent: #f59e0b;
  --danger: #b42318;
  --ok: #067647;
  --warn: #b54708;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514;
    --surface: #18211f;
    --text: #e6eeec;
    --muted: #9fb0ac;
    --border: #2a3634;
    --primary: #2dd4bf;
    --primary-ink: #04201d;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); font-size: .9rem; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(.75rem + env(safe-area-inset-top, 0px)) 16px .75rem; background: var(--primary); color: var(--primary-ink);
}
.brand { font-weight: 800; font-size: 1.2rem; }
.brand span { color: var(--accent); }
#session { display: flex; gap: .5rem; align-items: center; font-size: .85rem; }
#session button { background: transparent; color: inherit; border: 1px solid currentColor; padding: .3rem .6rem; }

.tabs {
  display: flex; gap: .25rem; overflow-x: auto; padding: .5rem 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.tabs button {
  background: transparent; color: var(--muted); border: 0; border-bottom: 3px solid transparent;
  border-radius: 0; padding: .5rem .75rem; white-space: nowrap;
}
.tabs button[aria-current="page"] { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

.container { max-width: 880px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat .value { font-size: 1.4rem; font-weight: 700; }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat.highlight { border-color: var(--primary); }
.stat.highlight .value { color: var(--primary); }

form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: .9rem; font-weight: 600; }
label small { font-weight: 400; color: var(--muted); }
input, select, textarea {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; width: 100%;
}
textarea { min-height: 70px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.checks { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-weight: 400; }
.checks label { display: flex; gap: .3rem; align-items: center; font-weight: 400; }
.checks input { width: auto; }

button, .button {
  font: inherit; cursor: pointer; border: 0; border-radius: 8px;
  padding: .65rem 1rem; background: var(--primary); color: var(--primary-ink); font-weight: 600;
}
button.secondary { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button:disabled { opacity: .6; cursor: progress; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.camera {
  display: grid; place-items: center; gap: .5rem; text-align: center;
  border: 2px dashed var(--primary); border-radius: var(--radius); padding: 28px 16px; cursor: pointer;
}
.camera input { display: none; }
.camera .icon { font-size: 2.5rem; }
.preview { width: 100%; max-height: 320px; object-fit: contain; border-radius: 8px; background: #0002; }

.list { display: grid; gap: 10px; }
.item { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface); }
.item-head { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.badge {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px;
  background: var(--border); color: var(--text); white-space: nowrap;
}
.badge.reponer_ya { background: #fee4e2; color: var(--danger); }
.badge.proxima_compra { background: #fef0c7; color: var(--warn); }
.badge.ok { background: #dcfae6; color: var(--ok); }
.badge.complementaria { background: #e0eaff; color: #3538cd; }
.badge.discount { background: var(--accent); color: #1c1402; }
.reasons { margin: .4rem 0; padding-left: 1.1rem; font-size: .88rem; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table-wrap { overflow-x: auto; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: 8px;
  max-width: calc(100% - 32px); z-index: 50; pointer-events: none;
}
.toast.error { background: var(--danger); color: #fff; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* Puntos e incentivos */
.points-hero { text-align: center; }
.points-balance { font-size: 2.6rem; font-weight: 800; color: var(--primary); line-height: 1.1; font-variant-numeric: tabular-nums; }
.badge.points { background: var(--accent); color: #1c1402; }
label.button { display: inline-block; font-weight: 600; }
.code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-weight: 700; letter-spacing: .05em; white-space: nowrap; }
.check-row { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
.check-row input { width: auto; }
td.plus { color: var(--ok); font-weight: 700; white-space: nowrap; }
td.minus { color: var(--danger); font-weight: 700; white-space: nowrap; }
.item .preview { margin: .5rem 0; }
.actions input { flex: 1 1 200px; width: auto; }
.question-row { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; }
@media (max-width: 520px) { .question-row { grid-template-columns: 1fr auto; } .question-row input { grid-column: 1 / -1; } }

/* Apps: almacenes (verde) y HORECA (vino) */
:root[data-app="horeca"] { --primary: #7a1f3d; --accent: #f5b93d; }
@media (prefers-color-scheme: dark) {
  :root[data-app="horeca"] { --primary: #f49ab9; --primary-ink: #2a0713; }
}
.brand .app-name { font-weight: 600; font-size: .8rem; color: var(--primary-ink); opacity: .85; margin-left: .35rem; }
.app-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-top: 12px; }
.app-card {
  display: flex; gap: 14px; align-items: center; text-decoration: none; color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--bg);
}
.app-card img { border-radius: 16px; flex: none; }
.app-card strong { display: block; font-size: 1.1rem; }
.app-card.almacen:hover { border-color: #0b6e66; }
.app-card.horeca:hover { border-color: #7a1f3d; }
.app-card.cafeterias:hover { border-color: #5b3421; }
.install-hint { border-color: var(--accent); }
.brand { white-space: nowrap; }
.topbar { gap: .75rem; }
#session { flex: 1 1 auto; min-width: 0; justify-content: flex-end; }
#session > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#session > button { flex: none; }
@media (max-width: 420px) { .brand .app-name { display: none; } }

/* Opción «Pronto» en el inicio (no navegable) */
.app-card.pronto { opacity: .55; cursor: default; pointer-events: none; }
.badge-pronto { display: inline-block; margin-left: .35rem; padding: .05rem .45rem; border-radius: 999px; font-size: .7rem; font-weight: 700; background: #eee; color: #555; vertical-align: middle; }
