:root {
  color-scheme: light;
  --azul: #0f5c85;
  --azul-oscuro: #0a4463;
  --azul-claro: #e3f0f7;
  --fondo: #f1f4f6;
  --tarjeta: #ffffff;
  --texto: #18242c;
  --suave: #55656f;
  --borde: #c9d3d9;
  --rojo: #b3261e;
  --rojo-claro: #fdecea;
  --ambar-claro: #fff4d6;
  --toque: 52px;
  --azul-logo: #1d3161;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(92px + env(safe-area-inset-bottom));
}

h1, h2, p { margin: 0; }

/* Barra superior */
.barra {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--azul);
  color: #fff;
}
.barra-texto { min-width: 0; }
.barra h1 { font-size: 20px; line-height: 1.2; }
.barra p { font-size: 14px; opacity: .9; overflow-wrap: anywhere; }

/* Botones */
.btn {
  min-height: var(--toque);
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
:focus-visible { outline: 3px solid #f0a81e; outline-offset: 1px; }
.ancho { width: 100%; }
.btn-primario { background: var(--azul); color: #fff; }
.btn-primario:active { background: var(--azul-oscuro); }
.btn-secundario { background: #fff; color: var(--azul-oscuro); border-color: var(--azul); }
.btn-peligro { background: var(--rojo); color: #fff; }
.btn-barra { min-height: 46px; flex: none; background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.65); }
.btn-flecha { width: var(--toque); flex: none; padding: 0; background: #fff; color: var(--azul-oscuro); border-color: var(--borde); font-size: 30px; line-height: 1; }
.btn-enlace { min-height: 36px; padding: 4px 8px; border: 0; background: none; color: var(--azul); font: inherit; font-size: 15px; font-weight: 600; text-decoration: underline; cursor: pointer; }
.btn-ahora { flex: none; min-width: 66px; padding: 4px 6px; background: var(--azul-claro); color: var(--azul-oscuro); border-color: var(--azul); font-size: 15px; }
.btn-cerrar { flex: none; width: 44px; height: 44px; border: 0; background: none; color: inherit; font-size: 26px; cursor: pointer; }

/* Avisos */
.aviso {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 10px 12px 0;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--rojo);
  border-radius: 10px;
  background: var(--rojo-claro);
  color: #7c1a14;
  font-weight: 600;
}
.aviso span { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  z-index: 20;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: #18242c;
  color: #fff;
  transform: translateX(-50%);
  text-align: center;
}

/* Entradas rápidas */
.rapidas {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
}
.rapidas .btn-primario { min-height: 62px; font-size: 18px; }
.rapidas .ancho { grid-column: 1 / -1; }

/* Selector de semana */
.semana-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 12px;
}
.semana-centro {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.semana-rotulo { color: var(--suave); font-size: 13px; }
#semana-texto { font-size: 17px; }

/* Días y entradas */
#dias { display: grid; gap: 10px; padding: 0 12px; }
.dia {
  overflow: hidden;
  border: 1px solid var(--borde);
  border-radius: 12px;
  background: var(--tarjeta);
}
.dia.hoy { border-color: var(--azul); box-shadow: 0 0 0 1px var(--azul); }
.dia.domingo { border-color: #c98f00; }
.dia-cab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  background: var(--azul-claro);
}
.dia.domingo .dia-cab { background: var(--ambar-claro); }
.dia-nombre { font-weight: 700; }
.dia-horas { display: block; color: var(--suave); font-size: 14px; }
.dia-agregar { min-height: 46px; min-width: 104px; font-size: 15px; }
.dia-vacio, .dia-aviso { padding: 10px 12px; color: var(--suave); font-size: 15px; }
.dia-aviso { color: #6d4e00; font-weight: 600; }

.entrada { padding: 10px 12px; border-top: 1px solid #e3e8eb; }
.entrada-prin { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; }
.entrada-hora { font-weight: 750; font-variant-numeric: tabular-nums; }
.entrada-hora.falta { color: var(--rojo); }
.entrada-cliente { overflow-wrap: anywhere; }
.entrada-datos { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.dato { padding: 2px 7px; border-radius: 6px; background: #edf1f3; color: #33434d; font-size: 14px; font-variant-numeric: tabular-nums; }
.entrada-acciones { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.entrada-acciones .btn { min-height: 46px; font-size: 15px; }
.btn-borrar { background: #fff; color: var(--rojo); border-color: var(--rojo); }

/* Barra de impresión */
.barra-imprimir {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(241,244,246,.96);
  border-top: 1px solid var(--borde);
}

/* Ajustes y formularios */
#vista-ajustes { display: grid; gap: 12px; padding: 12px; }
.tarjeta {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--borde);
  border-radius: 12px;
  background: var(--tarjeta);
}
.tarjeta h2 { font-size: 18px; }
.ayuda { color: var(--suave); font-size: 14px; }

label { display: block; margin-bottom: 3px; font-size: 15px; font-weight: 650; }

input, select {
  width: 100%;
  min-width: 0;
  min-height: var(--toque);
  padding: 8px 10px;
  border: 1px solid #8fa0aa;
  border-radius: 8px;
  background: #fff;
  color: var(--texto);
  font: inherit;
  font-size: 18px;
}

dialog {
  width: min(100vw - 16px, 540px);
  max-height: calc(100dvh - 16px);
  padding: 14px;
  border: 0;
  border-radius: 14px;
  color: var(--texto);
}
dialog::backdrop { background: rgba(10,25,35,.55); }
#form-entrada { display: grid; gap: 8px; }
#form-entrada h2 { font-size: 20px; outline: none; }
.form-error { padding: 8px 10px; border-radius: 8px; background: var(--rojo-claro); color: #7c1a14; font-weight: 600; }
.hora-fila { display: grid; gap: 8px; }
.con-ahora { display: flex; gap: 6px; }
.dlg-acciones {
  position: sticky;
  bottom: -14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
  padding: 8px 0;
  background: #fff;
}
#conf-texto { margin-bottom: 12px; font-size: 18px; white-space: pre-line; overflow-wrap: anywhere; }

/* Hoja imprimible: solo existe en papel */
.hoja-pagina { display: none; }

/* Recordatorio de respaldo y avisos del formulario */
.recordatorio {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 12px 12px 0;
  padding: 6px 4px 6px 12px;
  border: 1px solid #c98f00;
  border-radius: 10px;
  background: var(--ambar-claro);
  color: #5c4200;
  font-size: 15px;
  font-weight: 600;
}
.recordatorio span { flex: 1; min-width: 0; }
#drive-estado { overflow-wrap: anywhere; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.recordatorio .btn { flex: none; min-height: 46px; font-size: 15px; }
.dato-alerta { background: var(--rojo-claro); color: #7c1a14; font-weight: 650; }
.hora-vista { padding: 7px 10px; border-radius: 8px; background: var(--azul-claro); color: var(--azul-oscuro); font-size: 15px; font-weight: 650; }
.hora-vista.mal { background: var(--rojo-claro); color: #7c1a14; }

@page {
  size: letter portrait;
  margin: 0;
}

@media print {
  html, body {
    width: 8.5in;
    height: auto;
    margin: 0;
    padding: 0;
    overflow: visible;
    background: #fff !important;
  }

  #app, dialog, dialog::backdrop { display: none !important; }

  #hoja { break-after: page; }

  .hoja-pagina {
    display: block;
    position: relative;
    width: 8.5in;
    height: 10.98in;
    overflow: hidden;
    background: #fff;
    color: #000;
    font-family: Arial, Helvetica, sans-serif;
    break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .hoja-pagina > * { position: absolute; margin: 0; }

  .h-logo {
    top: .36in;
    left: .9in;
    width: 4.5in;
    height: .66in;
    object-fit: contain;
  }
  .h-titulo {
    top: 1.05in;
    left: .9in;
    width: 4.5in;
    font-size: 15.5pt;
    font-weight: 700;
    text-align: center;
    transform: scaleX(.92);
  }

  .h-campo { display: flex; align-items: flex-end; font-size: 12.5pt; font-weight: 700; }
  .h-campo span { flex: none; }
  .h-campo b {
    display: block;
    height: .27in;
    padding: 0 .08in;
    border-bottom: 1px solid #000;
    font-size: 14pt;
    font-weight: 400;
    line-height: .27in;
    white-space: nowrap;
    overflow: hidden;
  }
  .h-nombre { top: 1.46in; left: .23in; width: 5.08in; }
  .h-nombre b { flex: 1; }
  .h-semana { top: 2.24in; left: .73in; width: 4.72in; }
  .h-semana b:nth-of-type(1) { width: 1.42in; margin: 0 .23in 0 .03in; text-align: center; }
  .h-semana b:nth-of-type(2) { flex: 1; margin-left: .05in; text-align: center; }

  .h-claves {
    top: .15in;
    left: 5.96in;
    width: 2.21in;
    height: 2.86in;
    border: 1.5px solid #000;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 8.3pt;
    line-height: 1.16;
  }
  .h-claves td { padding: 0 2px; text-align: center; vertical-align: middle; }
  .h-claves td:first-child { font-weight: 700; white-space: nowrap; }
  .h-claves td:last-child { font-size: 10.5pt; }
  .h-claves th {
    border-top: 2px solid #000;
    border-bottom: 2px solid #000;
    background: #f0f0f0;
    font-size: 8.8pt;
  }
  .k-c1 { height: .25in; }
  .k-f1 { height: .21in; }
  .k-c2 { height: .22in; }
  .k-f2 { height: .25in; }
  .k-f3 { height: .5in; }
  .k-f4 { height: .33in; }
  .k-f5 { height: .17in; }

  .h-nota {
    top: 3.2in;
    left: .15in;
    width: 8.2in;
    font-size: 9.8pt;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
  }

  .h-tabla {
    top: 3.48in;
    left: .165in;
    width: 8in;
    border: 1.25px solid #000;
    border-collapse: collapse;
    table-layout: fixed;
  }
  .h-tabla th, .h-tabla td {
    border: 1px solid #000;
    padding: 0 .04in;
    overflow: hidden;
    white-space: nowrap;
  }
  .h-tabla thead th {
    height: .52in;
    padding-top: .16in;
    font-size: 10.5pt;
    font-weight: 700;
    text-align: center;
    vertical-align: middle;
  }
  .h-tabla thead small { font-size: 8pt; }
  .h-tabla tbody tr { height: var(--fila-alto, .2269in); }
  .h-tabla tbody td {
    height: var(--fila-alto, .2269in);
    max-height: var(--fila-alto, .2269in);
    font-size: var(--fila-letra, 10.5pt);
    line-height: 1;
    vertical-align: middle;
  }
  .h-tabla td.centro { text-align: center; }

  /* Página 2: Continuidad */
  .h2-titulo { top: .06in; left: .2in; font-size: 15.5pt; font-weight: 700; }
  .h2-nombre { top: .27in; left: .2in; width: 4.8in; }
  .h2-nombre b { flex: 1; }
  .h2-pagina { top: .27in; left: 6in; width: 1.04in; }
  .h2-pagina span { margin-right: .04in; }
  .h2-pagina b { flex: 1; text-align: center; }
  .h-tabla-2 { top: .74in; }
  .h-tabla-2 thead th {
    height: .235in;
    padding-top: 0;
    border-bottom: 3px double #000;
  }

  /* Títulos de cada sección con el azul del logo */
  .h-titulo,
  .h2-titulo,
  .h-campo > span,
  .h-claves th,
  .h-tabla thead th { color: var(--azul-logo); }

  .h-rev {
    top: 10.68in;
    right: .18in;
    font-size: 10pt;
    font-weight: 700;
  }
}
