:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #6b7684;
  --line: #dde2e8;
  --primary: #1f3a5f;
  --primary-ink: #ffffff;
  --accent: #e8a33d;
  --danger: #c0392b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--primary); color: var(--primary-ink);
}
.topbar h1 { font-size: 1.15rem; margin: 0; }

main { padding: 12px; max-width: 640px; margin: 0 auto; padding-bottom: 40px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card h2 { font-size: 1.05rem; margin: 0 0 10px; }

.lbl { display: block; font-weight: 600; font-size: .9rem; margin: 8px 0 6px; }

input, select, textarea {
  width: 100%;
  font: inherit;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
#ubicacion { font-size: 1.3rem; font-weight: 700; letter-spacing: .03em; }

.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.grow { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 38px; padding: 0 12px; font-size: .9rem; }
.btn.full { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .5; }

.icon-btn {
  background: none; border: 0; font-size: 1.3rem; cursor: pointer;
  color: inherit; padding: 4px 8px;
}

.preview { margin-top: 12px; border-radius: 10px; overflow: hidden; background: #000; }
.preview canvas { display: block; width: 100%; height: auto; }

.status {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: #eef3fa; color: var(--primary); font-weight: 600;
}
.status.error { background: #fdecea; color: var(--danger); }
.status.loading::before {
  content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 8px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  vertical-align: -2px; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .85rem; }
.hint { color: var(--muted); font-size: .8rem; margin: 6px 0 0; }

.prod {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; margin-bottom: 10px;
}
.prod-head { display: flex; align-items: center; gap: 8px; }
.prod-head input { font-weight: 700; padding: 8px 10px; }
.dot { flex: 0 0 14px; height: 14px; border-radius: 50%; }
.p-meta { margin: 6px 0 4px; word-break: break-word; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid3 label { font-size: .78rem; color: var(--muted); font-weight: 600; }
.grid3 input { margin-top: 4px; padding: 10px 8px; font-size: 1.05rem; font-weight: 700; text-align: center; }
.p-sub { margin-top: 8px; text-align: right; font-weight: 700; }
.badge {
  display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: 99px;
  background: #eee; margin-left: 4px; font-weight: 600;
}
.badge.alta { background: #e3f4e8; color: #1e7b3a; }
.badge.media { background: #fff3dc; color: #9a6400; }
.badge.baja { background: #fdecea; color: var(--danger); }

.totals {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin: 12px 0 4px; padding: 12px; border-radius: 12px;
  background: var(--primary); color: #fff; text-align: center;
}
.totals span { display: block; color: #c9d6e8; font-size: .8rem; }
.totals strong { font-size: 1.4rem; }

.obs { background: #fff8ea; border-left: 4px solid var(--accent); padding: 8px 10px; border-radius: 6px; font-size: .9rem; }

.history .h-item { border-top: 1px solid var(--line); padding: 10px 0; }
.history .h-item:first-child { border-top: 0; }
.h-top { display: flex; justify-content: space-between; font-weight: 700; }
.h-lines { font-size: .88rem; color: var(--muted); margin-top: 2px; }
.h-del { background: none; border: 0; color: var(--danger); font-size: .8rem; cursor: pointer; padding: 0; margin-top: 4px; }

dialog {
  width: min(560px, 94vw); border: 0; border-radius: var(--radius); padding: 0;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.settings { padding: 16px; }
.settings h2 { margin-top: 0; }
