/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --text: #17181a;
  --text-muted: #55585e;
  --border: #ddd8ce;
  --accent: #e15b0f;
  --accent-dark: #b8480a;
  --accent-ink: #ffffff;
  --success: #1e7a34;
  --success-bg: #e7f4e9;
  --warning: #8a4b06;
  --warning-bg: #fdf0dd;
  --danger: #b02a2a;
  --danger-bg: #fbe9e9;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(20, 16, 8, 0.08);
  --shadow-md: 0 8px 24px rgba(20, 16, 8, 0.12);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --display: "Manrope", var(--sans);
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16140f;
    --surface: #201d17;
    --surface-2: #29251d;
    --text: #f4f1ea;
    --text-muted: #b7b0a2;
    --border: #3c362a;
    --accent: #ff7a2e;
    --accent-dark: #ff9552;
    --accent-ink: #1a1206;
    --success-bg: #17301d;
    --success: #6fd989;
    --warning-bg: #3a2a0e;
    --warning: #f0b25c;
    --danger-bg: #3a1c1c;
    --danger: #f18787;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  --bg: #16140f;
  --surface: #201d17;
  --surface-2: #29251d;
  --text: #f4f1ea;
  --text-muted: #b7b0a2;
  --border: #3c362a;
  --accent: #ff7a2e;
  --accent-dark: #ff9552;
  --accent-ink: #1a1206;
  --success-bg: #17301d;
  --success: #6fd989;
  --warning-bg: #3a2a0e;
  --warning: #f0b25c;
  --danger-bg: #3a1c1c;
  --danger: #f18787;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html {
  -webkit-text-size-adjust: 100%;
  tab-size: 2;
  overflow-x: clip;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  overscroll-behavior-y: none;
}
img, svg, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.12; letter-spacing: -0.01em; font-family: var(--display); }
ul, ol { padding-left: 1.2em; }
::selection { background: var(--accent); color: var(--accent-ink); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .7rem 1.1rem; background: var(--accent); color: var(--accent-ink);
  z-index: 9999; border-radius: 8px; font-weight: 700;
}
.skip-link:focus { top: 1rem; }

/* =============================================================
   3. Utilities
   ============================================================= */
.container { width: 100%; max-width: 880px; margin-inline: auto; padding-inline: 1.1rem; }
.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;
}
.muted { color: var(--text-muted); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 1rem; }

/* =============================================================
   4. Header / nav
   ============================================================= */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header .container {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 62px; gap: .75rem;
}
.brand { display: flex; align-items: center; white-space: nowrap; }
.brand-logo { display: block; height: 42px; width: auto; }
.nav-link {
  font-weight: 700; font-size: .92rem; padding: .5rem .8rem; border-radius: 999px;
  border: 1px solid var(--border); white-space: nowrap;
  transition: background .2s var(--ease-out), border-color .2s var(--ease-out);
}
.nav-link:hover { background: var(--surface-2); border-color: var(--accent); }

/* =============================================================
   5. Hero / page intro
   ============================================================= */
.page-hero { padding: 1.6rem 0 .6rem; }
.page-hero h1 { font-size: clamp(1.55rem, 5vw, 2.3rem); }
.page-hero p.lead { margin-top: .5rem; color: var(--text-muted); font-size: 1.05rem; max-width: 60ch; }
.breadcrumb { font-size: .85rem; color: var(--text-muted); margin-bottom: .4rem; }
.breadcrumb a { text-decoration: underline; text-underline-offset: 2px; }

/* =============================================================
   6. Tool card — the hero component
   ============================================================= */
.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.1rem 1.1rem 1.3rem;
  margin-top: 1rem;
}
.tool-section-title {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 800; color: var(--accent-dark); margin-bottom: .6rem;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tool-section-title { color: var(--accent); } }
:root[data-theme="dark"] .tool-section-title { color: var(--accent); }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 700; font-size: .92rem; }
.field .hint { font-size: .78rem; color: var(--text-muted); }

input[type="number"], input[type="text"], select {
  width: 100%;
  font-size: 1.15rem;
  font-weight: 600;
  font-family: var(--sans);
  padding: .8rem .85rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 54px;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .15s var(--ease-out), box-shadow .15s var(--ease-out);
}
input[type="number"]:focus, input[type="text"]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'><path d='M5 8l5 5 5-5' fill='none' stroke='%2355585e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right .85rem center;
  padding-right: 2.4rem;
}
.suffix-field { position: relative; }
.suffix-field input { padding-right: 3.4rem; }
.suffix-field .suffix {
  position: absolute; right: .9rem; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-weight: 700; font-size: .92rem; pointer-events: none;
}

/* Openings (puertas/ventanas) repeating rows */
.opening-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: .5rem;
  align-items: end;
  padding: .7rem;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  margin-bottom: .55rem;
}
.opening-row .field label { font-size: .74rem; }
.opening-row input, .opening-row select { min-height: 46px; font-size: 1rem; padding: .55rem .6rem; }
.btn-remove-opening {
  min-height: 46px; width: 46px; border-radius: var(--radius-sm);
  background: var(--danger-bg); color: var(--danger); font-weight: 900; font-size: 1.2rem;
  display: grid; place-items: center;
}
.btn-add-opening {
  width: 100%; min-height: 50px; border-radius: var(--radius-md);
  border: 1.5px dashed var(--border); font-weight: 700; color: var(--accent-dark);
  display: flex; align-items: center; justify-content: center; gap: .4rem;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-add-opening { color: var(--accent); } }
:root[data-theme="dark"] .btn-add-opening { color: var(--accent); }
.btn-add-opening:hover { background: var(--surface-2); }

/* Range slider for % desperdicio */
.range-row { display: flex; align-items: center; gap: .8rem; }
input[type="range"] {
  flex: 1; height: 46px; accent-color: var(--accent);
}
.range-value {
  min-width: 3.4rem; text-align: center; font-weight: 800; font-size: 1.05rem;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: .4rem .3rem;
}

/* =============================================================
   7. Buttons
   ============================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 56px; padding: .9rem 1.4rem; border-radius: 999px;
  font-weight: 800; font-size: 1.02rem; white-space: nowrap;
  transition: transform .15s var(--ease-out), background .2s var(--ease-out), box-shadow .2s var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-block { width: 100%; }
.btn-lg { min-height: 62px; font-size: 1.12rem; }
.actions-row { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.1rem; }
.actions-row .btn { flex: 1 1 220px; }
.btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.btn.is-copied { background: var(--success); color: #fff; }

/* =============================================================
   8. Results panel
   ============================================================= */
.results {
  margin-top: 1.3rem;
  border-top: 2px dashed var(--border);
  padding-top: 1.1rem;
}
.results-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem;
}
.result-tile {
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: .85rem .9rem;
  border: 1px solid var(--border);
}
.result-tile .num {
  font-family: var(--display);
  font-size: clamp(1.5rem, 6vw, 1.9rem);
  font-weight: 800; line-height: 1;
  color: var(--accent-dark);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .result-tile .num { color: var(--accent); } }
:root[data-theme="dark"] .result-tile .num { color: var(--accent); }
.result-tile .label { font-size: .82rem; color: var(--text-muted); font-weight: 600; margin-top: .2rem; }
.result-tile.wide { grid-column: 1 / -1; }

.budget-box {
  margin-top: .9rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.2rem;
}
.budget-box .budget-label { font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; opacity: .92; font-weight: 700; }
.budget-box .budget-total { font-family: var(--display); font-size: clamp(1.9rem, 8vw, 2.6rem); font-weight: 900; margin-top: .15rem; }
.budget-box .budget-note { font-size: .8rem; opacity: .9; margin-top: .3rem; }

.line-items { margin-top: .8rem; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.line-item {
  display: flex; justify-content: space-between; gap: .6rem;
  padding: .65rem .85rem; font-size: .92rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.line-item:last-child { border-bottom: none; }
.line-item .qty { color: var(--text-muted); }
.line-item .cost { font-weight: 700; white-space: nowrap; }

/* =============================================================
   9. Honesty / disclaimer badges
   ============================================================= */
.notice {
  display: flex; gap: .6rem; align-items: flex-start;
  border-radius: var(--radius-md); padding: .8rem .9rem;
  font-size: .88rem; margin-top: .9rem; line-height: 1.45;
}
.notice svg { width: 20px; height: 20px; flex-shrink: 0; margin-top: .1rem; }
.notice-info { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); }
.notice-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent); }
.notice strong { color: var(--text); }

.privacy-badge {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .8rem; color: var(--text-muted); margin-top: .7rem;
}
.privacy-badge svg { width: 16px; height: 16px; }

/* =============================================================
   10. Wall / rebar drawing
   ============================================================= */
.drawing-wrap {
  margin-top: 1.1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: .8rem;
}
.drawing-wrap .drawing-title { font-weight: 800; font-size: .88rem; margin-bottom: .5rem; }
.drawing-svg-holder { width: 100%; overflow-x: auto; }
.drawing-svg-holder svg { width: 100%; height: auto; min-width: 280px; }
.drawing-legend {
  display: flex; flex-wrap: wrap; gap: .6rem 1rem; margin-top: .7rem; font-size: .78rem; color: var(--text-muted);
}
.drawing-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend-swatch { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }

/* =============================================================
   11. Ad slots
   ============================================================= */
.ad-slot {
  display: flex; align-items: center; justify-content: center;
  background: repeating-linear-gradient(135deg, var(--surface-2), var(--surface-2) 10px, var(--surface) 10px, var(--surface) 20px);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: .78rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  margin: 1.3rem auto;
}
.ad-slot::before { content: "Anuncio"; }
.ad-slot span.tag { display:none; }
.ad-banner { min-height: 90px; max-width: 728px; }
.ad-incontent { min-height: 250px; max-width: 336px; }
.ad-corner {
  position: fixed; right: .8rem; bottom: .8rem; z-index: 45;
  width: 220px; min-height: 90px; margin: 0;
  box-shadow: var(--shadow-md);
  background: var(--surface);
}
.ad-side {
  position: fixed; top: 50%; transform: translateY(-50%);
  width: 160px; min-height: 600px; max-height: 80vh;
  margin: 0; z-index: 20;
  writing-mode: initial;
}
.ad-side-left { left: 14px; }
.ad-side-right { right: 14px; }
@media (max-width: 1400px) {
  .ad-side { display: none; }
}
.ad-corner .ad-close {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  display: grid; place-items: center; font-size: .9rem; font-weight: 900;
}

/* =============================================================
   12. How it works / usos / FAQ
   ============================================================= */
.section { padding: 2.2rem 0; }
.section h2 { font-size: clamp(1.3rem, 4vw, 1.7rem); margin-bottom: 1rem; }
.steps-grid { display: grid; gap: .9rem; }
.step-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.1rem; display: flex; gap: .9rem; align-items: flex-start;
}
.step-num {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 900;
  display: grid; place-items: center; font-family: var(--display);
}
.step-card h3 { font-size: 1.02rem; margin-bottom: .25rem; }
.step-card p { color: var(--text-muted); font-size: .92rem; }

.usos-grid { display: grid; gap: .8rem; grid-template-columns: 1fr; }
.uso-card {
  background: var(--surface-2); border-radius: var(--radius-md); padding: 1rem 1.1rem;
  border: 1px solid var(--border);
}
.uso-card h3 { font-size: .98rem; margin-bottom: .3rem; }
.uso-card p { font-size: .88rem; color: var(--text-muted); }

.seo-copy { color: var(--text-muted); font-size: .96rem; }
.seo-copy p + p { margin-top: .8rem; }
.seo-copy h3 { color: var(--text); font-size: 1.05rem; margin: 1.1rem 0 .4rem; }

details.faq-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: .2rem .2rem; margin-bottom: .6rem;
}
details.faq-item summary {
  cursor: pointer; list-style: none; font-weight: 700; padding: .9rem 1rem;
  display: flex; justify-content: space-between; gap: .6rem; align-items: center;
}
details.faq-item summary::-webkit-details-marker { display: none; }
details.faq-item summary::after {
  content: "+"; font-size: 1.4rem; font-weight: 400; color: var(--accent); flex-shrink: 0;
  transition: transform .2s var(--ease-out);
}
details.faq-item[open] summary::after { transform: rotate(45deg); }
details.faq-item .faq-answer { padding: 0 1.1rem 1rem; color: var(--text-muted); font-size: .92rem; }

/* Más calculadoras */
.tools-grid { display: grid; gap: .8rem; grid-template-columns: 1fr; }
.tool-link-card {
  display: flex; gap: .8rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: .9rem 1rem; transition: border-color .2s var(--ease-out), transform .15s var(--ease-out);
}
.tool-link-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.tool-link-card .icon {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: var(--radius-sm);
  background: var(--surface-2); display: grid; place-items: center;
}
.tool-link-card .icon svg { width: 24px; height: 24px; color: var(--accent-dark); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tool-link-card .icon svg { color: var(--accent); } }
:root[data-theme="dark"] .tool-link-card .icon svg { color: var(--accent); }
.tool-link-card h3 { font-size: .98rem; }
.tool-link-card p { font-size: .82rem; color: var(--text-muted); margin-top: .1rem; }
.tool-link-card.is-current { border-color: var(--accent); background: var(--surface-2); }

/* =============================================================
   13. Footer
   ============================================================= */
.site-footer { border-top: 1px solid var(--border); padding: 2rem 0 6rem; margin-top: 1rem; }
.site-footer .foot-links { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .85rem; margin-bottom: .8rem; }
.site-footer .foot-links a { text-decoration: underline; text-underline-offset: 3px; color: var(--text-muted); }
.site-footer .foot-note { font-size: .78rem; color: var(--text-muted); }

/* =============================================================
   14. Dialog (popup on copiar/imprimir) + toast
   ============================================================= */
dialog.ad-dialog {
  border: none; border-radius: var(--radius-lg); padding: 0;
  max-width: 92vw; width: 380px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-md);
}
dialog.ad-dialog::backdrop { background: rgba(10, 8, 4, 0.55); }
.ad-dialog-inner { padding: 1.2rem; position: relative; }
.ad-dialog-close {
  position: absolute; top: .6rem; right: .6rem;
  width: 34px; height: 34px; border-radius: 999px; background: var(--surface-2);
  display: grid; place-items: center; font-weight: 900; font-size: 1.1rem;
}
.ad-dialog-inner .ad-slot { margin: .6rem 0 0; min-height: 220px; }
.ad-dialog-title { font-weight: 800; padding-right: 2rem; }
.ad-dialog-sub { font-size: .82rem; color: var(--text-muted); margin-top: .2rem; }

.toast-confirm {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(0);
  background: var(--success); color: #fff; font-weight: 700; font-size: .9rem;
  padding: .7rem 1.1rem; border-radius: 999px; box-shadow: var(--shadow-md);
  z-index: 60; opacity: 0; pointer-events: none;
  transition: opacity .25s var(--ease-out), transform .25s var(--ease-out);
}
.toast-confirm.is-visible { opacity: 1; transform: translateX(-50%) translateY(-8px); }

/* =============================================================
   15. Print styles
   ============================================================= */
@media print {
  .site-header, .site-footer, .ad-slot, .ad-corner, .actions-row, .breadcrumb,
  .section, dialog, .toast-confirm, .skip-link, .field-grid, .tool-section-title,
  .drawing-wrap, .btn-add-opening { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .print-sheet { display: block !important; }
  .print-sheet h1 { font-size: 18pt; margin-bottom: 4pt; }
  .print-sheet table { width: 100%; border-collapse: collapse; margin-top: 10pt; }
  .print-sheet th, .print-sheet td { border: 1px solid #999; padding: 6pt 8pt; text-align: left; font-size: 11pt; }
  .print-sheet .print-total { margin-top: 12pt; font-size: 14pt; font-weight: 800; }
}
.print-sheet { display: none; }

/* =============================================================
   16. Responsive
   ============================================================= */
@media (min-width: 540px) {
  .results-grid { grid-template-columns: repeat(3, 1fr); }
  .usos-grid { grid-template-columns: 1fr 1fr; }
  .tools-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 720px) {
  .steps-grid { grid-template-columns: repeat(3, 1fr); }
  .opening-row { grid-template-columns: 1fr 1fr 1fr 1fr auto; }
}
@media (min-width: 960px) {
  .tools-grid { grid-template-columns: repeat(3, 1fr); }
}

/* =============================================================
   17. Reduced motion — only intrusive effects
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  .toast-confirm { transition: none; }
}
