/* El Precio Justo — sistema de diseño (mobile first) */
:root {
  --c-bg: #F6F8FA;
  --c-surface: #FFFFFF;
  --c-surface-2: #F1F5F9;
  --c-border: #E2E8F0;
  --c-text: #0F172A;
  --c-text-soft: #475569;
  --c-text-mute: #94A3B8;
  --c-primary: #0F766E;
  --c-primary-dark: #115E59;
  --c-primary-soft: #CCFBF1;
  --c-accent: #B45309;
  --c-accent-soft: #FEF3C7;
  --c-danger: #DC2626;
  --c-danger-soft: #FEE2E2;
  --c-success: #15803D;
  --c-success-soft: #DCFCE7;
  --c-info: #1D4ED8;
  --c-info-soft: #DBEAFE;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-pill: 999px;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;

  --shadow-1: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  --shadow-2: 0 4px 12px rgba(15,23,42,.08);
  --shadow-fab: 0 6px 16px rgba(15,118,110,.35);

  --nav-h: 62px;
  --top-h: 56px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", "Roboto Mono", Menlo, monospace;
}

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

html, body {
  margin: 0; padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100dvh; }

h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0 0 var(--sp-3); }
a { color: var(--c-primary); text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }

/* ---------- App shell ---------- */
.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--top-h);
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 0 var(--sp-4);
  background: var(--c-primary);
  color: #fff;
  box-shadow: var(--shadow-1);
}
.topbar__title {
  font-size: 1.05rem; font-weight: 650; letter-spacing: .2px;
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__back {
  background: rgba(255,255,255,.15); color: #fff; border: 0;
  width: 36px; height: 36px; border-radius: var(--r-pill);
  font-size: 1.15rem; cursor: pointer; display: grid; place-items: center;
}
.topbar__back:active { background: rgba(255,255,255,.3); }
.topbar__back[hidden] { display: none; }
.topbar__status {
  width: 10px; height: 10px; border-radius: 50%;
  background: #4ADE80; box-shadow: 0 0 0 3px rgba(74,222,128,.25);
}
.topbar__status.is-offline { background: #FBBF24; box-shadow: 0 0 0 3px rgba(251,191,36,.25); }

.view {
  flex: 1;
  padding: var(--sp-4);
  padding-bottom: calc(var(--nav-h) + var(--sp-6) + env(safe-area-inset-bottom));
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
  outline: none;
}
.view.is-wide { max-width: 1100px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  box-shadow: 0 -2px 10px rgba(15,23,42,.05);
}
.tabbar__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .68rem; color: var(--c-text-mute); font-weight: 600;
  padding-top: 6px;
}
.tabbar__item.is-active { color: var(--c-primary); }
.tabbar__icon { font-size: 1.15rem; line-height: 1; }
.tabbar__item--center { position: relative; }
.tabbar__fab {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--c-primary); color: #fff;
  display: grid; place-items: center; font-size: 1.7rem; font-weight: 300;
  box-shadow: var(--shadow-fab);
  margin-top: -18px;
  border: 3px solid var(--c-surface);
}

/* ---------- Layout helpers ---------- */
.page-head { margin-bottom: var(--sp-4); }
.page-head h2 { font-size: 1.35rem; font-weight: 750; }
.page-head p { color: var(--c-text-soft); font-size: .9rem; margin: 4px 0 0; }

.grid { display: grid; gap: var(--sp-3); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 620px) { .grid--3 { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid--2 { grid-template-columns: repeat(4, 1fr); } }

.row { display: flex; align-items: center; gap: var(--sp-2); }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: var(--sp-3); }

/* ---------- Cards ---------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-1);
}
.card--flat { box-shadow: none; }
.card__title { font-size: .95rem; font-weight: 700; margin-bottom: var(--sp-2); }
.card__hint { color: var(--c-text-mute); font-size: .8rem; }

.metric { display: flex; flex-direction: column; gap: 2px; }
.metric__label { font-size: .75rem; color: var(--c-text-mute); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.metric__value { font-size: 1.4rem; font-weight: 800; font-family: var(--font-num); }
.metric__value--sm { font-size: 1.1rem; }
.metric__sub { font-size: .78rem; color: var(--c-text-soft); }

.stat {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-md); padding: var(--sp-3); text-align: left;
}
.stat__value { font-size: 1.3rem; font-weight: 800; font-family: var(--font-num); }
.stat__label { font-size: .74rem; color: var(--c-text-soft); }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 var(--sp-4);
  border-radius: var(--r-md); font-size: .95rem; font-weight: 650;
  background: var(--c-primary); color: #fff;
  transition: filter .12s ease, background .12s ease;
  white-space: nowrap;
}
.btn:active { filter: brightness(.93); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--ghost { background: transparent; color: var(--c-primary); border-color: var(--c-border); }
.btn--soft { background: var(--c-primary-soft); color: var(--c-primary-dark); }
.btn--danger { background: var(--c-danger); }
.btn--danger-soft { background: var(--c-danger-soft); color: var(--c-danger); }
.btn--neutral { background: var(--c-surface-2); color: var(--c-text); border-color: var(--c-border); }
.btn--sm { min-height: 36px; font-size: .85rem; padding: 0 var(--sp-3); }
.btn--icon { min-height: 38px; width: 38px; padding: 0; border-radius: var(--r-md); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-3); }
.field__label { font-size: .82rem; font-weight: 650; color: var(--c-text-soft); }
.field__help { font-size: .74rem; color: var(--c-text-mute); }
.field__error { font-size: .76rem; color: var(--c-danger); font-weight: 600; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--c-border); border-radius: var(--r-md);
  background: #fff; color: var(--c-text); font-size: 1rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--c-primary); outline-offset: 0; border-color: var(--c-primary); }
input[type="number"] { font-family: var(--font-num); }
textarea { min-height: 76px; resize: vertical; }
.input-group { display: flex; gap: var(--sp-2); }
.input-group > input { flex: 1; }
.input-group > select { width: 110px; flex: 0 0 auto; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: var(--sp-2); }
.list-item {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-md); padding: var(--sp-3);
}
.list-item__main { flex: 1; min-width: 0; }
.list-item__title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item__sub { font-size: .78rem; color: var(--c-text-mute); }
.list-item__value { font-family: var(--font-num); font-weight: 750; font-size: .95rem; text-align: right; }
.list-item__actions { display: flex; gap: 4px; }
a.list-item { color: inherit; }

.empty {
  text-align: center; color: var(--c-text-mute);
  padding: var(--sp-8) var(--sp-4); font-size: .9rem;
}
.empty__icon { font-size: 2.2rem; display: block; margin-bottom: var(--sp-2); opacity: .5; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: var(--r-pill);
  background: var(--c-surface-2); color: var(--c-text-soft);
}
.badge--ok { background: var(--c-success-soft); color: var(--c-success); }
.badge--warn { background: var(--c-accent-soft); color: var(--c-accent); }
.badge--bad { background: var(--c-danger-soft); color: var(--c-danger); }
.badge--info { background: var(--c-info-soft); color: var(--c-info); }

/* ---------- Chips / segmented ---------- */
.chips { display: flex; gap: var(--sp-2); overflow-x: auto; padding-bottom: 4px; }
.chip {
  border: 1px solid var(--c-border); background: var(--c-surface);
  color: var(--c-text-soft); border-radius: var(--r-pill);
  padding: 7px 14px; font-size: .82rem; font-weight: 650; cursor: pointer; white-space: nowrap;
}
.chip.is-active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }

/* ---------- Totals / breakdown ---------- */
.breakdown { display: flex; flex-direction: column; gap: 6px; }
.breakdown__row { display: flex; justify-content: space-between; font-size: .86rem; }
.breakdown__row span:last-child { font-family: var(--font-num); font-weight: 650; }
.breakdown__row--total {
  border-top: 1px dashed var(--c-border); padding-top: 8px; margin-top: 4px;
  font-size: 1rem; font-weight: 800;
}
.breakdown__row--total span:last-child { color: var(--c-primary); }
.breakdown__row--cost span:last-child { color: var(--c-danger); }
.breakdown__row--util span:last-child { color: var(--c-success); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 90;
  background: #0F172A; color: #fff; padding: 12px 18px; border-radius: var(--r-pill);
  font-size: .88rem; font-weight: 600; box-shadow: var(--shadow-2);
  max-width: min(92vw, 520px); text-align: center;
}
.toast--ok { background: var(--c-success); }
.toast--err { background: var(--c-danger); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 80;
  display: grid; place-items: end center; padding: 0;
}
@media (min-width: 620px) { .modal-backdrop { place-items: center; } }
.modal {
  background: var(--c-surface); width: 100%; max-width: 560px;
  border-radius: var(--r-lg) var(--r-lg) 0 0; padding: var(--sp-5);
  max-height: 88dvh; overflow: auto;
  animation: slideUp .18s ease;
}
@media (min-width: 620px) { .modal { border-radius: var(--r-lg); } }
@keyframes slideUp { from { transform: translateY(12px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal__title { font-size: 1.1rem; font-weight: 750; margin-bottom: var(--sp-3); }
.modal__actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-4); }
.modal__actions .btn { flex: 1; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--c-border); margin: var(--sp-4) 0; border: 0; }
.text-mute { color: var(--c-text-mute); }
.text-soft { color: var(--c-text-soft); }
.text-sm { font-size: .84rem; }
.text-xs { font-size: .76rem; }
.num { font-family: var(--font-num); }
.right { text-align: right; }
.mt-2 { margin-top: var(--sp-2); } .mt-4 { margin-top: var(--sp-4); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--sp-2); } .mb-4 { margin-bottom: var(--sp-4); }
.w-100 { width: 100%; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

.alert { border-radius: var(--r-md); padding: var(--sp-3); font-size: .85rem; border: 1px solid; display: flex; gap: 8px; }
.alert--warn { background: var(--c-accent-soft); border-color: #FDE68A; color: #92400E; }
.alert--bad { background: var(--c-danger-soft); border-color: #FCA5A5; color: #991B1B; }
.alert--info { background: var(--c-info-soft); border-color: #BFDBFE; color: #1E40AF; }
.alert--ok { background: var(--c-success-soft); border-color: #86EFAC; color: #166534; }

.hero {
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-primary-dark) 100%);
  color: #fff; border-radius: var(--r-lg); padding: var(--sp-5);
}
.hero__value { font-size: 2rem; font-weight: 800; font-family: var(--font-num); }
.hero__label { opacity: .85; font-size: .82rem; font-weight: 600; }

.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); }
@media (min-width: 620px) { .quick-grid { grid-template-columns: repeat(4, 1fr); } }
.quick {
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md);
  padding: var(--sp-4) var(--sp-3); text-align: center; color: var(--c-text);
  display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: var(--shadow-1);
}
.quick__icon { font-size: 1.5rem; }
.quick__label { font-size: .8rem; font-weight: 650; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Estado de sincronización ---------- */
.sync-badge {
  font-size: .68rem; font-weight: 700; padding: 3px 9px; border-radius: var(--r-pill);
  background: rgba(255,255,255,.18); color: #fff; white-space: nowrap;
}
.sync-badge.is-ok { background: rgba(74,222,128,.25); }
.sync-badge.is-pending { background: rgba(251,191,36,.3); }
.sync-badge.is-offline { background: rgba(0,0,0,.25); }
