:root {
  --color-bg: #f0f7fc;
  --color-surface: #ffffff;
  --color-primary: #0369a1;
  --color-primary-dark: #0c4a6e;
  --color-accent: #b45309;
  --color-success: #15803d;
  --color-danger: #b91c1c;
  --color-warn: #b45309;
  --color-text: #0f172a;
  --color-muted: #64748b;
  --color-line: #dbe7f0;
  --font-display: "Sora", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(12, 74, 110, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  color: var(--color-text);
  background:
    radial-gradient(1200px 500px at 10% -10%, #dbeafe 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #e0f2fe 0%, transparent 50%),
    var(--color-bg);
  min-height: 100vh;
}

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-line);
}
.brand {
  display: flex; align-items: center; gap: .75rem;
  text-decoration: none; color: inherit; min-width: 210px;
}
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #0284c7, #0c4a6e);
  color: #fff; font-size: 1.2rem;
}
.brand strong {
  display: block; font-family: var(--font-display); font-size: .95rem;
}
.brand small { color: var(--color-muted); font-size: .75rem; }
.topnav { display: flex; gap: .35rem; flex: 1; flex-wrap: wrap; }
.topnav a {
  text-decoration: none; color: var(--color-muted);
  padding: .45rem .85rem; border-radius: 999px; font-weight: 600; font-size: .9rem;
}
.topnav a.is-active, .topnav a:hover {
  background: #e0f2fe; color: var(--color-primary-dark);
}
.topbar-meta { display: flex; align-items: center; gap: .4rem; }
.user-chip {
  font-size: .85rem; color: var(--color-muted);
  background: #f8fafc; border: 1px solid var(--color-line);
  border-radius: 999px; padding: .35rem .7rem;
}
.btn-ghost {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 10px; color: var(--color-muted); text-decoration: none;
  border: 1px solid transparent;
}
.btn-ghost:hover { background: #f1f5f9; color: var(--color-text); }
.btn-portal {
  white-space: nowrap;
  padding: .45rem .75rem !important;
  font-size: .85rem !important;
}
@media (max-width: 720px) {
  .btn-portal span, .btn-portal { font-size: .8rem !important; }
  .topbar-meta .user-chip { display: none; }
}

.page { width: min(1180px, calc(100% - 2rem)); margin: 1.25rem auto 3rem; }
html:has(body.is-wide),
body.is-wide {
  height: 100%;
  min-height: 100%;
}
body.is-wide {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.is-wide .topbar {
  flex-wrap: nowrap;
  padding: .5rem .85rem;
}
body.is-wide .page.is-wide {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: .65rem .85rem .85rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}
body.is-wide .hero {
  margin-bottom: .65rem;
}
body.is-wide .hero h1 {
  font-size: 1.35rem;
}
body.is-wide .hero p {
  max-width: none;
}
body.is-wide .page-foot {
  padding: .4rem;
  flex-shrink: 0;
}
body.is-wide .page.is-wide {
  display: flex;
  flex-direction: column;
}
body.is-wide .panel {
  width: 100%;
}
body.is-wide .form-row {
  grid-template-columns: minmax(280px, 1fr) auto auto;
}
body.is-wide .form-grid-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
body.is-wide #panelLista {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body.is-wide #panelLista .table-wrap {
  flex: 1 1 auto;
  min-height: 42vh;
}
body.is-wide #panelLista table.data {
  width: 100%;
}
.field-desc-closet {
  max-width: 280px;
}
#descCloset {
  min-height: 70px;
  max-width: 280px;
  width: 100%;
}
body.is-wide #tbodyMuebles td:nth-child(6) {
  max-width: 200px;
  width: 160px;
  overflow-wrap: anywhere;
}
.bodega-grid {
  display: grid;
  gap: .85rem;
  align-items: start;
}
.bodega-grid .panel {
  margin-bottom: 0;
  min-width: 0;
}
.bodega-grid .table-wrap {
  max-height: none;
  overflow-x: auto;
}
body.is-wide table.data {
  font-size: .86rem;
}
body.is-wide table.data th,
body.is-wide table.data td {
  padding: .5rem .55rem;
  white-space: normal;
}
.acciones-fila {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
}
.viaje-stack {
  display: grid;
  gap: .45rem;
  min-width: 220px;
}
.viaje-mini {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .35rem .55rem;
  align-items: center;
  padding: .5rem .6rem;
  border: 1px solid var(--color-line);
  border-radius: 8px;
  background: #fff;
}
.viaje-mini-main strong {
  display: block;
  font-size: .88rem;
}
.viaje-mini-meta {
  color: var(--color-muted);
  font-size: .78rem;
}
.viaje-mini-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}
.viaje-mini-actions .btn {
  padding: .32rem .55rem;
  font-size: .78rem;
}
.ot-camion-list {
  display: grid;
  gap: .75rem;
}
.ot-camion-card {
  border: 1px solid var(--color-line);
  border-radius: 12px;
  background: #fff;
  padding: .85rem 1rem;
}
.ot-camion-card.is-sel {
  outline: 2px solid var(--color-primary);
}
.ot-camion-head {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: .65rem;
}
.ot-camion-head strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
  margin-right: .35rem;
}
.ot-camion-meta {
  margin-top: .25rem;
  color: var(--color-muted);
  font-size: .88rem;
}
.page-foot {
  text-align: center; color: #94a3b8; font-size: .8rem; padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
}

.hero {
  display: grid; gap: .35rem; margin-bottom: 1.25rem;
  animation: rise .45s ease both;
}
.hero h1 {
  margin: 0; font-family: var(--font-display); font-size: clamp(1.45rem, 2.4vw, 2rem);
  letter-spacing: -.02em;
}
.hero p { margin: 0; color: var(--color-muted); max-width: 60ch; }

.grid-cards {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem;
}
.action-card {
  background: var(--color-surface); border: 1px solid var(--color-line);
  border-radius: var(--radius); padding: 1.2rem; text-decoration: none;
  color: inherit; box-shadow: var(--shadow);
  transition: transform .2s ease, border-color .2s ease;
  animation: rise .5s ease both;
}
.action-card:nth-child(2) { animation-delay: .05s; }
.action-card:nth-child(3) { animation-delay: .1s; }
.action-card:hover { transform: translateY(-3px); border-color: #7dd3fc; }
.action-card .icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  background: #e0f2fe; color: var(--color-primary); font-size: 1.3rem; margin-bottom: .8rem;
}
.action-card h2 { margin: 0 0 .35rem; font-family: var(--font-display); font-size: 1.1rem; }
.action-card p { margin: 0; color: var(--color-muted); font-size: .92rem; }

.panel {
  background: var(--color-surface); border: 1px solid var(--color-line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem;
  margin-bottom: 1rem; animation: rise .4s ease both;
}
.panel h2, .panel h3 {
  margin: 0 0 .85rem; font-family: var(--font-display); font-size: 1.05rem;
}

.stats {
  display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .75rem; margin-bottom: 1rem;
}
.stat {
  background: var(--color-surface); border: 1px solid var(--color-line);
  border-radius: var(--radius); padding: .9rem 1rem;
}
.stat b { display: block; font-family: var(--font-display); font-size: 1.4rem; }
.stat span { color: var(--color-muted); font-size: .82rem; }

.form-row {
  display: grid; grid-template-columns: 1.2fr .7fr auto; gap: .6rem; align-items: end;
}
.form-grid-5 {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .6rem;
  align-items: end;
}
.tipo-tabs {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: .25rem;
}
.tipo-tab {
  appearance: none;
  border: 1px solid var(--color-line);
  background: #fff;
  color: var(--color-muted);
  border-radius: 10px;
  padding: .7rem 1.1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.tipo-tab:hover { border-color: #7dd3fc; color: var(--color-primary-dark); }
.tipo-tab.is-active {
  background: #e0f2fe;
  border-color: #38bdf8;
  color: var(--color-primary-dark);
}
@media (max-width: 1100px) {
  .form-grid-5 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .form-grid-5 { grid-template-columns: 1fr; }
}
.field { display: grid; gap: .3rem; }
.field label { font-size: .8rem; font-weight: 600; color: var(--color-muted); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--color-line); border-radius: 8px;
  padding: .65rem .75rem; font: inherit; background: #fff;
}
.field textarea {
  font-family: ui-monospace, Consolas, monospace; font-size: .88rem; line-height: 1.45;
  resize: vertical; min-height: 140px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid #bae6fd; border-color: #38bdf8;
}

.btn {
  appearance: none; border: 0; border-radius: 8px; cursor: pointer;
  font: inherit; font-weight: 600; padding: .65rem 1rem;
  display: inline-flex; align-items: center; gap: .4rem; text-decoration: none;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-accent { background: var(--color-accent); color: #fff; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-outline {
  background: #fff; color: var(--color-primary-dark);
  border: 1px solid #7dd3fc;
}
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-warn {
  background: #c2410c;
  color: #fff;
}
.btn-warn:hover { background: #9a3412; }
.btn-lg { padding: .9rem 1.2rem; font-size: 1.05rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.table-wrap { overflow: auto; border: 1px solid var(--color-line); border-radius: 8px; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td {
  padding: .7rem .75rem; border-bottom: 1px solid var(--color-line); text-align: left; vertical-align: middle;
}
table.data th {
  background: #f8fafc; color: var(--color-muted); font-size: .78rem;
  text-transform: uppercase; letter-spacing: .04em;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tr.is-done td { background: #f0fdf4; }
table.data tr.is-pending td { background: #fff; }

.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  border-radius: 999px; padding: .2rem .55rem; font-size: .75rem; font-weight: 700;
}
.badge-armado { background: #e2e8f0; color: #334155; }
.badge-lista { background: #e0f2fe; color: #075985; }
.badge-pt { background: #fef3c7; color: #92400e; }
.badge-prebodega { background: #ecfccb; color: #3f6212; }
.badge-despacho { background: #ffedd5; color: #9a3412; }
.badge-completa { background: #dcfce7; color: #166534; }
.badge-guia { background: #ede9fe; color: #5b21b6; }
.badge-pendiente { background: #fee2e2; color: #991b1b; }
.badge-warn { background: #ffedd5; color: #9a3412; }
.badge-ok { background: #dcfce7; color: #166534; }

.progress {
  height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden;
}
.progress > span {
  display: block; height: 100%; background: linear-gradient(90deg, #0284c7, #15803d);
  transition: width .35s ease;
}

.search-results {
  margin-top: .5rem; border: 1px solid var(--color-line); border-radius: 8px;
  max-height: 240px; overflow: auto; background: #fff;
}
.search-results button {
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--color-line);
  background: transparent; padding: .7rem .8rem; cursor: pointer; font: inherit;
}
.search-results button:hover { background: #f0f9ff; }
.search-results button:last-child { border-bottom: 0; }
.search-results strong { display: block; }
.search-results small { color: var(--color-muted); }

/* Tablet modo pistola */
.tablet-shell { width: min(820px, 100%); margin: 0 auto; }
.scan-box {
  background: linear-gradient(160deg, #0c4a6e, #0369a1);
  color: #fff; border-radius: 16px; padding: 1.25rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.scan-box-prebodega {
  background: linear-gradient(160deg, #3f5c4a, #4d7c0f);
}
.prebodega-ot {
  border: 1px solid var(--color-line);
  border-radius: 12px;
  margin-bottom: .75rem;
  background: #fff;
}
.prebodega-ot summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  padding: .85rem 1rem;
  font-family: var(--font-display);
}
.prebodega-ot summary::-webkit-details-marker { display: none; }
.prebodega-ot summary span { color: var(--color-muted); font-weight: 500; font-family: var(--font-body); }
.prebodega-ot .table-wrap { border-top: 1px solid var(--color-line); }
.scan-box h2 { margin: 0 0 .35rem; font-family: var(--font-display); }
.scan-box p { margin: 0 0 .9rem; opacity: .9; }
.scan-input {
  width: 100%; font-size: 1.35rem; padding: 1rem 1.1rem; border-radius: 12px;
  border: 0; font-family: var(--font-body); font-weight: 600;
}
.scan-feedback {
  min-height: 1.4rem; margin-top: .75rem; font-weight: 600;
}
.scan-feedback.ok { color: #bbf7d0; }
.scan-feedback.err { color: #fecaca; }
.big-progress {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  margin-bottom: .5rem;
}
.big-progress b { font-family: var(--font-display); font-size: 1.6rem; }
.mueble-tap {
  display: flex; justify-content: space-between; gap: .75rem; align-items: center;
  width: 100%; text-align: left; border: 1px solid var(--color-line);
  background: #fff; border-radius: 10px; padding: .85rem 1rem; margin-bottom: .5rem;
  cursor: pointer; font: inherit;
}
.mueble-tap.is-done {
  background: #f0fdf4; border-color: #86efac; cursor: default;
}
.mueble-tap.is-selected {
  border-color: var(--color-primary);
  background: #e0f2fe;
  box-shadow: 0 0 0 2px rgba(3, 105, 161, .22);
}
.mueble-tap.is-selected strong {
  color: var(--color-primary-dark);
}
.mueble-tap.is-locked {
  opacity: .55;
  cursor: not-allowed;
  background: #f8fafc;
}
.mueble-tap code {
  font-weight: 700; color: var(--color-primary-dark); font-size: .95rem;
}

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%); background: #fff; border: 1px solid var(--color-line);
  border-radius: 16px; padding: 1.5rem; box-shadow: var(--shadow);
}
.login-card h1 { font-family: var(--font-display); margin: 0 0 .25rem; font-size: 1.4rem; }
.login-card .hint { color: var(--color-muted); margin: 0 0 1rem; font-size: .9rem; }
.login-card .stack { display: grid; gap: .75rem; }
.alert {
  padding: .7rem .85rem; border-radius: 8px; margin-bottom: .85rem; font-size: .9rem;
}
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-ok { background: #dcfce7; color: #166534; }
.alert-info { background: #e0f2fe; color: #075985; }

.print-only { display: none; }

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}
.panel-head h2 { margin: 0; }
.report-filters {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: .75rem;
  align-items: end;
}
.report-hint {
  margin: .25rem 0 0;
  color: var(--color-muted);
  font-size: .88rem;
}
@media (max-width: 720px) {
  .report-filters { grid-template-columns: 1fr; }
}
.flota-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}
.viaje-card {
  display: grid;
  gap: .45rem;
  padding: .95rem 1rem;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  background: #f8fafc;
  margin: .75rem 0 0;
}
.viaje-card.is-pending {
  border-color: #fcd34d;
  background: #fffbeb;
}
.viaje-card.is-ok {
  border-color: #86efac;
  background: #f0fdf4;
}
.viaje-card.is-empty {
  border-style: dashed;
  background: #fff;
}
.viaje-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: .95rem;
}
.viaje-meta {
  display: grid;
  gap: .15rem;
  color: var(--color-muted);
  font-size: .9rem;
}
.viaje-meta strong { color: var(--color-text); }
.viaje-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .25rem;
}
.swal-viaje {
  text-align: left;
}
.swal-viaje label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: #64748b;
  margin: .55rem 0 .2rem;
}
.swal-viaje select, .swal-viaje input[type="checkbox"] {
  width: 100%;
}
.confirm-viaje {
  display: flex;
  gap: .55rem;
  align-items: flex-start;
  text-align: left;
  margin: .65rem 0 .2rem;
  padding: .65rem .75rem;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  font-size: .9rem;
}
.confirm-viaje input { margin-top: .15rem; }

.viaje-list {
  display: grid;
  gap: .45rem;
  margin-top: .75rem;
}
.viaje-list h3 {
  margin: 0 0 .15rem;
  font-size: .82rem;
  color: var(--color-muted);
  font-weight: 600;
}
.lote-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: none;
  gap: .65rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: .85rem 1rem calc(.85rem + var(--safe-bottom));
  background: #0c4a6e;
  color: #fff;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -8px 24px rgba(12, 74, 110, .22);
}
.lote-bar.is-on { display: flex; }
.lote-bar strong { font-family: var(--font-display); font-size: 1.05rem; }
.lote-bar .lote-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}
.lote-bar .btn-outline {
  background: transparent;
  color: #fff;
  border-color: rgba(255,255,255,.45);
}
.tap-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin: .75rem 0 .5rem;
}
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 900px) {
  .grid-cards, .stats, .flota-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .brand { min-width: 0; }
  .topnav { order: 3; width: 100%; }
}

@media print {
  body { background: #fff; }
  .topbar, .page-foot, .no-print { display: none !important; }
  .page { width: 100%; margin: 0; }
  .panel { box-shadow: none; border: 0; padding: 0; }
  .print-only { display: block; }
}
