/* ==========================================================================
   MINETECH DESIGN SYSTEM - MANTENIMIENTO MINETECH
   Paleta extraída de logo.png:
   - Oro / Ámbar MineTech:    #D8B128 (Hover: #B59016, Fondo suave: #FDF9EC)
   - Rojo Carmesí / Minería:  #C94132 (Hover: #A72F22, Fondo suave: #FDEEEC)
   - Grafito / Gris Oscuro:   #14171A, #1E2328, #2B3239
   - Pizarra / Slate:         #47515C, #73808E, #D6DCE4, #EEF2F6
   - Fondo y Tarjetas:        #F4F6F9, #FFFFFF
   - Semáforos:               OK: #2E7D32, REG: #D97706, MAL: #C94132
   ========================================================================== */

:root {
  --brand-gold:       #D8B128;
  --brand-gold-dark:  #B59016;
  --brand-gold-light: #FDF9EC;
  --brand-gold-glow:  rgba(216, 177, 40, 0.28);

  --brand-red:        #C94132;
  --brand-red-dark:   #A72F22;
  --brand-red-light:  #FDEEEC;
  --brand-red-glow:   rgba(201, 65, 50, 0.25);

  --brand-dark:       #14171A;
  --brand-surface-dark:#1E2328;
  --brand-slate-700:  #2B3239;
  --brand-slate-600:  #47515C;
  --brand-slate-400:  #73808E;
  --brand-slate-200:  #D6DCE4;
  --brand-slate-100:  #EEF2F6;

  --bg:               #F4F6F9;
  --surface:          #FFFFFF;
  --border:           #D9E1E8;
  --border-focus:     #D8B128;

  --text-main:        #161B20;
  --text-muted:       #556270;
  --text-light:       #8A97A6;

  --ok:               #2E7D32;
  --ok-bg:            #E8F5E9;
  --ok-border:        #A5D6A7;

  --reg:              #D97706;
  --reg-bg:           #FEF3C7;
  --reg-border:       #FCD34D;

  --mal:              #C94132;
  --mal-bg:           #FDEEEC;
  --mal-border:       #FCA5A5;

  --radius-sm:        6px;
  --radius:           10px;
  --radius-lg:        16px;
  --radius-pill:      999px;

  --shadow-sm:        0 1px 3px rgba(0,0,0,0.06);
  --shadow:           0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg:        0 12px 30px rgba(0,0,0,0.14);

  --safe-bottom:      env(safe-area-inset-bottom, 0px);
  --safe-top:         env(safe-area-inset-top, 0px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(74px + var(--safe-bottom));
}

/* ==========================================================================
   PANTALLA DE INICIO DE SESIÓN (LOGIN VIEW)
   ========================================================================== */
#login-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 20%, #2B3239 0%, #14171A 100%);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

#login-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: rgba(30, 35, 40, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(216, 177, 40, 0.35);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: 0 20px 45px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: loginCardPop 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes loginCardPop {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo-wrap {
  position: relative;
  width: 88px;
  height: 88px;
  margin-bottom: 16px;
}

.login-logo-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: #FFFFFF;
  padding: 4px;
  box-shadow: 0 0 24px rgba(216, 177, 40, 0.45);
}

.login-title {
  color: #FFFFFF;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-align: center;
  margin-bottom: 4px;
}

.login-title span.gold { color: var(--brand-gold); }
.login-title span.red  { color: var(--brand-red); }

.login-sub {
  color: var(--brand-slate-400);
  font-size: 12.5px;
  text-align: center;
  margin-bottom: 24px;
}

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field label {
  color: var(--brand-slate-200);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.login-input {
  width: 100%;
  height: 46px;
  background: #14171A;
  border: 1.5px solid var(--brand-slate-700);
  border-radius: var(--radius);
  padding: 0 14px;
  color: #FFFFFF;
  font-size: 15px;
  font-weight: 600;
  outline: none;
  transition: all 0.2s;
}

.login-input:focus {
  border-color: var(--brand-gold);
  box-shadow: 0 0 0 3px var(--brand-gold-glow);
}

.login-btn {
  width: 100%;
  height: 48px;
  background: linear-gradient(135deg, var(--brand-gold), #C89518);
  color: var(--brand-dark);
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  box-shadow: 0 6px 16px rgba(216, 177, 40, 0.35);
  transition: all 0.2s;
}

.login-btn:active {
  transform: scale(0.98);
}

.login-quick-btn {
  background: rgba(255,255,255,0.06);
  border: 1px dashed rgba(216, 177, 40, 0.5);
  color: var(--brand-gold);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  margin-top: 4px;
  transition: all 0.2s;
}

.login-quick-btn:hover {
  background: rgba(216, 177, 40, 0.12);
}

/* ==========================================================================
   TOPBAR PRINCIPAL
   ========================================================================== */
.topbar {
  background: var(--brand-dark);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 16px 8px;
  min-height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  border-bottom: 2px solid var(--brand-gold);
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-logo-img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: #FFFFFF;
  padding: 2px;
  flex-shrink: 0;
}

.brand-title {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: #FFFFFF;
  line-height: 1.1;
}

.brand-name span.gold { color: var(--brand-gold); }
.brand-name span.red  { color: var(--brand-red); }

.brand-sub {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--brand-slate-400);
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pwa-install-btn {
  background: linear-gradient(135deg, var(--brand-gold), #D8A518);
  color: #14171A;
  border: none;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 800;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  animation: pulseInstall 2s infinite ease-in-out;
}

@keyframes pulseInstall {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--brand-surface-dark);
  border: 1px solid var(--brand-slate-700);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}

.user-avatar-circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-gold), var(--brand-red));
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-display-text {
  font-size: 12px;
  font-weight: 700;
  color: #FFFFFF;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: transparent;
  border: none;
  color: var(--brand-slate-400);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
  display: flex;
  align-items: center;
}

.btn-logout:hover {
  color: var(--brand-red);
}

/* ==========================================================================
   DESKTOP / TABLET NAV TABS (HIDDEN ON PHONE, VISIBLE >= 768px)
   ========================================================================== */
.desktop-nav-bar {
  display: none;
  background: var(--brand-surface-dark);
  border-bottom: 1px solid var(--brand-slate-700);
  padding: 0 24px;
  gap: 8px;
}

.desktop-nav-item {
  padding: 12px 18px;
  color: var(--brand-slate-400);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  user-select: none;
}

.desktop-nav-item:hover {
  color: #FFFFFF;
  background: rgba(255,255,255,0.04);
}

.desktop-nav-item.active {
  color: #FFFFFF;
  border-bottom-color: var(--brand-gold);
  background: rgba(216, 177, 40, 0.08);
}

/* ==========================================================================
   BOTTOM NAVIGATION BAR (MOBILE FIRST STYLE)
   ========================================================================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(64px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--brand-dark);
  border-top: 1px solid var(--brand-slate-700);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 900;
  box-shadow: 0 -4px 14px rgba(0,0,0,0.25);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  color: var(--brand-slate-400);
  font-size: 10px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  gap: 3px;
  transition: all 0.2s;
  user-select: none;
  position: relative;
}

.bottom-nav-item .nav-icon {
  font-size: 20px;
  transition: transform 0.2s;
}

.bottom-nav-item.active {
  color: var(--brand-gold);
}

.bottom-nav-item.active .nav-icon {
  transform: translateY(-2px);
}

.bottom-nav-item .badge-count {
  position: absolute;
  top: 8px;
  right: calc(50% - 18px);
  background: var(--brand-red);
  color: #FFFFFF;
  font-size: 9px;
  font-weight: 900;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 14px;
  text-align: center;
}

/* ==========================================================================
   VISTAS Y CONTENEDORES
   ========================================================================== */
.app-view {
  display: none;
  padding: 14px 12px 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.app-view.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-header-card {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.page-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.page-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.35;
}

.header-action-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}

/* ==========================================================================
   BOTONES Y ACCIONES
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
  text-decoration: none;
  min-height: 42px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-gold {
  background: linear-gradient(135deg, var(--brand-gold), #C89518);
  color: var(--brand-dark);
}

.btn-red {
  background: linear-gradient(135deg, var(--brand-red), var(--brand-red-dark));
  color: #FFFFFF;
}

.btn-outline {
  background: #FFFFFF;
  color: var(--brand-slate-700);
  border-color: var(--border);
}

.btn-dark {
  background: var(--brand-slate-700);
  color: #FFFFFF;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 11.5px;
  min-height: 32px;
}

.btn-block {
  width: 100%;
}

/* ==========================================================================
   METADATOS DE CABECERA (FORMULARIO PRINCIPAL)
   ========================================================================== */
.meta-card {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.meta-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.meta-field label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--brand-slate-600);
}

.meta-field select,
.meta-field input {
  width: 100%;
  height: 40px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--brand-dark);
  background: #FFFFFF;
  transition: border-color 0.2s;
}

.meta-field select:focus,
.meta-field input:focus {
  outline: none;
  border-color: var(--brand-gold);
  box-shadow: 0 0 0 3px var(--brand-gold-glow);
}

/* ==========================================================================
   TARJETAS DE SECCIÓN (ACORDEÓN TÁCTIL)
   ========================================================================== */
.section-card {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 0.2s;
}

.section-header {
  background: var(--brand-surface-dark);
  color: #FFFFFF;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  border-left: 4px solid var(--brand-gold);
}

.section-num {
  width: 24px;
  height: 24px;
  background: var(--brand-gold);
  color: var(--brand-dark);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
  flex-shrink: 0;
}

.section-title {
  font-size: 13.5px;
  font-weight: 700;
  flex: 1;
  color: #FFFFFF;
  line-height: 1.25;
}

.section-badge {
  font-size: 10px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
}

.chevron-icon {
  font-size: 11px;
  color: var(--brand-gold);
  transition: transform 0.25s;
}

.section-card.collapsed .chevron-icon {
  transform: rotate(-90deg);
}

.section-card.collapsed .section-body {
  display: none;
}

.section-body {
  padding: 14px 12px;
}

/* ==========================================================================
   TARJETA / FILA TÉCNICA MOBILE-FIRST CON BOTÓN DE FOTO
   ========================================================================== */
.field-item-card {
  background: #FAFBFD;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.field-item-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand-dark);
}

.field-item-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.3;
}

/* Botón de cámara por fila */
.btn-photo-row {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: var(--radius-pill);
  background: #FFFFFF;
  border: 1.5px solid var(--border);
  color: var(--brand-slate-600);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s;
}

.btn-photo-row:active {
  transform: scale(0.95);
}

.btn-photo-row.has-photos {
  background: var(--brand-gold-light);
  border-color: var(--brand-gold);
  color: #7A5B00;
}

.btn-photo-row .photo-badge {
  background: var(--brand-gold);
  color: #000;
  font-size: 9px;
  font-weight: 900;
  padding: 1px 5px;
  border-radius: 8px;
}

.field-item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.input-group label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--brand-slate-600);
  text-transform: uppercase;
}

.input-mobile {
  height: 38px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-dark);
  background: #FFFFFF;
}

.input-mobile:focus {
  outline: none;
  border-color: var(--brand-gold);
}

/* Selectores de Estado OK / REG / MAL */
.status-select {
  height: 38px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  border: 1.5px solid var(--border);
  background: #FFFFFF;
  transition: all 0.15s;
}

.status-select.s-ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok-border);
}

.status-select.s-reg {
  background: var(--reg-bg);
  color: var(--reg);
  border-color: var(--reg-border);
}

.status-select.s-mal {
  background: var(--mal-bg);
  color: var(--mal);
  border-color: var(--mal-border);
}

.obs-textarea {
  width: 100%;
  height: 60px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--brand-dark);
  resize: vertical;
  margin-top: 6px;
}

.obs-textarea:focus {
  outline: none;
  border-color: var(--brand-gold);
}

/* ==========================================================================
   TILDE DE OPERATIVIDAD MODERNO (STATUS SELECTOR CARDS)
   ========================================================================== */
.dictamen-selector-box {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  margin-bottom: 14px;
}

.dictamen-box-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--brand-slate-600);
  margin-bottom: 10px;
  text-align: center;
}

.dictamen-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.dictamen-card-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 6px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: #FAFBFD;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: center;
  user-select: none;
  min-height: 80px;
}

.dictamen-card-btn:active {
  transform: scale(0.96);
}

.dictamen-card-icon {
  font-size: 22px;
  margin-bottom: 4px;
  transition: transform 0.2s;
}

.dictamen-card-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.2px;
  line-height: 1.15;
}

/* Estados Activos */
.dictamen-card-btn.state-ok.active {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: var(--ok);
  box-shadow: 0 4px 14px rgba(46, 125, 50, 0.25);
}

.dictamen-card-btn.state-reg.active {
  background: var(--reg-bg);
  border-color: var(--reg);
  color: #B45309;
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.25);
}

.dictamen-card-btn.state-mal.active {
  background: var(--mal-bg);
  border-color: var(--mal);
  color: var(--mal);
  box-shadow: 0 4px 14px rgba(201, 65, 50, 0.25);
}

/* ==========================================================================
   FIRMAS DIGITALES TÁCTILES
   ========================================================================== */
.sig-box {
  background: #FAFBFD;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 10px;
}

.sig-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.sig-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--brand-slate-700);
}

.sig-clear-btn {
  background: transparent;
  border: none;
  color: var(--brand-red);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.sig-canvas-wrap {
  width: 100%;
  height: 90px;
  background: #FFFFFF;
  border: 1.5px dashed var(--brand-slate-200);
  border-radius: var(--radius-sm);
  touch-action: none;
  position: relative;
  overflow: hidden;
}

.sig-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ==========================================================================
   MODAL DE FOTOS (MULTI-FOTO HASTA 5 POR FILA)
   ========================================================================== */
.photo-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 9999;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.photo-modal-overlay.active {
  display: flex;
}

.photo-modal-sheet {
  background: #FFFFFF;
  width: 100%;
  max-width: 500px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  box-shadow: 0 -8px 25px rgba(0,0,0,0.3);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease forwards;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.photo-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.photo-modal-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--brand-dark);
}

.photo-modal-close {
  background: var(--brand-slate-100);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 800;
  color: var(--brand-slate-600);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-grid-scroll {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
  max-height: 280px;
  overflow-y: auto;
  padding: 2px;
}

.photo-thumb-card {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #F0F3F6;
}

.photo-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-thumb-del {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(201, 65, 50, 0.9);
  color: #FFFFFF;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-actions-row {
  display: flex;
  gap: 8px;
}

/* ==========================================================================
   MODAL DE VISUALIZACIÓN DE FOTO A PANTALLA COMPLETA
   ========================================================================== */
.photo-viewer-fullscreen {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 10000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.photo-viewer-fullscreen.active {
  display: flex;
}

.photo-viewer-img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: var(--radius);
  object-fit: contain;
}

.photo-viewer-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255,255,255,0.2);
  color: #FFFFFF;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}

/* ==========================================================================
   MÉTRICAS Y FLOTA (KPIs INTERACTIVOS)
   ========================================================================== */
.kpi-mobile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.kpi-touch-card {
  background: #FFFFFF;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-sm);
  user-select: none;
}

.kpi-touch-card:active {
  transform: scale(0.96);
}

.kpi-touch-card.kpi-green {
  border-left: 5px solid var(--ok);
}

.kpi-touch-card.kpi-orange {
  border-left: 5px solid var(--reg);
  background: #FFFDF9;
}

.kpi-touch-card.kpi-red {
  border-left: 5px solid var(--mal);
  background: #FFFBFB;
}

.kpi-touch-card.kpi-gold {
  border-left: 5px solid var(--brand-gold);
}

.kpi-heading {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-muted);
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 6px 0 2px;
}

.kpi-big-num {
  font-size: 26px;
  font-weight: 900;
  color: var(--brand-dark);
}

.kpi-arrow-icon {
  font-size: 14px;
  color: var(--brand-slate-400);
}

.kpi-sub-text {
  font-size: 10.5px;
  color: var(--text-light);
}

/* Mapa táctico mobile */
.tactical-map-box {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.map-header {
  padding: 10px 14px;
  background: var(--brand-surface-dark);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 12.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.map-viewport {
  height: 240px;
  background: 
    radial-gradient(circle at 50% 50%, rgba(216, 177, 40, 0.06), transparent 70%),
    repeating-linear-gradient(0deg, #E6EBF0, #E6EBF0 1px, transparent 1px, transparent 24px),
    repeating-linear-gradient(90deg, #E6EBF0, #E6EBF0 1px, transparent 1px, transparent 24px),
    linear-gradient(135deg, #F0F4F8 0%, #DCE5EE 100%);
  position: relative;
  overflow: hidden;
}

.car-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.car-marker:active {
  transform: translate(-50%, -50%) scale(1.15);
}

.marker-bubble {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-dark);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 12px;
  border: 2.5px solid #FFFFFF;
  box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

.marker-bubble.m-ok  { background: var(--ok); }
.marker-bubble.m-reg { background: var(--reg); }
.marker-bubble.m-mal { background: var(--mal); }

.marker-tag {
  background: rgba(255,255,255,0.95);
  color: var(--brand-dark);
  font-size: 9.5px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 3px;
  margin-top: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  white-space: nowrap;
}

/* ==========================================================================
   HISTORIAL DE INSPECCIONES (BÚSQUEDA AVANZADA POR FECHAS)
   ========================================================================== */
.history-filter-section {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quick-filter-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.quick-filter-scroll::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  padding: 6px 12px;
  background: #FAFBFD;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  color: var(--brand-slate-600);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.filter-chip.active {
  background: var(--brand-gold);
  border-color: var(--brand-gold-dark);
  color: #000000;
  box-shadow: 0 2px 6px rgba(216, 177, 40, 0.3);
}

.date-range-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.history-card-item {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-tag-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--brand-dark);
}

.history-date-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.history-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.history-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: calc(76px + var(--safe-bottom));
  left: 16px;
  right: 16px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast-msg {
  background: var(--brand-dark);
  color: #FFFFFF;
  border-left: 4px solid var(--brand-gold);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  max-width: 90%;
  animation: toastPop 0.25s ease forwards;
}

@keyframes toastPop {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   MODAL GUÍA PARA INSTALAR EN IOS (SAFARI)
   ========================================================================== */
.ios-guide-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.ios-guide-modal.active {
  display: flex;
}

.ios-guide-box {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 16px 36px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

/* ==========================================================================
   ADAPTACIONES PARA PANTALLAS GRANDES (PC / MAC / TABLET >= 768px)
   ========================================================================== */
@media (min-width: 768px) {
  body {
    padding-bottom: 24px;
  }

  .desktop-nav-bar {
    display: flex;
  }

  .bottom-nav {
    display: none;
  }

  .meta-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .field-item-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .kpi-mobile-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .dictamen-cards-grid {
    grid-template-columns: repeat(3, 1fr);
    max-width: 600px;
    margin: 0 auto;
  }

  .header-action-group {
    width: auto;
  }

  .page-header-card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

/* ==========================================================================
   PRINT MEDIA (COPIA FIEL PDF OFICIAL PARA SUBIR / ENVIAR REPORTE)
   ========================================================================== */
@media print {
  body {
    background: #FFFFFF !important;
    color: #000000 !important;
    font-size: 8.5pt !important;
    padding-bottom: 0 !important;
  }
  .topbar, .desktop-nav-bar, .bottom-nav, .header-action-group, 
  .btn-photo-row, .sig-clear-btn, .history-filter-section,
  .toast-container, .btn, .no-print, #login-screen {
    display: none !important;
  }
  .app-view {
    padding: 0 !important;
    max-width: 100% !important;
    display: block !important;
  }
  #view-metrics, #view-history, #view-guide {
    display: none !important;
  }
  #view-sheet {
    display: block !important;
  }
  .section-card {
    border: 1px solid #777 !important;
    box-shadow: none !important;
    margin-bottom: 8px !important;
    page-break-inside: avoid;
  }
  .section-card.collapsed .section-body {
    display: block !important;
  }
  .section-header {
    background: #222 !important;
    color: #FFF !important;
    padding: 4px 8px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .section-body {
    padding: 6px 8px !important;
  }
}
