:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent2: #16a34a;
  --danger: #f87171;
  --card: #1e293b;
  --border: #334155;
  --font: "Segoe UI", "Trebuchet MS", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: linear-gradient(160deg, #0f172a 0%, #14532d 45%, #0f172a 100%);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
.hero {
  min-height: 88vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
}
.brand {
  font-size: clamp(2.4rem, 6vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0;
}
.brand span { color: var(--accent); }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 36rem; }
.cta { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: .5rem; }
.btn {
  display: inline-block;
  background: var(--accent);
  color: #052e16;
  font-weight: 700;
  border: 0;
  border-radius: 8px;
  padding: .75rem 1.2rem;
  cursor: pointer;
}
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: rgba(15,23,42,.92);
  border-right: 1px solid var(--border);
  padding: 1.25rem;
}
.side .logo { font-weight: 800; font-size: 1.25rem; margin-bottom: 1.5rem; }
.side nav a {
  display: block;
  padding: .55rem .7rem;
  border-radius: 6px;
  color: var(--muted);
  margin-bottom: .25rem;
}
.side nav a.active, .side nav a:hover {
  background: var(--bg2);
  color: var(--text);
  text-decoration: none;
}
.main { padding: 1.5rem; }
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}
.kpi-grid.dash-hero {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.kpi {
  background: rgba(30,41,59,.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.5rem; font-weight: 700; margin-top: .35rem; }
.kpi .hint { color: var(--muted); font-size: .75rem; margin-top: .35rem; font-weight: 400; line-height: 1.3; }
.kpi.kpi-emphasis {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.kpi.warn { border-color: #ca8a0488; }
.kpi.warn .value { color: #fde68a; }
.table-edit input, .table-edit select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: .4rem .5rem;
  font: inherit;
}
.table-edit input[type="number"] { width: 6.2rem; }
.table-edit input[type="date"] { width: 9.5rem; }
.table-edit input[type="text"] { width: 10rem; }
.table-edit select { width: 8.5rem; }
.table-edit .btn { padding: .4rem .75rem; font-size: .85rem; }
.card {
  background: rgba(30,41,59,.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-top: 1rem;
}
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .55rem .4rem; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-weight: 600; }
.form { display: grid; gap: .75rem; max-width: 480px; }
.form label { display: grid; gap: .3rem; color: var(--muted); font-size: .9rem; }
.form input, .form textarea, .form select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: .65rem .75rem;
}
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert.error { background: #7f1d1d55; color: #fecaca; }
.alert.warn { background: #78350f55; color: #fde68a; }
.alert.info { background: #14532d55; color: #bbf7d0; }
.code-big {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--accent);
}
.filters { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.badge-ok {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 6px;
  background: #14532d88;
  color: #86efac;
  font-size: .8rem;
  font-weight: 600;
}
.badge-warn {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 6px;
  background: #713f1288;
  color: #fde68a;
  font-size: .8rem;
  font-weight: 600;
}
.badge-danger {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 6px;
  background: #7f1d1d88;
  color: #fecaca;
  font-size: .8rem;
  font-weight: 600;
}
.badge-off {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 6px;
  background: #33415588;
  color: #cbd5e1;
  font-size: .8rem;
  font-weight: 600;
}
.alta-banner {
  padding: 1rem 1.15rem;
  border-radius: 10px;
  font-weight: 800;
  letter-spacing: .02em;
  margin-top: .5rem;
}
.alta-banner.si {
  background: #14532d99;
  color: #86efac;
  border: 1px solid #22c55e66;
}
.alta-banner.no {
  background: #7f1d1d66;
  color: #fecaca;
  border: 1px solid #f8717166;
}
.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
}
.timeline li {
  border-left: 2px solid var(--border);
  padding: 0 0 1rem 1rem;
  margin-left: .4rem;
}
.timeline li:last-child { padding-bottom: 0; }
.admin-body .admin-side .logo span { color: #38bdf8; }
.dl-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: .4rem .75rem;
  margin: 0;
}
.dl-grid dt { color: var(--muted); }
.dl-grid dd { margin: 0; }

/* —— CRM leads —— */
.crm-page { max-width: 1180px; }
.crm-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}
.crm-head h1 { margin: 0; }
.crm-head .sub { color: var(--muted); margin: .35rem 0 0; font-size: .9rem; max-width: 38rem; }
.crm-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.crm-search {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: .55rem .75rem;
  min-width: 200px;
  font: inherit;
}
.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: rgba(30,41,59,.9);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover, .icon-btn:focus {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}
.icon-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #052e16;
}
.icon-btn.primary:hover { filter: brightness(1.08); color: #052e16; }
.crm-stats {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin: .25rem 0 .85rem;
}
.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: rgba(30,41,59,.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .28rem .75rem;
  font-size: .82rem;
  color: var(--muted);
}
.stat-pill strong { color: var(--text); font-size: .95rem; }
.stat-pill.warn { border-color: #ca8a0488; color: #fde68a; }
.stat-pill.warn strong { color: #fde68a; }
.stat-pill.danger { border-color: #f8717166; color: #fecaca; }
.stat-pill.danger strong { color: #fecaca; }
.crm-chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: .32rem .8rem;
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: #64748b; }
.chip.active {
  background: #14532d88;
  border-color: var(--accent);
  color: #bbf7d0;
}
.inbox-strip {
  background: rgba(30,41,59,.7);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .65rem .85rem;
  margin-bottom: .85rem;
}
.inbox-strip h2 { margin: 0 0 .5rem; font-size: .95rem; }
.inbox-item {
  display: grid;
  grid-template-columns: 7.5rem 1fr auto;
  gap: .5rem;
  align-items: center;
  padding: .4rem 0;
  border-top: 1px solid var(--border);
  font-size: .9rem;
}
.inbox-item:first-of-type { border-top: 0; }
.lead-table { width: 100%; }
.lead-row { cursor: pointer; }
.lead-row:hover { background: rgba(34,197,94,.08); }
.lead-row td:last-child { white-space: nowrap; color: var(--muted); }
.cell-sub { color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.crm-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}
.crm-flash {
  position: sticky;
  top: .5rem;
  z-index: 40;
}
.crm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,.62);
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}
.crm-overlay[hidden] { display: none; }
.crm-drawer {
  width: min(440px, 100%);
  height: 100%;
  background: #0f172a;
  border-left: 1px solid var(--border);
  padding: 1.25rem 1.35rem 2rem;
  overflow: auto;
  box-shadow: -16px 0 40px rgba(0,0,0,.35);
}
.crm-drawer h2 { margin: 0; }
.crm-drawer header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.crm-drawer .hint { color: var(--muted); font-size: .9rem; margin: 0 0 1rem; }
.crm-drawer .form { max-width: none; }
body.crm-lock { overflow: hidden; }

.ficha-top { margin-bottom: .35rem; }
.ficha-top a { color: var(--muted); font-size: .9rem; }
.ficha-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.ficha-header h1 { margin: 0 0 .4rem; font-size: 1.65rem; }
.ficha-meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.ficha-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.ficha-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1.15rem;
  align-items: start;
}
.composer {
  background: rgba(30,41,59,.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .85rem;
  margin-bottom: 1rem;
}
.composer-tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .7rem; }
.composer-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: .35rem .65rem;
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.composer-tab.active {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}
.composer textarea, .composer input[type="date"], .composer input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: .65rem .75rem;
  font: inherit;
}
.composer-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  margin-top: .65rem;
  flex-wrap: wrap;
}
.presets { display: flex; gap: .35rem; flex-wrap: wrap; }
.preset {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: .2rem .5rem;
  font: inherit;
  font-size: .78rem;
  cursor: pointer;
}
.preset:hover { color: var(--text); }
.timeline.crm-tl li {
  position: relative;
  padding-left: 1.15rem;
}
.timeline.crm-tl li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: .35rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
}
.timeline.crm-tl li.tl-alta::before,
.timeline.crm-tl li.tl-asignado::before { background: var(--accent); }
.timeline.crm-tl li.tl-llamada::before { background: #38bdf8; }
.timeline.crm-tl li.tl-visita::before { background: #a78bfa; }
.timeline.crm-tl li.tl-solicitud::before { background: #fbbf24; }
.timeline.crm-tl li.tl-descartado::before,
.timeline.crm-tl li.tl-caducado::before { background: var(--danger); }
.prop-card { margin-top: 0; }
.prop-card + .prop-card { margin-top: .85rem; }
.prop-card h2 { margin: 0 0 .75rem; font-size: .95rem; }
.prop-row {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  padding: .4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.prop-row:last-child { border-bottom: 0; }
.prop-row dt { color: var(--muted); }
.prop-row dd { margin: 0; text-align: right; word-break: break-word; }
.alta-mini {
  border-radius: 8px;
  padding: .7rem .8rem;
  font-weight: 700;
  font-size: .85rem;
  margin-bottom: .5rem;
}
.alta-mini.si { background: #14532d99; color: #86efac; }
.alta-mini.no { background: #7f1d1d66; color: #fecaca; }
.remind-item {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  align-items: flex-start;
  padding: .45rem 0;
  border-top: 1px solid var(--border);
  font-size: .85rem;
}
.remind-item:first-of-type { border-top: 0; }
@media (max-width: 960px) {
  .ficha-shell { grid-template-columns: 1fr; }
  .inbox-item { grid-template-columns: 1fr; }
}

/* —— Admin comerciales —— */
a.chip { text-decoration: none; display: inline-flex; align-items: center; }
a.chip:hover { text-decoration: none; }
.admin-tabs {
  display: flex;
  gap: .1rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin: .85rem 0 1.1rem;
}
.admin-tabs a {
  color: var(--muted);
  padding: .7rem .95rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  text-decoration: none;
  font-weight: 600;
  font-size: .92rem;
}
.admin-tabs a:hover { color: var(--text); text-decoration: none; }
.admin-tabs a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.admin-count { color: var(--muted); font-size: .85rem; margin: 0 0 .65rem; }
.money-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem;
}
.money-box .value { font-size: 1.25rem; font-weight: 700; margin-top: .2rem; }
.money-box .label { color: var(--muted); font-size: .8rem; }
.money-box .hint { color: var(--muted); font-size: .75rem; margin-top: .25rem; }
.pago-card {
  background: rgba(30,41,59,.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.15rem;
  margin-top: .85rem;
}
.pago-card.paid { opacity: .96; }
.pago-desglose { width: 100%; font-size: .9rem; margin: .35rem 0 .15rem; }
.pago-desglose th, .pago-desglose td { padding: .35rem .2rem; }
.pago-desglose .label { color: var(--muted); font-size: .8rem; margin-bottom: .25rem; }

.dash-alerts { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1rem 0 0; }
.dash-alert {
  display: inline-block;
  padding: .45rem .75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(30,41,59,.85);
  color: var(--muted);
  font-size: .88rem;
  text-decoration: none;
}
.dash-alert.warn { border-color: #ca8a0488; color: #fde68a; }
.dash-alert strong { color: var(--text); margin-right: .2rem; }
.dash-alert.warn strong { color: #fde68a; }
a.dash-alert:hover { text-decoration: none; color: var(--text); }
.dash-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.dash-bars {
  display: flex;
  align-items: flex-end;
  gap: .35rem;
  height: 140px;
  margin-top: .75rem;
}
.dash-bar-col {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}
.dash-bar-pair {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 100%;
  width: 100%;
  justify-content: center;
}
.dash-bar {
  width: 100%;
  max-width: 22px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 0;
}
.dash-bar-pair .dash-bar { max-width: 12px; }
.dash-bar.alt { background: #64748b; }
.dash-bar-label {
  font-size: .65rem;
  color: var(--muted);
  margin-top: .3rem;
  white-space: nowrap;
}
.legend-dot {
  display: inline-block;
  width: .55rem;
  height: .55rem;
  border-radius: 50%;
  background: #64748b;
  vertical-align: middle;
}
.legend-dot.accent { background: var(--accent); }
.lead-row.rank-top td:first-child strong { color: var(--accent); }
