/* =====================================================================
   app.css — Estilo de «SolarLead Pro»
   Idea visual: azul noche de panel solar + ámbar de sol + verde ahorro.
   Escritorio con menú lateral; móvil con barra inferior.
   ===================================================================== */

/* ---------- Colores y medidas ---------- */
:root {
  --bg: #f2f5fa;
  --card: #ffffff;
  --ink: #0f1f3a;
  --ink-2: #33415c;
  --muted: #64708a;
  --line: #dfe5ef;
  --navy: #0f1f3a;
  --navy-2: #182c50;
  --sun: #f5a524;
  --sun-2: #d9860b;
  --sun-soft: #fff4dd;
  --green: #15803d;
  --green-soft: #e3f4e8;
  --blue: #2558c9;
  --red: #b42318;
  --red-soft: #fde7e4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 31, 58, .05), 0 8px 24px rgba(15, 31, 58, .06);
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 var(--font); color: var(--ink); background: var(--bg); overflow-x: hidden; padding-bottom: 72px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.015em; }
h1 { font-weight: 800; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.dim { color: #9fb0cc; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; border: 1px solid transparent; border-radius: 10px; padding: .6em 1.1em; font: 700 .95rem var(--font); cursor: pointer; text-decoration: none; min-height: 44px; transition: background .2s, transform .1s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--sun); color: var(--navy); }
.btn-primary:hover { background: var(--sun-2); }
.btn-dark { background: var(--navy); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: #c5cfdf; }
.btn-outline { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .35); }
.btn-link { background: none; color: #9fb0cc; border: 0; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ok { background: var(--green); color: #fff; }
.btn-small { padding: .35em .8em; font-size: .85rem; min-height: 36px; }
.btn-lg { padding: .9em 1.8em; font-size: 1.05rem; }
.icon-btn { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: var(--ink-2); width: 40px; height: 40px; border-radius: 50%; }
.icon-btn.light { color: #fff; }

/* ---------- Bienvenida ---------- */
.welcome { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; transition: opacity .35s;
  background: radial-gradient(circle at 80% 10%, rgba(245, 165, 36, .45), transparent 35%), linear-gradient(160deg, #0f1f3a, #1d3b6e); }
.welcome.out { opacity: 0; }
.welcome-card { max-width: 480px; text-align: center; color: #fff; }
.welcome-card h1 { font-size: 2.6rem; margin-top: .2em; }
.welcome-card .lead { color: #d3def0; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; color: var(--sun); margin: 10px 0 0; font-weight: 700; }

/* ---------- Estructura ---------- */
.shell { display: block; }
.sidebar { display: none; }
.mobile-top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: var(--navy); color: #fff; }
.mobile-top .brand { margin-right: auto; display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; }
main { max-width: 1200px; margin: 0 auto; padding: 18px 16px 24px; outline: none; }

.bottombar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(6, 1fr); background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottombar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 9px; font-size: .68rem; color: var(--muted); font-weight: 700; text-decoration: none; }
.bottombar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bottombar a.active { color: var(--navy); }
.bottombar a.active svg { stroke: var(--sun-2); }

/* ---------- Cabeceras de página ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 1.7rem; margin: 0; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.section-title { font-size: 1.05rem; margin: 24px 0 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }

/* ---------- Tarjetas y cifras ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpi { padding: 14px; position: relative; overflow: hidden; }
.kpi b { display: block; font-size: 1.7rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: .85rem; }
.kpi.sun { background: var(--navy); color: #fff; border-color: var(--navy); }
.kpi.sun span { color: #b9c6dd; }
.kpi > * { position: relative; z-index: 1; }
.kpi.sun::after { content: ""; position: absolute; right: -34px; top: -34px; width: 74px; height: 74px; z-index: 0; border-radius: 50%; background: var(--sun); opacity: .9; }
.grid-2 { display: grid; gap: 14px; }
.list { display: grid; gap: 10px; }
.row { display: flex; gap: 12px; align-items: center; padding: 12px 14px; }
.row .grow { flex: 1; min-width: 0; }
.row h3 { font-size: 1rem; margin: 0; }
.row p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.avatar { width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center; font-weight: 800; background: var(--sun-soft); color: var(--sun-2); }
.clickable { cursor: pointer; text-align: left; font: inherit; color: inherit; width: 100%; }
.clickable:hover { border-color: #c5cfdf; }

/* Etiquetas */
.tag { display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: .76rem; font-weight: 800; background: #eef2f8; color: var(--ink-2); white-space: nowrap; }
.tag.sun { background: var(--sun-soft); color: #8a5300; }
.tag.ok { background: var(--green-soft); color: var(--green); }
.tag.bad { background: var(--red-soft); color: var(--red); }
.tag.blue { background: #e4ecfb; color: var(--blue); }
.tag.dark { background: var(--navy); color: #fff; }

/* Barras horizontales (embudo y orígenes) */
.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: 96px 1fr 34px; gap: 10px; align-items: center; font-size: .88rem; }
.bar .track { background: #eef2f8; border-radius: 6px; height: 14px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 6px; background: var(--navy); }
.bar .fill.sun { background: var(--sun); }
.bar b { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Contactos (tablero por estados) ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chip { border: 1px solid var(--line); background: #fff; color: var(--ink-2); border-radius: 999px; padding: 7px 13px; font: 700 .84rem var(--font); cursor: pointer; white-space: nowrap; min-height: 38px; }
.chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip .count { opacity: .65; margin-left: 4px; }
.board { display: grid; gap: 12px; }
.col { display: none; }
.col.sel { display: grid; gap: 10px; align-content: start; }
.col-head { display: none; }
.lead-card { display: grid; gap: 6px; padding: 12px 14px; }
.lead-card h3 { font-size: 1rem; margin: 0; }
.lead-card .meta { color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.lead-card .foot { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.lead-card .foot .spacer { flex: 1; }

/* ---------- Calculadora ---------- */
.calc { display: grid; gap: 14px; }
.calc-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.calc-form .full { grid-column: 1 / -1; }
.results { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.res { background: #f6f8fc; border-radius: 12px; padding: 12px; }
.res b { display: block; font-size: 1.45rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.res span { font-size: .82rem; color: var(--muted); }
.res.big { grid-column: 1 / -1; background: var(--navy); color: #fff; }
.res.big span { color: #b9c6dd; }
.res.big b { font-size: 2rem; color: var(--sun); }
.res.green b { color: var(--green); }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Agenda ---------- */
.day { display: grid; gap: 8px; }
.day-head { font-weight: 800; font-size: .9rem; color: var(--ink-2); margin-top: 8px; display: flex; gap: 8px; align-items: center; }
.day-head .tag { font-weight: 700; }
.visit { display: grid; grid-template-columns: 58px 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; }
.visit .hour { font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.visit.done { opacity: .55; }
.visit.done h3 { text-decoration: line-through; }
.visit h3 { font-size: .98rem; margin: 0; }
.visit p { margin: 0; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }

/* ---------- Instalaciones ---------- */
.works { display: grid; gap: 14px; }
.progress { height: 10px; background: #eef2f8; border-radius: 6px; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--sun), #f7c15a); border-radius: 6px; }
.checklist { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }
.checklist label { display: flex; gap: 10px; align-items: center; padding: 6px 4px; border-radius: 8px; cursor: pointer; font-size: .92rem; }
.checklist label:hover { background: #f6f8fc; }
.checklist input { width: 20px; height: 20px; accent-color: var(--green); flex: none; }
.checklist .done { color: var(--muted); text-decoration: line-through; }
.checklist small { margin-left: auto; color: var(--muted); white-space: nowrap; }

/* ---------- Documento de presupuesto ---------- */
.doc { display: grid; gap: 12px; font-size: .93rem; }
.doc-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-bottom: 3px solid var(--sun); padding-bottom: 10px; }
.doc-head h3 { margin: 0; font-size: 1.3rem; }
.doc table td, .doc table th { padding: 7px 6px; }
.doc .total td { font-weight: 800; font-size: 1.05rem; border-bottom: 0; }

/* ---------- Ventanas y formularios ---------- */
.modal { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: #fff; color: var(--ink); box-shadow: 0 24px 60px rgba(15, 31, 58, .3); }
.modal-wide { width: min(780px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(15, 31, 58, .55); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px 20px; position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-head h2 { margin: 0; font-size: 1.25rem; }
.modal-body { padding: 6px 20px 20px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field label { font-weight: 700; font-size: .86rem; color: var(--ink-2); }
.field small { color: var(--muted); }
.field-check { grid-template-columns: auto 1fr; align-items: center; }
.field-check label { order: 2; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #cdd6e4; border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--navy); }
input[type="range"] { padding: 0; accent-color: var(--sun-2); }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: 2px solid rgba(37, 88, 201, .2); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }
.steps { padding-left: 1.2em; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; border: 1px dashed #cdd6e4; border-radius: var(--radius); }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-size: .92rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

#toasts { position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 700; transition: opacity .4s, transform .4s; border-left: 4px solid var(--sun); }
.toast-bad { border-left-color: #ff7a6b; }
.toast.out { opacity: 0; transform: translateY(8px); }
.demo-note { text-align: center; font-size: .8rem; color: var(--muted); padding: 10px 16px 18px; }

/* ---------- Pantallas medianas ---------- */
@media (min-width: 640px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .full { grid-column: 1 / -1; }
  .results { grid-template-columns: repeat(3, 1fr); }
}
/* ---------- Escritorio: menú lateral y tablero completo ---------- */
@media (min-width: 960px) {
  body { padding-bottom: 0; }
  .bottombar, .mobile-top { display: none; }
  .shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
  .sidebar { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; padding: 20px 14px; background: var(--navy); color: #fff; }
  .sidebar .brand { display: flex; gap: 10px; align-items: center; color: #fff; text-decoration: none; padding: 0 6px; }
  .sidebar .brand span { display: flex; flex-direction: column; line-height: 1.15; }
  .sidebar .brand small { color: #9fb0cc; font-size: .75rem; }
  .side-nav { display: grid; gap: 2px; }
  .side-nav a { color: #c9d4e6; text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 700; font-size: .95rem; }
  .side-nav a:hover { background: var(--navy-2); color: #fff; }
  .side-nav a.active { background: var(--sun); color: var(--navy); }
  .side-foot { margin-top: auto; display: grid; gap: 6px; }
  main { padding: 26px 28px 30px; }
  .grid-2 { grid-template-columns: 1.3fr 1fr; align-items: start; }
  .chips.board-chips { display: none; }
  .board { grid-template-columns: repeat(6, minmax(0, 1fr)); align-items: start; }
  .col { display: grid; gap: 8px; align-content: start; background: #e9eef6; border-radius: 12px; padding: 8px; min-height: 200px; }
  .col-head { display: flex; justify-content: space-between; align-items: center; font-weight: 800; font-size: .82rem; padding: 4px 4px 2px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
  .lead-card { padding: 10px; }
  .lead-card h3 { font-size: .92rem; }
  .calc { grid-template-columns: 1fr 1.15fr; align-items: start; }
  #toasts { bottom: 28px; }
}
#print-area { display: none; }
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing #print-area { display: block; padding: 10mm; }
  body { background: #fff; padding: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
/* Cifras más pequeñas dentro del documento de presupuesto (caben en móvil) */
.doc .res b { font-size: 1.1rem; }
