:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1d2321;
  --muted: #66706c;
  --line: #e2ded5;
  --primary: #1f5f5b;
  --primary-ink: #ffffff;
  --primary-soft: #e3efed;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn-soft: #fff4d6;
  --ok: #1e7a3c;
  --ok-soft: #e2f3e6;
  --info: #1d5fa8;
  --info-soft: #e4eefa;
  --whatsapp: #1c9a52;
  --radius: 14px;
  --nav-height: 64px;
  --primary-shadow: rgb(31 95 91 / 0.35);
  --pressed: #f1efe9;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.has-nav { padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 16px); }

a { color: inherit; }

button, input, textarea, select { font: inherit; color: inherit; }

.page { max-width: 640px; margin: 0 auto; padding: 16px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: var(--primary-ink);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}

.topbar__title { font-weight: 700; text-decoration: none; font-size: 1.05rem; }

.nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.nav__inner {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  max-width: 640px;
  height: var(--nav-height);
  margin: 0 auto;
}

.nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.72rem;
  color: var(--muted);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.nav__item--active { color: var(--primary); font-weight: 600; }

.nav__item--primary.nav__item--active { font-weight: 700; }

.nav__item--primary .nav__icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-top: -20px;
  border-radius: 16px;
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: 0 4px 12px var(--primary-shadow);
}

.nav__item--primary:active .nav__icon { transform: scale(0.95); }

.h1 { font-size: 1.4rem; margin: 0; }
.h2 { font-size: 1.05rem; margin: 0 0 12px; }
.muted { color: var(--muted); }

.link { color: var(--primary); font-weight: 600; text-decoration: none; background: none; border: 0; padding: 0; cursor: pointer; }
.link--danger { color: var(--danger); font-weight: 500; font-size: 0.85rem; }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 16px;
}

.flash { margin: 0 0 16px; padding: 12px 14px; border-radius: var(--radius); }
.flash--notice { background: var(--ok-soft); color: var(--ok); }
.flash--alert { background: var(--danger-soft); color: var(--danger); }

.search { margin-bottom: 12px; }

.search input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 1rem;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 -16px 16px;
  padding: 0 16px 4px;
  scrollbar-width: none;
}

.tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

.tab--active { background: var(--ink); border-color: var(--ink); color: #fff; }
.tab__count { font-weight: 700; }
.tab--alert:not(.tab--active) { border-color: var(--danger); color: var(--danger); }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.card {
  display: block;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  text-decoration: none;
}

.card--late { border-left: 4px solid var(--danger); }
.card__row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card__number { font-weight: 700; font-variant-numeric: tabular-nums; }
.card__customer { font-weight: 600; margin-top: 4px; }
.card__description { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card__meta { margin-top: 6px; font-size: 0.9rem; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--line);
}

.badge--recibido { background: var(--warn-soft); color: #7a5a00; }
.badge--en_proceso { background: var(--info-soft); color: var(--info); }
.badge--listo { background: var(--ok-soft); color: var(--ok); }
.badge--entregado { background: #ecebe7; color: var(--muted); }

.due { color: var(--muted); }
.due--late { color: var(--danger); font-weight: 600; }
.balance { font-weight: 600; }

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

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.callout {
  display: grid;
  gap: 10px;
  padding: 14px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  background: var(--primary-soft);
}

.callout p { margin: 0; }
.callout--ready { background: var(--ok-soft); }

.customer-line__name { display: block; font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.customer-line .muted { text-decoration: none; }
.description { font-size: 1.05rem; margin: 12px 0; white-space: pre-line; }
.notes { background: var(--bg); border-radius: 10px; padding: 10px 12px; white-space: pre-line; }

.facts, .money, .stats { display: grid; gap: 8px; margin: 0 0 12px; }
.facts div, .money div, .stats div { display: flex; justify-content: space-between; gap: 12px; }
.facts dt, .money dt, .stats dt { color: var(--muted); }
.facts dd, .money dd, .stats dd { margin: 0; text-align: right; font-weight: 500; }
.money dd, .stats dd { font-variant-numeric: tabular-nums; }
.money__balance { border-top: 1px solid var(--line); padding-top: 8px; }
.money__balance dt, .money__balance dd { font-weight: 700; color: var(--ink); font-size: 1.1rem; }

.steps { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 0; margin: 0 0 14px; }

.steps__item {
  padding-top: 8px;
  border-top: 4px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.steps__item--done { border-color: var(--primary); color: var(--ink); font-weight: 600; }

.payments, .log { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; font-size: 0.9rem; }
.payments li { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; }
.payments__amount { font-weight: 600; font-variant-numeric: tabular-nums; }

.payment-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.payment-form .chip { grid-column: 1 / -1; justify-self: start; }

.stack { display: grid; gap: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; }

.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field__hint { margin: 0; color: var(--muted); font-size: 0.85rem; }
.field__error { margin: 0; color: var(--danger); font-size: 0.85rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="date"], input[type="number"], textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1rem;
  min-height: 48px;
}

.field_with_errors { display: contents; }
.field_with_errors input, .field_with_errors textarea { border-color: var(--danger); }

input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.85rem;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn--block { width: 100%; }
.btn--primary { background: var(--primary); color: var(--primary-ink); }
.btn--secondary { background: var(--primary-soft); color: var(--primary); }
.btn--ghost { background: transparent; color: var(--muted); border-color: var(--line); margin-top: 8px; }
.btn--whatsapp { background: var(--whatsapp); color: #fff; }
.btn--danger-outline { background: transparent; color: var(--danger); border-color: var(--danger); margin-top: 24px; }

form.button_to { margin: 0; }

.login { max-width: 380px; margin: 12vh auto 0; display: grid; gap: 12px; }
.login__title { margin: 0; color: var(--primary); }

.page > .h1 { margin: 4px 0 16px; }
.stack > p, .stack > .h2 { margin: 0; }

.icon { flex: none; }
.cards > li, .card, .card__row > * { min-width: 0; }
.card__row .badge { flex: none; }
.badge { white-space: nowrap; }

.topbar { padding-inline: max(16px, calc((100% - 640px) / 2 + 16px)); }

.btn, .card, .tab, .chip { -webkit-tap-highlight-color: transparent; transition: transform 0.06s ease, filter 0.06s ease; }
.btn:active, .chip:active { transform: scale(0.98); filter: brightness(0.95); }
.card:active { background: var(--pressed); }
.btn[disabled], .btn[aria-busy="true"] { opacity: 0.6; pointer-events: none; }
.turbo-progress-bar { background: var(--primary); height: 3px; }

.link--danger { display: inline-flex; align-items: center; min-height: 40px; padding: 0 4px; }

.money-input { position: relative; }
.money-input::before { content: "$"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.money-input input { padding-left: 26px; }

select { height: 48px; }

.phone-link { display: inline-flex; align-items: center; gap: 6px; color: var(--primary); font-weight: 600; text-decoration: none; min-height: 40px; }

.login__brand { display: flex; align-items: center; gap: 12px; }
.login__brand img { border-radius: 14px; }
