:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #b78a3f;
  --primary-dark: #8b6426;
  --navy: #0f172a;
  --success: #15803d;
  --danger: #b91c1c;
  --warning: #b45309;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  overflow-x: hidden;
  font-family: "Inter", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
input, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.78rem 0.85rem;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus {
  outline: 3px solid rgba(183, 138, 63, 0.18);
  border-color: var(--primary);
}
label { display: grid; gap: 0.45rem; font-weight: 600; font-size: 0.9rem; }
small, .muted { color: var(--muted); }

.container { width: min(1180px, calc(100% - 2rem)); margin-inline: auto; }
.section { padding: 5rem 0; }
.section-alt { background: #eef2f7; }
.section-heading { max-width: 720px; margin-bottom: 2rem; }
.section-heading h2, .panel h2 { margin: 0.25rem 0; }
.section-heading p, .panel-header p { color: var(--muted); margin: 0.35rem 0 0; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-weight: 800; font-size: .75rem; color: var(--primary-dark); }

.skip-link {
  position: absolute; left: -9999px; top: 0;
}
.skip-link:focus {
  left: 1rem; top: 1rem; z-index: 9999; background: #fff; padding: .75rem; border-radius: 8px;
}

.hero {
  background:
    radial-gradient(circle at 85% 20%, rgba(183,138,63,.22), transparent 28%),
    linear-gradient(145deg, #07111f 0%, #0f172a 58%, #17223a 100%);
  color: #fff;
  min-height: 680px;
}
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 1.4rem 0; }
.brand { display: flex; gap: .8rem; align-items: center; color: #fff; text-decoration: none; }
.brand-mark {
  width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08);
  overflow: hidden; flex: 0 0 auto;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand small { display: block; color: #cbd5e1; }
.top-actions, .hero-cta, .toolbar-actions { display: flex; gap: .75rem; flex-wrap: wrap; }

.hero-content {
  display: grid; grid-template-columns: 1.2fr .8fr; gap: 4rem; align-items: center; padding: 6rem 0;
}
.hero h1 {
  font-family: "Playfair Display", serif; font-size: clamp(2.8rem, 6vw, 5.6rem);
  line-height: .98; max-width: 800px; margin: .7rem 0 1.4rem;
}
.hero-copy > p { color: #cbd5e1; max-width: 690px; font-size: 1.08rem; }
.hero-note { font-size: .88rem !important; }
.hero-card {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14);
  border-radius: 28px; padding: 1.25rem; backdrop-filter: blur(15px); box-shadow: var(--shadow);
}
.mock-card, .mock-grid > div {
  background: rgba(255,255,255,.08); border-radius: 18px; padding: 1.2rem;
}
.mock-card span, .mock-grid span { display: block; color: #cbd5e1; font-size: .88rem; }
.mock-card strong { font-size: 2.4rem; }
.mock-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: .75rem; }
.mock-grid strong { font-size: 1.35rem; }
.hero-chart { height: 170px; display: flex; gap: .7rem; align-items: end; padding: 1.5rem .5rem .25rem; }
.hero-chart div { flex: 1; height: var(--h); border-radius: 12px 12px 4px 4px; background: linear-gradient(#d4af66, #8b6426); }

.btn {
  border: 0; border-radius: 12px; padding: .72rem 1rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #111827; }
.btn-primary:hover { background: #c9a35f; }
.btn-secondary { background: var(--navy); color: #fff; }
.btn-ghost { background: transparent; color: inherit; border: 1px solid currentColor; opacity: .9; }
.btn-lg { padding: .95rem 1.25rem; }
.btn-whatsapp { background: #16a34a; color: #fff; }
.danger-text { color: var(--danger) !important; }
.file-button input { display: none; }

.steps-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem;
}
.step-card {
  background: var(--surface); border: 1px solid var(--border); padding: 1.3rem; border-radius: 18px;
}
.step-card > span {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%;
  background: #f5ead7; color: var(--primary-dark); font-weight: 800;
}
.step-card h3 { margin-bottom: .4rem; }
.step-card p { margin: 0; color: var(--muted); }

.app-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 1.4rem; align-items: start; min-width: 0; }
.sidebar { position: sticky; top: 1rem; display: grid; gap: 1rem; }
.sidebar-card, .save-state {
  background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 1rem;
}
.sidebar-card nav { display: grid; margin-top: .7rem; }
.sidebar-card a { color: var(--muted); text-decoration: none; padding: .48rem 0; font-size: .9rem; }
.sidebar-card a:hover { color: var(--primary-dark); }
.save-state { font-size: .8rem; color: var(--success); }

.calculator-content { display: grid; gap: 1.2rem; min-width: 0; width: 100%; max-width: 100%; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.4rem; box-shadow: 0 8px 26px rgba(15,23,42,.04); scroll-margin-top: 1rem;
  min-width: 0; max-width: 100%; overflow: hidden;
}
.panel-header { display: flex; justify-content: space-between; gap: 1rem; align-items: start; margin-bottom: 1.2rem; }
.section-number { color: var(--primary-dark); font-weight: 800; letter-spacing: .12em; font-size: .75rem; }
.info-button, .dialog-close {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border); background: #fff; font-weight: 800;
}
.form-grid { display: grid; gap: 1rem; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.summary-strip {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-top: 1rem;
}
.summary-strip div { background: var(--surface-2); border-radius: 14px; padding: .9rem; }
.summary-strip span { display: block; color: var(--muted); font-size: .8rem; }
.summary-strip strong { font-size: 1.1rem; }

.toolbar {
  display: flex; justify-content: space-between; gap: 1rem; align-items: center;
  margin-bottom: 1rem; flex-wrap: wrap;
}
.switch-row { display: flex; align-items: center; gap: .7rem; font-weight: 700; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  width: 46px; height: 26px; border-radius: 99px; background: #cbd5e1; position: relative; flex: 0 0 auto;
}
.switch::after {
  content: ""; width: 20px; height: 20px; position: absolute; top: 3px; left: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch-row input:checked + .switch { background: var(--primary); }
.switch-row input:checked + .switch::after { transform: translateX(20px); }
.compact { font-size: .85rem; }

.table-scroll-hint {
  display: none; margin: 0 0 .55rem; color: var(--muted); font-size: .78rem; font-weight: 600;
}
.table-wrap {
  width: 100%; max-width: 100%; overflow-x: auto; overflow-y: hidden;
  border: 1px solid var(--border); border-radius: 14px;
  -webkit-overflow-scrolling: touch; overscroll-behavior-inline: contain;
  scrollbar-gutter: stable;
}
.table-wrap:focus { outline: 3px solid rgba(183, 138, 63, 0.18); outline-offset: 2px; }
.materials-table { width: max(100%, 1120px); border-collapse: collapse; table-layout: auto; }
.materials-table th, .materials-table td { border-bottom: 1px solid var(--border); padding: .65rem; text-align: left; vertical-align: middle; }
.materials-table th { background: var(--surface-2); font-size: .76rem; color: var(--muted); }
.materials-table td input, .materials-table td select { min-width: 90px; padding: .55rem; }
.materials-table .name-input { min-width: 160px; }
.materials-table .row-cost { white-space: nowrap; font-weight: 800; }
.icon-button { border: 0; background: transparent; color: var(--danger); font-size: 1.15rem; }

.inline-note {
  margin-top: 1rem; background: #fff8e8; border: 1px solid #f0d8a2; border-radius: 12px; padding: .9rem;
  color: #6b4b13; font-size: .9rem;
}
.calculation-line {
  margin-top: 1rem; padding: 1rem; border-radius: 14px; background: var(--navy); color: #fff;
  display: flex; justify-content: space-between; gap: 1rem;
}
.collapsible-content.is-disabled, .is-disabled { opacity: .46; pointer-events: none; filter: grayscale(.25); }

.editable-list { display: grid; gap: .7rem; margin-bottom: .8rem; }
.editable-row {
  display: grid; grid-template-columns: 1.6fr 1fr auto; gap: .7rem; align-items: end;
  padding: .8rem; background: var(--surface-2); border-radius: 12px;
}
.tool-row { grid-template-columns: 1.4fr 1fr 1fr 1fr auto; }
.divider { height: 1px; background: var(--border); margin: 1.4rem 0; }
.subsection-heading { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.subsection-heading h3 { margin: 0; }
.subsection-heading p { margin: .2rem 0 0; color: var(--muted); }

.price-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; margin-bottom: 1.2rem; }
.method-card {
  display: flex; align-items: start; gap: .7rem; border: 1px solid var(--border); padding: 1rem; border-radius: 14px;
}
.method-card input { width: auto; margin-top: .2rem; }
.method-card small { display: block; font-weight: 400; margin-top: .25rem; }

.definition-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-top: 1rem; }
.definition-grid article { background: var(--surface-2); padding: 1rem; border-radius: 14px; }
.definition-grid p { margin: .35rem 0 0; color: var(--muted); font-size: .88rem; }

.live-badge { background: #dcfce7; color: #166534; padding: .35rem .65rem; border-radius: 99px; font-size: .78rem; font-weight: 800; }
.alerts { display: grid; gap: .6rem; margin-bottom: 1rem; }
.alert {
  border-radius: 12px; padding: .8rem .9rem; font-size: .9rem; border: 1px solid;
}
.alert.warning { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.alert.danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }

.results-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .85rem; }
.results-grid article {
  border: 1px solid var(--border); border-radius: 16px; padding: 1rem; background: #fff;
}
.results-grid article.highlight { background: var(--navy); color: #fff; border-color: var(--navy); }
.results-grid span, .results-grid small { display: block; color: var(--muted); font-size: .8rem; }
.results-grid .highlight span, .results-grid .highlight small { color: #cbd5e1; }
.results-grid strong { display: block; font-size: 1.35rem; margin: .3rem 0; }

.breakdown { margin-top: 1.2rem; border-top: 1px solid var(--border); padding-top: 1.2rem; }
.breakdown-header { display: flex; justify-content: space-between; align-items: center; }
.bar-stack { display: flex; height: 18px; overflow: hidden; border-radius: 99px; background: var(--surface-2); margin: .8rem 0; }
.bar-stack span { width: 0%; transition: width .25s ease; }
#barMaterials { background: #b78a3f; }
#barLabor { background: #0f766e; }
#barOverhead { background: #7c3aed; }
#barSelling { background: #dc2626; }
.legend { display: flex; flex-wrap: wrap; gap: .8rem 1.2rem; color: var(--muted); font-size: .82rem; }
.legend strong { color: var(--text); margin-left: .25rem; }
.dot { width: 9px; height: 9px; display: inline-block; border-radius: 50%; margin-right: .3rem; }
.dot-1 { background: #b78a3f; }.dot-2 { background: #0f766e; }.dot-3 { background: #7c3aed; }.dot-4 { background: #dc2626; }

.action-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .7rem; margin-top: 1.2rem; }
.educational-panel details { border-bottom: 1px solid var(--border); padding: .8rem 0; }
.educational-panel summary { cursor: pointer; font-weight: 700; }
.educational-panel p { color: var(--muted); }

footer { background: var(--navy); color: #fff; padding: 2rem 0; }
.footer-content { display: flex; justify-content: space-between; gap: 2rem; }
.footer-brand { display: flex; gap: .85rem; align-items: center; }
.footer-brand img { width: 62px; height: 62px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.footer-brand p { margin: .15rem 0 0; }
.footer-content p { color: #cbd5e1; max-width: 600px; }

.help-dialog {
  width: min(620px, calc(100% - 2rem)); border: 0; border-radius: 20px; padding: 1.5rem; box-shadow: var(--shadow);
}
.help-dialog::backdrop { background: rgba(15,23,42,.62); }
.dialog-close { position: absolute; right: 1rem; top: 1rem; font-size: 1.2rem; }
.toast {
  position: fixed; right: 1rem; bottom: 1rem; background: var(--navy); color: #fff;
  padding: .85rem 1rem; border-radius: 12px; opacity: 0; transform: translateY(10px);
  transition: .2s; pointer-events: none; z-index: 9999;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1050px) {
  .results-grid { grid-template-columns: repeat(3, 1fr); }
  .action-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 850px) {
  .table-scroll-hint { display: block; }
  .hero-content { grid-template-columns: 1fr; padding: 4rem 0; }
  .hero-card { max-width: 520px; }
  .steps-grid { grid-template-columns: repeat(2, 1fr); }
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .form-grid-3, .price-methods, .definition-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
  .top-actions { display: none; }
  .hero { min-height: auto; }
  .hero h1 { font-size: 2.75rem; }
  .steps-grid, .form-grid-3, .form-grid-4, .price-methods, .definition-grid,
  .summary-strip, .results-grid, .action-grid { grid-template-columns: 1fr; }
  .panel { padding: 1rem; border-radius: 16px; overflow: hidden; }
  .table-wrap { margin-inline: 0; border-radius: 12px; }
  .materials-table { width: 1080px; min-width: 1080px; }
  .panel-header, .subsection-heading, .footer-content { flex-direction: column; }
  .editable-row, .tool-row { grid-template-columns: 1fr; }
  .toolbar { align-items: stretch; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .btn { flex: 1; }
  .hero-cta .btn { width: 100%; }
}

/* Protección adicional contra desbordes horizontales */
img, svg, canvas { max-width: 100%; }
.topbar, .hero-content, .steps-grid, .app-layout, .calculator-content, .panel, .form-grid, .summary-strip { min-width: 0; }
.panel > * { max-width: 100%; }

/* Navegación compacta de la calculadora */
.app-layout {
  display: block;
  width: 100%;
  min-width: 0;
}

.section-selector {
  position: sticky;
  top: .75rem;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(150px, .8fr) minmax(260px, 1.4fr) minmax(210px, auto);
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 100%;
  margin-bottom: 1.2rem;
  padding: .85rem 1rem;
  border: 1px solid rgba(226, 232, 240, .95);
  border-radius: 16px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 12px 34px rgba(15, 23, 42, .10);
  backdrop-filter: blur(14px);
}

.section-selector-copy {
  min-width: 0;
}

.section-selector-label {
  display: block;
  margin-bottom: .08rem;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.section-selector-copy strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-select-wrap {
  min-width: 0;
}

.section-select-wrap select {
  min-width: 0;
  width: 100%;
  padding-right: 2.6rem;
  border-color: #cbd5e1;
  background-color: #fff;
  font-weight: 700;
}

.section-selector .save-state {
  min-width: 0;
  padding: .72rem .85rem;
  border: 0;
  background: #f0fdf4;
  color: #166534;
  text-align: center;
  white-space: normal;
}

.calculator-content {
  width: 100%;
  max-width: 100%;
}

.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 (max-width: 800px) {
  .section-selector {
    grid-template-columns: 1fr;
    gap: .65rem;
    top: .35rem;
    padding: .75rem;
  }

  .section-selector-copy {
    display: none;
  }

  .section-selector .save-state {
    font-size: .76rem;
  }
}


/* Ayudas contextuales y recursos educativos */
.label-with-help { display: inline-flex; align-items: center; gap: .38rem; flex-wrap: wrap; }
.field-help {
  position: relative; display: inline-grid; place-items: center; flex: 0 0 auto;
  width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%;
  background: #dbeafe; color: #1d4ed8; font-size: .72rem; font-weight: 900;
  cursor: help;
}
.field-help::after {
  content: attr(data-tooltip); position: absolute; z-index: 80; left: 50%; bottom: calc(100% + 10px);
  width: min(280px, 78vw); padding: .7rem .8rem; border-radius: 10px;
  background: #0f172a; color: #fff; font-size: .78rem; font-weight: 500; line-height: 1.4;
  box-shadow: 0 10px 28px rgba(15,23,42,.24); opacity: 0; visibility: hidden;
  transform: translate(-50%, 5px); transition: .18s ease; pointer-events: none;
}
.field-help::before {
  content: ""; position: absolute; z-index: 81; left: 50%; bottom: calc(100% + 5px);
  border: 5px solid transparent; border-top-color: #0f172a; opacity: 0; visibility: hidden;
  transform: translateX(-50%); transition: .18s ease;
}
.field-help:hover::after, .field-help:focus::after, .field-help.is-open::after,
.field-help:hover::before, .field-help:focus::before, .field-help.is-open::before { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.field-help:hover::before, .field-help:focus::before, .field-help.is-open::before { transform: translateX(-50%); }

.panel-header { position: relative; }
.panel-decoration { margin-left: auto; align-self: center; }
.sushi-sticker { display: inline-block; font-size: clamp(2rem, 4vw, 3.4rem); filter: drop-shadow(0 8px 8px rgba(15,23,42,.15)); transform-origin: center; }
.sticker-float { animation: sushiFloat 3.2s ease-in-out infinite; }
.sticker-bounce { animation: sushiBounce 2.2s ease-in-out infinite; }
.sticker-wiggle { animation: sushiWiggle 2.8s ease-in-out infinite; }
.delay-1 { animation-delay: .45s; }.delay-2 { animation-delay: .9s; }
@keyframes sushiFloat { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-9px) rotate(3deg); } }
@keyframes sushiBounce { 0%,100% { transform: translateY(0) scale(1); } 45% { transform: translateY(-8px) scale(1.04); } 60% { transform: translateY(-3px) scale(.98); } }
@keyframes sushiWiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } 75% { transform: rotate(-3deg); } }
@media (prefers-reduced-motion: reduce) { .sushi-sticker { animation: none !important; } }

.learning-callout, .guide-final-callout {
  display: flex; gap: 1rem; align-items: center; margin: 0 0 1rem; padding: 1rem;
  border-radius: 16px; background: linear-gradient(135deg,#eff6ff,#fff7ed); border: 1px solid #dbeafe;
}
.learning-callout p, .guide-final-callout p { margin: .2rem 0 0; color: var(--muted); }

.budget-guide { overflow: hidden; }
.guide-hero { display: grid; grid-template-columns: 1fr auto; gap: 1.5rem; align-items: center; padding: 1.25rem; border-radius: 18px; background: linear-gradient(135deg,#0f172a,#1e293b); color: #fff; }
.guide-hero p { max-width: 760px; color: #cbd5e1; }
.guide-mascots { display: flex; gap: .4rem; align-items: center; }
.guide-index { display: flex; flex-wrap: wrap; gap: .55rem; margin: 1.2rem 0; }
.guide-index a { text-decoration: none; padding: .55rem .8rem; border-radius: 999px; background: #eff6ff; color: #1d4ed8; font-size: .82rem; font-weight: 800; }
.guide-block { display: grid; grid-template-columns: 54px 1fr; gap: 1rem; padding: 1.25rem 0; border-bottom: 1px solid var(--border); scroll-margin-top: 110px; }
.guide-block h3 { margin: 0 0 .5rem; font-size: 1.25rem; }
.guide-block p { color: var(--muted); }
.guide-icon { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 15px; background: #fff7ed; font-size: 1.6rem; }
.guide-block li { margin-bottom: .4rem; }
.numbered-guide { padding-left: 1.2rem; }
.guide-cards { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .8rem; }
.guide-cards > div { padding: 1rem; border-radius: 14px; background: var(--surface-2); }
.guide-cards p { margin: .3rem 0 0; }
.warning-guide { margin-top: .5rem; padding-inline: 1rem; border: 1px solid #fed7aa; border-radius: 16px; background: #fff7ed; }
.guide-final-callout { margin-top: 1.2rem; margin-bottom: 0; }
@media (max-width: 700px) {
  .guide-hero { grid-template-columns: 1fr; }
  .guide-mascots { justify-content: center; }
  .guide-block { grid-template-columns: 1fr; }
  .guide-cards { grid-template-columns: 1fr; }
  .panel-decoration { display: none; }
}
