:root {
  --bg: #faf6ef; --panel: #ffffff; --ink: #221b16; --muted: #756a5f; --line: #eadfd0; --hover: #f6efe3;
  --acc: #d4472a; --acc-ink: #ffffff; --gold: #d99a14;
  --ok: #2f7d4f; --warn: #a96a0a; --bad: #b3372a; --info: #3a6ea5;
  --radio: 10px; --sombra: 0 1px 2px rgb(60 40 20 / 6%), 0 4px 14px rgb(60 40 20 / 5%);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px; line-height: 1.45; color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="claro"]) {
    --bg: #161210; --panel: #211b17; --ink: #f3ebe0; --muted: #a79a8c; --line: #382c22; --hover: #2a221c;
    --acc: #ee6847; --acc-ink: #1a0f0b; --gold: #f0b43a; --ok: #5cc088; --warn: #e8b04a; --bad: #f0806f; --info: #7fb0e6;
    --sombra: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
h1 { font-size: 1.55rem; margin: 0 0 .15rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .7rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
p { margin: 0 0 .6rem; }
a { color: var(--acc); }
.muted { color: var(--muted); }
.peq { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--acc) 55%, transparent); outline-offset: 2px; border-radius: 6px; }

/* Estructura */
.marco { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.lateral { background: var(--panel); border-right: 1px solid var(--line); padding: 1.1rem .8rem; display: flex; flex-direction: column; gap: 1.2rem; position: sticky; top: 0; height: 100vh; }
.marca { display: flex; align-items: center; gap: .6rem; padding: 0 .4rem; font-weight: 700; font-size: 1.1rem; }
.marca img { width: 30px; height: 30px; }
.menu { display: flex; flex-direction: column; gap: 2px; }
.menu a { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: 8px; color: var(--ink); text-decoration: none; }
.menu a:hover { background: var(--hover); }
.menu a[aria-current="page"] { background: color-mix(in srgb, var(--acc) 13%, transparent); color: var(--acc); font-weight: 600; }
.menu .sep { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .9rem .7rem .2rem; }
.yo { margin-top: auto; padding: .6rem .7rem; border-top: 1px solid var(--line); font-size: .88rem; }
.principal { padding: 1.6rem clamp(1rem, 3vw, 2.4rem) 3rem; max-width: 1240px; width: 100%; }
.cabeza { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: .8rem; margin-bottom: 1.1rem; }
.cabeza p { margin: 0; color: var(--muted); }

/* Tarjetas y tablas */
.tarjeta { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio); box-shadow: var(--sombra); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.tarjeta.sin-pad { padding: 0; overflow: hidden; }
.enc-tarjeta { padding: 1rem 1.2rem .5rem; }
.enc-tarjeta h2 { margin-bottom: .3rem; }
.rejilla { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.rejilla .tarjeta { margin: 0; }
.tabla-caja { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .62rem .85rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; white-space: nowrap; background: color-mix(in srgb, var(--hover) 60%, transparent); }
th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
tbody tr.clic { cursor: pointer; }
tbody tr.clic:hover { background: var(--hover); }
td .nombre { font-weight: 600; color: var(--ink); text-decoration: none; }
td .nombre:hover { text-decoration: underline; }
.vacio { padding: 2rem 1rem; text-align: center; color: var(--muted); }

/* Controles */
.barra { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; align-items: center; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="search"], input[type="password"], select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; min-height: 40px;
}
input[type="search"] { flex: 1 1 240px; max-width: 360px; }
textarea { width: 100%; min-height: 110px; resize: vertical; }
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
.campo { margin-bottom: .9rem; }
.campo input, .campo select { width: 100%; }
.btn { display: inline-flex; align-items: center; gap: .4rem; background: var(--acc); color: var(--acc-ink); border: 0; border-radius: 8px; padding: .5rem .95rem; min-height: 40px; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(1.07); }
.btn.sec { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.sec:hover { background: var(--hover); }
.btn.peligro { background: var(--bad); color: #fff; }
.btn.peq { min-height: 32px; padding: .25rem .65rem; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: wait; }
.check { display: inline-flex; align-items: center; gap: .45rem; font-weight: 500; margin: 0; cursor: pointer; }
.paginas { display: flex; gap: .6rem; align-items: center; justify-content: flex-end; padding: .7rem .85rem; border-top: 1px solid var(--line); }

/* Etiquetas y estados */
.chip { display: inline-block; padding: .12rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: color-mix(in srgb, var(--c, var(--muted)) 15%, transparent); color: var(--c, var(--muted)); white-space: nowrap; }
.chip.activo, .chip.entregado, .chip.si { --c: var(--ok); }
.chip.nuevo, .chip.recibido, .chip.preparando, .chip.listo { --c: var(--info); }
.chip.dormido, .chip.en_camino, .chip.pendiente { --c: var(--warn); }
.chip.perdido, .chip.bloqueado, .chip.cancelado, .chip.no { --c: var(--bad); }
.chip.etiqueta { --c: var(--ink); background: var(--hover); border: 1px solid var(--line); }
.chip button { all: unset; cursor: pointer; margin-left: .35rem; opacity: .6; }
.chip button:hover { opacity: 1; }
.lista-chips { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }

/* Ficha */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio); padding: .8rem 1rem; }
.stat .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
details.pedido { border-bottom: 1px solid var(--line); }
details.pedido:last-child { border-bottom: 0; }
details.pedido summary { display: grid; grid-template-columns: 5rem 1fr auto auto; gap: .8rem; align-items: center; padding: .7rem 1rem; cursor: pointer; list-style: none; }
details.pedido summary::-webkit-details-marker { display: none; }
details.pedido summary:hover { background: var(--hover); }
details.pedido .detalle { padding: .2rem 1rem 1rem 1rem; }
.items { list-style: none; padding: 0; margin: 0 0 .6rem; }
.items li { padding: .25rem 0; border-bottom: 1px dashed var(--line); }
.items li:last-child { border-bottom: 0; }
.msg { padding: .45rem .7rem; border-radius: 10px; margin: .3rem 0; max-width: 85%; background: var(--hover); }
.msg.cliente { background: color-mix(in srgb, var(--info) 13%, transparent); }
.msg.persona { background: color-mix(in srgb, var(--ok) 14%, transparent); margin-left: auto; }
.msg small { display: block; color: var(--muted); }
.linea { border-left: 2px solid var(--line); padding: 0 0 .7rem .9rem; margin-left: .3rem; position: relative; }
.linea::before { content: ""; position: absolute; left: -6px; top: .3rem; width: 10px; height: 10px; border-radius: 50%; background: var(--acc); }
.aviso-legal { border-left: 4px solid var(--gold); background: color-mix(in srgb, var(--gold) 12%, transparent); padding: .6rem .9rem; border-radius: 6px; margin-bottom: 1rem; font-size: .9rem; }

/* Gráficas sencillas */
.fila-barra { display: grid; grid-template-columns: minmax(80px, 38%) 1fr 3rem; gap: .6rem; align-items: center; padding: .22rem 0; font-size: .9rem; }
.fila-barra .nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pista { height: 10px; background: var(--hover); border-radius: 999px; overflow: hidden; }
.pista > span { display: block; height: 100%; width: calc(var(--p, 0) * 1%); background: var(--acc); border-radius: 999px; }
.columnas { display: flex; align-items: end; gap: 6px; height: 150px; padding-top: .5rem; }
.columnas .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: end; height: 100%; min-width: 0; font-size: .72rem; color: var(--muted); }
.columnas .col .barra-v { width: 100%; max-width: 34px; height: calc(var(--p, 0) * 1%); min-height: 2px; background: var(--acc); border-radius: 5px 5px 0 0; }
.columnas .col .valor { color: var(--ink); font-weight: 600; font-size: .78rem; }
.columnas .col .eti { margin-top: 4px; white-space: nowrap; }

/* Entrada */
.entrada { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.entrada .tarjeta { width: min(400px, 100%); padding: 1.8rem; }
.entrada .marca { padding: 0; margin-bottom: 1.2rem; font-size: 1.3rem; }
.error { color: var(--bad); font-size: .9rem; min-height: 1.3em; margin: .3rem 0; }

#avisos { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 10; }
.toast { background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; box-shadow: 0 6px 24px rgb(0 0 0 / 25%); max-width: 360px; }
.toast.mal { background: var(--bad); color: #fff; }

@media (max-width: 860px) {
  .marco { grid-template-columns: 1fr; }
  .lateral { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .4rem .8rem; padding: .6rem .8rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .menu { flex-direction: row; flex-wrap: wrap; }
  .menu .sep { display: none; }
  .yo { margin: 0 0 0 auto; border: 0; padding: 0; }
  details.pedido summary { grid-template-columns: 1fr auto; }
  .fila-barra { grid-template-columns: minmax(70px, 40%) 1fr 2.4rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .menu a, tbody tr { transition: background-color .12s, filter .12s; }
}
