:root {
  --azul: #0265BC;
  --azul-oscuro: #024d91;
  --azul-claro: #eaf3fc;
  --tinta: #142b43;
  --gris: #566a7d;
  --borde: #dce5ee;
  --fondo: #f4f7fa;
  --blanco: #fff;
  --verde: #08783d;
  --rojo: #C62828;
  --amarillo: #F5B632;
  --radio: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Source Sans 3", "Source Sans Pro", Arial, sans-serif;
  font-size: 15px;
  color: var(--tinta);
  background: var(--fondo);
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
label { display: block; font-weight: 600; margin: 16px 0 6px; }
label small { font-weight: 400; color: var(--gris); }
input:not([type=checkbox]):not([type=radio]), textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--borde);
  border-radius: 8px;
  background: var(--blanco);
}
input:focus-visible, textarea:focus-visible, button:focus-visible, .btn:focus-within {
  outline: 3px solid #9cc7ee;
  outline-offset: 1px;
}

/* Marca */
.marca { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.marca__logo {
  display: grid; place-items: center; width: 30px; height: 30px;
  border-radius: 8px; background: var(--azul); color: #fff; font-size: 15px;
}

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 8px 16px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; margin: 0;
}
.btn:disabled { opacity: .55; cursor: progress; }
.btn--primario { background: var(--azul); color: #fff; }
.btn--primario:hover:not(:disabled) { background: var(--azul-oscuro); }
.btn--secundario { background: var(--blanco); border-color: #c9ddec; color: var(--azul-oscuro); }
.btn--secundario:hover { background: var(--azul-claro); }
.btn--peligro { background: var(--blanco); border-color: #f0c4c4; color: var(--rojo); }
.btn--peligro:hover { background: #fdeeee; }
.btn--texto { background: none; color: var(--gris); padding: 8px 10px; }
.btn--texto:hover { color: var(--tinta); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login__caja {
  width: 100%; max-width: 360px; background: var(--blanco); padding: 32px;
  border-radius: 14px; border: 1px solid var(--borde); box-shadow: 0 10px 30px rgba(14,59,101,.07);
}
.login__ayuda { color: var(--gris); margin: 6px 0 8px; }
.login__caja .btn { width: 100%; margin-top: 18px; }
.login__error { color: var(--rojo); min-height: 1.4em; margin: 12px 0 0; }

/* Barra superior */
.panel { min-height: 100%; display: flex; flex-direction: column; }
.barra {
  display: flex; align-items: center; gap: 24px; padding: 10px 20px;
  background: var(--blanco); border-bottom: 1px solid var(--borde);
  position: sticky; top: 0; z-index: 5;
}
.pestanas { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.pestanas button {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border: 0; border-radius: 8px; background: none;
  font-weight: 600; color: var(--gris); cursor: pointer; white-space: nowrap;
}
.pestanas button:hover { background: var(--fondo); color: var(--tinta); }
.pestanas button[aria-selected="true"] { background: var(--azul-claro); color: var(--azul-oscuro); }
.chip { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; letter-spacing: .3px; }
.chip:empty { display: none; }
.chip--on { background: #dcf1e5; color: var(--verde); }
.chip--off { background: #e8edf2; color: var(--gris); }
.chip--pendiente { background: #fff3d6; color: #8a5a00; }

.alerta-rails {
  margin: 12px 20px 0; padding: 10px 14px; border-radius: 8px;
  background: #fff8e6; border: 1px solid #f3dca2; color: #6b4a00; font-size: 14px;
}

/* Área de trabajo */
.trabajo {
  flex: 1; display: grid; grid-template-columns: minmax(340px, 460px) 1fr; gap: 20px; padding: 20px;
}
.editor, .previa {
  background: var(--blanco); border: 1px solid var(--borde); border-radius: 14px; padding: 20px; min-width: 0;
}
.editor__panel > label:first-child { margin-top: 0; }
.acciones { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.acciones--arriba { margin: 0 0 12px; }
.fila { display: flex; gap: 8px; align-items: center; }
.dos-columnas { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Estado */
.estado-aviso, .estado-bloque {
  padding: 12px 14px; border-radius: var(--radio); background: var(--fondo);
  margin-bottom: 16px; font-size: 14px; line-height: 1.5;
}
.estado-aviso strong, .estado-bloque strong { display: block; font-size: 15px; }
.estado--on { background: #edf8f2; border-left: 4px solid var(--verde); }
.estado--off { border-left: 4px solid #b7c4d1; }
.estado--pendiente { background: #fff8e6; border-left: 4px solid var(--amarillo); }

/* Interruptor */
.interruptor { display: flex; align-items: center; gap: 12px; cursor: pointer; margin: 0 0 4px; }
.interruptor input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.interruptor__pista {
  position: relative; width: 46px; height: 26px; border-radius: 99px; background: #c3ced9; transition: background .15s; flex-shrink: 0;
}
.interruptor__pista::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.interruptor input:checked + .interruptor__pista { background: var(--verde); }
.interruptor input:checked + .interruptor__pista::after { transform: translateX(20px); }
.interruptor input:focus-visible + .interruptor__pista { outline: 3px solid #9cc7ee; outline-offset: 2px; }

/* Tipos de aviso */
.tipos { border: 0; padding: 0; margin: 16px 0 0; }
.tipos legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.tipos label { display: inline-flex; align-items: center; gap: 6px; margin: 0 14px 6px 0; font-weight: 400; cursor: pointer; }
.tipo { padding: 3px 10px; border-radius: 6px; font-weight: 600; font-size: 14px; }
.tipo--info { background: #0265BC; color: #fff; }
.tipo--advertencia { background: #F5B632; color: #2b1f00; }
.tipo--urgente { background: #C62828; color: #fff; }

/* Código */
.codigo {
  min-height: 360px; height: 46vh; resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.5;
  white-space: pre; tab-size: 2;
}
.avisos-limpieza { margin: 10px 0 0; padding: 0; list-style: none; font-size: 13.5px; }
.avisos-limpieza li {
  padding: 8px 10px; margin-top: 6px; border-radius: 8px; background: #fff8e6; color: #6b4a00;
}

/* Vista previa */
.previa { display: flex; flex-direction: column; gap: 12px; }
.previa__barra { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.segmentado { display: inline-flex; background: var(--fondo); border-radius: 9px; padding: 3px; }
.segmentado button {
  border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--gris); font-size: 14px;
}
.segmentado button[aria-pressed="true"] { background: var(--blanco); color: var(--tinta); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.segmentado button:disabled { opacity: .4; cursor: not-allowed; }
.previa__marco {
  flex: 1; height: calc(100vh - 230px); min-height: 520px; background: #e9eef3; border-radius: var(--radio); overflow: hidden;
  display: flex; justify-content: center;
}
.previa__marco iframe { width: 100%; height: 100%; min-height: 520px; border: 0; background: #fff; transition: width .2s; }
.previa__marco.celular iframe { width: 390px; max-width: 100%; box-shadow: 0 0 0 1px var(--borde); }
.previa__nota { margin: 0; font-size: 13px; color: var(--gris); }

/* Historial */
.dialogo { border: 0; border-radius: 14px; padding: 24px; width: min(520px, calc(100% - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.dialogo::backdrop { background: rgba(20,43,67,.4); }
.dialogo h2 { margin: 0 0 14px; font-size: 19px; }
.historial { list-style: none; margin: 0 0 18px; padding: 0; max-height: 55vh; overflow: auto; }
.historial li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--borde); }
.historial li:last-child { border-bottom: 0; }
.historial .vacio { color: var(--gris); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  max-width: min(560px, calc(100% - 32px)); padding: 12px 18px; border-radius: 10px;
  background: var(--tinta); color: #fff; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--rojo); }

/* Responsive */
@media (max-width: 960px) {
  .trabajo { grid-template-columns: 1fr; padding: 16px; }
  .barra { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .pestanas { order: 3; flex-basis: 100%; }
  .codigo { height: 300px; min-height: 240px; }
}
@media (max-width: 520px) {
  .dos-columnas { grid-template-columns: 1fr; }
  .editor, .previa { padding: 16px; }
  .alerta-rails { margin: 12px 16px 0; }
}
