:root {
  --navy: #00214c;
  --orange: #ff6e00;
  --orange-soft: #fff1e6;
  --ink: #00214c;
  --muted: #4f5d73;
  --line: #e3e7ee;
  --bg: #f5f7fa;
  --card: #ffffff;
  --ok: #0f7a3d;
  --ok-soft: #e5f5ec;
  --bad: #b3261e;
  --bad-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --info-soft: #e8eef8;
  --radius: 16px;
  --tabs-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 400 1.0625rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

/* Botones */
.btn {
  display: block; width: 100%; min-height: 52px; padding: 12px 18px;
  border: 0; border-radius: 12px; background: var(--orange); color: var(--navy);
  font-weight: 700; cursor: pointer;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-secondary { background: var(--card); border: 2px solid var(--navy); color: var(--navy); }
.icon-btn {
  flex: none; width: 48px; height: 48px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: rgba(255,255,255,.12); color: #fff; cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.spin svg { animation: none; } }

/* Acceso */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: #fff; }
.login-box { width: 100%; max-width: 380px; display: grid; gap: 16px; text-align: center; }
.login-logo { width: 64px; height: 64px; margin: 0 auto; }
.login h1 { font-size: 1.6rem; }
.login p { margin: 0; color: var(--muted); }
.login-form { display: grid; gap: 12px; text-align: left; }
.login-form label { display: grid; gap: 4px; font-weight: 600; }
.login-form input { min-height: 48px; padding: 10px 12px; border: 1px solid #b9c2d0; border-radius: 10px; }
.fine { font-size: .9rem; }

/* Cabecera */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--navy); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.top-row { display: flex; gap: 10px; align-items: center; }
.store-select { flex: 1; min-width: 0; }
.store-select select {
  width: 100%; min-height: 48px; padding: 8px 36px 8px 12px;
  border: 0; border-radius: 12px; background: rgba(255,255,255,.12) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center / 20px;
  color: #fff; font-weight: 700; appearance: none; -webkit-appearance: none;
  text-overflow: ellipsis;
}
.store-select option { color: var(--ink); }
.sync-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 4px; }
.sync { margin: 0; font-size: .875rem; opacity: .85; }
.logout { flex: none; min-height: 40px; padding: 4px 2px; border: 0; background: none; color: #fff; font-size: .875rem; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.login-error { margin: 0; min-height: 1.4em; color: var(--bad); font-weight: 600; text-align: center; }

/* Contenido */
main { padding: 16px 16px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; outline: none; }
.section { margin-top: 24px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.section-head h2 { font-size: 1.15rem; }
.link { background: none; border: 0; padding: 6px 0; color: var(--navy); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.note { margin: 8px 0 0; font-size: .9rem; color: var(--muted); }

/* Selector de periodo / filtros */
.seg { display: flex; gap: 6px; padding: 4px; background: #e6eaf0; border-radius: 14px; }
.seg button {
  flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent;
  font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--navy); box-shadow: 0 1px 3px rgba(0,33,76,.15); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  min-height: 44px; padding: 8px 14px; border: 1px solid #c5cdd9; border-radius: 999px;
  background: var(--card); font-weight: 600; cursor: pointer;
}
.chips button[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }

/* Ventas */
.kpi { margin-top: 12px; }
.kpi-label { margin: 0; color: var(--muted); font-weight: 600; }
.kpi-value { margin: 2px 0 0; font-size: 2.4rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.delta { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; padding: 4px 10px; border-radius: 999px; font-weight: 700; font-size: .95rem; }
.delta svg { width: 16px; height: 16px; }
.delta.up { background: var(--ok-soft); color: var(--ok); }
.delta.down { background: var(--bad-soft); color: var(--bad); }
.delta.flat { background: var(--info-soft); color: var(--navy); }
.delta-note { display: block; margin-top: 4px; color: var(--muted); font-size: .9rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.stats p { margin: 0; }
.stats .s-label { color: var(--muted); font-size: .9rem; }
.stats .s-value { font-weight: 800; font-size: 1.3rem; font-variant-numeric: tabular-nums; }

.chart { margin-top: 16px; }
.chart svg { display: block; width: 100%; height: 120px; }
.chart .bar { fill: var(--orange); }
.chart .bar.prev { fill: #d7dde6; }
.chart-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; margin-top: 4px; }

/* Bloques de pedidos por atender */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.tile {
  display: grid; gap: 2px; min-height: 92px; padding: 14px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.tile b { font-size: 1.8rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-weight: 600; }
.tile.hot { border-color: var(--orange); background: var(--orange-soft); }

/* Listas */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row {
  display: flex; gap: 12px; align-items: center; width: 100%;
  padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; text-align: left;
}
button.row { cursor: pointer; }
/* Con letra grande, el importe baja solo debajo del texto: sin cortes fijos */
.row { flex-wrap: wrap; }
.row-main { flex: 1 1 8em; min-width: 0; }
.row-title { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.row-sub { margin: 2px 0 0; color: var(--muted); font-size: .92rem; }
.row-side { flex: none; margin-left: auto; text-align: right; display: grid; gap: 4px; justify-items: end; }
.row-amount { font-weight: 800; font-variant-numeric: tabular-nums; }
.rank { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--info-soft); font-weight: 800; }


.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 700; white-space: nowrap; }
.pill.processing { background: var(--info-soft); color: var(--navy); }
.pill.on-hold, .pill.pending { background: var(--warn-soft); color: var(--warn); }
.pill.completed { background: var(--ok-soft); color: var(--ok); }
.pill.failed, .pill.cancelled, .pill.refunded { background: var(--bad-soft); color: var(--bad); }
.pill.pickup { background: var(--orange-soft); color: var(--navy); }

.empty { padding: 24px 16px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed #c5cdd9; border-radius: 14px; }

/* Avisos */
.alert { display: flex; gap: 12px; align-items: flex-start; }
.alert-icon { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; }
.alert-icon svg { width: 22px; height: 22px; }
.alert.bad .alert-icon { background: var(--bad-soft); color: var(--bad); }
.alert.warn .alert-icon { background: var(--warn-soft); color: var(--warn); }
.alert.ok .alert-icon { background: var(--ok-soft); color: var(--ok); }
.alert.info .alert-icon { background: var(--info-soft); color: var(--navy); }

/* Barra inferior */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  min-height: var(--tabs-h); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; display: grid; justify-items: center; align-content: center; gap: 2px;
  padding: 8px 2px; color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 600;
}
.tabs a svg { width: 26px; height: 26px; }
.tabs a[aria-current="page"] { color: var(--navy); }
.tabs a[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--orange); }
.badge {
  position: absolute; top: 4px; left: calc(50% + 6px);
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--orange); color: var(--navy); font-size: .75rem; line-height: 20px; text-align: center;
}

/* Ficha de pedido */
.sheet {
  width: min(100% - 24px, 520px); max-height: calc(100% - 48px);
  border: 0; border-radius: 20px; padding: 20px 16px 16px; color: var(--ink);
}
.sheet::backdrop { background: rgba(0, 21, 50, .55); }
.sheet h2 { font-size: 1.3rem; }
.sheet dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 14px 0; }
.sheet dt { color: var(--muted); }
.sheet dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.sheet .items { margin: 0 0 16px; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.sheet .items li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.sheet .items li span:last-child { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.sheet .total { display: flex; justify-content: space-between; font-size: 1.15rem; font-weight: 800; margin-bottom: 16px; }
