:root {
  --fondo: #f4f5f2;
  --superficie: #ffffff;
  --borde: #e2e4de;
  --borde-fuerte: #c9ccc3;
  --texto: #1f231d;
  --suave: #6a7066;
  --marca: #3f9a3f;
  --marca-oscura: #2f7a30;
  --marca-tenue: #e8f4e6;
  --rojo: #c23b2e;
  --rojo-tenue: #fbe9e6;
  --ambar: #a86a00;
  --ambar-tenue: #fdf2dc;
  --azul: #2b5fab;
  --azul-tenue: #e6eefa;
  --radio: 8px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--texto);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--fondo); font-size: 14px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ── Botones ── */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--radio); border: 1px solid var(--borde-fuerte); background: var(--superficie); font-weight: 500; white-space: nowrap; }
a.btn { text-decoration: none; color: inherit; }
.btn:hover { background: #f0f1ed; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primario { background: var(--marca); border-color: var(--marca); color: #fff; }
.btn.primario:hover:not(:disabled) { background: var(--marca-oscura); }
.btn.peligro { color: var(--rojo); }
.btn.chico { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-icono { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: var(--radio); border: 1px solid transparent; background: transparent; color: var(--suave); }
.btn-icono:hover { background: #eceee8; color: var(--texto); }
.btn-icono svg { width: 18px; height: 18px; }

/* ── Ingreso ── */
.ingreso { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.ingreso form { width: 100%; max-width: 360px; background: var(--superficie); border: 1px solid var(--borde); border-radius: 14px; padding: 28px; box-shadow: 0 8px 30px rgba(0,0,0,.05); }
.ingreso img { width: 150px; display: block; margin: 0 auto 18px; }
.ingreso h1 { font-size: 18px; margin: 0 0 4px; text-align: center; }
.ingreso p { color: var(--suave); text-align: center; margin: 0 0 20px; font-size: 13px; }
.ingreso input { width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--borde-fuerte); border-radius: var(--radio); margin-bottom: 12px; background: #fff; }
.ingreso input:focus { outline: 2px solid var(--marca); outline-offset: -1px; }
.ingreso .btn { width: 100%; justify-content: center; height: 42px; }
.ingreso .error { color: var(--rojo); font-size: 13px; min-height: 18px; margin: 0 0 8px; text-align: left; }

/* ── Estructura ── */
.app { height: 100%; display: flex; flex-direction: column; }
.barra { display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 56px; background: var(--superficie); border-bottom: 1px solid var(--borde); flex-shrink: 0; }
.barra .logo { height: 30px; }
.barra h1 { font-size: 15px; margin: 0; white-space: nowrap; }
.pestanas { display: flex; gap: 2px; margin-left: 8px; }
.pestana { height: 34px; padding: 0 14px; border: 0; background: transparent; border-radius: var(--radio); color: var(--suave); font-weight: 500; }
.pestana:hover { background: #f0f1ed; color: var(--texto); }
.pestana.activa { background: var(--marca-tenue); color: var(--marca-oscura); }
.pestana .cuenta { margin-left: 4px; font-size: 12px; opacity: .75; }
.barra .derecha { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.guardado { font-size: 12px; color: var(--suave); margin-right: 8px; white-space: nowrap; }

.avisos { padding: 10px 16px 0; display: grid; gap: 6px; }
.aviso { background: var(--ambar-tenue); color: #6b4400; border: 1px solid #f1d9a6; padding: 8px 12px; border-radius: var(--radio); font-size: 13px; }

.vista { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px 16px 16px; gap: 10px; }
.herramientas { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.herramientas .ayuda { color: var(--suave); font-size: 13px; }
.herramientas .espacio { flex: 1; }
.marco-tabla { flex: 1; min-height: 0; overflow: auto; background: var(--superficie); border: 1px solid var(--borde); border-radius: 10px; }

/* ── Hoja ── */
table.hoja { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1908px; table-layout: fixed; }
.hoja th { position: sticky; top: 0; z-index: 2; background: #f8f9f6; border-bottom: 1px solid var(--borde); text-align: left; font-size: 12px; font-weight: 600; color: var(--suave); padding: 8px 6px; white-space: nowrap; }
.hoja td { border-bottom: 1px solid #eef0eb; padding: 0; height: 36px; vertical-align: middle; }
.hoja td + td, .hoja th + th { border-left: 1px solid #eef0eb; }
.hoja tr:hover td { background: #fbfcfa; }
.hoja input[type=text] { width: 100%; height: 35px; border: 0; background: transparent; padding: 0 8px; outline: none; }
.hoja input[type=text]:focus { box-shadow: inset 0 0 0 2px var(--marca); background: #fff; }
.hoja .num { text-align: right; font-variant-numeric: tabular-nums; }
.hoja .centro { text-align: center; }
.hoja input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--marca); cursor: pointer; }
.hoja .indice { color: var(--suave); font-size: 12px; text-align: center; width: 36px; }
.hoja .neto { padding: 0 8px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--suave); }
.hoja tr.con-problema .indice { color: var(--rojo); font-weight: 700; }
.hoja .acciones { width: 76px; text-align: center; white-space: nowrap; }
.vacio { padding: 48px 16px; text-align: center; color: var(--suave); }
.vacio strong { display: block; color: var(--texto); font-size: 15px; margin-bottom: 4px; }

/* ── Enviados ── */
.resumen { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--borde); background: var(--superficie); font-size: 13px; }
.chip.filtro { cursor: pointer; }
.chip.filtro.activo { border-color: var(--texto); }
.chip b { font-variant-numeric: tabular-nums; }
.buscar { height: 34px; padding: 0 12px; border: 1px solid var(--borde-fuerte); border-radius: var(--radio); background: #fff; width: 240px; max-width: 100%; }
table.lista { border-collapse: collapse; width: 100%; min-width: 980px; }
.lista th { position: sticky; top: 0; background: #f8f9f6; border-bottom: 1px solid var(--borde); text-align: left; font-size: 12px; font-weight: 600; color: var(--suave); padding: 8px 10px; white-space: nowrap; }
.lista td { border-bottom: 1px solid #eef0eb; padding: 0 10px; height: 44px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.lista .num { text-align: right; font-variant-numeric: tabular-nums; }
.lista .acciones { text-align: right; }
.lista .suave { color: var(--suave); font-size: 12px; }
.estado { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.estado::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.estado.bien { background: var(--marca-tenue); color: var(--marca-oscura); }
.estado.camino { background: var(--azul-tenue); color: var(--azul); }
.estado.espera { background: var(--ambar-tenue); color: var(--ambar); }
.estado.mal { background: var(--rojo-tenue); color: var(--rojo); }

/* ── Panel lateral ── */
.velo { position: fixed; inset: 0; background: rgba(20,24,18,.35); z-index: 20; }
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--superficie); z-index: 21; display: flex; flex-direction: column; box-shadow: -10px 0 40px rgba(0,0,0,.12); }
.panel header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--borde); }
.panel header h2 { font-size: 16px; margin: 0; }
.panel .cuerpo { flex: 1; overflow: auto; padding: 18px; display: grid; gap: 16px; align-content: start; }
.panel footer { padding: 12px 18px; border-top: 1px solid var(--borde); display: flex; justify-content: flex-end; gap: 8px; }
.campo { display: grid; gap: 6px; }
.campo label { font-size: 13px; font-weight: 600; }
.campo .nota { font-size: 12px; color: var(--suave); }
.campo input, .campo textarea, .campo select { width: 100%; padding: 9px 12px; border: 1px solid var(--borde-fuerte); border-radius: var(--radio); background: #fff; }
.campo textarea { min-height: 150px; resize: vertical; line-height: 1.45; }
.campo input:focus, .campo textarea:focus, .campo select:focus { outline: 2px solid var(--marca); outline-offset: -1px; }
.datos { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.datos dt { color: var(--suave); }
.datos dd { margin: 0; word-break: break-word; }

/* ── Mensajes ── */
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1f231d; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 40; max-width: min(640px, calc(100% - 32px)); white-space: pre-line; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.mal { background: var(--rojo); }
.cargando { position: fixed; inset: 0; background: rgba(255,255,255,.7); z-index: 30; display: grid; place-items: center; font-weight: 600; }
.cargando span { background: var(--superficie); border: 1px solid var(--borde); padding: 14px 20px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.08); }

@media (max-width: 720px) {
  .barra { gap: 8px; padding: 0 12px; }
  .barra h1, .barra .logo, .guardado { display: none; }
  .pestanas { margin-left: 0; }
  .vista { padding: 10px 12px 12px; }
  .herramientas .ayuda { display: none; }
}

/* ── Programación ── */
.interruptor { display: grid; gap: 4px; padding: 12px 14px; border: 1px solid var(--borde); border-radius: var(--radio); background: #fafbf8; }
.interruptor label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.interruptor input { width: 18px; height: 18px; accent-color: var(--marca); }
.interruptor .nota { font-size: 12px; color: var(--suave); }
.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel hr { border: 0; border-top: 1px solid var(--borde); margin: 4px 0; width: 100%; }
.hoja .mes { padding: 0 8px; white-space: nowrap; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.campo select { height: 40px; }
.campo input { height: 40px; }
.hoja input.dia { text-align: center; }
.aviso.apagado { background: #eef0eb; color: var(--texto); border-color: var(--borde); display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.etiqueta-auto { font-size: 11px; color: var(--suave); border: 1px solid var(--borde); border-radius: 4px; padding: 1px 5px; margin-left: 6px; }
