:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1c1f24;
  --muted: #6b7079;
  --line: #e3e1dc;
  /* Colores de la marca (logo Terra-Monte) */
  --navy: #0c2642;
  --navy-2: #163a5f;
  --navy-3: #081a2e;
  --green: #2f7d32;        /* verde accesible para botones (texto blanco legible) */
  --green-logo: #3f8f3a;
  --green-claro: #5cb253;  /* para destacar sobre fondos azules */
  --accent: var(--green);
  --accent-ink: #ffffff;
  --dark: var(--navy);
  --ok: #2f8a57;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
h2 { font-size: 1.6rem; margin: 0 0 .4rem; }

/* Topbar */
.topbar { background: var(--dark); color: #fff; position: sticky; top: 0; z-index: 1000; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; }
.brand svg { width: 24px; height: 24px; fill: var(--accent); }
/* Logo vectorial (SVG, fondo transparente) */
.brand-logo { width: 40px; height: 48px; object-fit: contain; flex: none; }
nav { display: flex; align-items: center; gap: 20px; }
nav a { color: #d7d9dd; text-decoration: none; font-size: .95rem; }
nav a:hover { color: #fff; }
.cart-btn { position: relative; background: none; border: 0; color: #fff; cursor: pointer; padding: 6px; }
.cart-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge { position: absolute; top: -2px; right: -4px; background: var(--accent); color: #fff; font-size: .7rem; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }

/* Franja de indicadores */
.indicadores-bar { background: var(--navy-3); border-bottom: 1px solid var(--navy-2); color: #fff; }
.indicadores { display: flex; gap: 8px 28px; flex-wrap: wrap; padding: 10px 16px; align-items: baseline; }
.ind { display: flex; flex-direction: column; line-height: 1.25; }
.ind-l { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: #9aa0a8; }
.ind strong { font-size: .98rem; font-variant-numeric: tabular-nums; }
.ind small { font-size: .74rem; color: #c3c7ce; }
.portal .indicadores-bar { border-radius: var(--radius); margin-bottom: 16px; }

/* Hero */
.hero { background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%); color: #fff; padding: 64px 0 72px; }
.hero h1 { font-size: clamp(1.9rem, 4vw, 2.8rem); margin: 0 0 .5rem; letter-spacing: -.02em; }
.hero p { color: #c3c7ce; font-size: 1.1rem; margin: 0 0 1.5rem; max-width: 560px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 10px 16px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: #c9c6bf; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: 0; font-size: 1.8rem; line-height: 1; cursor: pointer; color: var(--muted); }

/* Sections */
.section { padding: 48px 0 8px; scroll-margin-top: 60px; }

/* Catalog */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-top: 16px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; display: flex; flex-direction: column; gap: 10px; border-top: 4px solid var(--c, var(--accent)); }
.card h3 { margin: 0; font-size: 1.1rem; }
.card p { margin: 0; color: var(--muted); font-size: .92rem; flex: 1; }
.price { font-size: 1.35rem; font-weight: 700; }
.price small { font-size: .8rem; font-weight: 500; color: var(--muted); }
.qty-row { display: flex; gap: 8px; }
.qty-row input { width: 90px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.qty-row .btn { flex: 1; }
.min-note { font-size: .78rem; color: var(--muted); }

/* Search */
.search { display: flex; gap: 8px; margin: 16px 0 0; flex-wrap: wrap; }
.search input { flex: 1 1 260px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--surface); }
.results { list-style: none; margin: 6px 0 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; max-height: 220px; overflow: auto; }
.results li { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: .92rem; }
.results li:last-child { border-bottom: 0; }
.results li:hover { background: #eef5ee; }

/* Route */
.route-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; margin-top: 16px; }
#map { height: 460px; border-radius: var(--radius); box-shadow: var(--shadow); z-index: 0; }
.route-panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.kpi-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kpi { font-size: 2.2rem; font-weight: 800; color: var(--accent); line-height: 1.1; }
.depots { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: .9rem; }
.depots th, .depots td { text-align: left; padding: 7px 4px; border-bottom: 1px solid var(--line); }
.depots th { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.depots tr.best td { font-weight: 700; color: var(--ok); }
.depots td:nth-child(n+2), .depots th:nth-child(n+2) { text-align: right; }
.warn { color: #b3261e; font-weight: 600; }

/* Orders */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin: 16px 0 48px; }
.orders { width: 100%; border-collapse: collapse; font-size: .9rem; }
.orders th, .orders td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.orders th { background: #fafaf8; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.orders td.wrap-cell { white-space: normal; min-width: 140px; }
.orders td.dest-cell { max-width: 200px; }
.orders td { vertical-align: top; }

/* Footer */
.footer { background: var(--dark); color: #9aa0a8; padding: 24px 0; font-size: .9rem; }

/* Drawer */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1100; }
.drawer { position: fixed; top: 0; right: 0; height: 100%; width: min(420px, 100%); background: var(--surface); z-index: 1200; transform: translateX(100%); transition: transform .25s ease; display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; }
.drawer-body { padding: 16px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.cart-list { list-style: none; margin: 0; padding: 0; }
.cart-list li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.cart-list .name { font-weight: 600; }
.cart-list .line-total { font-weight: 700; text-align: right; }
.cart-list .controls { display: flex; align-items: center; gap: 6px; }
.cart-list .controls input { width: 70px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.cart-list .remove { background: none; border: 0; color: #b3261e; cursor: pointer; font-size: .85rem; text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.summary > div { display: flex; justify-content: space-between; padding: 4px 0; }
.summary .total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-size: 1.2rem; font-weight: 800; }
.checkout { display: flex; flex-direction: column; gap: 8px; }
.checkout input, .checkout textarea { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; resize: vertical; }
.form-error { color: #b3261e; font-size: .9rem; }
.form-ok { color: var(--ok); font-size: .9rem; background: #e2f3e8; border-radius: 8px; padding: 8px 10px; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 0; text-align: left; }
.loading-note { color: var(--muted); font-size: .9rem; }

/* Cuenta (header) */
.account { display: flex; align-items: center; gap: 10px; }
.account .btn { padding: 6px 12px; font-size: .9rem; }
.account .btn-ghost { background: transparent; color: #fff; border-color: #2c4a6b; }
.account .btn-ghost:hover { border-color: #6b7079; }
.account .user { color: #fff; font-size: .9rem; font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .role { font-size: .7rem; background: var(--accent); color: #fff; border-radius: 4px; padding: 1px 6px; margin-left: 4px; font-weight: 700; }

.login-cta { background: #eef5ee; border: 1px solid #cfe3cf; border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.login-cta p { margin: 0 0 4px; }
#orders-login { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 16px 0 48px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1250; display: grid; place-items: center; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--surface); border-radius: var(--radius); width: min(420px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.modal-head h3 { margin: 0; }
.tabs { display: flex; gap: 4px; padding: 12px 20px 0; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 600; }
.auth-form input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-weight: 400; }
.auth-form input:focus, .checkout input:focus, .checkout textarea:focus, .search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* Pago por transferencia */
.channel { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0; display: flex; gap: 16px; flex-wrap: wrap; }
.channel legend { font-size: .85rem; font-weight: 600; padding: 0 4px; }
.channel label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.pay-note { margin: 0; font-size: .88rem; color: var(--muted); }
.small { font-size: .85rem; }
.modal-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 10px; }
.modal-body p { margin: 0; }
.bank-box { background: #eef5ee; border: 1px solid #cfe3cf; border-radius: 10px; padding: 14px 16px; }
.bank-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--accent); margin-bottom: 8px; }
.bank-box dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: .92rem; }
.bank-box dt { color: var(--muted); }
.bank-box dd { margin: 0; font-weight: 600; text-align: right; }
.bank-amount { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid #cfe3cf; margin-top: 10px; padding-top: 10px; }
.bank-amount strong { font-size: 1.3rem; }
.auth-form .check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.auth-form p { margin: 0; }

/* Impuestos */
.tax-lines { font-size: .82rem; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.tax-lines span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.tax-note { font-size: .78rem; color: var(--muted); }
.quick-qty { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-qty button { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: .8rem; cursor: pointer; }
.quick-qty button:hover { border-color: var(--accent); color: var(--accent); }
.card-wide { grid-column: 1 / -1; max-width: 560px; }
.tax-detail { border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; margin: 6px 0; font-size: .88rem; }
.tax-detail summary { cursor: pointer; font-weight: 600; color: var(--muted); font-size: .82rem; padding: 2px 0; }
.tax-detail > div { display: flex; justify-content: space-between; padding: 2px 0; color: var(--muted); }
.tax-detail small { font-size: .72rem; }
.tax-detail > div.sub { padding-left: 12px; font-size: .82rem; }
.tax-detail > div.sub span:first-child::before { content: "↳ "; opacity: .6; }
.tax-detail > div.strong { color: var(--ink); }
.tax-lines .sub { padding-left: 12px; }
.admin-tax { background: #eef4fb; border: 1px solid #cfe0f3; border-radius: var(--radius); padding: 12px 16px; margin: 12px 0 0; font-size: .9rem; }
.admin-tax.stale { background: #fdf0e1; border-color: #f3d2ad; }
.admin-tax strong { font-variant-numeric: tabular-nums; }
.admin-tax a { color: inherit; font-weight: 600; }

/* Descuentos por volumen */
.vol-tiers { display: flex; flex-direction: column; gap: 2px; background: #eef7f1; border: 1px solid #cfe8d8; border-radius: 8px; padding: 8px 12px; font-size: .88rem; }
.vol-tiers > strong { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ok); }
.vol-tiers em { color: var(--ok); font-style: normal; font-weight: 600; }
.vol-ok, .vol-hint { grid-column: 1 / -1; font-size: .8rem; }
.vol-ok { color: var(--ok); font-weight: 600; }
.vol-hint { color: #9a4a0b; background: #fdf0e1; border-radius: 6px; padding: 4px 8px; }
.summary .desc-row { color: var(--ok); font-weight: 600; }

/* Precio privado */
.price-locked { background: var(--bg); border: 1px dashed #c9c6bf; border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.price-locked p { margin: 0; color: var(--ink); flex: none; }
.price-locked .row { display: flex; gap: 8px; flex-wrap: wrap; }
.price-tag { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ok); background: #e2f3e8; border-radius: 4px; padding: 2px 6px; margin-bottom: 4px; }

.confirm-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.channel label small { color: var(--muted); }

/* Estado de pedidos */
.estado { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.estado-pendiente { background: #fdf0e1; color: #9a4a0b; }
.estado-informada { background: #e3eefa; color: #1f5487; }
.estado-pagado { background: #e2f3e8; color: #22683f; }
.tx-info { display: block; font-size: .78rem; color: var(--muted); margin-top: 4px; white-space: normal; }
.acciones { display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 160px; }
.orders .tx-info { max-width: 170px; }
.acciones .btn { padding: 6px 10px; font-size: .85rem; }
.aviso-ok { font-size: .75rem; color: var(--ok); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--dark); color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 1300; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

/* Map markers */
.pin { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.pin-depot { background: var(--dark); }
.pin-dest { background: var(--accent); }

/* Pedidos como tarjetas en pantallas angostas */
@media (max-width: 1180px) {
  .table-wrap { background: none; box-shadow: none; overflow: visible; }
  .orders thead { display: none; }
  .orders, .orders tbody { display: block; }
  .orders tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px 20px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
  .orders td { display: block; padding: 0; border: 0; white-space: normal; min-width: 0 !important; max-width: none !important; }
  .orders td[data-label]::before { content: attr(data-label); display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
  .orders td.acciones-cell { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 12px; }
  .orders td.acciones-cell::before { display: none; }
  .orders .acciones { flex-direction: row; flex-wrap: wrap; align-items: center; min-width: 0; }
  .orders .tx-info { max-width: none; }
}

@media (max-width: 860px) {
  .route-layout { grid-template-columns: 1fr; }
  #map { height: 360px; }
  nav a { display: none; }
  nav { gap: 10px; }
  .account .user { max-width: 90px; }
}
