:root {
  --cream: #f3ead8;
  --paper: #faf6ee;
  --ink: #1c1915;
  --pine: #1b3d32;
  --sage: #3d6b54;
  --butter: #d4a017;
  --brick: #9a3b2f;
  --muted: #6b6459;
  --line: rgba(27, 61, 50, .1);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  background: var(--cream);
  color: var(--ink);
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

h1,
h2,
.font-display {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
}

a {
  color: var(--pine);
  font-weight: 700;
  text-decoration: none;
  touch-action: manipulation;
}

button,
.button {
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--sage);
  color: var(--cream);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: .55rem 1rem;
  touch-action: manipulation;
  user-select: none;
}

button:hover,
.button:hover {
  filter: brightness(.96);
}

.tap-active {
  transform: scale(.985);
}

body.is-navigating {
  cursor: progress;
}

body.is-navigating::after {
  background: var(--pine);
  border-radius: 999px;
  color: var(--cream);
  content: attr(data-loading-label);
  font-weight: 800;
  left: 50%;
  min-width: 8rem;
  padding: .7rem 1rem;
  position: fixed;
  text-align: center;
  top: .85rem;
  transform: translateX(-50%);
  z-index: 1000;
  box-shadow: 0 10px 24px rgba(28, 25, 21, .18);
}

button.primary,
.primary {
  background: var(--pine);
  color: var(--cream);
}

button.ghost {
  background: transparent;
  border: 1px solid rgba(27, 61, 50, .18);
  color: var(--pine);
}

.yellow {
  background: rgba(212, 160, 23, .25);
  color: #6d4c00;
}

.danger {
  background: var(--brick);
  color: #fff;
}

.big {
  width: 100%;
  min-height: 52px;
}

.update-strip {
  background: var(--paper);
  color: var(--muted);
  font-size: .82rem;
  padding: .65rem .55rem .35rem;
}

.alert-action {
  border: 0;
  cursor: pointer;
  display: block;
  font: inherit;
  min-height: 44px;
  margin: 0 .55rem .75rem;
  border-radius: 14px;
  background: var(--sage);
  color: #fff7c9;
  font-weight: 700;
  padding: .8rem 1rem;
  text-align: center;
  width: calc(100% - 1.1rem);
}

.alert-action.active {
  background: var(--pine);
}

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--paper);
  border-bottom: 1px solid rgba(27, 61, 50, .08);
  padding: 1.05rem .85rem 1.1rem;
}

.brand {
  min-width: 230px;
}

.eyebrow {
  color: var(--sage);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .25em;
  text-transform: uppercase;
}

.topbar h1 {
  color: var(--pine);
  font-size: clamp(1.65rem, 2.2vw, 2rem);
  line-height: 1.08;
  margin: .12rem 0 .15rem;
}

.topbar p {
  color: var(--muted);
  margin: 0;
}

.topnav {
  display: flex;
  align-items: center;
  gap: .35rem;
  background: rgba(243, 234, 216, .72);
  border-radius: 12px;
  padding: .25rem;
}

.topnav a {
  border-radius: 8px;
  color: var(--pine);
  font-size: .9rem;
  padding: .65rem .95rem;
}

.topnav a.active {
  background: var(--pine);
  color: var(--cream);
}

.topnav form {
  margin: 0 0 0 .25rem;
}

.topnav .ghost {
  background: var(--paper);
  min-height: 40px;
}

.page {
  width: min(1114px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.55rem 0 2.2rem;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(28, 25, 21, .06);
  margin-bottom: 1rem;
  padding: 1.05rem 1.25rem;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: .75rem;
  margin-bottom: 1.45rem;
}

.kpi {
  min-height: 88px;
  min-width: 0;
  overflow: hidden;
}

.kpi span {
  color: var(--muted);
  display: block;
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.kpi strong {
  color: var(--pine);
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.55rem, 2.2vw, 2.05rem);
  font-weight: 500;
  line-height: 1;
  margin-top: .4rem;
  overflow-wrap: anywhere;
}

.kpi small {
  display: block;
  font-size: .78rem;
  margin-top: .35rem;
}

.upload-card {
  border-style: dashed;
  box-shadow: none;
  margin: 0 auto 1.45rem;
  max-width: 100%;
  padding: 1.35rem;
}

.upload-card h2,
.section-head h2 {
  color: var(--pine);
  font-size: 1.45rem;
  margin: 0 0 .3rem;
}

.upload-form {
  display: grid;
  grid-template-columns: max-content minmax(180px, 1fr) max-content;
  align-items: center;
  gap: .7rem;
  max-width: 560px;
  margin-top: 1rem;
}

.file-picker input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-picker span,
.file-name {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: 12px;
}

.file-picker span {
  background: var(--pine);
  color: var(--cream);
  cursor: pointer;
  font-weight: 700;
  padding: 0 1rem;
  white-space: nowrap;
}

.file-name {
  min-width: 0;
  border: 1px solid rgba(27, 61, 50, .18);
  background: #fff;
  color: var(--muted);
  overflow: hidden;
  padding: 0 .9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-head {
  align-items: end;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin: 0 0 .75rem;
}

.section-head form {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  justify-content: flex-end;
  max-width: 100%;
}

.section-head input[name="q"] {
  width: 360px;
}

.section-head select {
  width: 160px;
}

.section-head select[name="area"] {
  width: 180px;
}

.section-head select[name="per_page"] {
  width: 145px;
}

.inline,
.actions {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.picking-form > .actions {
  align-items: stretch;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(28, 25, 21, .06);
  display: grid;
  gap: .65rem;
  grid-template-columns: 1fr 1.2fr 1fr;
  padding: .75rem;
  position: sticky;
  bottom: .75rem;
  z-index: 5;
}

.action-button {
  min-height: 46px;
  width: 100%;
}

.action-complete {
  background: var(--sage);
}

.filters-grid {
  align-items: end;
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) max-content;
  gap: .75rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.25fr .9fr;
  gap: 1rem;
  margin: 1rem 0;
}

.chart-card { min-width: 0; }
.chart-heading { align-items: center; display: flex; justify-content: space-between; gap: 1rem; }
.chart-heading h2 { margin: .2rem 0 0; }
.chart-total { color: var(--muted); font-weight: 800; }
.status-chart, .area-chart { display: grid; gap: .85rem; margin-top: 1.25rem; }
.status-row { align-items: center; display: grid; grid-template-columns: 7rem 1fr 2rem; gap: .65rem; }
.status-row span, .status-row strong { font-size: .85rem; }
.status-row strong { text-align: right; }
.bar-track { background: rgba(27,61,50,.1); border-radius: 999px; height: .65rem; overflow: hidden; }
.bar-track i { border-radius: inherit; display: block; height: 100%; min-width: .25rem; }
.bar-revision { background: #9aa0a6; }.bar-por_pickear { background: #6f7b84; }.bar-preparando { background: var(--butter); }.bar-por_facturar { background: #8c6f3c; }.bar-facturada { background: var(--sage); }
.area-row { align-items: center; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; padding: .7rem 0; }
.area-label { align-items: center; display: flex; gap: .5rem; }.area-label small { color: var(--muted); margin-left: .4rem; }.area-value { font-family: Georgia, serif; font-size: 1.15rem; }
.dot { border-radius: 50%; display: inline-block; height: .75rem; width: .75rem; }.dot-butter { background: var(--butter); }.dot-sage { background: var(--sage); }
.trend-card { margin-bottom: 1rem; }.trend-chart { align-items: end; display: flex; gap: .65rem; min-height: 12rem; overflow-x: auto; padding: 1.5rem .5rem .2rem; }
.trend-item { align-items: center; display: flex; flex: 1 0 3.5rem; flex-direction: column; height: 10rem; justify-content: end; min-width: 3.5rem; }.trend-item strong { color: var(--pine); }.trend-item i { background: linear-gradient(180deg, var(--sage), var(--pine)); border-radius: 8px 8px 2px 2px; display: block; margin: .35rem 0; min-height: .4rem; width: 1.8rem; }.trend-item span { color: var(--muted); font-size: .72rem; max-width: 5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(27, 61, 50, .2);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  min-height: 40px;
  padding: .55rem .75rem;
}

input[type="checkbox"] {
  min-height: auto;
  accent-color: var(--pine);
}

label {
  color: var(--pine);
  display: grid;
  font-weight: 700;
  gap: .35rem;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wide {
  grid-column: 1 / -1;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

.orders-section {
  margin-top: 1.45rem;
}

.table-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.list-meta {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: .9rem;
  justify-content: space-between;
  margin: 0 0 .6rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: .25rem;
}

.table-wrap table {
  min-width: 980px;
}

#lines {
  table-layout: fixed;
}

#lines th:nth-child(1),
#lines td:nth-child(1) {
  width: 260px;
}

#lines th:nth-child(2),
#lines td:nth-child(2) {
  width: 180px;
}

#lines th:nth-child(3),
#lines td:nth-child(3),
#lines th:nth-child(5),
#lines td:nth-child(5) {
  width: 110px;
}

#lines th:nth-child(4),
#lines td:nth-child(4),
#lines th:nth-child(6),
#lines td:nth-child(6) {
  width: 150px;
}

#lines th:nth-child(7),
#lines td:nth-child(7) {
  width: 105px;
}

#lines input {
  min-width: 0;
}

#lines td:nth-child(1) input {
  text-overflow: ellipsis;
}

#lines td:last-child {
  text-align: right;
}

thead {
  background: rgba(243, 234, 216, .8);
}

th {
  color: var(--muted);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-align: left;
  text-transform: uppercase;
}

.sort-link {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  gap: .35rem;
  min-height: 34px;
  padding: .15rem 0;
}

.sort-link.active,
.sort-link:hover {
  color: var(--pine);
}

.sort-link span {
  color: var(--sage);
  font-size: .9rem;
  line-height: 1;
}

td,
th {
  border-top: 1px solid var(--line);
  padding: .8rem 1rem;
  vertical-align: middle;
}

tbody tr:hover {
  background: rgba(243, 234, 216, .5);
}

td:nth-child(3) {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  align-items: center;
  border-radius: 999px;
  display: inline-flex;
  font-size: .72rem;
  font-weight: 800;
  margin: .1rem .18rem .1rem 0;
  min-height: 24px;
  padding: .22rem .62rem;
  background: rgba(27, 61, 50, .1);
  color: var(--pine);
}

.badge.area {
  background: rgba(212, 160, 23, .25);
  color: #6d4c00;
}

.badge.warn,
.flash.error {
  background: rgba(154, 59, 47, .12);
  color: var(--brick);
}

.flash {
  border-radius: 8px;
  font-weight: 800;
  margin-bottom: .85rem;
  padding: .8rem 1rem;
}

.flash.ok {
  background: rgba(61, 107, 84, .12);
  color: var(--pine);
}

.notice {
  display: block;
  background: rgba(154, 59, 47, .06);
  border: 1px solid rgba(154, 59, 47, .25);
  border-radius: 16px;
  margin-bottom: 1rem;
  padding: 1rem 1.25rem;
}

.muted,
small {
  color: var(--muted);
}

.empty {
  color: var(--muted);
  padding: 2.5rem;
  text-align: center;
}

.pagination {
  align-items: center;
  display: flex;
  gap: .75rem;
  justify-content: space-between;
  margin-top: .9rem;
}

.pagination .disabled {
  opacity: .45;
  pointer-events: none;
}

.page-pills {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  justify-content: center;
}

.page-pills a,
.page-pills span {
  align-items: center;
  border-radius: 10px;
  display: inline-flex;
  min-height: 38px;
  min-width: 38px;
  justify-content: center;
  padding: .4rem .55rem;
}

.page-pills a {
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(27, 61, 50, .15) inset;
}

.page-pills a.active {
  background: var(--pine);
  color: var(--cream);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .5rem;
  margin: 0 auto 1rem;
  max-width: 36rem;
}

.tabs a {
  background: var(--paper);
  border-radius: 12px;
  color: var(--pine);
  padding: .75rem .7rem;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(27, 61, 50, .15) inset;
}

.tabs a.active {
  background: var(--pine);
  color: var(--cream);
}

.tabs strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 500;
}

.mobile-list {
  display: grid;
  gap: .75rem;
  margin: 0 auto;
  max-width: 36rem;
}

.dispatch-panel {
  margin: 0 auto;
  max-width: 36rem;
  position: relative;
}

.dispatch-panel.htmx-request {
  opacity: .62;
  pointer-events: none;
}

.dispatch-panel.htmx-request::after {
  background: var(--pine);
  border-radius: 999px;
  color: var(--cream);
  content: "Cargando...";
  font-weight: 800;
  left: 50%;
  padding: .55rem 1rem;
  position: fixed;
  top: 1rem;
  transform: translateX(-50%);
  z-index: 20;
}

.dispatch-toolbar {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: .9rem;
  justify-content: space-between;
  margin: 0 0 .75rem;
}

.dispatch-toolbar form {
  align-items: end;
  display: flex;
  gap: .65rem;
  margin: 0;
}

.dispatch-toolbar select {
  min-height: 38px;
  width: 145px;
}

.sort-select {
  color: var(--muted);
  display: grid;
  font-size: .75rem;
  font-weight: 800;
  gap: .2rem;
  text-transform: uppercase;
}

.dispatch-pagination {
  margin-left: auto;
  margin-right: auto;
  max-width: 36rem;
}

.page-current {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 40px;
}

.pick-card {
  display: block;
  padding: 1.25rem;
  transition: transform .08s ease, background .08s ease, box-shadow .08s ease;
  will-change: transform;
}

.pick-card.status-por_pickear {
  border-left: 6px solid #9aa0a6;
}

.pick-card.status-preparando {
  border-left: 6px solid #d7a51d;
  background: #fff8dc;
}

.pick-card.status-por_facturar,
.pick-card.status-facturada {
  border-left: 6px solid #3d7b5e;
}

.pick-card.is-overdue {
  border-left-color: var(--brick);
  background: #fff0ed;
}

.overdue-label {
  color: var(--brick) !important;
  font-weight: 800;
}

.is-overdue-row td {
  background: #fff0ed;
}

.is-overdue-row td:first-child {
  border-left: 5px solid var(--brick);
}

.pick-card:active,
.pick-card.tap-active {
  background: #fffaf0;
  box-shadow: 0 0 0 2px rgba(27, 61, 50, .18), 0 4px 12px rgba(28, 25, 21, .08);
}

.pick-card span {
  color: var(--sage);
  display: block;
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.pick-requested {
  color: var(--muted);
  font-size: 1.1rem;
  margin: .35rem 0 1rem;
}

.pick-requested strong {
  color: var(--pine);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
  font-weight: 500;
}

.pick-requested small { font-size: .85rem; }

.pick-inputs {
  display: grid;
  gap: .75rem;
  grid-template-columns: 1fr 1fr;
}

.pick-inputs label { gap: .25rem; }

.pick-meta {
  border-top: 1px solid var(--line);
  display: grid !important;
  gap: .75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: .35rem;
  padding-top: .65rem;
}

.pick-meta span {
  display: grid !important;
  gap: .12rem;
}

.pick-meta b {
  color: var(--muted);
  font-size: .68rem;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.pick-meta strong {
  color: var(--pine);
  font-size: .95rem;
}

.pick-card strong {
  color: var(--pine);
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  font-weight: 500;
  margin-top: .15rem;
}

.pick-card em {
  float: right;
  border-radius: 999px;
  background: rgba(212, 160, 23, .25);
  color: #6d4c00;
  font-size: .72rem;
  font-style: normal;
  font-weight: 800;
  padding: .22rem .62rem;
}

.login {
  min-height: 78vh;
  display: grid;
  place-content: center;
}

.login h1 {
  color: var(--pine);
  font-size: 2rem;
  margin: 0 0 1rem;
  text-align: center;
}

.login form {
  width: min(390px, 92vw);
}

.form {
  display: grid;
  gap: 1rem;
}

dl.grid {
  margin: 0 0 1rem;
}

dt {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: .15rem 0 0;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topnav {
    justify-content: flex-start;
    overflow-x: auto;
    width: 100%;
  }

  .page {
    width: min(100% - 1rem, 1114px);
    padding-top: 1rem;
  }

  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid { grid-template-columns: 1fr; }
  .status-row { grid-template-columns: 6.5rem 1fr 1.5rem; }
  .trend-chart { margin-inline: -.4rem; }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .section-head form,
  .inline,
  .filters-grid {
    display: grid;
    justify-content: stretch;
  }

  .section-head input[name="q"],
  .section-head select,
  .section-head select[name="area"],
  .section-head select[name="per_page"],
  .upload-form {
    width: 100%;
  }

  .list-meta,
  .dispatch-toolbar,
  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .dispatch-toolbar select {
    width: 100%;
  }

  .dispatch-toolbar form { align-items: stretch; display: grid; width: 100%; }

  .picking-form > .actions { grid-template-columns: 1fr; position: static; }

  .pagination .button {
    text-align: center;
    width: 100%;
  }

  .upload-form {
    grid-template-columns: 1fr;
    max-width: none;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 720px;
  }
}
