/* =========================================================
   MEDIDOR PWA — Estilos Principales
   ========================================================= */

:root {
  --primary:     #2563eb;
  --primary-dark:#1d4ed8;
  --secondary:   #10b981;
  --warning:     #f59e0b;
  --danger:      #ef4444;
  --dark:        #1f2937;
  --gray-100:    #f3f4f6;
  --gray-200:    #e5e7eb;
  --gray-500:    #6b7280;
  --radius:      0.875rem;
  --shadow:      0 4px 20px rgba(0,0,0,.08);
  --shadow-lg:   0 10px 40px rgba(0,0,0,.15);
  --nav-height:  60px;
}

/* ── Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--gray-100);
  color: var(--dark);
  padding-top: var(--nav-height);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ── Navbar ───────────────────────────────────────────── */
#mainNavbar {
  height: var(--nav-height);
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  box-shadow: 0 2px 20px rgba(37,99,235,.4);
  backdrop-filter: blur(8px);
}

.brand-icon {
  width: 32px; height: 32px;
  background: rgba(255,255,255,.2);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}

.brand-text { font-size: 1.05rem; letter-spacing: -.3px; }

/* ── Status Badge ─────────────────────────────────────── */
.status-badge {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  transition: all .3s;
}
.status-online  { background: rgba(16,185,129,.2); color: #6ee7b7; border: 1px solid rgba(16,185,129,.3); }
.status-offline { background: rgba(239,68,68,.2);  color: #fca5a5; border: 1px solid rgba(239,68,68,.3);  }

.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  animation: pulse-dot 2s infinite;
}
.status-online  .status-dot { background: #10b981; }
.status-offline .status-dot { background: #ef4444; animation: none; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.8); }
}

/* ── Sync Progress Bar ────────────────────────────────── */
.sync-progress-bar {
  position: fixed; top: var(--nav-height); left: 0; right: 0; z-index: 1039;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white; padding: 8px 16px; text-align: center;
  font-size: .85rem; font-weight: 600;
  box-shadow: 0 2px 10px rgba(245,158,11,.4);
}

/* ── Cards ────────────────────────────────────────────── */
.card {
  border: none; border-radius: var(--radius);
  box-shadow: var(--shadow); transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow-lg); }

.stat-card {
  border-radius: var(--radius); padding: 1.25rem; color: white;
  position: relative; overflow: hidden; border: none;
}
.stat-card::after {
  content: ''; position: absolute; right: -20px; top: -20px;
  width: 100px; height: 100px; border-radius: 50%;
  background: rgba(255,255,255,.1);
}
.stat-card .stat-icon {
  width: 52px; height: 52px; background: rgba(255,255,255,.2);
  border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label { font-size: .8rem; opacity: .85; margin-top: 2px; }

.stat-blue   { background: linear-gradient(135deg, #2563eb, #3b82f6); }
.stat-green  { background: linear-gradient(135deg, #059669, #10b981); }
.stat-orange { background: linear-gradient(135deg, #d97706, #f59e0b); }
.stat-purple { background: linear-gradient(135deg, #7c3aed, #8b5cf6); }

/* ── Botones grandes (táctiles) ───────────────────────── */
.btn-touch {
  min-height: 52px; border-radius: var(--radius);
  font-weight: 600; font-size: 1rem;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all .2s; border: none;
}
.btn-touch:active { transform: scale(.97); }

.btn-primary-custom {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white; box-shadow: 0 4px 15px rgba(37,99,235,.35);
}
.btn-primary-custom:hover { box-shadow: 0 6px 20px rgba(37,99,235,.5); color: white; }

.btn-success-custom {
  background: linear-gradient(135deg, #059669, var(--secondary));
  color: white; box-shadow: 0 4px 15px rgba(16,185,129,.35);
}
.btn-success-custom:hover { color: white; box-shadow: 0 6px 20px rgba(16,185,129,.5); }

/* ── Forms ────────────────────────────────────────────── */
.form-control, .form-select {
  border-radius: .625rem; border: 1.5px solid var(--gray-200);
  padding: .65rem .9rem; font-size: .95rem;
  transition: border-color .2s, box-shadow .2s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-label {
  font-weight: 600; font-size: .85rem; color: var(--gray-500);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: .4rem;
}
.input-group-text {
  background: var(--gray-100); border: 1.5px solid var(--gray-200);
  border-radius: .625rem; color: var(--gray-500);
}

/* ── Lectura Card (formulario de campo) ───────────────── */
.field-card {
  background: white; border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.field-card-title {
  font-weight: 700; font-size: .9rem; color: var(--primary);
  text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 2px solid var(--gray-100); padding-bottom: .5rem; margin-bottom: 1rem;
  display: flex; align-items: center; gap: .4rem;
}

/* ── Consumo display ──────────────────────────────────── */
.consumo-display {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white; border-radius: var(--radius); padding: 1rem 1.25rem;
  display: flex; justify-content: space-between; align-items: center;
}
.consumo-value { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.consumo-unit  { font-size: .85rem; opacity: .8; }

/* ── Estado badges ────────────────────────────────────── */
.badge-pendiente  { background: rgba(245,158,11,.15); color: #b45309; border: 1px solid rgba(245,158,11,.3); }
.badge-synced     { background: rgba(16,185,129,.15);  color: #065f46; border: 1px solid rgba(16,185,129,.3);  }
.badge-error      { background: rgba(239,68,68,.15);   color: #991b1b; border: 1px solid rgba(239,68,68,.3);   }
.badge-status { padding: 4px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; }

/* ── Historial items ──────────────────────────────────── */
.lectura-item {
  background: white; border-radius: var(--radius); padding: 1rem;
  margin-bottom: .75rem; box-shadow: var(--shadow);
  border-left: 4px solid transparent; transition: all .2s;
  cursor: pointer;
}
.lectura-item:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.lectura-item.pendiente   { border-left-color: var(--warning); }
.lectura-item.sincronizado { border-left-color: var(--secondary); }
.lectura-item .lectura-codigo { font-size: .8rem; color: var(--gray-500); }
.lectura-item .lectura-nombre { font-weight: 700; font-size: 1rem; }
.lectura-item .lectura-consumo { font-size: 1.5rem; font-weight: 800; color: var(--primary); }

/* ── Autocomplete subscriber ──────────────────────────── */
.autocomplete-results {
  position: absolute; z-index: 1050; background: white;
  border: 1.5px solid var(--gray-200); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 240px; overflow-y: auto;
  width: 100%; top: 100%; left: 0;
}
.autocomplete-item {
  padding: .75rem 1rem; cursor: pointer; transition: background .15s;
  border-bottom: 1px solid var(--gray-100);
}
.autocomplete-item:hover, .autocomplete-item.active { background: rgba(37,99,235,.06); }
.autocomplete-item .sub-codigo  { font-size: .75rem; color: var(--gray-500); }
.autocomplete-item .sub-nombre  { font-weight: 600; font-size: .95rem; }
.autocomplete-item .sub-ruta    { font-size: .75rem; color: var(--primary); }

/* ── Foto preview ─────────────────────────────────────── */
.foto-preview-wrapper {
  border: 2px dashed var(--gray-200); border-radius: var(--radius);
  min-height: 130px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; background: var(--gray-100);
  transition: border-color .2s;
}
.foto-preview-wrapper:hover { border-color: var(--primary); }
.foto-preview-wrapper img { width: 100%; height: 160px; object-fit: cover; }
.foto-placeholder { text-align: center; color: var(--gray-500); }

/* ── GPS ──────────────────────────────────────────────── */
.gps-display {
  background: var(--gray-100); border-radius: .625rem;
  padding: .6rem 1rem; font-size: .85rem; font-family: monospace;
}

/* ── Toast / Notificaciones ───────────────────────────── */
.toast-container-custom {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 9999; max-width: 320px;
}
.toast-custom {
  background: white; border-radius: .75rem; padding: .9rem 1.1rem;
  box-shadow: var(--shadow-lg); border-left: 4px solid var(--primary);
  margin-bottom: .5rem; animation: slideInRight .3s ease;
  display: flex; align-items: flex-start; gap: .75rem;
}
.toast-custom.success { border-left-color: var(--secondary); }
.toast-custom.warning { border-left-color: var(--warning); }
.toast-custom.error   { border-left-color: var(--danger); }
.toast-custom .toast-icon { font-size: 1.3rem; margin-top: .05rem; }
.toast-custom.success .toast-icon { color: var(--secondary); }
.toast-custom.warning .toast-icon { color: var(--warning); }
.toast-custom.error   .toast-icon { color: var(--danger); }
.toast-custom .toast-msg { flex: 1; font-size: .9rem; }
.toast-close { cursor: pointer; opacity: .5; border: none; background: none; font-size: .9rem; }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Login ────────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh; background: linear-gradient(145deg,#1e40af,#1d4ed8,#2563eb);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.login-card {
  background: white; border-radius: 1.25rem; padding: 2.5rem 2rem;
  box-shadow: 0 25px 60px rgba(0,0,0,.3); width: 100%; max-width: 400px;
}
.login-logo {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.5rem; font-size: 2rem; color: white;
  box-shadow: 0 8px 20px rgba(37,99,235,.4);
}

/* ── Offline Banner ───────────────────────────────────── */
.offline-banner {
  background: linear-gradient(135deg, #b45309, var(--warning));
  color: white; padding: 10px 16px; text-align: center;
  font-size: .875rem; font-weight: 600; display: none;
}
.offline-banner.visible { display: block; }

/* ── Spinner ──────────────────────────────────────────── */
.spin { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive móvil ─────────────────────────────────── */
@media (max-width: 576px) {
  body { padding-top: var(--nav-height); }
  .stat-card { padding: 1rem; }
  .stat-card .stat-value { font-size: 1.7rem; }
  .brand-text { font-size: .9rem; }
  .login-card { padding: 2rem 1.25rem; }
  .field-card { padding: 1rem; }
  .lectura-item { padding: .875rem; }
}

/* ── Dashboard quick-actions ──────────────────────────── */
.quick-action-btn {
  background: white; border: none; border-radius: var(--radius);
  padding: 1.25rem; text-align: center; cursor: pointer;
  box-shadow: var(--shadow); transition: all .2s; display: block; width: 100%;
  text-decoration: none; color: var(--dark);
}
.quick-action-btn:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); color: var(--dark); }
.quick-action-btn .action-icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; margin: 0 auto .75rem;
}

/* ── Filter toolbar ───────────────────────────────────── */
.filter-bar {
  background: white; border-radius: var(--radius); padding: .75rem 1rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}

/* ── PWA install prompt ───────────────────────────────── */
.install-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1050;
  background: white; padding: 1rem 1.25rem;
  box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  border-radius: 1rem 1rem 0 0;
  transform: translateY(100%); transition: transform .3s ease;
}
.install-banner.visible { transform: translateY(0); }

/* ── Empty state ──────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--gray-500);
}
.empty-state i { font-size: 3.5rem; opacity: .3; display: block; margin-bottom: 1rem; }

/* ── Page header ──────────────────────────────────────── */
.page-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white; padding: 1.5rem; margin: -1rem -1rem 1.5rem;
  border-radius: 0 0 1.5rem 1.5rem;
}
.page-header h5 { font-weight: 700; margin: 0; }
.page-header .subtitle { opacity: .8; font-size: .875rem; }

/* ── Section titles ───────────────────────────────────── */
.section-title {
  font-size: .8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--gray-500); margin-bottom: .75rem;
}
