:root {
  --acento: #4b2a78;
  --acento-2: #efe9f8;
  --texto: #1f1a2b;
  --suave: #6c6480;
  --linea: #e7e2f0;
  --linea-hora: #d3cbe3;
  --linea-dia: #9a87ba;
  --fondo: #f6f4fa;
  --finde: #f8f5ee;
  --hoy: #fff8e1;
  --externa: #efecf4;
  --fila: 22px;
  --panel: 400px;
  --rojo: #b3261e;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--texto);
}
* { box-sizing: border-box; }
body { margin: 0; background: #fff; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
body.login-body { display: grid; overflow: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- botones y campos ---------- */
.btn { border: 1px solid #d9d1e8; background: #fff; border-radius: 8px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--acento-2); }
.btn.primary { background: var(--acento); border-color: var(--acento); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #6a3fa6; }
.btn.danger { color: var(--rojo); border-color: #e8c4c1; }
.btn.danger:hover { background: #fdecea; }
.btn.icon { padding: 4px 10px; font-size: 18px; line-height: 1; }
.btn.small { padding: 3px 8px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=search], input[type=password], input[type=date], input[type=number], input[type=email], input[type=tel], select, textarea {
  border: 1px solid #d9d1e8; border-radius: 8px; padding: 6px 8px; background: #fff; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid #8d63cf; outline-offset: 1px; }
textarea { resize: vertical; width: 100%; }
input[type=checkbox], input[type=radio] { accent-color: var(--acento); }
label { display: block; }
.msg { padding: 8px 10px; border-radius: 8px; margin: 8px 0; }
.msg.err { background: #fdecea; color: var(--rojo); }
.msg.ok { background: #e7f4ea; color: #1e6b33; }
.msg.aviso { background: #fff6dc; color: #6d5200; }
.suave { color: var(--suave); }

/* ---------- login ---------- */
.login-body { background: var(--fondo); display: grid; place-items: center; min-height: 100vh; }
.login { background: #fff; padding: 32px; border-radius: 16px; box-shadow: 0 6px 30px rgba(0,0,0,.08); width: min(360px, 92vw); display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 20px; }
.login label { display: grid; gap: 4px; color: var(--suave); }
.login input { width: 100%; padding: 9px 10px; }

/* ---------- cabecera ---------- */
.top { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: linear-gradient(90deg, #4b2a78, #5b3590); color: #fff; z-index: 30; flex-wrap: wrap; position: relative; box-shadow: 0 1px 3px rgba(30,20,50,.18); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: #fff; text-decoration: none; white-space: nowrap; }
.brand img { border-radius: 8px; box-shadow: 0 0 0 1px rgba(255,255,255,.35); }
.top .btn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.28); color: #fff; }
.top .btn:hover { background: rgba(255,255,255,.24); }
.top select, .top input[type=search] { border-color: transparent; color: var(--texto); background: #fff; }
.top input[type=search]::placeholder { color: #8a819c; }
.top .menu { color: var(--texto); }
.top .menu .btn, .top .menu button { color: var(--texto); }
#centro { font-weight: 600; }
.nav { display: flex; align-items: center; gap: 6px; }
.nav h2 { font-size: 18px; font-weight: 600; margin: 0 0 0 8px; white-space: nowrap; }
.nav h2::first-letter { text-transform: uppercase; }
.vistas { display: flex; border: 1px solid rgba(255,255,255,.28); border-radius: 8px; overflow: hidden; margin-left: auto; }
.vistas button { border: 0; background: transparent; color: #fff; padding: 6px 12px; cursor: pointer; }
.vistas button:hover { background: rgba(255,255,255,.16); }
.vistas button + button { border-left: 1px solid rgba(255,255,255,.28); }
.vistas button.on { background: #fff; color: var(--acento); font-weight: 600; }
#buscar { width: 220px; }
.usuario { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--linea); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 180px; padding: 6px; z-index: 50; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--acento-2); }
.menu form { margin: 0; border-top: 1px solid var(--linea); margin-top: 4px; padding-top: 4px; }

.leyenda { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 6px 14px; border-bottom: 1px solid var(--linea); background: var(--fondo); font-size: 12.5px; }
.leyenda span { display: inline-flex; align-items: center; gap: 5px; }
.chip { display: inline-grid; place-items: center; min-width: 26px; height: 18px; padding: 0 4px; border-radius: 4px; font-weight: 700; font-size: 11px; }

main { flex: 1; overflow: auto; padding: 0 0 30px; }
.cargando { padding: 30px; color: var(--suave); }

/* ---------- rejilla de semana y día ---------- */
.grid { display: grid; user-select: none; position: relative; min-width: 900px; }
.grid-dia { min-width: 0; }
.grid > .h-dia { position: sticky; top: 0; height: 28px; z-index: 6; background: #fff; text-align: center; padding: 4px 2px; font-weight: 600; border-left: 2px solid var(--linea-dia); border-bottom: 1px solid var(--linea); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid > .h-dia::first-letter { text-transform: uppercase; }
.grid > .h-dia:hover { background: var(--acento-2); }
.grid > .h-dia.hoy { background: var(--hoy); }
.grid > .h-dia .num { display: inline-block; min-width: 24px; padding: 1px 5px; border-radius: 12px; }
.grid > .h-dia.hoy .num { background: var(--acento); color: #fff; }
.grid > .h-sala { position: sticky; top: 28px; height: 20px; z-index: 6; background: var(--fondo); text-align: center; font-size: 11.5px; color: var(--suave); border-bottom: 1px solid var(--linea-hora); border-left: 1px solid var(--linea); padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid > .h-sala.dstart { border-left: 2px solid var(--linea-dia); }
.grid > .h-sala.ext { background: var(--externa); font-style: italic; }
.grid > .esquina { position: sticky; top: 0; left: 0; z-index: 7; background: #fff; border-bottom: 1px solid var(--linea-hora); }
.grid > .hora { font-size: 11px; color: var(--suave); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.grid > .cell { border-left: 1px solid var(--linea); border-top: 1px dotted var(--linea); cursor: cell; }
.grid > .cell.hh { border-top: 1px solid var(--linea-hora); }
.grid > .cell.dstart { border-left: 2px solid var(--linea-dia); }
.grid > .cell.finde { background: var(--finde); }
.grid > .cell.hoy { background: var(--hoy); }
.grid > .cell.ext { background: repeating-linear-gradient(135deg, var(--externa) 0 6px, #f9f8fb 6px 12px); }
.grid > .cell:hover { background: #f1ecf8; }
.grid > .banda { background: #f4f1f9; border-left: 1px solid var(--linea); border-bottom: 1px solid var(--linea-hora); cursor: pointer; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 2px; padding: 2px; min-height: 22px; }
.grid > .banda.dstart { border-left: 2px solid var(--linea-dia); }
.grid > .banda .punto { width: 7px; height: 7px; border-radius: 50%; }
.grid > .banda-label { background: #f4f1f9; border-bottom: 1px solid var(--linea-hora); font-size: 11px; color: var(--acento); cursor: pointer; display: grid; place-items: center; text-align: center; line-height: 1.1; font-weight: 600; }
.grid > .banda-label:hover, .grid > .banda:hover { background: var(--acento-2); }
.grid > .cierre { border-top: 2px solid var(--linea-dia); background: var(--fondo); border-radius: 0 0 8px 8px; box-shadow: 0 2px 4px rgba(30,20,50,.06); }
.grid > .plegar { font-size: 11px; color: var(--acento); cursor: pointer; text-align: center; padding: 2px; font-weight: 600; }
.grid > .plegar:hover { background: var(--acento-2); }
.bloque { margin: 1px 1px 0 2px; border-radius: 4px; padding: 1px 3px; overflow: hidden; font-size: 11.5px; line-height: 1.2; cursor: pointer; z-index: 2; position: relative; box-shadow: 0 0 0 1px rgba(0,0,0,.08) inset; min-width: 0; }
.bloque:hover { filter: brightness(.95); z-index: 3; }
.bloque .cod { font-weight: 800; }
.bloque .rep { font-size: 10px; opacity: .8; margin-left: 2px; }
.bloque .txt { display: block; white-space: pre-line; overflow: hidden; }
.bloque .hrs { display: block; font-size: 10.5px; opacity: .85; }
.bloque.cortado { border-top: 2px dashed rgba(0,0,0,.35); }
.bloque.pend { box-shadow: white 0 0 0 2px inset, rgb(0,116,232) 0 0 0 4px inset; }
.bloque.activo { outline: 3px solid #1a73e8; outline-offset: 0; z-index: 4; }
.grid-semana .bloque { text-align: center; padding: 1px 0; }
.grid-semana .bloque .txt, .grid-semana .bloque .hrs { display: none; }
.grid-dia .bloque { font-size: 13px; padding: 3px 6px; }
.sel { background: rgba(75,42,120,.18); border: 2px solid var(--acento); border-radius: 4px; z-index: 5; pointer-events: none; font-size: 11px; color: var(--acento); font-weight: 700; padding: 1px 3px; overflow: hidden; white-space: nowrap; }

/* ---------- mes ---------- */
.mes { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-left: 1px solid var(--linea); }
.mes .dsem { text-align: center; font-size: 12px; color: var(--suave); padding: 6px 0; border-bottom: 1px solid var(--linea); border-right: 1px solid var(--linea); text-transform: capitalize; }
.mdia { border-right: 1px solid var(--linea); border-bottom: 1px solid var(--linea); padding: 4px 6px 6px; cursor: pointer; min-height: 120px; display: flex; flex-direction: column; gap: 3px; }
.mdia:hover { background: #f5f1fb; }
.mdia.otro { background: #fafafa; }
.mdia.otro .mnum { color: #b8b0c6; }
.mdia.finde { background: #fcfbf6; }
.mdia.hoy .mnum { background: var(--acento); color: #fff; }
.mdia .mcab { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.mnum { font-weight: 600; padding: 1px 6px; border-radius: 12px; }
.mdia .manana { font-size: 11px; color: var(--suave); }
.mini { display: grid; flex: 1; min-height: 84px; background: #fff; border: 1px solid var(--linea); border-radius: 4px; gap: 0 2px; padding: 1px; }
.mini > div { border-radius: 2px; min-height: 0; }
.mini > .ext { background: repeating-linear-gradient(135deg, var(--externa) 0 3px, #fff 3px 6px); }
.mlibre { font-size: 11px; color: var(--suave); text-align: right; }

/* ---------- búsqueda y listas ---------- */
.lista { padding: 16px 20px; max-width: 1100px; }
.lista h3 { margin: 0 0 12px; }
table.tabla { border-collapse: collapse; width: 100%; }
.tabla th, .tabla td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--linea); vertical-align: top; }
.tabla th { font-size: 12px; color: var(--suave); font-weight: 600; }
.tabla tr.click { cursor: pointer; }
.tabla tr.click:hover td { background: #f5f1fb; }
.tabla .pre { white-space: pre-line; }
.tabla input[type=text] { width: 100%; }

/* ---------- panel lateral ---------- */
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: var(--panel); max-width: 100vw; background: #fff; box-shadow: -8px 0 30px rgba(0,0,0,.15); z-index: 40; display: flex; flex-direction: column; }
.panel .p-cab { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--linea); }
.panel .p-cab h3 { margin: 0; font-size: 17px; flex: 1; }
.panel .p-cuerpo { padding: 12px 14px; overflow-y: auto; flex: 1; display: grid; gap: 12px; align-content: start; }
.panel .p-pie { padding: 10px 14px; border-top: 1px solid var(--linea); display: flex; gap: 8px; align-items: center; }
.panel .p-pie .der { margin-left: auto; }
.campo > span, .campo > legend { display: block; font-size: 12px; color: var(--suave); margin-bottom: 4px; font-weight: 600; }
.campo { border: 0; padding: 0; margin: 0; min-width: 0; }
.fila2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fila3 { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; }
.fila2 > *, .fila3 > * { min-width: 0; }
.fila2 input, .fila2 select, .fila3 input, .fila3 select { width: 100%; }
.tipos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tipo-btn { display: flex; align-items: center; gap: 6px; border: 2px solid transparent; background: #f4f1f9; border-radius: 8px; padding: 5px 6px; cursor: pointer; text-align: left; font-size: 12.5px; line-height: 1.15; min-width: 0; }
.tipo-btn:hover { background: #ebe4f5; }
.tipo-btn.on { border-color: var(--acento); background: #fff; box-shadow: 0 0 0 1px var(--acento); }
.tipo-btn .chip { flex: none; }
.rep-caja { background: var(--fondo); border-radius: 10px; padding: 10px; display: grid; gap: 10px; }
.rep-caja .cada { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.rep-caja .cada input { width: 60px; }
.dias-sem { display: flex; gap: 4px; }
.dias-sem button { width: 30px; height: 30px; border-radius: 50%; border: 1px solid #d9d1e8; background: #fff; cursor: pointer; font-weight: 600; font-size: 12px; }
.dias-sem button.on { background: var(--acento); color: #fff; border-color: var(--acento); }
.opciones label { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.opciones input[type=date] { padding: 3px 6px; }
.opciones input[type=number] { width: 70px; padding: 3px 6px; }
.vista-previa { font-size: 13px; }
.choques { max-height: 140px; overflow: auto; font-size: 12.5px; margin: 4px 0 0; padding-left: 18px; }
details.mas > summary { cursor: pointer; color: var(--acento); font-weight: 600; font-size: 13px; }
details.mas[open] > summary { margin-bottom: 8px; }
details.mas .campo { margin-bottom: 8px; }
.check { display: flex; align-items: center; gap: 8px; }
.info { font-size: 12px; color: var(--suave); line-height: 1.5; }
.hist { font-size: 12px; margin: 6px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.hist li { border-left: 3px solid var(--linea); padding-left: 8px; }
.serie-info { background: var(--acento-2); border-radius: 8px; padding: 8px 10px; font-size: 13px; }

/* ---------- ventana modal ---------- */
.modal-fondo { position: fixed; inset: 0; background: rgba(30,20,50,.38); display: grid; place-items: center; z-index: 60; }
.modal { background: #fff; border-radius: 14px; padding: 20px; width: min(440px, 92vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); display: grid; gap: 12px; max-height: 90vh; overflow: auto; }
.modal h3 { margin: 0; font-size: 17px; }
.modal .botones { display: flex; justify-content: flex-end; gap: 8px; }
.modal .opciones label { margin: 8px 0; }
.modal .pass { font: 600 20px ui-monospace, Consolas, monospace; background: var(--fondo); padding: 10px; border-radius: 8px; text-align: center; user-select: all; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2a2238; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 70; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; }
.toast.err { background: var(--rojo); }

/* ---------- administración ---------- */
.admin { padding: 16px 20px; max-width: 1100px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--linea); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 14px; cursor: pointer; border-bottom: 3px solid transparent; font-weight: 600; color: var(--suave); }
.tabs button.on { color: var(--acento); border-bottom-color: var(--acento); }
.tarjeta { border: 1px solid var(--linea); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.tarjeta h4 { margin: 0 0 10px; }
.en-linea { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.en-linea input[type=text] { width: 260px; }
.tabla input[type=color] { width: 44px; height: 30px; padding: 0; border: 1px solid #d9d1e8; border-radius: 6px; background: #fff; }
.tabla input.cod { width: 60px; }
.tabla input.ord { width: 60px; }
.tabla td.c { text-align: center; }
.tabla td.acciones { white-space: nowrap; }
.tabla td.acciones .btn + .btn { margin-left: 6px; }
.btn.papelera { padding: 3px 7px; border-color: #e8c4c1; }
.btn.papelera:hover { background: #fdecea; }
.btn.danger-fill { background: var(--rojo); border-color: var(--rojo); color: #fff; font-weight: 600; }
.btn.danger-fill:hover { background: #8f1d17; }
.rojo { color: var(--rojo); }
.opciones select { margin-left: 6px; }
.inactivo td { color: #a39cb0; }

@media (max-width: 1100px) {
  #buscar { width: 150px; }
  .brand span { display: none; }
}
@media print {
  .top, .leyenda, .panel { display: none !important; }
}
