/* =====================================================================================
   CRM Hornyt — estilos base (P0). Variables, shell, componentes comunes.
   P6 y P7 añaden sdr/sdr.css y gestion/gestion.css (cargarEstilo de lib/ui.js).
   Pensado para 1366×768 como mínimo cómodo.
   ===================================================================================== */
:root {
  --fondo: #f5f6f8;
  --superficie: #ffffff;
  --superficie-2: #f0f1f4;
  --borde: #dfe2e8;
  --texto: #1d2230;
  --texto-2: #5b6275;
  --marca: #d6336c;
  --marca-osc: #b02658;
  --primario: #2f5bd8;
  --primario-osc: #2449b3;
  --ok: #1f9d55;
  --aviso: #c77700;
  --error: #c92a2a;
  --caliente: #e03131;
  --tibio: #f08c00;
  --frio: #4c6ef5;
  --radio: 8px;
  --sombra: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .06);
  --fuente: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ancho-lateral: 216px;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--fuente); color: var(--texto); background: var(--fondo); line-height: 1.45; }
a { color: var(--primario); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.sutil { color: var(--texto-2); font-size: .9em; }
[hidden] { display: none !important; }

/* ----- Marco ----- */
.marco { display: flex; height: 100vh; overflow: hidden; }
.lateral { width: var(--ancho-lateral); flex: 0 0 var(--ancho-lateral); background: #1d2230; color: #d7dbe6; display: flex; flex-direction: column; }
.marca { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; padding: 1rem 1rem .75rem; color: #fff; }
.marca-grande { color: var(--texto); font-size: 1.5rem; padding: 0 0 .5rem; }
.marca-punto { width: 12px; height: 12px; border-radius: 50%; background: var(--marca); display: inline-block; }
.menu { flex: 1; overflow-y: auto; padding: .25rem .5rem; }
.menu-grupo { margin-bottom: .75rem; }
.menu-titulo { text-transform: uppercase; font-size: .7rem; letter-spacing: .06em; color: #8a91a6; padding: .4rem .6rem .2rem; }
.menu-enlace { display: block; color: #d7dbe6; padding: .42rem .6rem; border-radius: 6px; }
.menu-enlace:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.menu-enlace.activo { background: rgba(214, 51, 108, .22); color: #fff; }
.lateral-pie { border-top: 1px solid rgba(255, 255, 255, .08); padding: .75rem 1rem; }
.lateral-pie .sutil { color: #8a91a6; }
.lateral-pie .btn-enlace { color: #c9cede; padding-left: 0; }
.usuario-nombre { font-weight: 600; color: #fff; }

.principal { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.superior { height: 52px; flex: 0 0 52px; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0 1rem; background: var(--superficie); border-bottom: 1px solid var(--borde); }
.superior-derecha { display: flex; align-items: center; gap: .75rem; }
.contenido { flex: 1; overflow-y: auto; padding: 1.1rem 1.25rem 2rem; outline: none; }
.pagina { max-width: 1400px; }
.reloj { display: flex; align-items: center; gap: .5rem; color: var(--texto-2); font-variant-numeric: tabular-nums; }

/* ----- Búsqueda y desplegables ----- */
.busqueda { position: relative; flex: 0 1 420px; }
.busqueda-entrada { width: 100%; }
.desplegable { position: absolute; right: 0; top: calc(100% + 6px); width: 360px; max-height: 70vh; overflow-y: auto; background: var(--superficie);
  border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); z-index: 50; }
.desplegable-izq { left: 0; right: auto; width: 100%; }
.desplegable-cabecera { display: flex; justify-content: space-between; align-items: center; padding: .6rem .75rem; border-bottom: 1px solid var(--borde); }
.notificacion { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--superficie-2);
  padding: .55rem .75rem; cursor: pointer; font: inherit; color: inherit; }
.notificacion:hover { background: var(--superficie-2); }
.notificacion.no-leida { border-left: 3px solid var(--marca); background: #fff5f8; }
.campana-zona { position: relative; }
.campana { position: relative; }
.campana-contador { position: absolute; top: -4px; right: -6px; background: var(--marca); color: #fff; border-radius: 10px; font-size: .7rem;
  padding: 0 5px; min-width: 18px; text-align: center; line-height: 18px; }

/* ----- Botones ----- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; border: 1px solid var(--borde); background: var(--superficie);
  color: var(--texto); border-radius: 6px; padding: .4rem .8rem; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--superficie-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primario { background: var(--primario); border-color: var(--primario); color: #fff; }
.btn-primario:hover { background: var(--primario-osc); }
.btn-peligro { background: var(--error); border-color: var(--error); color: #fff; }
.btn-peligro:hover { filter: brightness(.92); background: var(--error); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-enlace { border: 0; background: none; color: var(--primario); padding: .2rem .4rem; cursor: pointer; font: inherit; }
.btn-pequeno { padding: .2rem .5rem; font-size: .85rem; }
.btn-bloque { width: 100%; }
.btn-icono { border: 0; background: none; cursor: pointer; font-size: 1.25rem; line-height: 1; padding: .3rem .45rem; border-radius: 6px; color: var(--texto-2); }
.btn-icono:hover { background: var(--superficie-2); }
.grupo-botones { display: flex; flex-wrap: wrap; gap: .35rem; }

/* ----- Formularios ----- */
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--borde); border-radius: 6px; padding: .4rem .55rem; background: #fff; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid rgba(47, 91, 216, .35); outline-offset: 1px; border-color: var(--primario); }
.formulario { display: grid; gap: .7rem; }
.formulario-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem 1rem; }
.campo { display: flex; flex-direction: column; gap: .25rem; }
.campo label { font-weight: 600; font-size: .9rem; }
.campo-check { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: .5rem; }
.campo .ayuda { color: var(--texto-2); }
.campo.con-error input, .campo.con-error select, .campo.con-error textarea { border-color: var(--error); background: #fff5f5; }
.obligatorio { color: var(--error); }

/* ----- Tarjetas, avisos, insignias ----- */
.tarjeta { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: .9rem 1rem; box-shadow: var(--sombra); }
.rejilla { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.aviso { background: #eef3ff; border: 1px solid #cfdcff; color: #24407f; border-radius: var(--radio); padding: .65rem .85rem; margin: .5rem 0; white-space: pre-line; }
.aviso-error { background: #fff0f0; border-color: #ffc9c9; color: #8a1c1c; }
.aviso-ok { background: #ebfbee; border-color: #b2f2bb; color: #1b5e2b; }
.insignia { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--superficie-2); color: var(--texto-2); }
.insignia-caliente { background: #ffe3e3; color: var(--caliente); }
.insignia-tibio { background: #fff4e6; color: var(--tibio); }
.insignia-frio { background: #edf2ff; color: var(--frio); }
.insignia-A { background: #d3f9d8; color: #2b8a3e; }
.insignia-B { background: #fff3bf; color: #946800; }
.insignia-C { background: #f1f3f5; color: #495057; }
.insignia-aviso { background: #fff4e6; color: var(--aviso); }
.insignia-ok { background: #ebfbee; color: var(--ok); }
.insignia-error { background: #fff0f0; color: var(--error); }
.vacio { color: var(--texto-2); text-align: center; padding: 1.5rem 1rem; }
.cargando { color: var(--texto-2); padding: 2rem; text-align: center; }

/* ----- Tabla ----- */
.tabla-contenedor { overflow-x: auto; background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); }
.tabla { width: 100%; border-collapse: collapse; }
.tabla th, .tabla td { padding: .5rem .7rem; border-bottom: 1px solid var(--superficie-2); text-align: left; vertical-align: top; }
.tabla th { background: var(--superficie-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--texto-2); position: sticky; top: 0; }
.tabla tr.clicable { cursor: pointer; }
.tabla tr.clicable:hover td { background: #f8f9fc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ----- Tablero (kanban) base ----- */
.tablero { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: .75rem; overflow-x: auto; align-items: start; }
.columna { background: var(--superficie-2); border-radius: var(--radio); padding: .5rem; min-height: 200px; }
.columna-titulo { display: flex; justify-content: space-between; font-weight: 700; padding: .25rem .35rem .5rem; }
.columna.soltar { outline: 2px dashed var(--primario); }

/* ----- Pestañas ----- */
.pestanas { display: flex; gap: .25rem; border-bottom: 1px solid var(--borde); margin-bottom: 1rem; }
.pestana { border: 0; background: none; padding: .55rem .85rem; cursor: pointer; font: inherit; color: var(--texto-2); border-bottom: 2px solid transparent; }
.pestana.activa { color: var(--texto); border-bottom-color: var(--marca); font-weight: 600; }

/* ----- Modal ----- */
.modal-fondo { position: fixed; inset: 0; background: rgba(20, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 1rem; z-index: 100; overflow-y: auto; }
.modal { background: var(--superficie); border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.modal-cabecera { display: flex; justify-content: space-between; align-items: center; padding: .85rem 1rem; border-bottom: 1px solid var(--borde); }
.modal-cabecera h2 { margin: 0; }
.modal-cuerpo { padding: 1rem; max-height: 70vh; overflow-y: auto; }
.modal-pie { display: flex; justify-content: flex-end; gap: .5rem; padding: .75rem 1rem; border-top: 1px solid var(--borde); }

/* ----- Toast ----- */
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; max-width: 420px; }
.toast { background: #1d2230; color: #fff; padding: .65rem .9rem; border-radius: 8px; box-shadow: var(--sombra); white-space: pre-line; transition: opacity .3s, transform .3s; }
.toast-ok { background: #1f7a45; }
.toast-error { background: #a61e1e; }
.toast-aviso { background: #a35f00; }
.toast.saliendo { opacity: 0; transform: translateY(6px); }

/* ----- Login ----- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-caja { width: 100%; max-width: 360px; background: var(--superficie); border: 1px solid var(--borde); border-radius: 12px; padding: 1.75rem; box-shadow: var(--sombra); }

/* ----- Utilidades ----- */
.fila { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.entre { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }

@media (max-width: 1100px) {
  :root { --ancho-lateral: 184px; font-size: 13.5px; }
  .formulario-2 { grid-template-columns: 1fr; }
}
