:root {
  --ink: #101820;
  --ink-soft: #1b2a35;
  --ink-muted: #3d5363;
  --copper: #c46a2d;
  --copper-deep: #9a4e1c;
  --sand: #f3ead9;
  --paper: #fffcf6;
  --line: #d9cbb3;
  --ok: #2c6a4a;
  --danger: #a33b2a;
  --info: #1f5f73;
  --shadow: 0 18px 40px rgba(16, 24, 32, 0.08);
  --radius: 18px;
  --sidebar: 260px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: radial-gradient(1200px 500px at 10% -10%, #efe3c8 0%, var(--sand) 45%, #e7dcc6 100%);
  color: var(--ink);
  min-height: 100vh;
}

h1, h2, h3, .brand, .stat-value {
  font-family: "Syne", "Trebuchet MS", sans-serif;
  letter-spacing: -0.03em;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--ink) 0%, var(--ink-soft) 100%);
  color: #f6efe4;
  padding: 28px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.15rem;
}
.brand-logo {
  display: block;
  height: 44px;
  width: auto;
  max-width: 210px;
  object-fit: contain;
}
.brand-sidebar {
  display: flex;
  align-items: center;
  background: #ffffff;
  border-radius: 14px;
  padding: 10px 12px;
  margin: 0 0 4px;
}
.brand-sidebar .brand-logo {
  height: 40px;
}
.brand-public img {
  height: 56px;
  width: auto;
  max-width: 240px;
  object-fit: contain;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: transparent;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
}
.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.brand small {
  display: block;
  color: #b7c3cc;
  font-family: "IBM Plex Sans", sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.65rem;
}
.brand-auth {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
.brand-auth small {
  color: var(--ink-muted);
}

.nav-group { display: flex; flex-direction: column; gap: 6px; }
.nav-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #8ea0ad;
  margin: 8px 10px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: #dce6ec;
  transition: 0.18s ease;
}
.nav-link:hover, .nav-link.active {
  background: rgba(196, 106, 45, 0.18);
  color: #fff;
}
.nav-link.active { box-shadow: inset 3px 0 0 var(--copper); }

.sidebar-foot { margin-top: auto; }
.user-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 10px 12px;
}
.btn-ghost {
  background: transparent;
  border: 1px solid #5b6f7c;
  color: #f6efe4;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

.content { padding: 28px 32px 48px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 24px;
  gap: 16px;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  color: var(--copper-deep);
  font-weight: 600;
}
.page-title { margin: 4px 0 0; font-size: 2rem; }

.card {
  background: var(--paper);
  border: 1px solid rgba(217, 203, 179, 0.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-2 > div { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.stat {
  padding: 18px;
  border-radius: 16px;
  min-height: 140px;
  color: var(--ink);
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: "";
  position: absolute;
  right: -20px;
  bottom: -24px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
}
.stat h3 { margin: 0 0 8px; font-size: 0.95rem; }
.stat p { margin: 0; font-size: 0.85rem; opacity: 0.85; }
.stat-value { font-size: 1.45rem; margin-top: 10px; }
.stat-contado { background: linear-gradient(160deg, #d9efe0, #b7dcc4); }
.stat-credito { background: linear-gradient(160deg, #efe0f3, #d4c0e0); }
.stat-remito { background: linear-gradient(160deg, #d7eaf3, #b7d3e4); }
.stat-agencia { background: linear-gradient(160deg, #f8e6c4, #edcf91); }
.stat-cancel { background: linear-gradient(160deg, #f5d4cc, #e8b3a8); }
.stat-caja { background: linear-gradient(160deg, #cfe8d8, #9fd0b3); }
.stat-pagos { background: linear-gradient(160deg, #d5e4f4, #b4cbe3); }
.informe-h { font-size: 1.15rem; margin: 28px 0 12px; }

.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0,1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
label { font-size: 0.82rem; font-weight: 600; color: var(--ink-muted); }
input, select, textarea {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--copper);
  box-shadow: 0 0 0 3px rgba(196, 106, 45, 0.15);
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--copper-deep); }
.btn-copper { background: var(--copper); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 0.85rem; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); }
th.num, td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.flash {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 16px;
}
.flash-ok { background: #dcefe4; color: var(--ok); }
.flash-error { background: #f6dcd6; color: var(--danger); }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--sand);
}
.badge-ok { background: #d7ecdd; color: var(--ok); }
.badge-warn { background: #f8e4c4; color: #8a5a12; }
.badge-info { background: #d5e8f0; color: var(--info); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.muted { color: var(--ink-muted); }

.csv-mapeo { margin-bottom: 18px; }
.csv-map-grid { display: grid; gap: 10px; margin: 16px 0 20px; }
.csv-map-row { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(180px, 1.4fr); gap: 12px; align-items: center; }
.csv-map-head { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-muted); }
.csv-map-row label { display: flex; gap: 8px; align-items: center; margin: 0; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(440px, 100%);
  background: var(--paper);
  border-radius: 28px;
  padding: 36px;
  box-shadow: var(--shadow);
}
.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 28px;
  align-items: center;
}
.hero-copy h1 { font-size: 3.1rem; margin: 8px 0 12px; }
.hero-copy p { font-size: 1.1rem; color: var(--ink-muted); max-width: 520px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(16,24,32,0.55);
  display: none;
  place-items: center;
  padding: 20px;
  z-index: 30;
}
.modal.open { display: grid; }
.modal-card {
  width: min(720px, 100%);
  background: var(--paper);
  border-radius: 22px;
  padding: 24px;
  max-height: 90vh;
  overflow: auto;
}
.modal-card.wide {
  width: min(1180px, calc(100vw - 40px));
}
.bultos-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink);
  font: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.bultos-toggle::after {
  content: "▾";
  font-size: 0.75em;
  text-decoration: none;
  color: var(--ink-muted);
}
.bultos-toggle.is-open::after { content: "▴"; }
.bultos-detalle > td {
  background: var(--sand);
  padding: 8px 12px 12px;
}
.bultos-detalle table { margin: 0; background: var(--paper); border-radius: 12px; overflow: hidden; }

.line-item {
  display: grid;
  grid-template-columns: 2fr 80px 100px 100px 1fr 120px 40px;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.search-select {
  position: relative;
}
.search-select > select {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.search-select-list {
  position: absolute;
  z-index: 25;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 240px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: none;
}
.search-select-list.open { display: block; }
.search-select-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.92rem;
}
.search-select-item:hover,
.search-select-item.active {
  background: var(--sand);
}
.search-select-empty {
  padding: 10px 12px;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.ingreso-page .page-title { font-size: 1.55rem; }
.ingreso-topbar { margin-bottom: 14px; }
.ingreso-actions { display: flex; gap: 8px; align-items: center; }
.ingreso-block {
  background: var(--paper);
  border: 1px solid rgba(217, 203, 179, 0.8);
  border-radius: 16px;
  padding: 14px 16px 16px;
  margin-bottom: 12px;
}
.ingreso-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  margin-bottom: 10px;
  font-size: 0.95rem;
}
.step-n {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 0.72rem;
  margin-right: 6px;
}
.party-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.who-card {
  margin-top: 8px;
  background: #f7f1e6;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.82rem;
  line-height: 1.35;
}
.who-card strong { display: block; font-size: 0.92rem; margin-bottom: 2px; }
.who-card p { margin: 0; color: var(--ink-muted); }
.who-kicker {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.65rem;
  color: var(--copper-deep);
  font-weight: 700;
  margin-bottom: 2px;
}
.destino-grid, .billing-grid {
  display: grid;
  gap: 10px;
}
.destino-grid { grid-template-columns: 1.4fr 1fr 1fr 1.6fr; }
.choice-row {
  display: flex;
  gap: 8px;
}
.choice {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin: 0;
  cursor: pointer;
  position: relative;
}
.choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.choice span {
  display: block;
  width: 100%;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 8px;
  font-size: 0.85rem;
  font-weight: 600;
  background: #fff;
}
.choice input:checked + span {
  background: var(--ink);
  color: #f6efe4;
  border-color: var(--ink);
}
.choice input:focus-visible + span {
  outline: 2px solid var(--copper-deep);
  outline-offset: 2px;
}
.billing-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.line-head {
  display: grid;
  grid-template-columns: 2fr 80px 100px 100px 1fr 120px 40px;
  gap: 8px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin-bottom: 6px;
  padding: 0 2px;
}
.ingreso-bar {
  position: sticky;
  bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--ink);
  color: #f6efe4;
  border-radius: 16px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  z-index: 15;
}
.ingreso-totales { margin: 0; font-weight: 700; }
.ingreso-page { padding-bottom: 8px; }

@media (max-width: 1100px) {
  .party-grid, .destino-grid, .billing-grid, .line-head { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .grid-5, .grid-3, .grid-2, .form-grid, .hero, .line-item { grid-template-columns: 1fr; }
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}
.check-row input { width: auto; margin-top: 2px; }
.permiso-grupos {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.permiso-grupo {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}
.permiso-grupo h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}
.permiso-grupo .check-row { margin-bottom: 8px; }

@media (max-width: 1100px) {
  .permiso-grupos { grid-template-columns: 1fr; }
}

.pdf-frame {
  display: block;
  width: 100%;
  height: calc(100vh - 210px);
  min-height: 560px;
  border: 0;
  border-radius: 10px;
  background: #4a4f55;
}
