* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --primary: #0d4a6e;
  --primary-dark: #0a3854;
  --accent: #f59e0b;
  --ok: #16a34a;
  --fail: #dc2626;
  --skip: #94a3b8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.5;
  overscroll-behavior: none;
  min-height: 100vh;
}

input, button, textarea { font-family: inherit; font-size: inherit; }

.view { display: none; min-height: 100vh; }
.view.active { display: block; }

.hidden { display: none !important; }

/* HERO (HOME) */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 56px 24px 64px;
  text-align: center;
}
.hero h1 { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.hero .subtitle { font-size: 16px; opacity: 0.85; margin-top: 6px; }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

.form-card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-top: -32px;
  display: grid;
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.field input, .field textarea {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 17px;
  background: white;
  transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--primary); }

.section-title {
  margin: 32px 0 16px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

.building-grid { display: grid; gap: 12px; }
.building-card {
  background: var(--card);
  border-radius: 14px;
  padding: 22px 20px;
  box-shadow: var(--shadow);
  border: none;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: transform 0.1s, box-shadow 0.15s;
}
.building-card:active { transform: scale(0.98); }
.building-card .name { font-size: 19px; font-weight: 600; }
.building-card .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.building-card .arrow { font-size: 24px; color: var(--muted); }

.pendientes { margin-top: 28px; }
.pendientes h3 { font-size: 15px; color: var(--muted); margin-bottom: 12px; font-weight: 600; }
.pendiente-card {
  background: #fef3c7;
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.pendiente-card .info strong { display: block; }
.pendiente-card .info span { font-size: 13px; color: var(--muted); }
.pendiente-card .delete-btn {
  background: transparent;
  border: none;
  color: var(--fail);
  font-size: 22px;
  padding: 4px 10px;
  cursor: pointer;
}

/* TOPBAR */
.topbar {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.topbar-info { flex: 1; display: flex; flex-direction: column; }
.topbar-info strong { font-size: 16px; }
.topbar-info span { font-size: 12px; opacity: 0.85; }
.btn-back, .btn-finalizar {
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-finalizar { background: var(--accent); color: #1a1a1a; }
.btn-back:active, .btn-finalizar:active { opacity: 0.8; }

.progress-bar { height: 4px; background: rgba(0,0,0,0.06); }
#progress-fill { height: 100%; background: var(--ok); transition: width 0.3s; width: 0%; }

/* SECTION NAV */
.section-nav {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: sticky;
  top: 56px;
  z-index: 9;
}
.section-nav::-webkit-scrollbar { display: none; }
.section-nav button {
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  color: var(--text);
}
.section-nav button.active { background: var(--primary); color: white; }
.section-nav button.has-issues { border-color: var(--fail); }
.section-nav button.complete::after { content: " ✓"; color: var(--ok); }
.section-nav button.active.complete::after { color: white; }

/* CHECKLIST */
.checklist {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px 100px;
}

.section-block { margin-bottom: 32px; }
.section-block > h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--primary);
  letter-spacing: -0.01em;
}
.subsection-block { margin-top: 20px; }
.subsection-block h3 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 10px;
  font-weight: 700;
}

.item-card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  border-left: 4px solid var(--border);
  transition: border-color 0.15s;
}
.item-card.ok { border-left-color: var(--ok); }
.item-card.fail { border-left-color: var(--fail); background: #fef2f2; }

.item-text { font-size: 16px; margin-bottom: 14px; line-height: 1.4; }

.toggle-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.toggle-btn {
  background: white;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.1s;
}
.toggle-btn.selected.ok-btn { background: var(--ok); border-color: var(--ok); color: white; }
.toggle-btn.selected.fail-btn { background: var(--fail); border-color: var(--fail); color: white; }
.toggle-btn:active { transform: scale(0.97); }

.observation-area {
  display: none;
  margin-top: 8px;
}
.item-card.fail .observation-area { display: block; }

.observation-area textarea {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  resize: vertical;
  min-height: 70px;
  background: white;
}
.observation-area textarea:focus { outline: none; border-color: var(--fail); }

.photo-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  align-items: center;
}
.photo-thumb {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  border: 2px solid var(--border);
  position: relative;
}
.photo-wrap { position: relative; }
.photo-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--fail);
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.btn-add-photo {
  background: white;
  border: 2px dashed var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
.btn-add-photo input { display: none; }

.checklist-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  z-index: 10;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 16px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}
.btn-primary.big { padding: 18px; font-size: 18px; }
.btn-primary:active { background: var(--primary-dark); }

.btn-secondary {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}

.btn-onedrive {
  background: #0078d4;
  color: white;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background 0.2s;
}
.btn-onedrive:active { background: #005fa3; }
.btn-onedrive:disabled { opacity: 0.7; cursor: not-allowed; }

/* SUMMARY */
.summary-card {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.summary-card h2 { font-size: 24px; margin-bottom: 4px; }
.muted { color: var(--muted); font-size: 14px; }

.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 20px 0;
}
.stat {
  background: var(--bg);
  border-radius: 12px;
  padding: 16px 8px;
  text-align: center;
}
.stat span { font-size: 32px; font-weight: 700; display: block; }
.stat label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat.ok span { color: var(--ok); }
.stat.fail span { color: var(--fail); }
.stat.skip span { color: var(--skip); }

.actions { display: grid; gap: 10px; margin: 20px 0; }

.problemas { margin-top: 24px; }
.problemas h3 { font-size: 16px; margin-bottom: 12px; color: var(--fail); }
.problema-item {
  background: #fef2f2;
  border-left: 3px solid var(--fail);
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 14px;
}
.problema-item strong { display: block; color: var(--text); }
.problema-item .obs { color: var(--muted); margin-top: 4px; }

@media (max-width: 480px) {
  .hero h1 { font-size: 26px; }
  body { font-size: 16px; }
}

/* ===== Cuenta de OneDrive (visible en la pantalla de inicio) ===== */
.onedrive-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 14px;
  margin: 16px 0 4px;
}
.onedrive-info { display: flex; flex-direction: column; min-width: 0; }
.onedrive-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #64748b;
}
#onedrive-cuenta {
  font-size: 14px;
  color: #0d4a6e;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#onedrive-cuenta.sin-conectar { color: #b45309; }
.btn-cambiar-cuenta {
  flex: 0 0 auto;
  background: #fff;
  border: 1px solid #cbd5e1;
  color: #0d4a6e;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-cambiar-cuenta:active { background: #e2e8f0; }

/* ==========================================================================
   BITÁCORA DE TRABAJOS
   ========================================================================== */

/* --- Selector de modo en el inicio --- */
.modo-selector { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.modo-btn {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  padding: 14px; border-radius: 12px; border: 1px solid #e2e8f0;
  background: #fff; cursor: pointer; font-family: inherit;
}
.modo-btn strong { font-size: 14px; color: #0d4a6e; }
.modo-btn small { font-size: 11px; color: #64748b; }
.modo-btn.activo { background: #0d4a6e; border-color: #0d4a6e; cursor: default; }
.modo-btn.activo strong, .modo-btn.activo small { color: #fff; }

/* --- Lista de trabajos --- */
.bita-selector { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.bita-chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid #cbd5e1;
  background: #fff; color: #0d4a6e; font-weight: 600; font-size: 13px;
  cursor: pointer; font-family: inherit;
}
.bita-chip.activo { background: #0d4a6e; border-color: #0d4a6e; color: #fff; }
.bita-titulo { font-size: 18px; color: #0d4a6e; margin: 0 0 12px; }
.bita-vacio { color: #64748b; font-size: 14px; text-align: center; padding: 28px 12px; line-height: 1.6; }
.bita-mes {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: #94a3b8; margin: 20px 0 8px;
}
.bita-item {
  display: block; width: 100%; text-align: left; background: #fff;
  border: 1px solid #e2e8f0; border-radius: 12px; padding: 12px 14px;
  margin-bottom: 8px; cursor: pointer; font-family: inherit;
}
.bita-item-top { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; flex-wrap: wrap; }
.bita-fecha { font-size: 12px; font-weight: 700; color: #0d4a6e; }
.bita-item-titulo { font-size: 15px; color: #1e293b; line-height: 1.35; margin-bottom: 3px; }
.bita-item-meta { font-size: 12px; color: #64748b; }
.bita-tipo {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: 3px 8px; border-radius: 999px; color: #fff; white-space: nowrap;
}
.tipo-preventivo { background: #16a34a; }
.tipo-correctivo { background: #d97706; }
.tipo-mejora     { background: #2563eb; }
.tipo-gestion    { background: #64748b; }
.tipo-incidente  { background: #dc2626; }
.bita-flag {
  font-size: 10px; font-weight: 700; color: #b45309;
  background: #fef3c7; padding: 3px 8px; border-radius: 999px;
}
.bita-pendientes {
  background: #fef3c7; border: 1px solid #fde68a; color: #92400e;
  padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 14px;
}
.btn-link {
  background: none; border: none; color: #92400e; text-decoration: underline;
  font-weight: 700; cursor: pointer; font-family: inherit; font-size: 13px;
}

/* --- Formulario de trabajo --- */
.hint { display: block; font-size: 11px; color: #94a3b8; margin-top: 4px; line-height: 1.4; }
.field em { font-style: normal; color: #94a3b8; font-weight: 400; }
.opciones { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-top: 6px; }
.opciones.chicas { grid-template-columns: repeat(3, 1fr); }
.opcion {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 10px;
  background: #fff; cursor: pointer; font-family: inherit; font-size: 13px; color: #1e293b;
}
.opcion small { font-size: 10px; color: #94a3b8; }
.opcion.sel { background: #0d4a6e; border-color: #0d4a6e; color: #fff; }
.opcion.sel small { color: #cbd5e1; }
.bita-fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 8px 0; }
.bita-foto { position: relative; }
.bita-foto img { width: 100%; height: 100px; object-fit: cover; border-radius: 8px; display: block; }
.foto-x {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px;
  border-radius: 50%; border: none; background: rgba(0,0,0,.6); color: #fff;
  font-size: 16px; line-height: 1; cursor: pointer;
}
.foto-pie {
  width: 100%; margin-top: 4px; font-size: 11px; padding: 5px 7px;
  border: 1px solid #e2e8f0; border-radius: 6px; font-family: inherit;
}

/* --- Generador de informe --- */
.atajos { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.atajos button {
  padding: 8px 12px; border-radius: 8px; border: 1px solid #cbd5e1;
  background: #f8fafc; color: #0d4a6e; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.rango { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.informe-conteo { font-size: 14px; color: #0d4a6e; margin: 14px 0 10px; }
.informe-item {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 11px 13px; margin-bottom: 7px; font-size: 13px; cursor: pointer;
}
.informe-item input[type=checkbox] { width: 19px; height: 19px; flex: 0 0 auto; }
.informe-fecha { font-size: 11px; font-weight: 700; color: #0d4a6e; white-space: nowrap; }
.informe-titulo { flex: 1 1 140px; color: #1e293b; line-height: 1.35; }
.informe-fotos { font-size: 11px; color: #64748b; }
.bita-pendientes strong { display: block; margin-bottom: 4px; }
.bita-motivo { display: block; font-size: 12px; line-height: 1.5; opacity: .85; }
.bita-pendientes .btn-link { margin-top: 6px; display: inline-block; }
