:root {
  --fondo: #f4f6f8; --tinta: #212529; --suave: #6c757d; --linea: #dee2e6;
  --lateral: #343a40; --azul: #0d6efd; --verde: #198754; --amarillo: #ffc107; --rojo: #dc3545;
}
* { box-sizing: border-box; }
body {
  margin: 0; display: grid; grid-template-columns: 230px 1fr; min-height: 100vh;
  background: var(--fondo); color: var(--tinta);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; font-size: 15px; line-height: 1.45;
}

/* Barra lateral */
.lateral { background: var(--lateral); color: #fff; padding: 20px 14px; display: flex; flex-direction: column; }
.lateral h1 { margin: 0 0 18px; text-align: center; font-size: 22px; font-weight: 600; }
.lateral nav { display: grid; gap: 6px; }
.lateral button {
  text-align: left; padding: 9px 12px; background: transparent; color: #fff;
  border: 1px solid transparent; border-radius: 6px; font: inherit; cursor: pointer;
}
.lateral button:hover { background: rgba(255,255,255,.1); }
.lateral button.activa { border-color: #fff; background: rgba(255,255,255,.08); }
.cuenta { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.2); font-size: 14px; }
.cuenta small { color: #ced4da; }
.cuenta button { width: 100%; margin-top: 10px; border-color: rgba(255,255,255,.4); }

/* Inicio de sesión */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--fondo); }
.login form { width: min(400px, 100%); margin: 0; }

main { padding: 28px 32px 60px; min-width: 0; }
h2 { margin: 0 0 6px; font-size: 28px; font-weight: 500; }
h3 { margin: 0 0 12px; font-size: 17px; font-weight: 600; }
.sub { margin: 0 0 18px; color: var(--suave); font-size: 17px; }
[hidden] { display: none !important; }

/* Tarjetas de color */
.tarjetas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 24px; }
.tarjeta { border-radius: 6px; padding: 14px 18px; color: #fff; }
.tarjeta h3 { margin: 0 0 4px; }
.tarjeta p { margin: 0; }
.azul { background: var(--azul); border: 1px solid #0a58ca; }
.verde { background: var(--verde); border: 1px solid #146c43; }
.amarilla { background: var(--amarillo); color: #000; border: 1px solid #cc9a06; }

.panel { background: #fff; border: 1px solid var(--linea); border-radius: 6px; padding: 18px; margin-bottom: 18px; }
.encabezado { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.encabezado h2, .encabezado h3 { margin: 0; }

/* Formularios */
label { display: block; margin: 12px 0 4px; font-size: 13px; font-weight: 600; color: var(--suave); }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #adb5bd; border-radius: 6px;
  background: #fff; color: var(--tinta); font: inherit;
}
textarea { resize: vertical; }
select:disabled { background: #e9ecef; }
.error { border-color: var(--rojo) !important; background: #fff5f5; }
.dos, .tres { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tres { grid-template-columns: 1fr 2fr 2fr; }
.dos > div > label:first-child, .tres > div > label:first-child { margin-top: 0; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.dos + .dos, .dos + .tres, .tres + .dos { margin-top: 12px; }
fieldset:disabled input, fieldset:disabled select, fieldset:disabled textarea { background: #f8f9fa; color: var(--tinta); opacity: 1; }
h4 { margin: 24px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--linea); font-size: 15px; font-weight: 600; }
.fila { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.fila input { flex: 1 1 150px; width: auto; }
.botones { display: flex; gap: 10px; margin-top: 16px; }

button { font: inherit; cursor: pointer; }
.botones button, .tabla-caja button, .encabezado button, .cal-cab button {
  padding: 7px 14px; border: 1px solid #adb5bd; border-radius: 6px; background: #fff; color: var(--tinta);
}
button.primario { background: var(--azul); border-color: var(--azul); color: #fff; font-weight: 600; padding: 8px 16px; border-radius: 6px; border-style: solid; border-width: 1px; }
button.primario:hover { background: #0b5ed7; }
button.borrar { color: var(--rojo) !important; border-color: #efb3b9 !important; }
button.borrar:hover { background: #fdecee !important; }
:focus-visible { outline: 3px solid #86b7fe; outline-offset: 1px; }

/* Tablas */
.tabla-caja { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 8px; border-bottom: 2px solid var(--linea); font-size: 13px; }
td { padding: 9px 8px; border-bottom: 1px solid var(--linea); vertical-align: top; }
tbody tr:nth-child(odd) td { background: #f8f9fa; }
td.acciones { white-space: nowrap; text-align: right; }
.tabla-caja td button { padding: 3px 10px; font-size: 13px; margin-left: 6px; }
td.vacio { text-align: center; color: var(--suave); padding: 22px; }

/* Inicio: calendario */
.inicio-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
.cal-cab { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cal-cab h3 { margin: 0; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .cab { text-align: center; font-size: 12px; font-weight: 600; color: var(--suave); padding-bottom: 4px; }
.dia {
  min-height: 54px; padding: 4px; border: 1px solid var(--linea); border-radius: 6px; background: #fff;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; text-align: left;
}
.dia:hover { background: #eef4ff; }
.dia.hoy { border-color: var(--azul); font-weight: 700; }
.dia.sel { background: var(--azul); color: #fff; border-color: var(--azul); }
.puntos { display: flex; gap: 3px; }
i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.t-cor { background: var(--rojo); } .t-pre { background: var(--verde); } .t-rev { background: var(--azul); }
.dia.sel .puntos i { outline: 1px solid #fff; }
.leyenda { margin: 12px 0 0; font-size: 13px; color: var(--suave); }
.leyenda i { margin: 0 4px 0 12px; }
.leyenda i:first-child { margin-left: 0; }
.item-agenda { padding: 8px 0; border-bottom: 1px solid var(--linea); }
.item-agenda:last-child { border-bottom: 0; }
.item-agenda small, .vacio-txt { color: var(--suave); }

/* Reportes */
.lista-rep { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.lista-rep .panel { margin: 0; }
.lista-rep h3 { margin-bottom: 2px; }
.lista-rep img { width: 100%; max-height: 180px; object-fit: cover; border-radius: 6px; margin-top: 10px; }
.meta { color: var(--suave); font-size: 13px; margin: 0 0 8px; }

/* Ventana de orden */
dialog { border: 0; border-radius: 8px; padding: 22px; width: min(640px, 94vw); max-height: 92vh; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.previas { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.previas img { width: 84px; height: 84px; object-fit: cover; border-radius: 6px; border: 1px solid var(--linea); cursor: zoom-in; display: block; }
.mini { position: relative; }
.mini button {
  position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; padding: 0;
  border: 2px solid #fff; border-radius: 50%; background: var(--rojo); color: #fff; font-size: 12px; line-height: 1;
}

/* Orden y lugar: pantalla completa */
dialog.pantalla { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; border-radius: 0; padding: 28px 24px; overflow: auto; background: var(--fondo); }
dialog.pantalla form { max-width: 760px; margin: 0 auto; background: #fff; border: 1px solid var(--linea); border-radius: 6px; padding: 22px; }

/* Visor de imagen ampliada */
#dlg-img { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 20px; border-radius: 0; background: rgba(0,0,0,.88); }
#dlg-img[open] { display: flex; align-items: center; justify-content: center; }
#dlg-img img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
#dlg-img button { position: absolute; top: 16px; right: 20px; width: 40px; height: 40px; border: 0; border-radius: 50%; background: #fff; color: #000; font-size: 18px; }

#aviso {
  position: fixed; right: 20px; bottom: 20px; max-width: 340px; padding: 12px 16px; border-radius: 6px;
  background: var(--verde); color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.25);
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
#aviso.visible { opacity: 1; }
#aviso.error { background: var(--rojo); }

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  .lateral nav { grid-template-columns: 1fr 1fr; }
  main { padding: 20px 14px 50px; }
  .tarjetas, .inicio-grid, .dos, .tres { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { #aviso { transition: none; } }
