:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --card2: #16213e;
  --accent: #e94560;
  --accent2: #0f3460;
  --text: #eaeaea;
  --muted: #a0a0b0;
  --ok: #2ecc71;
  --warn: #f39c12;
  --danger: #e74c3c;
  --border: #2a2a40;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.screen { display: none; min-height: 100%; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* AUTH */
#auth-screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(145deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
}
#auth-screen.active { display: flex; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 20px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.logo { font-size: 48px; margin-bottom: 8px; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: 4px; }
.subtitle { color: var(--muted); font-size: .9rem; margin-bottom: 24px; }

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  border-radius: 8px;
  font-size: .95rem;
  cursor: pointer;
  transition: .2s;
}
.tab.active { background: var(--accent); color: #fff; font-weight: 600; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form.hidden { display: none; }

input, textarea, select {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border .2s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

.btn {
  padding: 14px 20px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: .2s;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { transform: scale(.98); }
.btn.secondary { background: var(--accent2); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.msg { margin-top: 12px; font-size: .9rem; min-height: 20px; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* HEADER */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-left { display: flex; align-items: center; gap: 8px; }
.logo-sm { font-size: 1.4rem; }
#user-name { font-weight: 600; font-size: .95rem; }
.badge {
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent2);
  color: #fff;
  text-transform: uppercase;
}
.badge.tecnico { background: var(--ok); }
.header-right { display: flex; gap: 4px; }
.btn-icon {
  background: transparent;
  border: none;
  font-size: 1.3rem;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 8px;
}
.btn-icon:active { background: var(--border); }

/* NAV */
.nav {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;
  z-index: 40;
}
.nav-btn {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: .9rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: .2s;
}
.nav-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.nav-btn.hidden { display: none; }

/* MAIN */
#main { padding: 16px; padding-bottom: 40px; max-width: 700px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; }

.stats {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.stat {
  flex: 1;
  min-width: 80px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  border: 1px solid var(--border);
}
.stat .num { font-size: 1.5rem; font-weight: 700; }
.stat .lbl { font-size: .75rem; color: var(--muted); }

.lista { display: flex; flex-direction: column; gap: 12px; }

.card-act {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: .2s;
  position: relative;
  overflow: hidden;
}
.card-act:active { transform: scale(.99); }
.card-act.urgente { border-left: 4px solid var(--danger); }
.card-act.alta { border-left: 4px solid var(--warn); }
.card-act.finalizada { opacity: .7; }

.card-act .titulo { font-weight: 600; font-size: 1.05rem; margin-bottom: 4px; }
.card-act .meta { font-size: .8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.card-act .desc { font-size: .9rem; color: var(--muted); margin-bottom: 10px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.progress-bar {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 3px;
  transition: width .3s;
}
.progress-fill.done { background: var(--ok); }

.status-tag {
  display: inline-block;
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  text-transform: uppercase;
}
.status-tag.pendiente { background: #3a3a50; color: #ccc; }
.status-tag.en_progreso { background: #1a3a5c; color: #5dade2; }
.status-tag.finalizada { background: #1a3a2a; color: var(--ok); }

.vacio { text-align: center; color: var(--muted); padding: 40px 20px; line-height: 1.6; }

/* FORM NUEVA */
#view-nueva h2, #view-filtro h2 { margin-bottom: 16px; font-size: 1.2rem; }
#form-nueva { display: flex; flex-direction: column; gap: 10px; }
#form-nueva label { font-size: .85rem; color: var(--muted); margin-top: 4px; }

/* FILTROS */
.filtros { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filtro-btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 20px;
  font-size: .85rem;
  cursor: pointer;
}
.filtro-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* DETALLE */
.btn-back {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 1rem;
  padding: 8px 0;
  margin-bottom: 12px;
  cursor: pointer;
}

.detalle-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
}
.detalle-card h2 { font-size: 1.25rem; margin-bottom: 8px; }
.detalle-meta { font-size: .85rem; color: var(--muted); margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 10px; }
.detalle-desc { margin-bottom: 16px; line-height: 1.5; white-space: pre-wrap; }

.fotos-section { margin: 16px 0; }
.fotos-section h3 { font-size: .95rem; margin-bottom: 8px; color: var(--muted); }
.fotos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.foto-card-item {
  background: var(--bg);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
  display: flex;
  flex-direction: column;
}
.foto-card-item img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  cursor: pointer;
  transition: transform .2s;
}
.foto-card-item img:hover {
  transform: scale(1.03);
}
.foto-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  font-size: .72rem;
  background: var(--card);
}
.foto-tag-badge {
  background: var(--accent2);
  color: #5dade2;
  padding: 2px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  font-weight: 700;
  font-size: .65rem;
}
.foto-tag-badge.antes { background: #3a3a50; color: #ccc; }
.foto-tag-badge.despues { background: #1a3a2a; color: var(--ok); }
.btn-del-foto {
  background: rgba(231, 76, 60, 0.85);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: .75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 10;
  transition: .2s;
}
.btn-del-foto:hover {
  background: var(--danger);
  transform: scale(1.1);
}
.foto-upload-controls {
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
  border: 1px dashed var(--border);
  margin-top: 10px;
}
.foto-upload-controls h4 {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 10px;
}
.foto-btn-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.foto-btn-group .btn-foto-opt {
  flex: 1;
  min-width: 140px;
}
.foto-box {
  background: var(--bg);
  border-radius: 10px;
  overflow: hidden;
  border: 1px dashed var(--border);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}
.foto-box img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  cursor: pointer;
}
.foto-box .label { font-size: .75rem; color: var(--muted); padding: 6px; }
.foto-box .btn-add-foto {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: .9rem;
  padding: 20px;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.foto-box input[type=file] { display: none; }
.foto-box-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 8px;
  width: 100%;
  align-items: center;
  justify-content: center;
}
.foto-box-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.btn-foto-opt {
  width: 100%;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all .2s;
}
.btn-foto-opt:active { transform: scale(.97); }
.btn-foto-opt.btn-camera {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-foto-opt.btn-gallery {
  background: var(--card2);
  color: var(--text);
  border-color: var(--border);
}

.avance-box {
  margin: 16px 0;
  background: var(--bg);
  border-radius: 10px;
  padding: 14px;
}
.avance-box label { font-size: .9rem; color: var(--muted); display: block; margin-bottom: 8px; }
.avance-row { display: flex; align-items: center; gap: 12px; }
.avance-row input[type=range] { flex: 1; accent-color: var(--accent); }
.avance-val { font-weight: 700; font-size: 1.1rem; min-width: 45px; text-align: right; }

.acciones { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.acciones .btn { width: 100%; }

.notas-box { margin-top: 16px; }
.notas-box textarea { min-height: 70px; }
.notas-box button { margin-top: 8px; }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-content { position: relative; max-width: 100%; max-height: 90vh; }
.modal-content img { max-width: 100%; max-height: 85vh; border-radius: 8px; }
.modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
}

/* Responsive */
@media (min-width: 600px) {
  .fotos-grid { grid-template-columns: 1fr 1fr; }
  .acciones { flex-direction: row; }
  .acciones .btn { flex: 1; }
}

/* Offline indicator */
.offline-banner {
  background: var(--warn);
  color: #000;
  text-align: center;
  padding: 6px;
  font-size: .85rem;
  font-weight: 600;
}

/* HISTORIAL Y COMENTARIOS */
.comentarios-section {
  margin-top: 20px;
  background: var(--card2);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}
.comentarios-section h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.comentarios-lista {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.comentario-item {
  background: var(--card);
  border-radius: 10px;
  padding: 12px;
  border: 1px solid var(--border);
}
.comentario-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 6px;
  flex-wrap: wrap;
  gap: 6px;
}
.comentario-user { font-weight: 600; color: var(--text); }
.comentario-fecha { font-size: .78rem; color: var(--muted); }
.comentario-avance-tag {
  background: var(--accent2);
  color: #5dade2;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 600;
}
.comentario-texto {
  font-size: .92rem;
  color: var(--text);
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.vacio-comentarios {
  font-size: .85rem;
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 12px 0;
}
.hint-100 {
  margin-top: 8px;
  font-size: .82rem;
  color: var(--warn);
  background: rgba(243, 156, 18, 0.15);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(243, 156, 18, 0.3);
}
.hint-100.hidden { display: none; }
.finalizada-banner {
  background: rgba(46, 204, 113, 0.12);
  border: 1px solid var(--ok);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  margin: 16px 0;
}
.finalizada-banner .fin-title {
  color: var(--ok);
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 4px;
}
.finalizada-banner .fin-meta {
  font-size: .85rem;
  color: var(--muted);
}

