/* ═══════════════════════════════════════════════════════════════
   LOTCOM CRM — main.css
   Tema oscuro técnico. Paleta Lotcom: rojo #E5151A + azul eléctrico #1E90FF
   Tipografía: Rajdhani (display) + Inter (body/UI)
═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;600;700&family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Variables ───────────────────────────────────────────────── */
:root {
  --bg:       #0b1220;
  --bg2:      #111827;
  --bg3:      #1a2540;
  --surface:  #1e293b;
  --surface2: #243047;
  --border:   #2d3e5c;
  --border2:  #3d5275;

  --text:     #e2e8f0;
  --text2:    #94a3b8;
  --text3:    #64748b;

  --red:      #E5151A;
  --red-d:    #b80f13;
  --red-glow: rgba(229,21,26,0.18);
  --blue:     #1E90FF;
  --blue-d:   #1472d1;
  --blue-glow:rgba(30,144,255,0.15);

  --green:    #22c55e;
  --yellow:   #f59e0b;
  --orange:   #f97316;
  --purple:   #a855f7;
  --teal:     #14b8a6;

  --rad:      8px;
  --rad-lg:   12px;
  --shadow:   0 4px 24px rgba(0,0,0,.45);
  --shadow-sm:0 2px 8px rgba(0,0,0,.3);

  --sidebar-w: 220px;
  --header-h:  56px;
  --font-display: 'Rajdhani', sans-serif;
  --font-body:    'Inter', sans-serif;
}

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.sidebar-locked { overflow: hidden; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: var(--font-body); font-size: 14px; }
button { cursor: pointer; border: none; background: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.nav-item, .tab, .folio-link, .btn, .card, .kpi-card { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ════════════════════════════════════════════════════════════════
   LOGIN PAGE
════════════════════════════════════════════════════════════════ */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 40% 50%, #0f2040 0%, var(--bg) 70%);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rad-lg);
  padding: 40px 36px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo img { height: 48px; }
.login-logo h1 {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 700;
  color: var(--text); margin-top: 10px;
}
.login-logo span { color: var(--red); }
.login-sub { color: var(--text2); font-size: 12px; text-align: center; margin-top: 2px; }

/* ════════════════════════════════════════════════════════════════
   LAYOUT PRINCIPAL
════════════════════════════════════════════════════════════════ */
#app { display: none; }
#app.logged-in { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

/* ── Header ──────────────────────────────────────────────────── */
.crm-header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; gap: 12px;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  position: sticky; top: 0; z-index: 100;
  flex-shrink: 0;
}
.header-logo {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-size: 18px; font-weight: 700;
  color: var(--text); letter-spacing: .5px;
  min-width: 0;
}
.menu-toggle { display: none; flex-shrink: 0; }
.header-logo img { height: 30px; }
.header-logo .logo-sep { color: var(--border2); font-weight: 300; }
.header-logo .crm-badge {
  font-size: 10px; font-weight: 600; font-family: var(--font-body);
  background: var(--red); color: #fff;
  padding: 2px 7px; border-radius: 4px; letter-spacing: 1px;
}
.header-spacer { flex: 1; }
.header-notif {
  position: relative;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; transition: background .2s;
  color: var(--text2); font-size: 18px;
}
.header-notif:hover { background: var(--surface); cursor: pointer; }
.notif-badge {
  position: absolute; top: 4px; right: 4px;
  background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
  display: none;
}
.notif-badge.show { display: flex; }
.header-user {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px; border-radius: var(--rad);
  cursor: pointer; transition: background .2s;
}
.header-user:hover { background: var(--surface); }
.header-user .uname { font-size: 13px; font-weight: 500; }
.header-user .urole { font-size: 11px; color: var(--text2); }
.header-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--red); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}

/* ── Main body ───────────────────────────────────────────────── */
.crm-body { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.crm-sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto; overflow-x: hidden;
  flex-shrink: 0;
  padding: 12px 0 calc(20px + env(safe-area-inset-bottom, 0px));
  transition: width .25s;
}
.nav-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1.2px;
  color: var(--text3); text-transform: uppercase;
  padding: 14px 18px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px; font-size: 13px; font-weight: 500;
  color: var(--text2); cursor: pointer;
  border-left: 3px solid transparent;
  transition: all .15s;
  user-select: none;
}
.nav-item:hover  { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--surface); color: var(--text); border-left-color: var(--red); }
.nav-item .nav-icon { font-size: 16px; flex-shrink: 0; opacity: .8; }
.nav-item.active .nav-icon { opacity: 1; }

/* ── Backdrop del sidebar (móvil) ────────────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 199;
  background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}

/* ── Contenido principal ─────────────────────────────────────── */
.crm-main {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 24px;
  background: var(--bg);
}

/* ── Page header ─────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-title {
  font-family: var(--font-display);
  font-size: 24px; font-weight: 700; color: var(--text);
  letter-spacing: .3px;
}
.page-title span { color: var(--red); }
.page-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ════════════════════════════════════════════════════════════════
   COMPONENTES UI
════════════════════════════════════════════════════════════════ */

/* ── Botones ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--rad);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .15s; user-select: none; border: 1px solid transparent;
  white-space: nowrap;
}
.btn-primary   { background: var(--red);  color: #fff; }
.btn-primary:hover { background: var(--red-d); }
.btn-blue      { background: var(--blue); color: #fff; }
.btn-blue:hover { background: var(--blue-d); }
.btn-outline   { background: transparent; color: var(--text2); border-color: var(--border2); }
.btn-outline:hover { border-color: var(--text2); color: var(--text); }
.btn-ghost     { background: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--surface); color: var(--text); }
.btn-success   { background: var(--green); color: #fff; }
.btn-warning   { background: var(--yellow); color: #0b1220; }
.btn-danger    { background: #dc2626; color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn-icon { padding: 7px; border-radius: var(--rad); }

/* ── Cards / Superficies ─────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rad-lg);
  padding: 20px;
}
.card-title {
  font-family: var(--font-display); font-size: 16px; font-weight: 600;
  color: var(--text); margin-bottom: 16px;
}

/* ── KPI cards ───────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--rad-lg); padding: 16px 18px;
  cursor: default; transition: border-color .2s;
}
.kpi-card:hover { border-color: var(--border2); }
.kpi-card.accent-red  { border-top: 3px solid var(--red); }
.kpi-card.accent-blue { border-top: 3px solid var(--blue); }
.kpi-card.accent-green{ border-top: 3px solid var(--green); }
.kpi-card.accent-yellow{border-top: 3px solid var(--yellow);}
.kpi-card.accent-purple{border-top: 3px solid var(--purple);}
.kpi-card.accent-teal  {border-top: 3px solid var(--teal);}
.kpi-val {
  font-family: var(--font-display); font-size: 32px; font-weight: 700;
  color: var(--text); line-height: 1.1;
}
.kpi-val.red    { color: var(--red); }
.kpi-val.blue   { color: var(--blue); }
.kpi-val.green  { color: var(--green); }
.kpi-val.yellow { color: var(--yellow); }
.kpi-val.purple { color: var(--purple); }
.kpi-label { font-size: 11px; color: var(--text2); margin-top: 4px; }

/* ── Alertas ─────────────────────────────────────────────────── */
.alerts-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--rad);
  font-size: 12px; font-weight: 500;
}
.alert-warning { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3); color: #fbbf24; }
.alert-danger  { background: rgba(229,21,26,.1);   border: 1px solid rgba(229,21,26,.25); color: #f87171; }
.alert-info    { background: rgba(30,144,255,.1);   border: 1px solid rgba(30,144,255,.25);color: #60a5fa; }

/* ── Pipeline kanban ─────────────────────────────────────────── */
.pipeline-scroll { overflow-x: auto; margin-bottom: 24px; padding-bottom: 8px; }
.pipeline-track {
  display: flex; gap: 8px;
  min-width: max-content;
}
.pipeline-col {
  min-width: 130px; max-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rad-lg);
  padding: 12px 14px;
  text-align: center;
  transition: border-color .2s;
}
.pipeline-col:hover { border-color: var(--border2); }
.pipeline-col-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text2); margin-bottom: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pipeline-col-count {
  font-family: var(--font-display); font-size: 28px; font-weight: 700;
  color: var(--text);
}
.pipeline-col.pl-nueva     { border-bottom: 2px solid var(--blue);  }
.pipeline-col.pl-contactado{ border-bottom: 2px solid #06b6d4;     }
.pipeline-col.pl-programado{ border-bottom: 2px solid var(--teal); }
.pipeline-col.pl-realizado { border-bottom: 2px solid var(--green);}
.pipeline-col.pl-cot-pend  { border-bottom: 2px solid var(--yellow);}
.pipeline-col.pl-cot-env   { border-bottom: 2px solid var(--orange);}
.pipeline-col.pl-cot-acep  { border-bottom: 2px solid #84cc16;    }
.pipeline-col.pl-cerrado   { border-bottom: 2px solid var(--green);}
.pipeline-col.pl-facturado { border-bottom: 2px solid var(--purple);}
.pipeline-col.pl-perdido   { border-bottom: 2px solid #ef4444;    }

/* ── Tablas ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--surface2); }
thead th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text2); white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .12s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 11px 14px; color: var(--text); vertical-align: middle; }
.folio-link {
  color: var(--blue); font-weight: 700; cursor: pointer;
  font-family: var(--font-body); font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 12px; border-radius: 8px;
  background: rgba(30,144,255,.10); border: 1px solid rgba(30,144,255,.22);
  line-height: 1.2; transition: background .12s, border-color .12s;
}
.folio-link:hover { background: rgba(30,144,255,.20); text-decoration: none; }
.folio-link:active { background: rgba(30,144,255,.28); }

/* ── Badges de estatus / prioridad ───────────────────────────── */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-nueva    { background: rgba(30,144,255,.15); color: var(--blue); }
.badge-contactado{background:rgba(6,182,212,.15);  color: #22d3ee; }
.badge-programado{background:rgba(20,184,166,.15); color: var(--teal);}
.badge-realizado { background: rgba(34,197,94,.15); color: var(--green);}
.badge-cotpend  { background: rgba(245,158,11,.15); color: var(--yellow);}
.badge-cotenv   { background: rgba(249,115,22,.15); color: var(--orange);}
.badge-cotacep  { background: rgba(132,204,22,.15); color: #84cc16; }
.badge-cerrado  { background: rgba(34,197,94,.2);   color: var(--green);}
.badge-facturado{ background: rgba(168,85,247,.15); color: var(--purple);}
.badge-perdido  { background: rgba(239,68,68,.15);  color: #ef4444; }
.badge-alta     { background: rgba(239,68,68,.15);  color: #f87171; }
.badge-urgente  { background: rgba(229,21,26,.2);   color: var(--red);}
.badge-media    { background: rgba(245,158,11,.15); color: var(--yellow);}
.badge-baja     { background: rgba(100,116,139,.15);color: var(--text2);}

/* Chip de estatus clickeable (select nativo con apariencia de badge) —
   usado en la tabla de Solicitudes para cambiar la etapa sin abrir modal */
.chip-select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  border: none; cursor: pointer; font-family: inherit;
  padding: 2px 22px 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23ffffff' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round' opacity='.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
  transition: filter .15s;
}
.chip-select:hover { filter: brightness(1.25); }
.chip-select:focus { outline: none; box-shadow: 0 0 0 2px var(--blue-glow); }
.chip-select option { background: var(--surface); color: var(--text); font-weight: 500; }

/* ── Formularios ─────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }
.form-label { font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .6px; }
.form-input, .form-select, .form-textarea {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 8px 12px;
  border-radius: var(--rad); font-size: 13px;
  transition: border-color .15s;
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-glow);
}
.form-input::placeholder { color: var(--text3); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-select option { background: var(--surface); }
.form-hint { font-size: 11px; color: var(--text3); margin-top: 3px; }
.form-error { font-size: 11px; color: #f87171; margin-top: 3px; }
.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--red); cursor: pointer; }

/* ── Modales ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.65); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--rad-lg);
  width: 100%; max-width: 680px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
  padding: 28px;
  position: relative;
}
.modal-box.modal-sm { max-width: 420px; }
.modal-box.modal-lg { max-width: 900px; }
.modal-box.modal-xl { max-width: 1100px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
}
.modal-title { font-family: var(--font-display); font-size: 19px; font-weight: 700; }
.modal-close {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2); font-size: 18px; cursor: pointer;
  transition: all .15s;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 24px; padding-top: 18px;
  border-top: 1px solid var(--border);
}

/* ── Filtros ─────────────────────────────────────────────────── */
.filters-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-input {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 7px 12px;
  border-radius: var(--rad); font-size: 13px; min-width: 180px;
}
.filter-input:focus { outline: none; border-color: var(--blue); }
.filter-select {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 7px 10px;
  border-radius: var(--rad); font-size: 12px;
}
.filter-select:focus { outline: none; }

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 9px 16px; font-size: 13px; font-weight: 500; color: var(--text2);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all .15s; white-space: nowrap; flex-shrink: 0;
}
.tab:hover  { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--red); }

/* ── Toast ───────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--rad); padding: 12px 18px;
  font-size: 13px; display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow);
  transform: translateY(20px); opacity: 0;
  transition: all .25s;
  pointer-events: none; max-width: 360px;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.toast-ok   { border-left: 3px solid var(--green); }
#toast.toast-err  { border-left: 3px solid var(--red);   }
#toast.toast-warn { border-left: 3px solid var(--yellow);}

/* ── Cotizaciones — constructor ──────────────────────────────── */
.cot-item-row {
  display: grid;
  grid-template-columns: 1fr 65px 50px 95px 75px 55px 28px;
  gap: 6px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.cot-item-row:last-child { border-bottom: none; }
.cot-header-row { padding: 0 0 6px; margin-bottom: 4px; }
.cot-totals { text-align: right; padding-top: 12px; }
.cot-totals .tot-row { display: flex; justify-content: flex-end; gap: 16px; padding: 3px 0; font-size: 13px; }
.cot-totals .tot-row.total-row { font-size: 16px; font-weight: 700; color: var(--text); border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }
.cot-totals .tot-label { color: var(--text2); }
.cot-totals .tot-val   { min-width: 100px; text-align: right; }

/* ── Calculadora márgenes ────────────────────────────────────── */
.calc-margen {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--rad-lg); padding: 16px;
}
.calc-margen h3 {
  font-family: var(--font-display); font-size: 15px; font-weight: 600;
  margin-bottom: 14px; color: var(--text2);
}
.calc-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; font-size: 13px; }
.calc-row .calc-lbl { color: var(--text2); }
.calc-ganancia {
  font-family: var(--font-display); font-size: 22px; font-weight: 700;
  padding: 10px 0 6px;
}
.calc-ganancia.pos { color: var(--green); }
.calc-ganancia.neg { color: var(--red); }

/* ── Stepper pipeline ────────────────────────────────────────── */
.stepper {
  display: flex; align-items: flex-start; gap: 0;
  overflow-x: auto; padding-bottom: 4px; margin-bottom: 20px;
}
.step {
  display: flex; flex-direction: column; align-items: center;
  min-width: 80px; flex: 1;
}
.step-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border2); background: var(--bg2);
  transition: all .2s; z-index: 1;
}
.step.done  .step-dot { background: var(--green); border-color: var(--green); }
.step.active .step-dot { background: var(--red); border-color: var(--red); box-shadow: 0 0 0 3px var(--red-glow); }
.step-line {
  height: 2px; flex: 1; background: var(--border);
  margin-top: 6px; align-self: flex-start;
  transition: background .2s;
}
.step.done ~ .step .step-line { background: var(--green); }
.step-label { font-size: 9px; color: var(--text3); text-align: center; margin-top: 5px; white-space: nowrap; }
.step.active .step-label { color: var(--text); }

/* ── Empty states ────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 48px 20px; color: var(--text2);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; opacity: .4; }
.empty-state h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.empty-state p  { font-size: 13px; color: var(--text3); }

/* ── Separadores ─────────────────────────────────────────────── */
.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Helpers ─────────────────────────────────────────────────── */
.mt-8  { margin-top: 8px;  } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom: 8px;  } .mb-16 { margin-bottom: 16px; }
.flex  { display: flex; } .flex-col { flex-direction: column; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.text-red { color: var(--red); } .text-blue { color: var(--blue); }
.text-green { color: var(--green); } .text-yellow { color: var(--yellow); }
.text-sm  { font-size: 12px; } .text-xs { font-size: 11px; }
.text-muted { color: var(--text2); } .fw-600 { font-weight: 600; }
.mono { font-family: 'Courier New', monospace; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Loading spinner ─────────────────────────────────────────── */
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--red);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
  position: absolute; inset: 0; background: rgba(11,18,32,.7);
  display: flex; align-items: center; justify-content: center;
  border-radius: inherit; z-index: 10;
}

/* ── Sección Perfil ──────────────────────────────────────────── */
.profile-avatar-lg {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--red); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 28px; font-weight: 700;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Tablets y móviles
   ══════════════════════════════════════════════════════════════ */

/* ── Tablets / móvil en general (≤768px) ─────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  .menu-toggle { display: flex; }

  /* Sidebar como cajón deslizante con backdrop */
  .crm-sidebar {
    position: fixed; left: -280px; top: var(--header-h);
    height: calc(100vh - var(--header-h)); height: calc(100dvh - var(--header-h));
    z-index: 200; transition: left .25s ease;
    width: 260px; max-width: 82vw;
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  .crm-sidebar.open { left: 0; }
  .sidebar-backdrop.open { display: block; opacity: 1; pointer-events: all; }

  /* Header: logo compacto, prioriza espacio para el botón de menú */
  .crm-header { padding: 0 10px; gap: 8px; }
  .header-logo { font-size: 15px; gap: 6px; overflow: hidden; }
  .header-logo .logo-sep { display: none; }
  .header-user { padding: 4px 6px; }
  .header-user .urole { display: none; }
  .header-user .uname { max-width: 32vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .crm-main { padding: 16px; }
  .crm-body { position: relative; }

  /* Grids que colapsan a una sola columna en pantallas angostas */
  .form-grid { grid-template-columns: 1fr; }
  .form-grid.cols-3 { grid-template-columns: 1fr; }
  .form-group.span-2, .form-group.span-3 { grid-column: span 1; }
  .grid-2 { grid-template-columns: 1fr; }
  .visita-detail .span-2 { grid-column: span 1; }
  .calc-margen .form-grid,
  .calc-margen .grid-2 { grid-template-columns: 1fr 1fr; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }

  /* Filtros: la búsqueda ocupa todo el ancho disponible */
  .filters-bar { gap: 8px; }
  .filter-input { min-width: 0; flex: 1 1 100%; }
  .filter-select { flex: 1 1 auto; }

  /* Tablas con scroll horizontal suave */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  table { font-size: 12px; }
  thead th, tbody td { padding: 9px 10px; }

  /* Pipeline y stepper: scroll táctil */
  .pipeline-scroll, .stepper { -webkit-overflow-scrolling: touch; }

  /* Modales: casi pantalla completa, menos padding */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box {
    max-width: 100% !important; width: 100%;
    max-height: 92vh; max-height: 92dvh;
    border-radius: var(--rad-lg) var(--rad-lg) 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1 1 auto; min-width: 120px; }

  /* Footer de cotización: siempre 2 arriba y 2 abajo en móvil */
  .modal-footer.cot-footer-4btn {
    display: grid; grid-template-columns: 1fr 1fr; flex-wrap: unset;
  }
  .modal-footer.cot-footer-4btn .btn { width: 100%; min-width: 0; }

  /* Cotizaciones: filas de partida se acomodan en una mini-cuadrícula */
  .cot-header-row { display: none; }
  .cot-item-row {
    grid-template-columns: 1fr 1fr 1fr;
    row-gap: 6px;
  }
  .cot-item-row > *:first-child { grid-column: 1 / span 2; }
  .cot-item-row > *:last-child  { grid-column: 3; justify-self: end; }

  /* Panel de notificaciones no debe desbordar pantallas angostas */
  #notif-panel { width: calc(100vw - 24px) !important; max-width: 320px; right: 12px !important; left: auto; }

  #toast { left: 16px; right: 16px; max-width: none; bottom: 16px; }
}

/* ── Teléfonos pequeños (≤480px) ──────────────────────────────── */
@media (max-width: 480px) {
  .crm-main { padding: 12px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi-val { font-size: 26px; }
  .card { padding: 16px; }
  .calc-margen .form-grid,
  .calc-margen .grid-2 { grid-template-columns: 1fr; }
  .modal-footer { flex-direction: column; }
  .modal-footer .btn { width: 100%; }
  .modal-footer.cot-footer-4btn { display: grid; grid-template-columns: 1fr 1fr; flex-direction: unset; }
  .header-logo img { height: 24px; } /* logo más compacto en pantallas pequeñas */
}

/* ── Objetivos táctiles: cualquier dispositivo sin hover preciso ─ */
@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; padding: 7px 12px; }
  .btn-icon { min-width: 40px; min-height: 40px; }
  .folio-link { min-height: 40px; min-width: 64px; padding: 9px 16px; font-size: 13px; }
  .nav-item { padding: 12px 18px; font-size: 14px; }
  .tab { padding: 12px 16px; }
  .modal-close { width: 36px; height: 36px; }
  .lightbox-close { width: 44px; height: 44px; }
  .form-check input[type=checkbox] { width: 20px; height: 20px; }
  /* Evita que iOS haga zoom automático al enfocar campos con fuente <16px
     (usa !important porque varios inputs traen font-size inline en el HTML generado) */
  .form-input, .form-select, .form-textarea, .filter-input, .filter-select { font-size: 16px !important; }
}


/* ── Notificación item hover ─────────────────────────────────── */
.notif-item:hover { background: var(--bg3) !important; }

/* ── Calculadora márgenes expandida ─────────────────────────── */
.calc-margen .form-grid {
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.calc-margen .form-group { margin-bottom: 8px; }
.calc-margen .form-label { font-size: 11px; margin-bottom: 3px; }
.calc-margen .form-input  { font-size: 12px; padding: 6px 8px; }

/* ── Historial de visitas cliente ───────────────────────────── */
.visita-item { transition: none; }
.visita-item .visita-detail { border-top: 1px solid var(--border); }
.visita-detail .span-2 { grid-column: span 2; }

/* ── Cronómetro display ──────────────────────────────────────── */
#crono-display { transition: color .3s; }

/* ── Recordatorios ───────────────────────────────────────────── */
#rec-list-* input[type="checkbox"] { cursor: pointer; }

/* ── Modal size medium ───────────────────────────────────────── */
.modal-md { max-width: 600px; }

/* ── Autocomplete dropdown ──────────────────────────────────── */
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-top: none;
  border-radius: 0 0 var(--rad) var(--rad);
  box-shadow: var(--shadow);
  z-index: 500;
  max-height: 220px;
  overflow-y: auto;
}
.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--bg3); }
.autocomplete-item strong { color: var(--text); }

/* ── Modal size medium (600px) ──────────────────────────────── */
.modal-md { max-width: 620px !important; }

/* ── Cronómetro resumen modal ───────────────────────────────── */
#crono-display { transition: color .3s; letter-spacing: 1px; }

/* ══════════════════════════════════════════════════════════════
   CALCULADORA DE PRECIO FINAL — Modulo independiente
   ══════════════════════════════════════════════════════════════ */

/* Contenedor principal */
.calc-margen {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--rad-lg);
  padding: 16px;
}
.calc-margen h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

/* Inputs compactos */
.calc-margen .form-group  { margin-bottom: 8px; }
.calc-margen .form-label  { font-size: 11px; margin-bottom: 3px; color: var(--text2); }
.calc-margen .form-input,
.calc-margen .form-select { font-size: 12px; padding: 6px 8px; }

/* Bloque de seccion del desglose */
.cm-bloque {
  margin-bottom: 6px;
}

/* Fila del desglose */
.cm-step {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.cm-step:last-child { border-bottom: none; }

.cm-step-label {
  color: var(--text2);
}
.cm-step-val {
  font-weight: 600;
  color: var(--text);
  min-width: 88px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Subtitulo de bloque */
.cm-subtitulo {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text3);
  padding: 6px 0 2px;
  border-bottom: none !important;
}

/* Fila de total de bloque (negrita) */
.cm-total-bloque .cm-step-label { font-weight: 600; color: var(--text); }
.cm-total-bloque .cm-step-val   { font-weight: 700; }

/* Subtotal separador */
.cm-subtotal-row {
  border-top: 1px solid var(--border2);
  border-bottom: 1px solid var(--border2);
  padding: 5px 0;
  margin: 4px 0;
}
.cm-subtotal-row .cm-step-label { font-weight: 700; color: var(--text); }
.cm-subtotal-row .cm-step-val   { font-size: 14px; font-weight: 700; }

/* Valor ganancia */
.cm-ganancia-val { transition: color .2s; }

/* Caja precio final */
.cm-precio-final-box {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--rad-lg);
  padding: 14px 16px;
  text-align: center;
  margin-top: 10px;
}
.cm-precio-final-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text3);
  margin-bottom: 4px;
}
.cm-precio-final-monto {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 900;
  color: var(--green);
  transition: color .2s;
}
.cm-margen-real {
  font-size: 11px;
  color: var(--text2);
  margin-top: 6px;
}
.cm-margen-real strong { transition: color .2s; }

/* ── Galería de fotos de levantamiento ───────────────────────── */
.foto-gallery { display: flex; flex-wrap: wrap; gap: 8px; }
.foto-thumb {
  width: 76px; height: 76px; border-radius: var(--rad);
  overflow: hidden; border: 1px solid var(--border2);
  cursor: pointer; position: relative; flex-shrink: 0;
  transition: transform .15s, border-color .15s;
}
.foto-thumb:hover { transform: scale(1.04); border-color: var(--blue); }
.foto-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.lightbox-overlay {
  position: fixed; inset: 0; z-index: 700;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; cursor: zoom-out;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.lightbox-overlay.open { opacity: 1; pointer-events: all; }
.lightbox-overlay img {
  max-width: 90vw; max-height: 90vh;
  border-radius: var(--rad); box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.lightbox-close {
  position: absolute; top: 20px; right: 24px;
  color: #fff; font-size: 28px; cursor: pointer; line-height: 1;
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: rgba(255,255,255,.1);
}
.lightbox-close:hover { background: rgba(255,255,255,.2); }

/* ── Cliente detalle — sub-tabs y bloques de sucursal ────────── */
.cli-tabs { margin-bottom: 16px; }
.sucursal-block {
  border: 1px solid var(--border); border-radius: var(--rad-lg);
  margin-bottom: 12px; overflow: hidden;
}
.sucursal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; background: var(--bg2); cursor: pointer;
}
.sucursal-header:hover { background: var(--bg3); }
.sucursal-body { padding: 12px 14px; background: var(--bg3); }
/* ── Banners PWA: instalar app / activar notificaciones ────────── */
#pwa-banners { position: fixed; left: 0; right: 0; bottom: 0; z-index: 500; display: flex; flex-direction: column; gap: 1px; }
.pwa-banner {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 16px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-size: 13px; color: var(--text); box-shadow: 0 -4px 16px rgba(0,0,0,.3);
  animation: pwaSlideUp .25s ease;
}
.pwa-banner-actions { display: flex; gap: 8px; flex-shrink: 0; }
@keyframes pwaSlideUp { from { transform: translateY(100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@media (max-width: 480px) { .pwa-banner { font-size: 12px; } }