/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f6f4ec;
  --surface: #ffffff;
  --surface-2: #f0eee2;
  --text: #17231f;
  --muted: #5c6b64;
  --accent: #0f6e5c;
  --accent-dark: #0b5347;
  --accent-2: #c98a2c;
  --danger: #b3392a;
  --danger-bg: #fbe9e6;
  --success-bg: #e6f3ec;
  --border: #e1ddce;
  --shadow: 0 10px 30px -12px rgba(15, 35, 30, 0.18);
  --radius: 14px;
  --radius-sm: 8px;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  --mono: "JetBrains Mono", "Consolas", monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101613;
    --surface: #17211d;
    --surface-2: #1d2822;
    --text: #edf2ef;
    --muted: #9db3ac;
    --accent: #2ba07f;
    --accent-dark: #1f8267;
    --accent-2: #e0a848;
    --danger: #e07564;
    --danger-bg: #3a201c;
    --success-bg: #163427;
    --border: #2a3630;
    --shadow: 0 10px 30px -12px 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; scroll-behavior: smooth; overflow-x: clip; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -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; }
a:hover { text-decoration: underline; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.1; font-family: var(--display); font-weight: 600; }
::selection { background: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

/* =============================================================
   3. Utilities
   ============================================================= */
.skip-link {
  position: fixed; top: -100px; left: 1rem; z-index: 9999;
  padding: .6rem 1rem; background: var(--text); color: var(--bg);
  border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 1rem; }
.container { width: 100%; max-width: 1120px; margin-inline: auto; padding-inline: 1.1rem; }
.muted-note { color: var(--muted); font-size: .9rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* =============================================================
   4. Buttons
   ============================================================= */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .8rem 1.3rem; border-radius: 999px; font-weight: 600;
  transition: transform .18s var(--ease-out), box-shadow .18s var(--ease-out), background .18s var(--ease-out);
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--accent-dark); transform: translateY(-1px); }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-sm { padding: .55rem .9rem; font-size: .88rem; }
.btn-calc { width: 100%; justify-content: center; font-size: 1.05rem; }

/* =============================================================
   5. Header / hero
   ============================================================= */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.header-inner { display: flex; align-items: center; justify-content: space-between; padding-block: .8rem; }
.logo { display: flex; align-items: center; gap: .5rem; font-family: var(--display); font-size: 1.2rem; font-weight: 600; }
.header-nav { display: flex; gap: 1.3rem; font-size: .92rem; font-weight: 500; }
.header-nav a:hover { color: var(--accent); }

.hero { padding-block: 2.6rem 1.4rem; text-align: center; }
.hero h1 { font-size: clamp(1.9rem, 4.4vw, 2.9rem); max-width: 20ch; margin-inline: auto; }
.hero-sub { color: var(--muted); max-width: 56ch; margin: .9rem auto 0; font-size: 1.05rem; }

/* =============================================================
   6. Tool shell / tabs
   ============================================================= */
.tool-shell { padding-bottom: 1rem; }
.tabs { display: flex; gap: .4rem; border-bottom: 1px solid var(--border); margin-bottom: 1.4rem; overflow-x: auto; }
.tab-btn {
  padding: .8rem 1.1rem; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab-btn.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel[hidden] { display: none; }

.tool-grid { display: grid; grid-template-columns: 1fr; gap: 1.2rem; }
@media (min-width: 960px) { .tool-grid { grid-template-columns: 1.5fr 1fr; align-items: start; } }

.tool-card, .glossary, .proj-side, .proj-main > * {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.4rem;
}
.tool-card { box-shadow: var(--shadow); }

.field { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.field label { font-weight: 600; font-size: .92rem; }
.field input, .field select {
  padding: .7rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font: inherit; font-size: 1rem;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field-hint { font-size: .85rem; color: var(--muted); }
.field-grid { display: grid; grid-template-columns: 1fr; gap: .8rem; }
@media (min-width: 540px) { .field-grid { grid-template-columns: 1fr 1fr; } }

.flow-field { border: 0; padding: 0; }
.flow-field legend { font-weight: 600; font-size: .92rem; margin-bottom: .4rem; }
.flow-options { display: flex; gap: .6rem; }
.flow-opt {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; font-size: .9rem; font-weight: 600;
}
.flow-opt input { accent-color: var(--accent); }
.flow-opt:has(input:checked).flow-in { background: var(--success-bg); border-color: var(--accent); }
.flow-opt:has(input:checked).flow-out { background: var(--danger-bg); border-color: var(--danger); }

.result-zone { margin-top: 1.3rem; padding-top: 1.2rem; border-top: 1px dashed var(--border); }
.result-label { color: var(--muted); font-weight: 600; font-size: .9rem; }
.result-value { font-family: var(--mono); font-size: clamp(1.8rem, 5vw, 2.6rem); font-weight: 700; color: var(--accent); margin: .2rem 0; }
.result-detail { color: var(--muted); font-size: .95rem; }
.result-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.result-error { color: var(--danger); background: var(--danger-bg); padding: .8rem 1rem; border-radius: var(--radius-sm); margin-top: 1rem; }

.glossary h2 { font-size: 1.1rem; margin-bottom: .8rem; }
.glossary dl { display: flex; flex-direction: column; gap: .7rem; }
.glossary dt { font-weight: 700; font-size: .92rem; color: var(--accent-dark); }
.glossary dd { color: var(--muted); font-size: .88rem; }

/* =============================================================
   7. History
   ============================================================= */
.panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; margin-bottom: .3rem; }
.panel-head h2 { margin-right: auto; font-size: 1.3rem; }
.hist-list { display: flex; flex-direction: column; gap: .7rem; margin-top: 1rem; }
.hist-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .9rem 1rem; display: flex; flex-wrap: wrap; align-items: center; gap: .8rem;
}
.hist-item .hist-badge { font-size: .75rem; font-weight: 700; padding: .2rem .55rem; border-radius: 999px; }
.hist-badge.in { background: var(--success-bg); color: var(--accent-dark); }
.hist-badge.out { background: var(--danger-bg); color: var(--danger); }
.hist-main { flex: 1; min-width: 220px; }
.hist-main strong { font-family: var(--mono); }
.hist-time { color: var(--muted); font-size: .8rem; }
.hist-actions { display: flex; gap: .4rem; }
.empty-state { color: var(--muted); text-align: center; padding: 2rem 1rem; }

/* =============================================================
   8. Projects
   ============================================================= */
.proj-grid { display: grid; grid-template-columns: 1fr; gap: 1.2rem; }
@media (min-width: 960px) { .proj-grid { grid-template-columns: 340px 1fr; align-items: start; } }
.proj-side h3 { font-size: 1rem; margin: 1rem 0 .6rem; }
.proj-main { display: flex; flex-direction: column; gap: 1rem; }
.proj-chart-wrap { overflow-x: auto; }
#proj-chart { width: 100%; height: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.proj-movs { display: flex; flex-direction: column; gap: .5rem; }
.mov-item {
  display: flex; align-items: center; gap: .7rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .7rem .9rem; font-size: .9rem;
}
.mov-item .mov-remove { margin-left: auto; color: var(--danger); font-weight: 700; }

/* =============================================================
   9. Ads
   ============================================================= */
.ad-slot {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 90px; margin-block: 1.6rem; border: 1px dashed var(--border); border-radius: var(--radius-sm);
  color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; gap: .3rem;
}
.ad-leaderboard { min-height: 100px; }
.ad-incontent { min-height: 120px; }

.ad-toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 60;
  width: 220px; padding: .9rem 1rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: .85rem;
}
.ad-toast-close { position: absolute; top: .4rem; right: .5rem; color: var(--muted); font-size: .9rem; }
.ad-toast-tag { display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: .3rem; }

/* =============================================================
   9b. Transient app notices (not ads — action confirmations)
   ============================================================= */
.app-notice {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translate(-50%, 12px);
  background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 999px;
  font-size: .88rem; font-weight: 600; box-shadow: var(--shadow); z-index: 80; opacity: 0;
  transition: opacity .25s var(--ease-out), transform .25s var(--ease-out);
}
.app-notice.is-in { opacity: 1; transform: translate(-50%, 0); }

/* =============================================================
   10. Dialogs
   ============================================================= */
dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: 520px; width: calc(100% - 2rem); box-shadow: var(--shadow); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(10, 15, 13, .55); }
.print-dialog-inner, .download-dialog-inner { padding: 1.4rem; position: relative; }
.print-tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin: 1rem 0; }
.print-tpl-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem; text-align: left; }
.print-tpl-card:hover, .print-tpl-card:focus-visible { border-color: var(--accent); background: var(--success-bg); }
.print-tpl-card strong { display: block; font-size: .92rem; margin-bottom: .2rem; }
.print-tpl-card span { font-size: .8rem; color: var(--muted); }
.print-dialog-actions { display: flex; justify-content: flex-end; }
.dialog-x { position: absolute; top: .9rem; right: .9rem; font-size: 1.1rem; color: var(--muted); }
.ad-placeholder-box {
  display: flex; align-items: center; justify-content: center; min-height: 160px;
  border: 1px dashed var(--border); border-radius: var(--radius-sm); color: var(--muted); margin: 1rem 0; font-weight: 700;
}

/* =============================================================
   11. Content sections
   ============================================================= */
.content-section { padding-block: 2.2rem; }
.content-section h2 { font-size: clamp(1.5rem, 3vw, 1.9rem); margin-bottom: 1.2rem; }
.seo-copy p { color: var(--muted); max-width: 74ch; margin-bottom: 1rem; }
.seo-copy strong { color: var(--text); }

.steps-grid, .ideas-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 720px) { .steps-grid { grid-template-columns: repeat(3, 1fr); } .ideas-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .ideas-grid { grid-template-columns: repeat(3, 1fr); } }
.step-card, .idea-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.3rem; transition: transform .2s var(--ease-out), box-shadow .2s var(--ease-out);
}
.step-card:hover, .idea-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.step-card svg { color: var(--accent); margin-bottom: .7rem; }
.step-card h3, .idea-card h3 { font-size: 1.02rem; margin-bottom: .4rem; }
.idea-card p, .step-card p { color: var(--muted); font-size: .92rem; }

#faq details {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .9rem 1.1rem; margin-bottom: .6rem;
}
#faq summary { font-weight: 600; cursor: pointer; }
#faq p { color: var(--muted); margin-top: .6rem; font-size: .95rem; }

/* =============================================================
   12. Footer
   ============================================================= */
.site-footer { border-top: 1px solid var(--border); padding-block: 1.6rem; margin-top: 1rem; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; font-size: .85rem; color: var(--muted); }
.footer-links { display: flex; gap: 1rem; }

/* =============================================================
   13. Responsive tweaks
   ============================================================= */
@media (max-width: 539px) {
  .header-nav { display: none; }
  .flow-options { flex-direction: column; }
}

/* =============================================================
   14. Reduced motion (only intrusive effects)
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* =============================================================
   15. Print — the tool UI never prints, only #print-area
   ============================================================= */
#print-area { display: none; }

@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area {
    display: block !important;
    color: #111; background: #fff; font-family: var(--sans); padding: 0;
  }
  .p-header { display: flex; align-items: center; justify-content: space-between; border-bottom: 3px solid #111; padding-bottom: .8rem; margin-bottom: 1.2rem; }
  .p-title { font-family: var(--display); font-size: 1.6rem; }
  .p-meta { font-size: .82rem; color: #444; margin-bottom: 1rem; }
  .p-result { font-family: var(--mono); font-size: 1.6rem; font-weight: 700; margin: 1rem 0; }
  .p-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
  .p-table th, .p-table td { border: 1px solid #ccc; padding: .45rem .6rem; text-align: left; font-size: .88rem; }
  .p-formula { font-family: var(--mono); background: #f2f2f2; padding: .6rem .8rem; border-radius: 6px; margin: .8rem 0; font-size: .85rem; }
  .p-footer { margin-top: 2rem; font-size: .75rem; color: #666; border-top: 1px solid #ccc; padding-top: .6rem; }

  /* Ejecutivo formal */
  body[data-print-template="ejecutivo"] #print-area { font-family: Georgia, var(--display), serif; }
  body[data-print-template="ejecutivo"] .p-header { border-bottom-color: #1b2f4b; }
  body[data-print-template="ejecutivo"] .p-title { color: #1b2f4b; }
  body[data-print-template="ejecutivo"] .p-result { color: #a9772c; }
  body[data-print-template="ejecutivo"] .p-table th { background: #1b2f4b; color: #fff; }

  /* Corporativo clásico */
  body[data-print-template="clasico"] .p-header { border-bottom-color: #0b5cab; }
  body[data-print-template="clasico"] .p-title { color: #0b5cab; }
  body[data-print-template="clasico"] .p-result { color: #0b5cab; }
  body[data-print-template="clasico"] .p-table th { background: #e6f0fb; color: #0b5cab; }

  /* Minimalista */
  body[data-print-template="minimalista"] .p-header { border-bottom: 1px solid #111; }
  body[data-print-template="minimalista"] .p-result { color: #111; }
  body[data-print-template="minimalista"] .p-table th { background: #fff; border-bottom: 2px solid #111; }
  body[data-print-template="minimalista"] .p-formula { background: #fff; border: 1px solid #ddd; }

  /* Moderno a color */
  body[data-print-template="moderno"] #print-area { font-family: var(--sans); }
  body[data-print-template="moderno"] .p-header { border-bottom: 4px solid #0f6e5c; border-radius: 0; }
  body[data-print-template="moderno"] .p-title { color: #0f6e5c; }
  body[data-print-template="moderno"] .p-result { color: #c98a2c; }
  body[data-print-template="moderno"] .p-table th { background: #0f6e5c; color: #fff; }
  body[data-print-template="moderno"] .p-formula { background: #eaf5f0; }

  /* Académico */
  body[data-print-template="academico"] #print-area { font-family: var(--mono); }
  body[data-print-template="academico"] .p-header { border-bottom: 1px dashed #111; }
  body[data-print-template="academico"] .p-table th { background: #f0f0f0; }
  body[data-print-template="academico"] .p-formula { border-left: 3px solid #111; background: #fafafa; }
}
