:root {
  --primary: #005b9f;
  --primary-dark: #004070;
  --accent: #f7941d;
  --accent-dark: #d9770e;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
  --info: #17a2b8;
  --light: #f4f6f9;
  --dark: #1a1a2e;
  --gray: #6c757d;
  --white: #ffffff;
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 16px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--light);
  color: var(--dark);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* Login */
.login-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.login-card {
  background: var(--white); width: 100%; max-width: 420px;
  border-radius: var(--radius); padding: 32px 24px;
  box-shadow: var(--shadow); text-align: center;
}
.login-card img { max-width: 180px; margin-bottom: 24px; }
.login-card h1 { font-size: 1.4rem; margin-bottom: 8px; color: var(--primary-dark); }
.login-card p { color: var(--gray); margin-bottom: 24px; font-size: 0.95rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px 20px; border: none; border-radius: var(--radius-sm);
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: transform .1s, box-shadow .2s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-accent { background: var(--accent); color: var(--white); }
.btn-success { background: var(--success); color: var(--white); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }

.equipos-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px;
}
.equipo-btn {
  background: var(--light); border: 2px solid #e1e5eb; border-radius: var(--radius-sm);
  padding: 18px; text-align: center; cursor: pointer; font-weight: 700; font-size: 1.1rem;
  transition: all .2s;
}
.equipo-btn:hover, .equipo-btn.selected {
  border-color: var(--primary); background: #e8f1fa; color: var(--primary);
}
.equipo-btn.admin { grid-column: 1 / -1; background: #fff7e6; border-color: var(--accent); color: var(--accent-dark); }

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  color: var(--white); padding: 14px 16px; display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow);
}
.app-header .logo-small { height: 36px; }
.app-header h2 { font-size: 1rem; font-weight: 600; }
.app-header .back-btn {
  background: rgba(255,255,255,0.2); border: none; color: var(--white);
  width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; cursor: pointer;
}

/* Container */
.container { padding: 16px; max-width: 960px; margin: 0 auto; }

/* Filtros fecha */
.date-filter {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 12px;
}
.date-chip {
  flex: 0 0 auto; padding: 10px 16px; background: var(--white); border: 2px solid #e1e5eb;
  border-radius: 24px; font-size: 0.85rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.date-chip.active { background: var(--primary); color: var(--white); border-color: var(--primary); }
.date-chip.date-green { background: #d4edda; color: #155724; border-color: #c3e6cb; }
.date-chip.date-yellow { background: #fff3cd; color: #856404; border-color: #ffeeba; }
.date-chip.date-red { background: #f8d7da; color: #721c24; border-color: #f5c6cb; }

/* Cards tienda */
.tienda-card {
  background: var(--white); border-radius: var(--radius-sm); padding: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06); margin-bottom: 12px;
  display: flex; align-items: center; gap: 14px; cursor: pointer;
  border-left: 5px solid var(--gray); transition: transform .15s;
}
.tienda-card:active { transform: scale(0.99); }
.tienda-card.estado-pendiente { border-left-color: var(--gray); }
.tienda-card.estado-curso { border-left-color: var(--warning); }
.tienda-card.estado-finalizada { border-left-color: var(--success); }

.tienda-icon {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem; font-weight: 700; color: var(--white);
}
.tienda-icon.estado-pendiente { background: var(--gray); }
.tienda-icon.estado-curso { background: var(--warning); color: var(--dark); }
.tienda-icon.estado-finalizada { background: var(--success); }

.tienda-info { flex: 1; }
.tienda-info h3 { font-size: 1rem; margin-bottom: 4px; color: var(--dark); }
.tienda-info p { font-size: 0.82rem; color: var(--gray); }

.estado-badge {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 4px 10px; border-radius: 12px; background: #eee;
}
.estado-badge.pendiente { background: #e9ecef; color: var(--gray); }
.estado-badge.curso { background: #fff3cd; color: #856404; }
.estado-badge.finalizada { background: #d4edda; color: #155724; }

/* Detalle tienda */
.tienda-hero {
  background: var(--white); border-radius: var(--radius-sm); padding: 20px; margin-bottom: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.tienda-hero h2 { font-size: 1.25rem; margin-bottom: 6px; }
.tienda-hero .meta { color: var(--gray); font-size: 0.9rem; margin-bottom: 12px; }
.tienda-hero .gps-btn {
  display: inline-flex; align-items: center; gap: 6px; background: #e8f1fa; color: var(--primary);
  border: none; padding: 8px 14px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}

/* Tipo limpieza */
.tipo-card {
  background: var(--white); border-radius: var(--radius-sm); padding: 16px; margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.tipo-card h4 { font-size: 1rem; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.tipo-card h4 .cat-tag { font-size: 0.65rem; text-transform: uppercase; background: var(--light); padding: 2px 8px; border-radius: 8px; color: var(--gray); }

.foto-row { display: flex; gap: 12px; margin-top: 10px; }
.foto-box {
  flex: 1; background: var(--light); border-radius: var(--radius-sm); padding: 12px; text-align: center;
  border: 2px dashed #d1d5db; min-height: 140px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
.foto-box img { max-width: 100%; border-radius: var(--radius-sm); object-fit: cover; }
.foto-box .label { font-size: 0.8rem; font-weight: 700; color: var(--gray); }
.foto-box .btn-cam {
  background: var(--primary); color: var(--white); border: none; width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem; cursor: pointer;
}
.foto-box .na-btn {
  background: transparent; color: var(--gray); border: 1px solid #d1d5db; padding: 6px 12px; border-radius: 14px; font-size: 0.75rem; cursor: pointer; margin-top: 6px;
}
.foto-box .na-btn.na-active { background: #e9ecef; color: #6c757d; font-weight: 700; }

/* Timer */
.timer-display {
  background: var(--dark); color: var(--white); border-radius: var(--radius-sm); padding: 16px; text-align: center; margin-bottom: 16px;
}
.timer-display .time { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.timer-display .label { font-size: 0.8rem; opacity: 0.8; }

/* Informe - Layout para A4 */
.informe-page {
  background: var(--white);
  border-radius: var(--radius-sm);
  padding: 16px;
  max-width: 210mm;
  margin: 0 auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.informe-header {
  text-align: center;
  border-bottom: 3px solid var(--primary);
  padding-bottom: 16px;
  margin-bottom: 20px;
}
.informe-header h1 { font-size: 1.3rem; color: var(--primary-dark); margin-bottom: 4px; }
.informe-header p { color: var(--gray); font-size: 0.9rem; }

.informe-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 20px;
  font-size: 0.85rem;
  color: var(--gray);
  margin-bottom: 16px;
}
.informe-meta strong { color: var(--dark); }

.informe-seccion { margin-bottom: 20px; }
.informe-seccion h3 {
  font-size: 1rem;
  color: var(--primary);
  margin-bottom: 10px;
  border-bottom: 2px solid var(--light);
  padding-bottom: 6px;
}

.informe-item {
  margin-bottom: 14px;
  page-break-inside: avoid;
}
.informe-item .item-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 6px;
}
.informe-item.na .item-title { color: var(--gray); }

.informe-fotos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.informe-fotos .foto-wrapper {
  text-align: center;
  border: 1px solid #ddd;
  border-radius: var(--radius-sm);
  padding: 6px;
  background: #fafafa;
}
.informe-fotos .foto-wrapper img {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: 4px;
  display: block;
}
.informe-fotos .foto-wrapper .caption {
  font-size: 0.7rem;
  color: var(--gray);
  margin-top: 4px;
}
.informe-fotos .foto-wrapper .missing {
  font-size: 0.75rem;
  color: var(--gray);
  padding: 40px 10px;
  display: block;
}

/* Albarán */
.albaran-box { border: 2px solid var(--dark); padding: 20px; border-radius: var(--radius-sm); }
.albaran-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.albaran-header img { height: 50px; }
.albaran-header .num { font-size: 1.2rem; font-weight: 700; }
.albaran-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #eee; }
.albaran-row strong { color: var(--primary-dark); }
.albaran-total { background: var(--light); padding: 14px; border-radius: var(--radius-sm); margin-top: 14px; text-align: right; font-size: 1.1rem; font-weight: 700; }

/* Print - A4 */
@media print {
  .no-print { display: none !important; }
  body { background: white; margin: 0; padding: 0; }

  .informe-page {
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    max-width: none;
    width: 100%;
  }

  .informe-fotos .foto-wrapper img {
    max-height: 65mm;
  }

  .informe-item {
    page-break-inside: avoid;
  }

  .informe-seccion {
    page-break-inside: avoid;
  }

  .informe-page {
    page-break-after: always;
  }

  .informe-page:last-child {
    page-break-after: auto;
  }
}

/* Modals */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-content {
  background: var(--white); border-radius: var(--radius); width: 100%; max-width: 400px; padding: 24px;
  box-shadow: var(--shadow); animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-content h3 { margin-bottom: 12px; }
.modal-content p { color: var(--gray); margin-bottom: 16px; font-size: 0.9rem; }

/* Inputs */
input[type="text"], input[type="date"], textarea, select {
  width: 100%; padding: 12px; border: 2px solid #e1e5eb; border-radius: var(--radius-sm); font-size: 1rem; margin-bottom: 12px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(120px);
  background: var(--dark); color: var(--white); padding: 12px 24px; border-radius: 24px; font-size: 0.9rem;
  box-shadow: var(--shadow); transition: transform .3s; z-index: 300;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* Responsive tweaks */
@media (max-width: 400px) {
  .equipos-grid { grid-template-columns: 1fr; }
  .foto-row { flex-direction: column; }
  .informe-fotos { grid-template-columns: 1fr; }
}

/* Permisos */
.perm-box { background: var(--white); border-radius: 12px; padding: 20px; text-align: left; }
.perm-box h3 { font-size: 1rem; margin-bottom: 12px; }
.perm-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #eee; }
.perm-item:last-child { border-bottom: none; }
.perm-item span { font-size: 0.9rem; }
.perm-status { font-size: 0.75rem; font-weight: 700; padding: 4px 10px; border-radius: 10px; }
.perm-status.ok { background: #d4edda; color: #155724; }
.perm-status.ko { background: #f8d7da; color: #721c24; }

/* PWA Install */
.pwa-install { display: none; background: #fff7e6; border: 2px solid var(--accent); border-radius: 12px; padding: 16px; text-align: center; }
.pwa-install p { font-size: 0.9rem; margin-bottom: 10px; color: var(--accent-dark); }

/* Metadatos en foto */
.foto-thumb { position: relative; display: inline-block; width: 100%; }
.foto-thumb img { width: 100%; border-radius: var(--radius-sm); }
.foto-meta {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.7); color: #fff; font-size: 0.65rem;
  padding: 4px 8px; border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  display: flex; justify-content: space-between; align-items: center;
}
.foto-meta .coords { font-size: 0.6rem; opacity: 0.9; }
.foto-warning {
  position: absolute; top: 4px; left: 4px;
  background: var(--danger); color: #fff; font-size: 0.65rem; font-weight: 700;
  padding: 2px 8px; border-radius: 8px;
}

/* Botón eliminar foto */
.foto-delete {
  position: absolute; top: 4px; right: 4px;
  background: var(--danger); color: #fff; border: none; width: 28px; height: 28px;
  border-radius: 50%; font-size: 0.9rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center; z-index: 2;
}

/* Admin reset */
.admin-reset {
  background: #fff3cd; border: 1px solid var(--warning); color: #856404;
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: 0.85rem;
  font-weight: 600; cursor: pointer; margin-top: 10px;
}

/* Login password */
#inputPassword { text-align: center; font-size: 1.2rem; letter-spacing: 4px; }

/* Foto row con columna */
.foto-row { display: flex; gap: 12px; margin-top: 10px; }
.foto-box { flex: 1; position: relative; }

/* Categoría tag */
.cat-tag { font-size: 0.65rem; text-transform: uppercase; background: var(--light); padding: 2px 8px; border-radius: 8px; color: var(--gray); margin-left: 8px; }
/* Foto row con columna */
.foto-row { display: flex; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.foto-box { flex: 1; position: relative; min-width: 140px; }
.foto-box.add { background: #e8f1fa; border: 2px dashed var(--primary); cursor: pointer; min-height: 140px; display: flex; align-items: center; justify-content: center; font-size: 2rem; color: var(--primary); transition: all .2s; }
.foto-box.add:hover { background: #d0e3f7; }
.foto-box.add .label { font-size: 0.75rem; font-weight: 600; }

/* Comentarios */
.comentarios-box { background: var(--white); border-radius: var(--radius-sm); padding: 16px; margin-top: 16px; box-shadow: 0 2px 6px rgba(0,0,0,0.06); }
.comentarios-box h4 { font-size: 1rem; color: var(--primary); margin-bottom: 10px; }
.comentarios-list { font-size: 0.85rem; color: var(--dark); margin-bottom: 10px; }
.comentarios-list .comentario-item { padding: 8px 0; border-bottom: 1px solid #eee; }
.comentarios-list .comentario-item:last-child { border-bottom: none; }
.comentarios-list .comentario-time { font-size: 0.7rem; color: var(--gray); }
.comentarios-box textarea { width: 100%; padding: 10px; border: 2px solid #e1e5eb; border-radius: var(--radius-sm); font-size: 0.9rem; min-height: 60px; margin-bottom: 8px; resize: vertical; }
.comentarios-box textarea:focus { outline: none; border-color: var(--primary); }

/* Fotos extra */
.fotos-extra-section { margin-top: 12px; padding-top: 12px; border-top: 1px solid #eee; }
.fotos-extra-section h5 { font-size: 0.85rem; color: var(--primary); margin-bottom: 8px; }
.fotos-extra-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.foto-extra-thumb { position: relative; width: 80px; height: 80px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid #ddd; cursor: pointer; }
.foto-extra-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.foto-extra-desc { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.6); color: #fff; font-size: 0.6rem; padding: 2px 4px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foto-extra-delete { position: absolute; top: 2px; right: 2px; background: var(--danger); color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 0.7rem; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; line-height: 1; }
.fotos-extra-upload { margin-top: 10px; }
.fotos-extra-upload .btn { width: 100%; padding: 10px; font-size: 0.85rem; }

/* Informe fotos extra */
.informe-fotos-extra { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.informe-foto-extra-item { width: 140px; text-align: center; }
.informe-foto-extra-item img { width: 100%; border-radius: var(--radius-sm); border: 1px solid #ddd; }
.informe-foto-extra-item .caption { font-size: 0.75rem; color: var(--gray); margin-top: 4px; }

/* Botón tickets */
.btn-tickets { background: var(--accent); color: var(--white); border: none; padding: 12px 20px; border-radius: var(--radius-sm); font-size: 0.9rem; font-weight: 600; cursor: pointer; width: 100%; margin-top: 12px; }
.btn-tickets:hover { background: var(--accent-dark); }

/* Modal tickets */
.modal-tickets { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-tickets-content { background: var(--white); border-radius: var(--radius); width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; padding: 24px; box-shadow: var(--shadow); box-sizing: border-box; }
.modal-tickets-content h3 { margin-bottom: 12px; color: var(--primary-dark); }
.modal-tickets-content input, .modal-tickets-content select { width: 100%; padding: 12px; border: 2px solid #e1e5eb; border-radius: var(--radius-sm); font-size: 1rem; margin-bottom: 12px; box-sizing: border-box; }
.modal-tickets-content input:focus, .modal-tickets-content select:focus { outline: none; border-color: var(--primary); }
.modal-tickets-content .btn-group { display: flex; gap: 10px; margin-top: 12px; }
.ticket-list { max-height: 200px; overflow-y: auto; margin-bottom: 12px; }
.ticket-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid #eee; font-size: 0.85rem; }
.ticket-item .ticket-cat { font-size: 0.7rem; background: var(--light); padding: 2px 8px; border-radius: 8px; color: var(--gray); }

/* Categoría tag */
.cat-tag { font-size: 0.65rem; text-transform: uppercase; background: var(--light); padding: 2px 8px; border-radius: 8px; color: var(--gray); margin-left: 8px; }
