/* software y código fuente propiedad de juan Manuel miras martinez, juanmanuelmiras@yahoo.com */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1c1e;
  --muted: #6b7280;
  --border: #e2e4e8;
  --primary: #2196f3;
  --primary-text: #ffffff;
  --primary-container: #dbeafe;
  --danger: #d32f2f;
  --today: #fff3cd;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2227;
    --text: #eceef0;
    --muted: #9aa1ab;
    --border: #33373d;
    --primary: #4dabf7;
    --primary-text: #0a0a0a;
    --primary-container: #1e3a5f;
    --danger: #ff6b6b;
    --today: #3a3320;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.view { min-height: 100vh; }
.view[hidden] { display: none; }

/* --- Selector de idioma --- */
.lang-menu-wrap { position: fixed; bottom: 16px; right: 16px; z-index: 1000; }
.lang-flag-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--border);
  background-color: var(--surface); background-size: cover; background-position: center; background-repeat: no-repeat;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.25); overflow: hidden;
}
.lang-menu {
  position: absolute; bottom: 56px; right: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.2); overflow: hidden; min-width: 160px;
}
.lang-menu-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; cursor: pointer; font-size: 14px;
  color: var(--text); white-space: nowrap;
}
.lang-flag-swatch {
  width: 20px; height: 20px; border-radius: 50%; flex: none; background-size: cover;
  background-position: center; background-repeat: no-repeat; border: 1px solid var(--border);
}
.lang-menu-item:hover { background: var(--bg); }
.lang-menu-item.active { font-weight: bold; background: var(--primary-container); }

/* --- Chat de ayuda (esfera "?") --- */
/* A la izquierda del navegador (esquina inferior izquierda), independiente de la esfera del idioma
   (que sigue a la derecha) — el panel del chat se abre anclado a este mismo botón (left:0 relativo a
   .help-chat-wrap), así que también queda siempre en el lado izquierdo. */
.help-chat-wrap { position: fixed; bottom: 16px; left: 16px; z-index: 1000; }
.help-chat-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--primary); color: var(--primary-text); font-size: 22px; font-weight: bold;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center;
}
/* :not([hidden]) porque .help-chat-panel { display:flex } sin condición ganaba siempre al
   display:none del atributo [hidden] (misma especificidad, pero esta regla va después en la hoja
   de estilos) — el panel aparecía desplegado nada más cargar la página en vez de empezar plegado. */
.help-chat-panel[hidden] { display: none; }
.help-chat-panel:not([hidden]) {
  position: absolute; bottom: 56px; left: 0; width: 320px; max-width: calc(100vw - 32px);
  height: 420px; max-height: 70vh; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,.3); display: flex; flex-direction: column; overflow: hidden;
}
.help-chat-header {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 12px;
  background: var(--primary); color: var(--primary-text); font-weight: bold; font-size: 14px;
}
.help-chat-header button {
  background: none; border: none; color: inherit; font-size: 18px; cursor: pointer; line-height: 1; padding: 0 4px;
}
.help-chat-messages { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.help-chat-msg { max-width: 85%; padding: 8px 10px; border-radius: 10px; font-size: 13px; line-height: 1.4; white-space: pre-wrap; }
.help-chat-msg.user { align-self: flex-end; background: var(--primary-container); color: var(--text); }
.help-chat-msg.assistant { align-self: flex-start; background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.help-chat-msg.pending { align-self: flex-start; color: var(--muted); font-style: italic; }
.help-chat-input-row { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); }
.help-chat-input-row input {
  flex: 1; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 13px;
}
.help-chat-input-row button {
  padding: 8px 12px; border-radius: 8px; border: none; background: var(--primary); color: var(--primary-text);
  cursor: pointer; font-size: 13px;
}
.help-chat-input-row button:disabled { opacity: .5; cursor: default; }

/* --- Pairing view --- */
/* :not([hidden]) en vez de solo #pairView: un selector de ID sin condición tiene más especificidad
   que .view[hidden], así que ganaba siempre y el QR nunca llegaba a ocultarse de verdad. */
#pairView:not([hidden]) { display: flex; align-items: center; justify-content: center; }
.pair-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 40px;
  max-width: 420px;
  text-align: center;
}
.pair-card h1 { font-size: 20px; margin: 0 0 8px; }
#qrBox { margin: 20px auto; width: 260px; height: 260px; display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 8px; }
#qrContainer svg { width: 240px; height: 240px; display: block; }
.muted { color: var(--muted); font-size: 13px; }
.muted a, .brand a { color: var(--primary); }
.credit { margin-top: 18px; }

.app-footer { display: flex; justify-content: center; padding: 24px 0 32px; }
.app-footer-logo { height: 40px; width: auto; border-radius: 6px; opacity: 0.85; transition: opacity 0.15s; }
.app-footer-logo:hover { opacity: 1; }

/* --- Main view --- */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { font-weight: 700; font-size: 18px; }
.toolbar { display: flex; gap: 8px; align-items: center; }

button {
  font: inherit; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 8px 14px; cursor: pointer;
}
button:hover { filter: brightness(0.96); }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.secondary { background: transparent; }
select, input[type=text], input[type=time] {
  font: inherit; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 8px 10px;
}
/* Selector de icono (día/turno, ver buildIconSelect): el emoji se veía diminuto con el tamaño de
   fuente normal de un <select> — aquí se agranda solo el emoji, no el resto de inputs del diálogo. */
.icon-select { font-size: 22px; padding: 6px 8px; }

.bell-btn { position: relative; padding: 9px 26px 9px 12px; font-size: 14px; line-height: 1; }
.bell-btn .badge {
  position: absolute; top: -7px; min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 11px; color: #fff; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.bell-btn .badge.badge-red { right: -6px; background: var(--danger, #dc3545); }
.bell-btn .badge.badge-blue { right: -6px; top: 14px; background: #1565c0; }
.bell-btn .badge.badge-green { right: -6px; background: #2e7d32; }
.bell-btn .badge:not(.badge-red):not(.badge-blue):not(.badge-green) { right: -6px; background: #1565c0; }

.banner { margin: 10px 20px; padding: 10px 14px; border-radius: 8px; background: #fff3cd; color: #664d03; font-size: 13px; }
.banner.error { background: #f8d7da; color: #842029; }
.banner.ok { background: #d1e7dd; color: #0f5132; }

/* --- Pestañas --- */
.tabbar { display: flex; gap: 4px; padding: 10px 20px 0; border-bottom: 1px solid var(--border); background: var(--surface); }
.tab-btn {
  border: none; border-bottom: 2px solid transparent; border-radius: 0; background: transparent;
  padding: 10px 14px; font-weight: 600; color: var(--muted);
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { padding: 4px 20px 24px; }
.tab-panel h2 { font-size: 17px; margin: 8px 0 4px; }
.tab-panel h3 { font-size: 14px; margin: 20px 0 4px; }
.tab-panel label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; margin: 10px 0; max-width: 420px; }
.row { display: flex; gap: 10px; align-items: center; margin: 10px 0; }

.list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
}

/* Misma tarjeta con fondo primary-container que "Calendarios gestionados" en Otros calendarios del
   móvil — antes cada bloque de Ajustes/Empleados era una lista plana sin fondo, con menos contraste
   que el resto de la app. */
.settings-card {
  background: var(--primary-container); border-radius: 12px; padding: 12px 16px; margin-bottom: 16px;
}
.settings-card h2 { margin-top: 0; }
.settings-card:last-child { margin-bottom: 0; }
.list-row.invalid { border-color: var(--danger); }
.list-row .grow { flex: 1; }

.tiles { display: flex; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 20px; min-width: 120px; text-align: center;
}
.stat-tile .stat-num { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat-tile .stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.dist-bar { display: flex; width: 100%; height: 22px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.dist-seg { height: 100%; }
.dist-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 13px; }
.dist-legend-item { display: flex; align-items: center; gap: 6px; }
.dist-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.palette { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 20px 4px; }
.chip {
  border-radius: 20px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
  border: 2px solid transparent; opacity: 0.85;
}
.chip.selected { border-color: var(--text); opacity: 1; }
.palette-actions { display: flex; justify-content: space-between; align-items: center; padding: 0 20px 14px; }

.month-nav { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 4px 0 12px; }
.month-nav button { border-radius: 50%; width: 32px; height: 32px; padding: 0; }
#monthLabel { font-weight: 600; min-width: 160px; text-align: center; text-transform: capitalize; }

.grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  margin: 0 20px 24px; border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: var(--surface);
}
.dow { text-align: center; font-size: 13px; color: var(--muted); font-weight: 600; padding-bottom: 4px; }
.day {
  position: relative; min-height: 110px; border: 1px solid var(--border); border-radius: 8px; padding: 5px;
  cursor: pointer; display: flex; flex-direction: column; gap: 3px;
}
.day.empty { visibility: hidden; }
.day.today { background: var(--today); }
.day .num { font-size: 14px; color: var(--muted); }
.day-main-icon { text-align: center; font-size: 20px; line-height: 1; }
.day .shift-tag { font-size: 18px; border-radius: 5px; padding: 4px 7px; font-weight: 700; }
.req-icon {
  position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%;
  color: #fff; font-size: 18px; font-weight: 800; display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.day-icons { position: absolute; bottom: 3px; left: 4px; display: flex; gap: 5px; font-size: 20px; line-height: 1; }

.dialog {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
}
.dialog[hidden] { display: none; }
.dialog-box {
  background: var(--surface); border-radius: 12px; padding: 22px; width: 320px;
  display: flex; flex-direction: column; gap: 10px;
}
.dialog-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.dialog-box .row { display: flex; gap: 10px; }
.dialog-box .row label { flex: 1; }
.dialog-actions { display: flex; gap: 8px; margin-top: 8px; }

#dayDetailDialog .dialog-box { width: 480px; max-width: 92vw; max-height: 85vh; overflow-y: auto; }
.day-note-input {
  width: 100%; min-height: 44px; font: inherit; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 8px 10px; margin: 4px 0 10px; resize: vertical;
}
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.photo-cell {
  width: 72px; height: 72px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg);
  display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden;
  font-size: 11px; color: var(--muted);
}
.photo-thumb { width: 100%; height: 100%; object-fit: cover; }
.video-thumb {
  display: flex; align-items: center; justify-content: center; background: #222; color: #fff;
  font-size: 26px; text-decoration: none;
}
.photo-dl {
  position: absolute; bottom: 2px; right: 2px; background: rgba(0,0,0,0.55); color: #fff;
  border-radius: 4px; padding: 1px 4px; font-size: 12px; text-decoration: none;
}

.video-lightbox-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.88); z-index: 3000;
  display: flex; align-items: center; justify-content: center;
}
.video-lightbox-player { max-width: 92vw; max-height: 92vh; background: #000; }
.photo-lightbox-player { max-width: 92vw; max-height: 92vh; object-fit: contain; }
.video-lightbox-close {
  position: absolute; top: 16px; right: 20px; background: rgba(255,255,255,0.15); color: #fff;
  border: none; border-radius: 50%; width: 40px; height: 40px; font-size: 18px; cursor: pointer;
}
.video-lightbox-close:hover { background: rgba(255,255,255,0.3); }

.cuadrante-wrap { overflow-x: auto; margin: 10px 0; }
.cuadrante-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.cuadrante-table th, .cuadrante-table td { border: 1px solid var(--border); padding: 4px 6px; text-align: center; white-space: nowrap; }
.cuadrante-table th:first-child, .cuadrante-table td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.cuadrante-table th.weekend, .cuadrante-table td.weekend { background: rgba(128,128,128,0.18); }
.cuadrante-table th.holiday, .cuadrante-table td.holiday { background: rgba(211,47,47,0.2); }
.cuadrante-own-row td:first-child { font-weight: 700; }
.cuadrante-shift-cell { padding: 4px !important; min-width: 38px; vertical-align: top; }
.cuadrante-shift-cell-inner { display: flex; flex-direction: column; gap: 3px; }
.cuadrante-shift-chip { border-radius: 4px; padding: 3px 6px; font-size: 14px; font-weight: 700; line-height: 1.3; }
.cuadrante-group-row td, .cuadrante-zone-row td {
  text-align: left !important; position: static !important; font-weight: 700; padding: 8px 10px !important;
}
.cuadrante-group-row td { background: var(--primary); color: var(--primary-text); font-size: 15px; }
.cuadrante-zone-row td { background: rgba(128,128,128,0.15); font-size: 14px; padding-left: 24px !important; }
.cuadrante-own-row { border-bottom: 2px solid var(--primary); }
.cuadrante-section-label { display: flex; align-items: center; gap: 8px; }
.cuadrante-section-label .icon-btn { margin-left: 2px; }
.icon-btn {
  background: transparent; border: none; cursor: pointer; font-size: 17px; line-height: 1;
  padding: 3px 6px; border-radius: 4px; color: inherit; opacity: 0.85;
}
.icon-btn:hover { opacity: 1; background: rgba(0,0,0,0.12); }
.cuadrante-employee-name { display: flex; align-items: center; gap: 8px; }
.cuadrante-avatar {
  width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
}
.cuadrante-avatar-initials {
  display: flex; align-items: center; justify-content: center; background: var(--primary); color: var(--primary-text);
  font-size: 13px; font-weight: 800;
}
.cuadrante-move-select {
  display: block; margin-top: 2px; font-size: 12px; padding: 2px 3px; max-width: 130px; opacity: 0.85;
}
