:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #f97316;
  --primary-dark: #ea580c;
  --navy: #0f172a;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 14px;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 84px;
}

.hidden { display: none !important; }

/* Banner sesion */
.auth-banner {
  background: #fef3c7;
  color: #92400e;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid #f59e0b;
}

/* Cabecera superior */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--navy);
  color: #fff;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
}

.topbar-brand strong {
  display: block;
  font-size: 15px;
  line-height: 1.1;
}

.topbar-brand small {
  color: #94a3b8;
  font-size: 11px;
}

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

.icon-pill {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}
.status-dot.offline { background: #ef4444; }
.status-dot.pending { background: #f59e0b; }

/* Buscador universal */
.search-bar-wrap {
  background: var(--surface);
  padding: 10px 14px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.search-bar-wrap input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  background: #f8fafc;
}

/* Contenido principal */
.main-content {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 14px 40px;
}

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

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
}

.muted { color: var(--muted); font-size: 12px; }
.helper-text { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.mt-sm { margin-top: 10px; }

/* Tarjetas */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.card.compact { padding: 12px; }
.card h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.kpi-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}
.kpi-box strong { display: block; font-size: 18px; color: var(--navy); }
.kpi-box span { font-size: 11px; color: var(--muted); }

/* Botones */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-sm { padding: 7px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-dark { background: var(--navy); color: #fff; }
.btn-success { background: #16a34a; color: #fff; }
.btn-warning { background: #d97706; color: #fff; }
.btn-outline { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn-warning-outline { background: #fffbeb; color: #b45309; border: 1px solid #f59e0b; }
.btn-ghost { background: transparent; color: var(--muted); }

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #e2e8f0;
  color: var(--ink);
}
.badge-dark { background: var(--navy); color: #fff; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }

/* Formularios */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}
.form-grid label.full { grid-column: 1 / -1; }

input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}

.select-sm {
  width: auto;
  padding: 6px 8px;
  font-size: 12px;
}

.checks-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
}

.check-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-size: 13px !important;
  cursor: pointer;
}
.check-row input { width: 18px; height: 18px; }

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.row-gap { display: flex; gap: 8px; }

.info-banner {
  margin-top: 10px;
  padding: 9px 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  border-radius: 9px;
  font-size: 12px;
}

/* Sub-pestanas peritaje */
.peritaje-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.peritaje-header-btns { display: flex; gap: 6px; }

.subtabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 12px;
}
.subtab {
  border: none;
  background: transparent;
  padding: 8px 4px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
}
.subtab.active {
  background: #fff;
  color: var(--navy);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.subview { display: none; }
.subview.active { display: block; }

/* Estancias y muebles */
.room-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 8px;
}
.room-pill {
  white-space: nowrap;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.room-pill.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.item-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 9px 10px;
  background: #f8fafc;
}
.item-row.selected {
  background: #fff7ed;
  border-color: #fdba74;
}

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

.item-info strong {
  display: block;
  font-size: 14px;
}
.item-info small {
  color: var(--muted);
  font-size: 11px;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}
.step-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid #cbd5e1;
  background: #fff;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.step-btn.plus {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.step-qty {
  min-width: 22px;
  text-align: center;
  font-weight: 800;
  font-size: 15px;
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}
.chip-btn {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
}
.chip-btn.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

/* Fotos */
.photo-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.photos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.photo-thumb {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1 / 1;
  background: #e2e8f0;
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-tag {
  position: absolute;
  bottom: 4px;
  left: 4px;
  right: 4px;
  background: rgba(15, 23, 42, 0.8);
  color: #fff;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 5px;
  text-align: center;
}

/* Metricas y margen */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.metric-item {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px;
}
.metric-item span { display: block; font-size: 11px; color: var(--muted); }
.metric-item strong { font-size: 15px; }

.margin-breakdown {
  font-size: 13px;
  line-height: 1.6;
}

/* Firma */
.sign-canvas {
  width: 100%;
  height: 150px;
  border: 1.5px dashed #94a3b8;
  border-radius: 10px;
  background: #f8fafc;
  touch-action: none;
  display: block;
}

.dual-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Barra resumen flotante */
.sticky-summary {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: 68px;
  max-width: 796px;
  margin: 0 auto;
  background: var(--navy);
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.25);
  z-index: 25;
  font-size: 13px;
}
.sticky-right {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}
.semaforo-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22c55e;
}

/* Navegacion inferior */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #fff;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 30;
}
.nav-btn {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.nav-btn span { font-size: 18px; }
.nav-btn.active { color: var(--primary); }

.pill-count {
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: 1px 5px;
  font-size: 10px;
}

/* Config list */
.config-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
}
.config-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.config-row small { display: block; color: var(--muted); font-size: 11px; }

/* Modal y Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.modal-box {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 16px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.modal-head h3 { margin: 0; }

.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 60;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
