:root {
  --azul: #003da5;
  --azul-oscuro: #002d7a;
  --cyan: #00b4d8;
  --bg: #f2f4f8;
  --card-bg: #ffffff;
  --texto: #1a1d29;
  --texto-suave: #6b7280;
  --borde: #e2e5eb;

  --verde: #22c55e;
  --amarillo: #f5a623;
  --rojo: #ef4444;
  --azul-badge: #60a5fa;

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

  --tabbar-height: 56px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--texto);
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

input,
select,
textarea,
button {
  font-size: 16px;
}

/* ---------- Layout ---------- */

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--azul);
  color: #fff;
  padding: calc(var(--safe-top) + 14px) calc(16px + var(--safe-right)) 14px calc(16px + var(--safe-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.top-bar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
}

.main-content {
  flex: 1;
  padding: 16px calc(16px + var(--safe-right)) calc(var(--tabbar-height) + var(--safe-bottom) + 24px) calc(16px + var(--safe-left));
}

.centered {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px calc(24px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(24px + var(--safe-left));
}

/* ---------- Tab bar ---------- */

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--borde);
  display: flex;
  z-index: 20;
}

.tab-bar a,
.tab-bar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--texto-suave);
  font-size: 11px;
  font-weight: 500;
  min-height: 44px;
  cursor: pointer;
}

.tab-bar a.active {
  color: var(--azul);
}

.tab-bar .tab-icon {
  font-size: 20px;
  line-height: 1;
}

.tab-bar a:active,
.tab-bar button:active {
  opacity: 0.6;
}

/* ---------- Login ---------- */

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 32px 24px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
  text-align: center;
}

.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--azul), var(--cyan));
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #fff;
}

.login-card h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.login-card p.subtitle {
  color: var(--texto-suave);
  font-size: 14px;
  margin: 0 0 24px;
}

.login-error {
  background: #fee2e2;
  color: #b91c1c;
  font-size: 13px;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 16px;
  display: none;
}

.login-error.show {
  display: block;
}

/* ---------- Forms ---------- */

.field {
  margin-bottom: 16px;
  text-align: left;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--texto-suave);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--borde);
  border-radius: 10px;
  background: #fff;
  color: var(--texto);
}

.field textarea {
  min-height: 90px;
  resize: vertical;
  font-family: inherit;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--azul);
  box-shadow: 0 0 0 3px rgba(0, 61, 165, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  background: var(--azul);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}

.btn:active {
  background: var(--azul-oscuro);
}

.btn.secondary {
  background: #fff;
  color: var(--azul);
  border: 1px solid var(--azul);
}

.btn.accent {
  background: var(--cyan);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.radio-group {
  display: flex;
  gap: 12px;
}

.radio-option {
  flex: 1;
  min-height: 48px;
  border: 2px solid var(--borde);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  cursor: pointer;
}

.radio-option input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.radio-option.checked-vendido {
  border-color: var(--verde);
  background: rgba(34, 197, 94, 0.08);
  color: #15803d;
}

.radio-option.checked-mnc {
  border-color: var(--rojo);
  background: rgba(239, 68, 68, 0.08);
  color: #b91c1c;
}

/* ---------- Search ---------- */

.search-bar {
  position: relative;
  margin-bottom: 14px;
}

.search-bar input {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--borde);
  padding: 10px 14px 10px 38px;
  background: #fff;
}

.search-bar::before {
  content: '🔍';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: 0.6;
}

/* ---------- Counters ---------- */

.counters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.counter-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.counter-card .num {
  font-size: 18px;
  font-weight: 700;
  color: var(--azul);
}

.counter-card .label {
  font-size: 10px;
  color: var(--texto-suave);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* ---------- Client list ---------- */

.cliente-item {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  min-height: 44px;
}

.cliente-item:active {
  background: #f8f9fc;
}

.badge-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-dot.sin_visitar {
  background: var(--azul-badge);
}

.badge-dot.vendido {
  background: var(--verde);
}

.badge-dot.pendiente {
  background: var(--amarillo);
}

.badge-dot.otros_mnc {
  background: var(--rojo);
}

.cliente-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.cliente-info .nombre {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cliente-info .direccion {
  font-size: 13px;
  color: var(--texto-suave);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cliente-info .nic {
  font-size: 12px;
  color: var(--texto-suave);
}

.deuda-tag {
  color: var(--rojo);
  font-weight: 700;
}

.deuda-badge {
  display: inline-block;
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
  font-weight: 700;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 8px;
}

.sin-deuda-badge {
  display: inline-block;
  background: rgba(34, 197, 94, 0.1);
  color: #15803d;
  font-weight: 700;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 8px;
}

.chevron {
  color: var(--borde);
  font-size: 18px;
}

.empty-state {
  text-align: center;
  color: var(--texto-suave);
  padding: 48px 16px;
  font-size: 14px;
}

/* ---------- FAB ---------- */

.fab {
  position: fixed;
  right: calc(20px + var(--safe-right));
  bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 20px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--azul);
  color: #fff;
  border: none;
  font-size: 26px;
  box-shadow: 0 6px 18px rgba(0, 61, 165, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
  cursor: pointer;
}

.fab:active {
  background: var(--azul-oscuro);
}

/* ---------- Modal / sheet ---------- */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 30;
  display: none;
  align-items: flex-end;
}

.sheet-overlay.open {
  display: flex;
}

.sheet {
  background: #fff;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px calc(20px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(20px + var(--safe-left));
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--borde);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.sheet h3 {
  margin-top: 0;
}

.tabs-inline {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tabs-inline button {
  flex: 1;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid var(--borde);
  background: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.tabs-inline button.active {
  background: var(--azul);
  color: #fff;
  border-color: var(--azul);
}

.import-pane {
  display: none;
}

.import-pane.active {
  display: block;
}

/* ---------- Detail page ---------- */

.detalle-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.detalle-card .nombre {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.detalle-card .row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 6px 0;
  border-bottom: 1px solid var(--borde);
}

.detalle-card .row:last-child {
  border-bottom: none;
}

.detalle-card .row .k {
  color: var(--texto-suave);
}

.maps-buttons {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.maps-buttons a.btn {
  flex: 1;
  text-decoration: none;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--texto-suave);
  margin: 20px 0 10px;
}

.historial-item {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.historial-item .top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.historial-item .resultado {
  font-weight: 700;
  font-size: 13px;
}

.historial-item .resultado.vendido {
  color: #15803d;
}

.historial-item .resultado.mnc {
  color: #b91c1c;
}

.historial-item .fecha {
  font-size: 12px;
  color: var(--texto-suave);
}

.historial-item .motivo {
  font-size: 13px;
  color: var(--texto);
}

.historial-item .obs {
  font-size: 13px;
  color: var(--texto-suave);
  margin-top: 4px;
}

/* ---------- Dashboard ---------- */

.dash-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.dash-card h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--texto-suave);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.dash-numbers {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 10px;
}

.dash-numbers .actual {
  font-size: 32px;
  font-weight: 800;
  color: var(--azul);
}

.dash-numbers .meta {
  font-size: 16px;
  color: var(--texto-suave);
}

.progress-track {
  width: 100%;
  height: 12px;
  border-radius: 6px;
  background: var(--bg);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--azul), var(--cyan));
  border-radius: 6px;
  transition: width 0.4s ease;
}

.dash-meta-row {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 13px;
  color: var(--texto-suave);
}

.dash-meta-row strong {
  color: var(--texto);
}

.loading-spinner {
  text-align: center;
  padding: 32px;
  color: var(--texto-suave);
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: var(--texto);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--rojo);
}

.toast.success {
  background: var(--verde);
}
