/* ============================================================
   DTC — Sistema Fotográfico · Tema CLARO "Faena clara" (v1.29)
   Rediseño completo: fondo claro de alta legibilidad para terreno.
   Se conservan TODOS los nombres de clase/ID (solo cambia lo visual).
   ============================================================ */
:root {
    --primary: #2e6bd6;
    --primary-dark: #2660c4;
    --primary-soft: #eaf1fb;
    --accent: #f5811e;          /* naranja obra — uso mínimo */
    --success: #22a366;
    --success-soft: #dff2e8;
    --danger: #d94848;
    --page: #eef1f5;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --line: #d7dee7;
    --line-soft: #e6ebf1;
    --text-primary: #16202b;
    --text-secondary: #5a6675;
    --text-muted: #8a97a6;
}

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

body {
    font-family: 'Source Sans 3', system-ui, sans-serif;
    background: var(--page);
    color: var(--text-primary);
    overflow: hidden;
}

#app {
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* dvh = alto REAL visible en móvil (excluye barras de Safari) */
    position: relative;
}

.view {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding: 20px;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    background: var(--page);
    overflow-y: auto; /* si el contenido no cabe, permite scroll en vez de cortarlo */
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.35s ease;
}

.hidden { display: none !important; }

/* ---------------- Pantalla de Inicio ---------------- */
#home-screen {
    justify-content: flex-start;
    align-items: stretch;
    text-align: left;
}

.home-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding-top: 24px;
}

/* v1.43: logo completo entregado por el usuario (cámara + casa + "PATROCINA"
   + "GESTIÓN FOTOGRÁFICA" ya incluidos en la imagen) — reemplaza al ícono
   chico de PYP + el texto "Patrocina" aparte que había antes. Sin borde
   redondeado ni sombra: es un lockup completo sobre fondo blanco, no un
   ícono cuadrado. */
.brand-logo-full {
    width: 220px !important;
    max-width: 72vw;
    height: auto;
    display: block;
    margin: 0 auto;
}

.logo-text {
    font-family: 'Lexend', sans-serif;
    font-size: 26px;
    line-height: 1.05;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin-top: 10px;
}

.subtitle {
    font-size: 12px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 4px;
}

/* Estado de base de datos (píldora) */
#db-status-container {
    margin-top: 16px !important;
    background: var(--surface) !important;
    border: 1px solid var(--line) !important;
    color: var(--text-secondary) !important;
    box-shadow: 0 2px 8px rgba(22, 32, 43, 0.05);
    backdrop-filter: none !important;
}

.spacer { flex: 1; min-height: 24px; }

/* Tarjetas de acción del inicio */
.home-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 12px;
}

.home-card {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    text-align: left;
    padding: 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    font-family: 'Source Sans 3', sans-serif;
    box-shadow: 0 2px 10px rgba(22, 32, 43, 0.05);
    transition: transform 0.12s ease, box-shadow 0.15s ease;
}
.home-card:active { transform: scale(0.985); }
.home-card:disabled { opacity: 0.55; cursor: default; }
.home-card:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; }

.home-card.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 8px 20px rgba(46, 107, 214, 0.28);
}

.home-card .hc-ico {
    width: 40px; height: 40px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    background: var(--primary-soft);
    color: var(--primary);
}
.home-card.primary .hc-ico { background: rgba(255,255,255,0.18); color: #fff; }

.home-card .hc-txt b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.home-card .hc-txt span { font-size: 12px; opacity: 0.85; }

/* ---------------- Header ---------------- */
header {
    display: flex;
    align-items: center;
    margin-bottom: 22px;
    padding-top: env(safe-area-inset-top);
}
header h2 {
    font-family: 'Lexend', sans-serif;
    font-size: 19px;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
    text-align: center;
    margin-right: 40px;
}
.btn-back {
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--primary);
    cursor: pointer;
    width: 40px; height: 40px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
}
.btn-back:active { transform: scale(0.95); }

/* ---------------- Contenedores / tarjetas ---------------- */
.glass-container {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 20px;
    box-shadow: 0 4px 16px rgba(22, 32, 43, 0.05);
}

/* ---------------- Forms ---------------- */
.input-group { margin-bottom: 18px; }
.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}
.input-group input,
.input-group select {
    width: 100%;
    padding: 13px 15px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
}
.input-group select {
    cursor: pointer;
    font-family: inherit;
}
.input-group input[readonly] { background: var(--surface-2); color: var(--text-secondary); }
.input-group input:focus,
.input-group select:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-flex { display: flex; gap: 10px; }
.search-flex input { flex: 1; }

.btn-search-icon {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 12px;
    width: 52px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 14px rgba(46, 107, 214, 0.25);
}
.btn-search-icon:active { transform: scale(0.95); }

.feedback-msg {
    display: block;
    margin-top: 8px;
    font-size: 13px;
    color: var(--danger);
}

.btn-primary {
    width: 100%;
    padding: 15px;
    border-radius: 14px;
    background: var(--primary);
    color: #fff;
    border: none;
    font-family: 'Lexend', sans-serif;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    margin-top: 10px;
    box-shadow: 0 8px 20px rgba(46, 107, 214, 0.28);
    transition: transform 0.15s ease;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { background: #b6c0cc; box-shadow: none; cursor: not-allowed; }

/* ---------------- Grid de Fotos ---------------- */
.photo-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    overflow-y: auto;
    padding: 4px 4px 90px;
    align-content: start;
}

.photo-item {
    aspect-ratio: 4/3;
    background: var(--surface-2);
    border-radius: 14px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--line);
    box-shadow: 0 2px 8px rgba(22, 32, 43, 0.06);
    cursor: pointer;
    transition: transform 0.15s ease;
}
.photo-item:active { transform: scale(0.98); }
.photo-item img { width: 100%; height: 100%; object-fit: cover; }

.status-badge {
    position: absolute;
    bottom: 8px; right: 8px;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 6px rgba(22, 32, 43, 0.15);
}

/* ---------------- Acciones flotantes (captura) ---------------- */
.actions {
    position: fixed;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 16px; right: 16px;
    display: flex;
    gap: 10px;
}
.btn-action {
    flex: 1;
    padding: 14px 8px;
    border-radius: 14px;
    border: none;
    font-family: 'Lexend', sans-serif;
    font-weight: 600;
    font-size: 14px;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(22, 32, 43, 0.12);
}
.btn-blue { background: var(--primary); color: #fff; }
.btn-purple { background: #fff !important; color: var(--primary) !important; border: 1px solid var(--line); }
.btn-green { background: var(--success); color: #fff; }
.btn-action.disabled { background: #b6c0cc; color: #fff; box-shadow: none; cursor: not-allowed; }

/* ---------------- Modales ---------------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(22, 32, 43, 0.45);
    backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000;
    padding: 20px;
}
.modal-content {
    width: 100%;
    max-width: 400px;
    padding: 30px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(22, 32, 43, 0.25);
    color: var(--text-primary);
}
.modal-content h3 { font-family: 'Lexend', sans-serif; margin-bottom: 8px; }
.modal-content p { color: var(--text-secondary); font-size: 14px; }

.success-icon {
    width: 60px; height: 60px;
    stroke: var(--success); stroke-width: 2; fill: none;
    margin: 0 auto 16px; display: block;
}
.spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--primary-soft);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Iconos SVG ---------------- */
.icon {
    width: 20px; height: 20px;
    stroke-width: 2; stroke: currentColor; fill: none;
    stroke-linecap: round; stroke-linejoin: round;
    display: inline-block; vertical-align: middle;
}
.icon-spin { animation: icon-spin-anim 1s linear infinite; }
@keyframes icon-spin-anim { to { transform: rotate(360deg); } }
.btn-back .icon { width: 22px; height: 22px; stroke-width: 2.4; }
.btn-search-icon .icon { width: 22px; height: 22px; }

/* ---------------- Modal de Zoom (preview foto) ---------------- */
.modal-content.preview-content {
    background: transparent; border: none; box-shadow: none;
    width: 95%; max-width: 800px; padding: 0;
    position: relative; display: flex; justify-content: center; align-items: center;
}
#preview-img {
    max-width: 100%; max-height: 80vh;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.4);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal:not(.hidden) #preview-img { transform: scale(1); }
.btn-close-zoom {
    position: absolute; top: -46px; right: 6px;
    background: var(--surface); border: 1px solid var(--line);
    color: var(--text-primary);
    width: 38px; height: 38px; border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.btn-close-zoom:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---------------- Badge pendientes ---------------- */
.pending-badge {
    position: fixed;
    bottom: max(16px, env(safe-area-inset-bottom)); right: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    padding: 8px 15px;
    border-radius: 100px;
    display: inline-flex; align-items: center; gap: 8px;
    box-shadow: 0 8px 22px rgba(22, 32, 43, 0.14);
    z-index: 1000;
    animation: slideUp 0.3s forwards cubic-bezier(0.16, 1, 0.3, 1);
}
.badge-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--accent);
    animation: pulse 1.5s infinite alternate;
}
#pending-badge-text { font-size: 12px; font-weight: 700; color: var(--text-primary); }
@keyframes pulse { 0% { opacity: 0.5; } 100% { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------------- Scrollbars ---------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ============================================================
   Proyectos en Ejecución (v1.27) — tema claro
   ============================================================ */
.res-group { margin-bottom: 16px; padding: 14px 16px; }
.res-title {
    font-family: 'Lexend', sans-serif;
    font-weight: 800;
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 10px;
    display: flex; align-items: center; gap: 6px;
}
.res-title .res-fecha { font-weight: 400; color: var(--text-secondary); font-size: 12px; }

.proj-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    margin-bottom: 8px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    cursor: pointer;
    font-family: 'Source Sans 3', sans-serif;
    transition: background 0.15s ease, transform 0.1s ease;
}
.proj-row:active { transform: scale(0.985); }
.proj-row:hover { background: var(--primary-soft); }
.proj-row-name { font-weight: 700; font-size: 14px; color: var(--text-primary); }
.proj-row-meta { font-size: 12px; color: var(--text-secondary); }

.pexec-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    padding: 34px 12px;
}
.pexec-file-fallback {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; font-size: 22px; color: var(--text-secondary); text-align: center; padding: 6px;
}
.pexec-file-fallback span { font-size: 9px; word-break: break-all; max-height: 3em; overflow: hidden; }

/* Buscador (v1.28) */
.pexec-search {
    display: flex; align-items: center; gap: 8px;
    padding: 11px 15px; margin-bottom: 14px;
}
.pexec-search input {
    flex: 1; border: none; background: transparent; outline: none;
    font-family: 'Source Sans 3', sans-serif; font-size: 15px; color: var(--text-primary);
}
.pexec-search input::placeholder { color: var(--text-muted); }

/* Contenedor scrollable de pantallas internas */
.content { flex: 1; overflow-y: auto; padding-bottom: 8px; }

/* v1.31 — Hitos de obra PHS (Inicio / Avance / Término) */
.pexec-hitos-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-muted); font-weight: 700; margin: 0 0 7px;
}
.pexec-hitos {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}
.pexec-hito {
    padding: 10px 6px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--text-secondary);
    font-family: 'Source Sans 3', sans-serif;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.pexec-hito:active { transform: scale(0.97); }
.pexec-hito.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(46, 107, 214, 0.25);
}

/* v1.31 — Agregar proyecto en ejecución manualmente */
.btn-add-proj {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; margin-bottom: 14px;
    padding: 12px;
    border-radius: 12px;
    border: 1px dashed var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
    font-family: 'Source Sans 3', sans-serif; font-size: 13.5px; font-weight: 700;
    cursor: pointer;
    transition: background 0.12s ease;
}
.btn-add-proj:active { transform: scale(0.99); }
#add-project-form { display: flex; flex-direction: column; gap: 10px; }
.ap-title { margin: 0 0 2px; font-size: 14px; font-weight: 700; color: var(--text-primary); }
.ap-input {
    width: 100%; padding: 12px 14px;
    border-radius: 11px; border: 1px solid var(--line);
    background: var(--surface-2); color: var(--text-primary);
    font-size: 16px; outline: none;
}
.ap-input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-soft); }
.ap-actions { display: flex; gap: 10px; margin-top: 2px; }
.ap-btn { flex: 1; padding: 12px; border-radius: 11px; border: none; font-family: 'Lexend', sans-serif; font-weight: 700; font-size: 14px; cursor: pointer; }
.ap-save { background: var(--primary); color: #fff; }
.ap-cancel { background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--line); }

/* Fila con botón de abrir + eliminar (solo proyectos manuales) */
.proj-row-manual { display: flex; align-items: stretch; gap: 8px; padding: 0; border: none; background: none; margin-bottom: 8px; }
.proj-row-open {
    flex: 1; text-align: left; display: flex; flex-direction: column; gap: 2px;
    padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
    background: var(--surface-2); cursor: pointer; font-family: 'Source Sans 3', sans-serif;
}
.proj-row-open:active { transform: scale(0.985); }
.proj-row-open:hover { background: var(--primary-soft); }
.proj-row-del {
    flex-shrink: 0; width: 44px; border-radius: 12px;
    border: 1px solid var(--line); background: var(--surface-2);
    color: var(--danger); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.proj-row-del:active { transform: scale(0.95); }

/* ============================================================
   v1.33 — Login (Firebase Auth) + chip de usuario conectado
   ============================================================ */
.login-wrap {
    height: 100dvh;
    min-height: 100vh;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 24px; text-align: center;
}
.login-box {
    width: 100%; max-width: 360px;
    margin-top: 26px; text-align: left;
}
.login-error {
    margin: 12px 0 0; font-size: 12px; font-weight: 600;
    color: var(--danger); text-align: center;
}
/* v1.35: mismo mensaje sirve para error (rojo) y para confirmación (verde). */
.login-error.login-ok { color: var(--success); }
.login-forgot {
    display: block; width: 100%; margin: 12px 0 0;
    background: none; border: 0; padding: 4px;
    font-size: 12px; font-weight: 600; color: var(--primary);
    text-decoration: underline; cursor: pointer;
}
.login-forgot:disabled { opacity: .6; cursor: default; text-decoration: none; }
.login-hint {
    margin-top: 16px; font-size: 11px; color: var(--text-muted);
}
.user-chip {
    display: inline-flex; align-items: center; gap: 6px;
    margin-top: 8px; padding: 4px 10px;
    border-radius: 100px; border: 1px solid var(--line-soft);
    background: var(--surface); font-size: 11px; color: var(--text-secondary);
}
.user-chip.hidden { display: none; }
.user-chip button {
    background: none; border: none; padding: 2px;
    cursor: pointer; color: var(--text-muted);
    display: inline-flex; align-items: center;
}
.user-chip button:active { color: var(--danger); }

/* ── Selector de ficha: cuando un RUT tiene varios proyectos (v1.39) ──────────
   Antes se elegía con .find(), o sea al azar. Cuando ninguno está en
   planificación no hay criterio automático y decide el técnico. */
.selector-fichas {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.selector-ficha-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 4px solid var(--primary);
    border-radius: 10px;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.selector-ficha-btn:active { background: var(--primary-soft); }

.selector-ficha-proyecto {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    line-height: 1.3;
}

.selector-ficha-etapa {
    font-size: 0.8rem;
    color: var(--text-muted);
}
