/* =========================================================================
   Cotizador de Topografía — estilos (mobile-first)
   ========================================================================= */
:root {
  --bg: #f2f4f3;
  --surface: #ffffff;
  --surface-2: #f7f9f8;
  --border: #dde3e0;
  --text: #14201b;
  --muted: #5b6b64;
  --brand: #0f3b2e;
  --brand-2: #17654c;
  --accent: #1f8a5b;
  --focus: #2563eb;

  --red: #b42318;      --red-bg: #fef3f2;    --red-bd: #fecdca;
  --orange: #c4320a;   --orange-bg: #fff4ed; --orange-bd: #fdd4b8;
  --amber: #a15c07;    --amber-bg: #fffaeb;  --amber-bd: #fedf89;
  --blue: #1d4ed8;     --blue-bg: #eff4ff;   --blue-bd: #c7d7fe;
  --violet: #6927da;   --violet-bg: #f5f3ff; --violet-bd: #d9d6fe;
  --wa: #128c4a;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}
.hidden { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.topbar__inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand__icon { width: 30px; height: 30px; fill: #9fe3c3; flex: none; }
.brand__title { font-size: 1.05rem; font-weight: 700; }
.brand__sub { font-size: .78rem; opacity: .8; }
.badge { font-size: .75rem; font-weight: 600; padding: 5px 10px; border-radius: 999px; white-space: nowrap; }
.badge--vendedor { background: rgba(255,255,255,.14); color: #fff; }
.badge--admin { background: #fde68a; color: #713f12; }

/* ---------- Layout ---------- */
.layout { max-width: 1200px; margin: 0 auto; padding: 12px; display: grid; gap: 12px; }
.panel { display: grid; gap: 12px; align-content: start; min-width: 0; }

@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); padding: 20px; gap: 20px; }
  .panel--results { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; padding-right: 4px; }
}

/* ---------- Sections ---------- */
.card-sec {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: grid; gap: 14px;
}
.sec-title { font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.sec-num {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: .8rem;
}
fieldset.svc { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; min-width: 0; }
fieldset.svc legend { font-weight: 600; font-size: .92rem; padding: 0; margin-bottom: 8px; }

.details { padding: 0; gap: 0; }
.details > summary {
  list-style: none; cursor: pointer; padding: 14px 16px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
}
.details > summary::-webkit-details-marker { display: none; }
.details > summary::after { content: "+"; font-size: 1.2rem; color: var(--muted); }
.details[open] > summary::after { content: "−"; }
.details[open] { padding-bottom: 16px; }
.details > :not(summary) { margin: 0 16px; }
.details[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 14px; }

/* ---------- Fields ---------- */
.field { display: grid; gap: 6px; min-width: 0; }
label, .label { font-size: .9rem; font-weight: 600; color: var(--text); }
.label small { font-weight: 400; color: var(--muted); }
.req { font-size: .72rem; font-weight: 600; color: var(--red); background: var(--red-bg); padding: 1px 6px; border-radius: 6px; margin-left: 4px; }
.opt { font-size: .75rem; font-weight: 400; color: var(--muted); }
.hint { font-size: .8rem; color: var(--muted); }
.field-error { font-size: .8rem; color: var(--red); min-height: 0; }
.field-error:empty { display: none; }

input[type="text"], input[type="number"], input[type="tel"], input[type="url"], input[type="password"], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* evita zoom en iOS */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  min-height: 46px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 80px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(37, 99, 235, .18); }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
.is-invalid { border-color: var(--red) !important; box-shadow: 0 0 0 3px rgba(180, 35, 24, .12) !important; }

.input-group { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.input-group select { min-width: 92px; }
.input-group input[type="number"] { width: 120px; }
.conversion { font-size: .82rem; color: var(--brand-2); font-weight: 500; min-height: 1.1em; }
.grid-2 { display: grid; gap: 12px; }
@media (min-width: 560px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* Segmented controls */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px; }
.seg label { position: relative; margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: grid; place-items: center; text-align: center;
  min-height: 40px; padding: 6px 8px; border-radius: 8px;
  font-size: .86rem; font-weight: 600; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.seg input:checked + span { background: var(--surface); color: var(--brand); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
.seg input:disabled + span { opacity: .45; cursor: not-allowed; }
.seg--yn { max-width: 260px; }
.seg--yn input[value="si"]:checked + span { color: var(--red); }

.stack { display: grid; gap: 8px; }
.radio-card { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font-weight: 500; }
.radio-card input { margin-top: 3px; accent-color: var(--brand-2); width: 18px; height: 18px; flex: none; }
.radio-card:has(input:checked) { border-color: var(--brand-2); background: #f0faf5; }

.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--brand-2); flex: none; }
.check--alert { padding: 12px; border-radius: var(--radius-sm); background: var(--orange-bg); border: 1px solid var(--orange-bd); color: var(--orange); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; font-size: .95rem;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 12px 16px; min-height: 48px; cursor: pointer; text-decoration: none;
  transition: filter .15s, transform .05s;
}
.btn svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: grayscale(.4); }
.btn--block { width: 100%; }
.btn--sm { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.btn--primary { background: var(--brand-2); color: #fff; }
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn--whatsapp { background: var(--wa); color: #fff; }
.btn--whatsapp:hover { filter: brightness(1.08); }
.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--text); }

/* ---------- Alerts ---------- */
.alerts { display: grid; gap: 8px; }
.alerts:empty { display: none; }
.alert {
  display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start;
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid; font-size: .9rem;
}
.alert svg { width: 22px; height: 22px; fill: currentColor; }
.alert__title { font-weight: 700; display: block; }
.alert__msg { color: var(--text); }
.alert--bloqueo { background: var(--red-bg); border-color: var(--red-bd); color: var(--red); }
.alert--zona_roja { background: var(--orange-bg); border-color: var(--orange-bd); color: var(--orange); }
.alert--viaticos { background: var(--amber-bg); border-color: var(--amber-bd); color: var(--amber); }
.alert--ric { background: #fefce8; border-color: #fde68a; color: #854d0e; }
.alert--aviso { background: var(--blue-bg); border-color: var(--blue-bd); color: var(--blue); }
.alert--premium { background: var(--violet-bg); border-color: var(--violet-bd); color: var(--violet); }
#red-error, #aviso-admin { display: block; }

/* ---------- Pending ---------- */
.pending { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px 16px; }
.pending h3 { font-size: .9rem; margin-bottom: 6px; }
.pending ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: .88rem; display: grid; gap: 3px; }

/* ---------- Block panel ---------- */
.block-panel { background: var(--surface); border: 2px solid var(--red-bd); border-radius: var(--radius); padding: 16px; display: grid; gap: 14px; }
.block-panel__head { display: flex; gap: 12px; align-items: flex-start; }
.block-panel__head svg { width: 28px; height: 28px; fill: var(--red); flex: none; }
.block-panel h3 { color: var(--red); font-size: 1.05rem; }
.block-panel p { color: var(--muted); font-size: .88rem; }

/* ---------- Price cards ---------- */
.tramo { font-size: .82rem; color: var(--muted); margin-bottom: 8px; }
.cards { display: grid; gap: 10px; }
@media (min-width: 560px) and (max-width: 959px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.price-card {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); display: grid; gap: 4px;
}
.price-card__name { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.price-card__total { font-size: 1.7rem; font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; }
.price-card__sub { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.price-card__rows { display: grid; gap: 2px; margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--border); font-size: .88rem; }
.price-card__row { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
.price-card__row strong { font-weight: 700; }
.price-card--piso { background: #fffbeb; border-color: #fcd34d; }
.price-card--piso .price-card__total { color: #92400e; }
.price-card--premium.is-recommended { border: 2px solid var(--violet); box-shadow: 0 0 0 4px rgba(105, 39, 218, .10), var(--shadow); }
.price-card--premium.is-recommended .price-card__total { color: var(--violet); }
.price-card--negociado { border-style: dashed; }
.price-card__tag { position: absolute; top: 12px; right: 12px; font-size: .7rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--violet); color: #fff; }
.price-card__error { color: var(--red); font-weight: 600; font-size: .9rem; }

.negociado { margin-top: 10px; }
.desglose { margin-top: 10px; background: #fffbeb; border: 1px solid #fcd34d; border-radius: var(--radius); padding: 14px 16px; font-size: .86rem; display: grid; gap: 8px; }
.desglose h4 { margin: 0; font-size: .9rem; color: #92400e; }
.desglose table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.desglose td { padding: 4px 0; border-bottom: 1px solid #fde68a; vertical-align: top; }
.desglose td:last-child { text-align: right; white-space: nowrap; padding-left: 10px; }
.desglose tr.total td { font-weight: 700; border-bottom: 0; }

.validacion { margin-top: 10px; }
.actions { margin-top: 10px; }
.seg--3 { grid-auto-columns: 1fr; }

/* ---------- Output ---------- */
.salida { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; box-shadow: var(--shadow); }
.salida__head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.salida textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; background: var(--surface-2); }

/* ---------- Footer / toast ---------- */
.footer { text-align: center; color: var(--muted); font-size: .78rem; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #10231b; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: .9rem; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 50;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--red); }

.is-loading .price-card__total { opacity: .55; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
