:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #16202c;
  --muted: #5b6878;
  --border: #dde3ea;
  --accent: #0b6bcb;
  --accent-ink: #ffffff;
  --accent-soft: #e5f0fb;
  --ok: #1a7f4b;
  --warn: #9a6200;
  --warn-bg: #fff5e0;
  --err: #b42318;
  --err-bg: #fdecea;
  --info-bg: #eef3f9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #1f2832;
    --text: #e6ebf1;
    --muted: #97a3b2;
    --border: #2b3643;
    --accent: #4da3ff;
    --accent-ink: #08121d;
    --accent-soft: #15283d;
    --ok: #4cc38a;
    --warn: #f0b44c;
    --warn-bg: #2d2412;
    --err: #ff7b72;
    --err-bg: #2f1716;
    --info-bg: #18222e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.4rem, 3.2vw, 2rem); letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: .4rem 0 .8rem; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-in { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  background-image: linear-gradient(var(--accent-ink), var(--accent-ink)), linear-gradient(var(--accent-ink), var(--accent-ink));
  background-size: 14px 3px; background-position: 6px 9px, 6px 15px; background-repeat: no-repeat; }
.badge { font-size: .7rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); }
.badge-soft { background: var(--accent-soft); color: var(--accent); }

.hero { padding: 28px 0 8px; max-width: 820px; }
.hero p { color: var(--muted); font-size: 1rem; }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 20px; align-items: start; margin-top: 12px; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.sticky { position: sticky; top: 72px; }
@media (max-width: 900px) { .sticky { position: static; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
details.card > summary { cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; align-items: baseline; gap: .6rem; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2 { margin: 0; }
details.card > summary::before { content: "▸"; color: var(--muted); }
details.card[open] > summary::before { content: "▾"; }
details.card[open] > summary { margin-bottom: 12px; }

/* Fields */
.field { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); min-width: 0; }
.field input, .field select, .zone input {
  font: inherit; font-size: .95rem; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
.field input:focus, .field select:focus, .zone input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.grid-params { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

/* Buttons */
.btn { font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; border-radius: 8px; padding: 8px 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.btn:hover { border-color: var(--accent); }
.btn-pro { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-pro:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-add { width: 100%; border-style: dashed; background: transparent; padding: 12px; color: var(--accent); }
.btn-icon { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 4px 8px; border-radius: 6px; }
.btn-icon:hover { color: var(--err); background: var(--err-bg); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.wrap-actions { margin: 12px 0; }

/* IDF */
.idf-head { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.idf-head .field:first-child { flex: 1 1 180px; }
.idf-head .field.pct { flex: 0 0 120px; }
.zones-head, .zone { display: grid; grid-template-columns: minmax(0, 2.2fr) repeat(4, minmax(0, .8fr)) repeat(2, minmax(0, .9fr)) 36px; gap: 6px; align-items: center; }
.zones-head { font-size: .72rem; color: var(--muted); padding: 0 2px 4px; text-transform: uppercase; letter-spacing: .02em; }
.zone { margin-bottom: 6px; }
.zone input { padding: 7px 8px; }
.zone label > span { display: none; }
.zone-meta { font-size: .78rem; color: var(--muted); margin: -2px 0 8px 2px; }
.zone-meta.err { color: var(--err); }
.btn-add-zone { font-size: .85rem; padding: 6px 10px; }
@media (max-width: 640px) {
  .zones-head { display: none; }
  .zone { grid-template-columns: repeat(2, minmax(0, 1fr)); background: var(--surface-2); padding: 10px; border-radius: 10px; }
  .zone label > span { display: block; font-size: .72rem; color: var(--muted); margin-bottom: 2px; }
  .zone input { background: var(--surface); }
  .zone .z-name { grid-column: 1 / -1; }
  .zone .btn-icon { grid-column: 1 / -1; justify-self: end; }
}

.hint { font-size: .85rem; color: var(--muted); margin-top: 12px; }

/* Results */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 8px 0 12px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.kpi b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi span { font-size: .78rem; color: var(--muted); }
.kpi.main { background: var(--accent-soft); }
.kpi.main b { color: var(--accent); }

.aviso { font-size: .84rem; border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.aviso.error { background: var(--err-bg); color: var(--err); }
.aviso.warn { background: var(--warn-bg); color: var(--warn); }
.aviso.info { background: var(--info-bg); color: var(--muted); }

.tbl-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }
tfoot td { font-weight: 700; border-bottom: 0; }

.pro-box { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 4px; }
.pro-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 420px) { .pro-grid { grid-template-columns: 1fr; } }
.pro-item { text-align: left; font: inherit; cursor: pointer; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; color: var(--text); }
.pro-item:hover { border-color: var(--accent); }
.pro-item b { display: block; font-size: .86rem; }
.pro-item b::after { content: " 🔒"; font-size: .75rem; }
.pro-item span { font-size: .76rem; color: var(--muted); }

.seo { margin-top: 8px; }
.seo h2 { margin-top: 1rem; }
.seo h2:first-child { margin-top: 0; }
.seo ol { padding-left: 1.2rem; }
.seo li { margin-bottom: .4rem; }
.seo details { border-top: 1px solid var(--border); padding: 8px 0; }
.seo summary { cursor: pointer; font-weight: 600; }

.footer { color: var(--muted); font-size: .82rem; padding-top: 8px; padding-bottom: 32px; }

/* Modal */
dialog { border: 0; padding: 0; border-radius: 14px; background: var(--surface); color: var(--text); width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 16, 24, .55); }
.modal { padding: 22px; position: relative; }
.modal .field { margin: 10px 0; }
.modal-x { position: absolute; top: 8px; right: 10px; background: none; border: 0; font-size: 1.4rem; color: var(--muted); cursor: pointer; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: .9rem; transition: all .2s; z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media print {
  .topbar, .inputs, .pro-box, .wrap-actions, .seo, #btn-ejemplo { display: none !important; }
  .layout { grid-template-columns: 1fr; }
}

/* Navegación */
.topnav { display: flex; align-items: center; gap: 14px; }
.topnav a { color: var(--text); text-decoration: none; font-weight: 600; font-size: .92rem; }
.topnav a:hover, .topnav a[aria-current] { color: var(--accent); }
.footnav { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 6px; }
.footnav a { color: var(--muted); }

/* Guías / artículos */
.article { max-width: 760px; margin: 0 auto; padding: 24px 0 8px; }
.crumbs { font-size: .82rem; color: var(--muted); margin-bottom: 10px; }
.crumbs a { color: var(--muted); }
.article h1 { margin-bottom: .4rem; }
.article .lead { font-size: 1.05rem; color: var(--muted); }
.article .meta { font-size: .8rem; color: var(--muted); margin-bottom: 18px; }
.article h2 { font-size: 1.25rem; margin: 2rem 0 .6rem; }
.article h3 { font-size: 1.02rem; margin: 1.4rem 0 .4rem; }
.article p, .article li { font-size: 1rem; line-height: 1.65; }
.article ul, .article ol { padding-left: 1.3rem; }
.article li { margin-bottom: .35rem; }
.article code, .formula { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.formula { display: block; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 10px 0 14px; white-space: pre-wrap; overflow-x: auto; }
.article table { margin: 10px 0 16px; font-size: .9rem; }
.article .tbl-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 4px 8px; }
.callout { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 12px 14px; border-radius: 0 10px 10px 0; margin: 16px 0; }
.callout.warn { border-color: var(--warn); background: var(--warn-bg); }
.cta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 24px 0; box-shadow: var(--shadow); }
.cta p { margin: 0; flex: 1 1 260px; }
.cta .btn { text-decoration: none; }
.related { border-top: 1px solid var(--border); margin-top: 28px; padding-top: 12px; }
.guide-list { list-style: none; padding: 0; display: grid; gap: 12px; }
.guide-list a { display: block; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.guide-list a:hover { border-color: var(--accent); }
.guide-list b { display: block; margin-bottom: 2px; }
.guide-list span { color: var(--muted); font-size: .9rem; }
.topnav a.btn-pro { color: var(--accent-ink); }
.hero-cta { margin-top: 12px; } .hero-cta .btn { text-decoration: none; display: inline-block; }
.topnav .badge { vertical-align: middle; margin-left: 2px; }
@media (max-width: 520px) { .topnav a[href="/guias/"] { display: none; } }
