/* Área — estilos locales de producción. No depende de Tailwind CDN. */
:root {
  --red: #eb3a2f;
  --red-dark: #c92d25;
  --red-soft: #fff0ee;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --ink: #17202a;
  --muted: #667085;
  --line: #e5e7eb;
  --surface: #ffffff;
  --page: #f7f8fa;
  --shadow: 0 12px 32px rgba(20, 28, 45, .08);
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
  font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--page); color: var(--ink); line-height: 1.5; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--red); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
.hidden { display: none !important; }
.center { text-align: center; }
.small { font-size: .875rem; }
.mt-2 { margin-top: .5rem !important; }
.mt-3 { margin-top: .75rem !important; }
.mt-4 { margin-top: 1rem !important; }
.mb-2 { margin-bottom: .5rem !important; }
.mb-3 { margin-bottom: .75rem !important; }
.grow { flex: 1 1 0; }

.app-header { position: sticky; top: 0; z-index: 80; display: flex; align-items: center; justify-content: space-between; height: 64px; padding: 0 1rem; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); box-shadow: 0 2px 14px rgba(16,24,40,.05); backdrop-filter: blur(12px); }
.brand { display: inline-flex; align-items: center; gap: .55rem; color: var(--ink); font-size: 1.25rem; font-weight: 800; text-decoration: none; }
.brand:hover { text-decoration: none; }
.logo { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; color: #fff; background: var(--red); box-shadow: 0 5px 14px rgba(235,58,47,.3); }
.menu-btn { display: grid; gap: 4px; place-content: center; width: 42px; height: 42px; padding: 0; border: 0; border-radius: 10px; background: transparent; cursor: pointer; }
.menu-btn:hover { background: var(--red-soft); }
.bar { display: block; width: 22px; height: 2px; border-radius: 3px; background: var(--ink); }
.menu-overlay { position: fixed; inset: 64px 0 0; z-index: 90; display: none; background: rgba(15,23,42,.42); }
.menu-overlay.open, .menu-overlay.show { display: block; }
.menu-panel { position: fixed; top: 0; right: 0; bottom: 0; z-index: 100; width: min(86vw, 340px); padding: 1rem; background: var(--surface); box-shadow: -14px 0 35px rgba(15,23,42,.16); transform: translateX(105%); transition: transform .22s ease; }
.menu-panel.open, .menu-panel.show { transform: translateX(0); }
.menu-head { display: flex; justify-content: space-between; align-items: center; padding: .7rem .4rem 1rem; font-size: 1.1rem; font-weight: 800; border-bottom: 1px solid var(--line); }
.menu-close { width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-size: 1.2rem; }
.menu-close:hover { background: var(--red-soft); color: var(--red); }
.menu-link { display: flex; align-items: center; gap: .75rem; padding: .9rem .7rem; color: var(--ink); border-radius: 10px; font-weight: 650; }
.menu-link:hover, .menu-link.active { color: var(--red); background: var(--red-soft); text-decoration: none; }
.menu-link.logout { margin-top: 1rem; color: #b42318; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
.ico { font-size: 1.2rem; line-height: 1; }

main { width: 100%; max-width: 1080px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page { display: none; width: 100%; animation: page-in .2s ease both; }
.page.active { display: block; }
@keyframes page-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.hero { max-width: 760px; margin: .75rem auto 2rem; padding: clamp(2rem, 8vw, 5rem) 1.25rem; text-align: center; background: linear-gradient(145deg, #fff, #fff6f4); border: 1px solid #ffe0dc; border-radius: 24px; box-shadow: var(--shadow); }
.badge { display: inline-block; padding: .35rem .75rem; border-radius: 999px; color: var(--red-dark); background: var(--red-soft); font-size: .78rem; font-weight: 800; letter-spacing: .02em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .55rem; font-size: clamp(1.65rem, 5vw, 2.5rem); line-height: 1.15; letter-spacing: -.025em; }
h2 { margin-bottom: .55rem; font-size: 1.25rem; line-height: 1.25; }
h3 { margin-bottom: .35rem; font-size: 1.05rem; }
.lead { max-width: 620px; margin: 0 auto 1.5rem; color: var(--muted); font-size: 1.05rem; }
.sub { color: var(--muted); margin-bottom: 1.25rem; }
.features { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.feature { padding: 1.25rem; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(20,28,45,.04); }
.feature p { margin: 0; color: var(--muted); font-size: .92rem; }
.feature .ico { margin-bottom: .75rem; font-size: 1.8rem; }
.card { width: 100%; max-width: 680px; margin: .75rem auto; padding: clamp(1.1rem, 4vw, 1.8rem); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; gap: .4rem; padding: .68rem 1rem; border: 1px solid transparent; border-radius: 10px; cursor: pointer; font-weight: 750; line-height: 1.2; text-align: center; transition: background .15s, border-color .15s, transform .15s, box-shadow .15s; }
.btn:hover { transform: translateY(-1px); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.btn-primary { color: #fff; background: var(--red); box-shadow: 0 5px 12px rgba(235,58,47,.22); }
.btn-primary:hover { background: var(--red-dark); }
.btn-outline { color: var(--red); background: #fff; border-color: #f09b95; }
.btn-outline:hover { background: var(--red-soft); border-color: var(--red); }
.btn-blue { color: #fff; background: var(--blue); }
.btn-blue:hover { background: var(--blue-dark); }
.btn-ghost { color: #475467; background: #f2f4f7; border-color: #eaecf0; }
.btn-ghost:hover { background: #e4e7ec; }
.btn-danger { color: #fff; background: #d92d20; }
.btn-sm { min-height: 36px; padding: .45rem .7rem; font-size: .86rem; }
.row { display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; }
.row > .btn { min-width: 0; }

.field { display: block; margin: 0 0 1rem; color: #344054; font-size: .9rem; font-weight: 700; }
.hint { color: var(--muted); font-weight: 400; }
input[type="email"], input[type="password"], input[type="number"], input[type="text"] { display: block; width: 100%; min-height: 44px; margin-top: .4rem; padding: .65rem .75rem; color: var(--ink); background: #fff; border: 1px solid #d0d5dd; border-radius: 9px; outline: 0; }
input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(235,58,47,.14); }
.alert { display: none; margin: 0 0 1rem; padding: .8rem .9rem; border-radius: 10px; font-size: .9rem; }
.alert:not(:empty) { display: block; }
.alert-error { color: #b42318; background: #fef3f2; border: 1px solid #fecdca; }
.alert-warn { color: #93370d; background: #fffaeb; border: 1px solid #fedf89; }

.preview-box { display: grid; place-items: center; min-height: 150px; padding: 1rem; color: var(--muted); background: #f8fafc; border: 2px dashed #d0d5dd; border-radius: 12px; text-align: center; }
.preview-box img { max-height: 360px; object-fit: contain; border-radius: 8px; }
.hsv-group { margin: 1rem 0 1.25rem; padding: .75rem .85rem; background: #f8fafc; border: 1px solid #eaecf0; border-radius: 10px; }
.hsv-group .row { justify-content: space-between; color: var(--muted); font-size: .9rem; }
.hsv-group .val { color: var(--ink); font-weight: 800; }
input[type="range"] { display: block; width: 100%; margin: .55rem 0; accent-color: var(--red); }
.range-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: .75rem; }
.loading-wrap { display: none; align-items: center; justify-content: center; gap: .6rem; padding: 1rem; color: var(--muted); }
.loading-wrap.show { display: flex; }
.spinner { width: 20px; height: 20px; border: 3px solid #ffd5d1; border-top-color: var(--red); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.area-badge { padding: 1.2rem; text-align: center; color: #fff; background: linear-gradient(135deg, var(--red), #f36b61); border-radius: var(--radius); box-shadow: var(--shadow); }
.area-badge .num { font-size: clamp(2.2rem, 10vw, 4rem); font-weight: 850; line-height: 1; }
.area-badge .lbl { margin-top: .35rem; opacity: .9; }
.result-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.result-imgs figure { margin: 0; min-width: 0; text-align: center; }
.result-imgs img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; }
.result-imgs figcaption { margin-top: .3rem; color: var(--muted); font-size: .8rem; }
.kv { display: flex; justify-content: space-between; gap: 1rem; padding: .7rem 0; border-bottom: 1px solid #f0f2f5; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .7rem .55rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.empty { padding: 2rem .5rem; color: var(--muted); text-align: center; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: 1rem; }
.pager .info { color: var(--muted); font-size: .86rem; }

.adjust-overlay { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: .75rem; overflow-y: auto; background: rgba(15,23,42,.62); }
.adjust-box { position: relative; width: min(100%, 760px); max-height: calc(100vh - 1.5rem); overflow-y: auto; padding: 1.2rem; background: #fff; border-radius: 16px; box-shadow: 0 24px 70px rgba(0,0,0,.25); }
.adjust-close { position: absolute; top: .7rem; right: .7rem; width: 34px; height: 34px; border: 0; border-radius: 8px; background: #f2f4f7; cursor: pointer; }
.adjust-sub { max-width: 650px; padding-right: 2rem; color: var(--muted); font-size: .9rem; }
.adjust-tools, .adj-calib-row, .adjust-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.adjust-tools { justify-content: space-between; margin: .8rem 0; }
.adj-tools-left { display: flex; flex-wrap: wrap; gap: .4rem; }
.adj-tool, .adj-chip { min-height: 44px; padding: .5rem .7rem; color: #344054; background: #f2f4f7; border: 1px solid #d0d5dd; border-radius: 8px; cursor: pointer; }
.adj-tool.active, .adj-tool:hover, .adj-chip:hover { color: var(--red); background: var(--red-soft); border-color: #f09b95; }
.adj-size { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .8rem; }
.adj-size input { width: 100px; }
.adjust-canvas-wrap { overflow: auto; margin: .75rem 0; min-height: 180px; background: #f8fafc; border: 1px solid #d0d5dd; border-radius: 10px; text-align: center; }
#adjust-canvas { display: block; max-width: 100%; margin: auto; touch-action: none; transform-origin: center center; }
.flow-steps { display: flex; gap: .4rem; margin: .7rem 0; overflow-x: auto; }
.flow-step { flex: 1 0 auto; padding: .45rem .6rem; color: var(--muted); background: #f2f4f7; border-radius: 999px; font-size: .78rem; font-weight: 750; text-align: center; }
.flow-step.active { color: #fff; background: var(--blue); }
.zoom-controls { display: flex; align-items: center; justify-content: center; gap: .45rem; margin: .55rem 0; }
.zoom-controls output { min-width: 4.5rem; color: var(--muted); font-size: .86rem; font-weight: 750; text-align: center; }
.adj-scale-bar, .adj-calib { margin: .7rem 0; padding: .7rem; background: #f8fafc; border: 1px solid #eaecf0; border-radius: 9px; }
.adj-scale-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; font-size: .88rem; }
.adj-scale-bar .dot, .adj-cal-result .dot { color: #98a2b3; margin: 0 .25rem; }
.adj-cal-result { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin: .7rem 0; font-size: .88rem; }
.adj-cal-result input { width: 75px; min-height: 36px; margin: 0; padding: .4rem; }
.adj-cal-quick { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-bottom: .6rem; color: var(--muted); font-size: .85rem; }
.adj-cal-scale { margin: .6rem 0; color: var(--muted); font-size: .85rem; }
.adjust-actions { position: sticky; bottom: 0; justify-content: flex-end; margin: 1rem -.25rem -.25rem; padding: .65rem .25rem calc(.25rem + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96); backdrop-filter: blur(8px); }
.adjust-hint { margin: 1rem 0 0; color: var(--muted); }

/* Compatibilidad con el módulo de calibración legado. */
.modal { display: none; position: fixed; z-index: 1000; inset: 0; overflow: auto; align-items: center; justify-content: center; background: rgba(0,0,0,.6); color: #333; }
.modal-content { position: relative; width: 90%; max-width: 600px; margin: auto; padding: 20px; background: #fefefe; border: 1px solid #888; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,.2); text-align: center; }
.modal h2 { color: var(--red); }
.close-modal-btn { position: absolute; top: 10px; right: 20px; color: #aaa; font-size: 28px; font-weight: bold; cursor: pointer; }
#calibration-image-container { position: relative; display: flex; align-items: center; justify-content: center; width: 100%; max-height: 60vh; margin-bottom: 20px; overflow: hidden; border: 1px dashed #ccc; cursor: crosshair; }
#calibration-image-container img { max-width: 100%; max-height: 100%; object-fit: contain; }
.calibration-point-marker { position: absolute; z-index: 10; width: 12px; height: 12px; background: var(--red); border: 2px solid #fff; border-radius: 50%; transform: translate(-50%,-50%); }
.calibration-line { position: absolute; z-index: 5; height: 3px; background: #ff0; transform-origin: 0 0; }
.calibration-controls { display: flex; align-items: center; justify-content: center; gap: 15px; margin-top: 15px; }
.calibration-controls input[type="number"] { width: 80px; padding: 8px; text-align: right; }
#save-scale-btn, .calibrate-btn { padding: 10px 20px; color: #fff; background: var(--red); border: 0; border-radius: 5px; cursor: pointer; }
.upload-container { display: flex; flex-direction: column; align-items: center; margin-bottom: 20px; padding: 15px; background: #f9f9f9; border: 1px solid #eee; border-radius: 5px; }
.image-preview { max-width: 100%; max-height: 400px; margin-top: 15px; border: 1px solid #ddd; border-radius: 5px; object-fit: contain; }
.scale-display { margin-top: 10px; color: #555; font-size: .9em; }

@media (min-width: 640px) {
  main { padding: 2rem 1.5rem 4rem; }
  .app-header { padding: 0 1.5rem; }
  .features { grid-template-columns: repeat(3, 1fr); }
  .hero { margin-top: 1rem; }
}
@media (min-width: 768px) {
  .menu-panel { width: 360px; padding: 1.25rem; }
  .card { margin-top: 1.25rem; }
}
@media (max-width: 480px) {
  .row > .btn { flex: 1 1 100%; }
  .adjust-actions > .btn { flex: 1 1 100%; }
  .adjust-tools { align-items: stretch; }
  .adj-tools-left { width: 100%; }
  .adj-tool { flex: 1 1 auto; }
}
