/* Covi Juande — paleta Coviran: dos verdes y el rojo del logo.
   Verde clásico #409048 (wordmark del logo), verde bosque #1f4e2b (textos) y el
   verde vivo #48b463 solo dentro del gradiente oficial del re-styling web.
   Rojo #d0281f: el punto de la "i" del logo. Blanco de fondo.
   Tipografía oficial: "Averta PE" (licenciada) — usamos su misma pila de fallbacks. */

:root {
  --verde: #409048;
  --verde-osc: #33753a;
  --bosque: #1f4e2b;
  --rojo: #d0281f;
  --grad-marca: linear-gradient(to right, #1f4e2b 0%, #1f4e2b 50%, #48b463 100%);
  --tinta: #212529;
  --gris: #6c757d;
  --borde: #e3e8e1;
  --crema: #f6f8f4;
  --blanco: #ffffff;
  --radio: 12px;
  --sombra: 0 2px 10px rgba(31, 78, 43, 0.08);
  --sans: "Averta PE", "Averta", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--tinta);
  background: var(--crema);
  -webkit-font-smoothing: antialiased;
}

.brandbar { height: 5px; background: var(--grad-marca); }

.top {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.4rem 1.4rem; flex-wrap: wrap;
  padding: 0.7rem 1rem; background: var(--blanco);
  border-bottom: 1px solid var(--borde);
  position: sticky; top: 0; z-index: 10;
}
.brand, .login-brand {
  font-size: 1.35rem; font-weight: 800; text-decoration: none; color: var(--bosque);
  letter-spacing: -0.02em;
}
.brand span, .login-brand span { color: var(--verde); }
.dot {
  display: inline-block; width: 0.45em; height: 0.45em; border-radius: 50%;
  background: var(--rojo); margin-left: 0.22em; vertical-align: middle;
}
.top nav { display: flex; gap: 0.9rem; align-items: center; }
.top nav a { color: var(--verde-osc); text-decoration: none; font-weight: 600; }
.top nav a:hover { color: var(--bosque); }
.linkbtn { background: none; border: none; color: var(--rojo); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }

.wrap { max-width: 680px; margin: 0 auto; padding: 1rem 1rem 3rem; }
.foot { text-align: center; color: var(--gris); font-size: 0.8rem; padding: 1rem; }

h1 { font-size: 1.5rem; margin: 0.6rem 0 0.2rem; color: var(--bosque); letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; margin: 0 0 0.7rem; color: var(--bosque); }
h2.section { margin-top: 1.6rem; }
.muted { color: var(--gris); font-size: 0.9rem; }
.center { text-align: center; }
.back { color: var(--verde-osc); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.page-head { display: flex; align-items: center; gap: 0.7rem; }

.card {
  background: var(--blanco); border: 1px solid var(--borde);
  border-radius: var(--radio); box-shadow: var(--sombra);
  padding: 1rem; margin: 0.9rem 0; display: block;
}

/* chips y badges */
.chip {
  display: inline-block; background: #e6f4ea; color: var(--verde-osc);
  border-radius: 999px; padding: 0.15rem 0.65rem; font-size: 0.78rem; font-weight: 700;
}
.chip.small { font-size: 0.7rem; }
.badge {
  display: inline-block; border-radius: 999px; padding: 0.18rem 0.7rem;
  font-size: 0.78rem; font-weight: 700;
}
.b-borrador { background: #eef1f5; color: var(--gris); }
.b-enviado { background: var(--rojo); color: var(--blanco); }
.b-despachado { background: var(--verde); color: var(--blanco); }
.b-edicion { background: #fdf1e3; color: #b35c00; }
.b-recibido { background: var(--bosque); color: var(--blanco); }
.b-pendiente { background: #e6f4ea; color: var(--verde-osc); }
.count {
  display: inline-block; min-width: 1.4em; text-align: center;
  background: var(--bosque); color: var(--blanco); border-radius: 999px;
  font-size: 0.78rem; padding: 0.1rem 0.4rem; margin-left: 0.3rem;
}
.obs { color: var(--rojo); font-weight: 700; font-size: 0.82rem; }

/* botones */
.btn {
  display: inline-block; border: none; cursor: pointer; text-decoration: none;
  font: inherit; font-weight: 700; border-radius: 999px;
  padding: 0.55rem 1.2rem; background: #e6f4ea; color: var(--verde-osc);
  transition: 0.2s;
}
.btn:hover { filter: brightness(0.96); }
.btn.primary { background: var(--verde); color: var(--blanco); }
.btn.primary:hover { background: var(--verde-osc); filter: none; }
.btn.primary:disabled { background: var(--borde); color: var(--gris); cursor: not-allowed; }
.btn.outline { background: var(--blanco); border: 2px solid var(--rojo); color: var(--rojo); }
.btn.big { width: 100%; padding: 0.85rem; font-size: 1.05rem; }

/* formularios */
input, select, textarea {
  font: inherit; width: 100%; padding: 0.6rem 0.7rem;
  border: 1.5px solid var(--borde); border-radius: 8px; background: var(--blanco);
}
/* Safari/iOS: el input de fecha tiene ancho intrínseco y se sale del contenedor */
input[type="date"] {
  -webkit-appearance: none; appearance: none;
  display: block; min-width: 0; max-width: 100%; min-height: 2.6rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--verde); border-color: var(--verde); }
label { display: block; font-weight: 600; font-size: 0.88rem; color: var(--bosque); }
label input, label select, label textarea { margin-top: 0.25rem; font-weight: 400; }
.stack > * + * { margin-top: 0.8rem; }
.row { display: flex; gap: 0.6rem; align-items: end; margin-top: 0.8rem; }
.row > * { flex: 1; }
.row .btn { flex: 0 0 auto; }
.check { display: flex; gap: 0.5rem; align-items: center; font-weight: 400; }
.check input { width: auto; }
.hidden { display: none; }
.inline { display: inline; }

/* login */
.login-card { max-width: 380px; margin: 3rem auto; text-align: left; padding: 1.6rem; }
.login-brand { display: block; text-align: center; font-size: 1.8rem; margin-bottom: 0.3rem; }
.alert {
  background: #fbecea; color: var(--rojo); border: 1px solid #f3c7c3;
  border-radius: 8px; padding: 0.6rem 0.8rem; margin: 0.8rem 0; font-weight: 600;
}
.alert.edicion { background: #fdf1e3; color: #b35c00; border-color: #f3ddc0; font-weight: 400; }
.toast {
  position: sticky; top: 4rem; z-index: 9;
  background: var(--bosque); color: var(--blanco);
  border-radius: 999px; padding: 0.6rem 1.1rem; margin: 0.5rem 0;
  font-weight: 600; box-shadow: var(--sombra); transition: opacity 0.6s;
}
.toast.bye { opacity: 0; }

/* panel tienda */
.supplier-head { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.supplier-head h2 { margin: 0.25rem 0 0; }
.supplier-row { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; flex-wrap: wrap; }

.orders { list-style: none; margin: 0.8rem 0 0; padding: 0; }
.orders.sep { border-top: 1px solid var(--borde); margin-top: 1rem; padding-top: 0.35rem; }
.row-actions { margin-left: auto; display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.row-actions form.inline { flex: 0 0 auto; }
.btn.mini {
  padding: 0.28rem 0.75rem; font-size: 0.8rem;
  flex-shrink: 0; white-space: nowrap; min-width: 5.6rem; text-align: center;
}
.btn.mini.danger { background: #fbecea; color: var(--rojo); }
ul.orders.card { padding: 0.4rem 1rem; }
.orders li + li { border-top: 1px solid var(--borde); }
.order-row {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  padding: 0.6rem 0; text-decoration: none; color: inherit;
}
.order-row:hover strong { color: var(--verde-osc); }
/* fila entera pulsable: enlace extendido bajo los botones de acción */
.order-row.tappable { position: relative; }
.row-link { position: absolute; inset: 0; z-index: 1; }
.order-row.tappable .row-actions { position: relative; z-index: 2; }
.msg-row .msg-snippet { flex: 1 1 100%; font-style: italic; }

/* editor de albarán */
.lines { list-style: none; margin: 0; padding: 0; }
.lines li {
  display: flex; justify-content: space-between; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0; border-bottom: 1px solid var(--borde);
}
.lines li:last-child { border-bottom: none; }
.line-desc { display: flex; flex-direction: column; }
.line-qty { display: flex; align-items: center; gap: 0.35rem; }
.qty {
  width: 6em; text-align: left; padding-left: 0.35em;
  font-weight: 700; color: var(--bosque);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.qty small { color: var(--gris); font-weight: 400; }
.qbtn {
  width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--borde);
  background: var(--blanco); font-size: 1.1rem; font-weight: 700; color: var(--verde-osc);
  cursor: pointer; line-height: 1;
}
.qbtn:hover { border-color: var(--verde); }
.qbtn.del { color: var(--rojo); }
.qbtn.del:hover { border-color: var(--rojo); }
.add-line select { margin-bottom: 0; }
.add-line input[name="note"] { margin-top: 0.8rem; }
.send { border-top: 4px solid var(--verde); }

/* detalle pedido */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem; }
.timeline li { display: flex; flex-direction: column; opacity: 0.45; position: relative; padding-left: 1.1rem; }
.timeline li::before {
  content: ''; position: absolute; left: 0; top: 0.35em;
  width: 0.6em; height: 0.6em; border-radius: 50%; background: var(--gris);
}
.timeline li.done { opacity: 1; }
.timeline li.done::before { background: var(--verde); }
.timeline li.next { opacity: 1; }
.timeline li.next::before { background: var(--rojo); }
.timeline span { font-weight: 700; font-size: 0.85rem; color: var(--bosque); }
.timeline small { color: var(--gris); }
.order-note { background: var(--crema); border-radius: 8px; padding: 0.6rem 0.8rem; margin: 0.9rem 0 0; }

.progress { height: 8px; background: var(--borde); border-radius: 999px; overflow: hidden; margin: 0.2rem 0 0.7rem; }
.progress-fill { height: 100%; background: var(--verde); border-radius: 999px; transition: width 0.3s; }

.lines-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.lines-table .chk { width: 34px; }
.ready-check { width: 22px; height: 22px; accent-color: var(--verde); cursor: pointer; }
.tick { color: var(--verde); font-weight: 700; }
.lines-table tr.done td { color: var(--gris); }
.qty-served { width: 4.6em; text-align: right; padding: 0.3rem 0.4rem; display: inline-block; font-weight: 700; }
.orig-qty { font-size: 0.75rem; color: #b35c00; font-weight: 700; white-space: nowrap; }
.lines-table tr.done td:nth-child(2) { text-decoration: line-through; text-decoration-color: var(--verde); }
.lines-table th { text-align: left; color: var(--gris); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 0.3rem 0.4rem; }
.lines-table td { padding: 0.5rem 0.4rem; border-top: 1px solid var(--borde); }
.lines-table .num { text-align: right; white-space: nowrap; }

/* observaciones */
.comments { list-style: none; margin: 0 0 0.8rem; padding: 0; }
.comments li { margin: 0.7rem 0; }
.comments .who { font-size: 0.8rem; font-weight: 700; color: var(--bosque); margin-bottom: 0.15rem; }
.comments .bubble {
  background: var(--crema); border-radius: 12px 12px 12px 4px;
  padding: 0.55rem 0.8rem; display: inline-block; max-width: 90%;
}
.comments li.mine .who { text-align: right; }
.comments li.mine { text-align: right; }
.comments li.mine .bubble { background: #e6f4ea; border-radius: 12px 12px 4px 12px; text-align: left; }

/* tarjetas proveedor */
.order-card { text-decoration: none; color: inherit; }
.order-card:hover { border-color: var(--verde); }
.order-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.3rem; }
.delivery { margin-top: 0.4rem; color: var(--bosque); }
.actions { text-align: center; }

/* enlaces de acceso y confirmación de envío */
.linkbox { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; margin-top: 0.5rem; }
.linkbox input { flex: 1 1 100%; font-size: 0.82rem; color: var(--gris); background: var(--crema); }
.linkbox.inline-row { flex-wrap: nowrap; }
.linkbox.inline-row input { flex: 1 1 auto; min-width: 0; }
.linkbox.inline-row .btn { flex: 0 0 auto; }
.sendok { text-align: center; }
.bigcheck {
  width: 64px; height: 64px; border-radius: 50%; margin: 0.4rem auto;
  background: var(--verde); color: var(--blanco);
  font-size: 2rem; line-height: 64px; font-weight: 700;
}
.pager { display: flex; gap: 0.6rem; justify-content: center; align-items: center; margin: 0.9rem 0; }
.del-sup { margin-top: 0.6rem; }
.small-note { font-size: 0.8rem; }
.wa-ok { color: var(--verde-osc); font-weight: 700; }
.tpl {
  background: var(--crema); border: 1px solid var(--borde); border-radius: 8px;
  padding: 0.7rem 0.9rem; font-size: 0.82rem; white-space: pre-wrap; overflow-x: auto;
}
.steps { padding-left: 1.2rem; }
.steps li { margin: 0.35rem 0; }
.msgbox {
  font-size: 0.88rem; background: var(--crema); color: var(--tinta);
  margin-bottom: 0.6rem; resize: vertical;
}

@media (max-width: 480px) {
  .row { flex-wrap: wrap; }
  .row > * { flex: 1 1 40%; }
  .row .btn { flex: 1 1 100%; }
  .supplier-head .btn { width: 100%; text-align: center; }
}
