/* ============================================================================
   BASE — componentes compartidos (macOS 26 en escritorio, iOS 26 en teléfono)
   ----------------------------------------------------------------------------
   Todos los módulos usan estas clases; cada módulo solo agrega su propio CSS
   de maquetación. Retícula de 4 px. Ver docs/interfaz.md para el catálogo.
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--canvas); color: var(--ink); font: 13px/1.4 var(--ui); -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: default; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ic { display: block; flex: none; }
.math { font-family: var(--math); }
.mono { font-family: var(--mono); }
.muted { color: var(--ink2); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- MATERIALES */
.glass { background: var(--glass); -webkit-backdrop-filter: var(--glass-fx); backdrop-filter: var(--glass-fx); box-shadow: inset 0 1px 0 var(--glass-hi), 0 0 0 .5px var(--glass-line), var(--float); }
.glass2 { background: var(--glass2); -webkit-backdrop-filter: var(--glass-fx); backdrop-filter: var(--glass-fx); box-shadow: inset 0 1px 0 var(--glass-hi), 0 0 0 .5px var(--glass-line), var(--float); }
.glass-bar { background: var(--glass); -webkit-backdrop-filter: var(--glass-fx); backdrop-filter: var(--glass-fx); box-shadow: inset 0 1px 0 var(--glass-hi); }

/* --------------------------------------------------- BOTONES (escritorio) */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 12px; border: 0; border-radius: 14px; background: var(--fill); color: var(--ink); font-size: 13px; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--fill2); }
.btn:active { filter: brightness(.94); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.btn-primary { background: var(--accent-fill); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-fill); filter: brightness(1.08); }
.btn-quiet { background: transparent; }
.btn-quiet:hover { background: var(--fill); }
.btn-icon { width: 30px; padding: 0; }
.btn-round { width: 34px; height: 34px; padding: 0; border-radius: 17px; }
.btn-lg { height: 34px; border-radius: 17px; padding: 0 16px; font-size: 13.5px; }
.btn-block { width: 100%; }
.btn-link { height: auto; padding: 0; border: 0; background: none; color: var(--accent-text); font-weight: 500; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-danger { color: var(--red-text); }
.btn[aria-pressed="true"] { background: var(--sel); }
/* cápsula de herramientas (barra superior) */
.cap { display: inline-flex; align-items: center; gap: 2px; height: 34px; padding: 0 3px; border-radius: 17px; }
.cap > .btn { height: 28px; border-radius: 14px; background: transparent; }
.cap > .btn:hover { background: var(--fill); }
.cap-sep { width: 1px; height: 18px; background: var(--sep2); margin: 0 2px; }

/* ------------------------------------------------------------ SEGMENTADO */
.seg { display: inline-flex; gap: 2px; padding: 2px; border-radius: 16px; background: var(--fill); }
.seg > button { height: 28px; padding: 0 16px; border: 0; border-radius: 14px; background: transparent; color: var(--ink2); font-size: 13px; font-weight: 500; white-space: nowrap; transition: background-color .15s, box-shadow .15s, color .15s; }
.seg > button:hover { color: var(--ink); }
.seg > button[aria-pressed="true"], .seg > button[aria-selected="true"] { background: var(--raised); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .16); }
.seg-sm { border-radius: 12px; }
.seg-sm > button { height: 22px; padding: 0 10px; border-radius: 10px; font-size: 12px; }
.seg-fill { display: flex; }
.seg-fill > button { flex: 1 1 0; padding: 0 6px; }

/* ----------------------------------------------------------- INTERRUPTOR */
.switch { display: inline-flex; align-items: center; gap: 8px; padding: 0; border: 0; background: none; font-size: 13px; color: var(--ink2); }
.switch-track { position: relative; flex: none; width: 38px; height: 22px; border-radius: 11px; background: var(--fill2); transition: background .15s; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 9px; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch[aria-checked="true"] .switch-track { background: var(--accent-fill); }
.switch[aria-checked="true"] .switch-track::after { transform: translateX(16px); }

/* --------------------------------------------------------------- CAMPOS */
.field { height: 28px; min-width: 0; padding: 0 8px; border: 0; border-radius: 8px; background: var(--raised); box-shadow: inset 0 0 0 .5px var(--sep2); font-size: 13px; }
.field:focus { outline: none; box-shadow: inset 0 0 0 1.5px var(--accent); }
.field.num { font-family: var(--mono); font-size: 12.5px; text-align: right; }
.field.is-error { box-shadow: inset 0 0 0 1.5px var(--red); }
.fld { display: flex; align-items: center; gap: 8px; min-width: 0; }
.fld > .field { flex: 1 1 auto; }
.unit { flex: none; min-width: 36px; font-size: 12px; color: var(--ink2); }
.popup { -webkit-appearance: none; appearance: none; height: 28px; min-width: 0; padding: 0 26px 0 8px; border: 0; border-radius: 8px; background: var(--raised) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 9l4-4 4 4M8 15l4 4 4-4'/%3E%3C/svg%3E") no-repeat right 8px center; box-shadow: inset 0 0 0 .5px var(--sep2); font-size: 13px; }
.popup:focus { outline: none; box-shadow: inset 0 0 0 1.5px var(--accent); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-fill); }

/* ----------------------------------------------------- PANELES (escritorio) */
.panel { display: flex; flex-direction: column; min-height: 0; border-radius: var(--r-panel); background: var(--panel); -webkit-backdrop-filter: var(--glass-fx); backdrop-filter: var(--glass-fx); box-shadow: 0 0 0 .5px var(--glass-line), var(--float); overflow: hidden; }
.panel-h { flex: none; display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 8px 0 12px; border-bottom: .5px solid var(--sep); font-size: 13px; font-weight: 600; }
.panel-h .sub { font-weight: 400; color: var(--ink2); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-h .acts { margin-left: auto; display: flex; gap: 2px; }
.panel-b { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 4px 12px 12px; }
.panel-f { flex: none; padding: 12px; border-top: .5px solid var(--sep); }
.sec-h { display: flex; align-items: center; gap: 6px; height: 28px; margin-top: 8px; font-size: 11px; font-weight: 600; color: var(--ink2); }
.sec-h .count { font-weight: 500; }
.sec-h .acts { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.sec-h .acts .btn-link { font-size: 11.5px; }
.sec + .sec { border-top: .5px solid var(--sep); margin-top: 8px; }

/* filas de lista alineadas por columnas: índice · ícono · nombre · valor · unidad */
.rows { display: flex; flex-direction: column; gap: 1px; margin: 0; padding: 0; list-style: none; }
.row { display: grid; grid-template-columns: 22px 18px minmax(0, 1fr) auto 36px; align-items: center; column-gap: 8px; width: 100%; min-height: 28px; padding: 2px 4px; border: 0; border-radius: 8px; background: transparent; font-size: 13px; text-align: left; }
.row:hover { background: var(--sel); }
.row[aria-selected="true"], .row.is-sel { background: var(--accent-soft); }
.row-2 { min-height: 40px; }
.row .idx { font-family: var(--mono); font-size: 11px; color: var(--ink2); text-align: center; }
.row .ic { color: var(--ink2); }
.row .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .nm small { display: block; font-size: 11.5px; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; }
.row .val { font-family: var(--mono); font-size: 12px; text-align: right; white-space: nowrap; }
.row .un { font-size: 12px; color: var(--ink2); white-space: nowrap; }
.row .grip { color: var(--ink3); cursor: grab; touch-action: none; }
.row-add { display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 4px 0 34px; border: 0; background: none; color: var(--accent-text); font-size: 13px; }
.row-add:hover { text-decoration: underline; }

/* formulario de inspector: etiquetas a la derecha (92 px) y controles */
.form { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: center; row-gap: 8px; column-gap: 10px; }
.form > .lbl, .form > label { justify-self: end; font-size: 12px; color: var(--ink2); text-align: right; }
.form > .full { grid-column: 1 / -1; }
.infobox { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--fill); font-size: 12px; color: var(--ink2); }
.infobox b { color: var(--ink); font-weight: 500; }

/* burbuja de letra (punto de interés) */
.bubble { display: inline-flex; align-items: center; justify-content: center; flex: none; min-width: 20px; height: 20px; padding: 0 3px; border-radius: 10px; background: var(--raised); box-shadow: inset 0 0 0 1px var(--ink2); font: italic 13.5px/1 var(--math); color: var(--ink); }
.bubble.ghost { box-shadow: none; outline: 1.2px dashed var(--accent); outline-offset: -1.2px; color: var(--accent-text); }
.bubble.lg { min-width: 26px; height: 26px; border-radius: 13px; font-size: 16px; }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border: 0; border-radius: 12px; background: var(--fill); font-size: 12px; color: var(--ink2); white-space: nowrap; }

/* ---------------------------------------------- MODOS: SALVIATI Y SAGREDO
   Salviati explica (ícono 'libro', --salviati); Sagredo pregunta y resuelve
   (ícono 'lapiz', --sagredo). Siempre ícono + nombre: el color acompaña,
   nunca va solo. Guía: docs/marca/modos.md.
     .chip-modo.is-salviati / .is-sagredo ... rótulo del modo (fondo *-soft
                   sobre una base opaca de --paper: el contraste no depende
                   de la superficie; sobre --desk, Sagredo claro daría 4.13:1)
     .seg-modo ... segmentado de dos opciones (<button aria-pressed>); la
                   opción que aún no existe lleva aria-disabled (ícono y nombre
                   atenuados) y .seg-modo-pronto; el activo lleva contorno --sep2
   tools/contraste.js lee estas reglas y mide cada texto en claro y oscuro. */
.chip-modo { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px 0 8px; border-radius: 12px; background: var(--fill); color: var(--ink2); font-size: 12px; font-weight: 600; line-height: 16px; white-space: nowrap; }
.chip-modo.is-salviati { background: linear-gradient(var(--salviati-soft), var(--salviati-soft)) var(--paper); color: var(--salviati); }
.chip-modo.is-sagredo { background: linear-gradient(var(--sagredo-soft), var(--sagredo-soft)) var(--paper); color: var(--sagredo); }
.seg-modo { display: inline-flex; gap: 2px; padding: 2px; border-radius: 16px; background: var(--fill); }
.seg-modo > button { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px 0 10px; border: 0; border-radius: 14px; background: transparent; color: var(--ink2); font-size: 13px; font-weight: 500; white-space: nowrap; }
.seg-modo > button:hover { color: var(--ink); }
.seg-modo > button[aria-pressed="true"] { background: var(--raised); color: var(--ink); box-shadow: 0 0 0 .5px var(--sep2), 0 1px 3px rgba(0, 0, 0, .16); }
.seg-modo > button.is-salviati[aria-pressed="true"] { color: var(--salviati); }
.seg-modo > button.is-sagredo[aria-pressed="true"] { color: var(--sagredo); }
.seg-modo > button[aria-disabled="true"] { cursor: not-allowed; }
.seg-modo > button[aria-disabled="true"]:hover { color: var(--ink2); }
/* deshabilitado: ícono y nombre atenuados, como los .btn inactivos (WCAG no
   pide contraste en controles inactivos); «Pronto» queda en --ink2 pleno   */
.seg-modo > button[aria-disabled="true"] > :not(.seg-modo-pronto) { opacity: .5; }
.seg-modo-pronto { display: inline-flex; align-items: center; height: 16px; padding: 0 5px; border-radius: 4px; box-shadow: inset 0 0 0 1px var(--sep2); font-size: 10.5px; font-weight: 600; line-height: 1; color: var(--ink2); }
.tag { display: inline-flex; align-items: center; height: 16px; padding: 0 5px; border-radius: 4px; background: var(--fill); font-size: 10.5px; font-weight: 500; color: var(--ink2); }

/* -------------------------------------------------- INSIGNIA DE FUNDADOR
   docs/fundadores.md. El emblema (VigaIcons 'fundador': el arco con su
   dovela clave) y «Fundador»: nunca solo el color. Fondo --fundador-soft
   sobre una base opaca de --paper, así el contraste no depende de dónde
   vaya (panel, lista, menú); .is-sm para un renglón de texto. La comparten
   la app y el sitio (cuenta.html). tools/contraste.js mide esta regla.    */
.chip-fundador { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px 0 6px; border-radius: 11px; background: linear-gradient(var(--fundador-soft), var(--fundador-soft)) var(--paper); color: var(--fundador); font-size: 12px; font-weight: 600; line-height: 16px; white-space: nowrap; vertical-align: middle; }
.chip-fundador.is-sm { gap: 4px; height: 18px; padding: 0 7px 0 5px; border-radius: 9px; font-size: 11px; line-height: 14px; }
.chip-fundador-d { font-weight: 500; }
/* el emblema va siempre en el tono de la insignia, también dentro de un menú (que tiñe sus íconos y los aclara al pasar) */
.chip-fundador > .ic, .menu .chip-fundador > .ic, .menu > button:hover .chip-fundador > .ic, .menu > button:focus-visible .chip-fundador > .ic { color: inherit; }
.kbd { font-family: var(--ui); font-size: 11px; color: var(--ink2); }

/* menú emergente */
.menu { position: fixed; z-index: 80; min-width: 200px; max-width: 320px; padding: 5px; border-radius: 12px; }
.menu > button, .menu > a { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 26px; padding: 0 10px; border: 0; border-radius: 6px; background: none; color: var(--ink); font-size: 13px; text-align: left; text-decoration: none; }
.menu > button:hover, .menu > a:hover { background: var(--accent-fill); color: #fff; }
.menu > button[aria-checked="true"]::after { content: "✓"; margin-left: auto; }
.menu > .menu-h { padding: 4px 10px 2px; font-size: 11px; font-weight: 600; color: var(--ink2); }
.menu > hr { border: 0; height: .5px; margin: 4px 6px; background: var(--sep2); }

/* aviso breve */
.toast { position: fixed; left: 50%; bottom: 48px; z-index: 90; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 14px; font-size: 13px; }
.toast .btn-link { color: var(--accent-text); }

/* diálogo */
.dlg { max-width: min(560px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 16px; background: var(--raised); color: var(--ink); box-shadow: var(--float), 0 0 0 .5px var(--glass-line); }
.dlg::backdrop { background: var(--backdrop); }
.dlg-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 8px; font-size: 15px; font-weight: 600; }
.dlg-b { padding: 8px 20px 16px; }
.dlg-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }

/* ------------------------------------------------------ TELÉFONO (iOS 26) */
.m-circle { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 22px; color: var(--ink); }
.m-capsule { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 16px; border: 0; border-radius: 22px; font-size: 15px; font-weight: 600; color: var(--ink); }
.m-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 50px; padding: 0 20px; border: 0; border-radius: 25px; background: var(--fill); font-size: 17px; font-weight: 600; }
.m-btn-primary { background: var(--accent-fill); color: #fff; }
.m-seg { display: flex; gap: 2px; height: 36px; padding: 2px; border-radius: 18px; background: var(--fill); }
.m-seg > button { flex: 1 1 0; min-height: 32px; padding: 0 10px; border: 0; border-radius: 16px; background: transparent; color: var(--ink2); font-size: 13px; font-weight: 500; }
.m-seg > button[aria-pressed="true"] { background: var(--raised); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .16); }
.m-switch { position: relative; flex: none; width: 51px; height: 31px; padding: 0; border: 0; border-radius: 16px; background: var(--fill2); transition: background .15s; }
.m-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 14px; background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, .25); transition: transform .15s; }
.m-switch[aria-checked="true"] { background: var(--green); }
.m-switch[aria-checked="true"]::after { transform: translateX(20px); }
.list-h { display: flex; align-items: center; gap: 8px; padding: 20px 16px 6px; font-size: 13px; font-weight: 600; color: var(--ink2); }
.list-h .acts { margin-left: auto; }
.list { margin: 0 16px; padding: 0; list-style: none; border-radius: 22px; background: var(--raised); overflow: hidden; }
.list-row { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 6px 16px; border: 0; background: var(--raised); font-size: 17px; text-align: left; color: var(--ink); }
.list-row.two { min-height: 56px; }
.list > li + li .list-row::before, .list > .list-row + .list-row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: .5px; background: var(--sep); }
.list-row .t { flex: 1 1 auto; min-width: 0; }
.list-row .t small { display: block; font-size: 13px; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .chev { color: var(--ink2); }
.list-add { color: var(--accent-text); }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex; flex-direction: column; max-height: calc(100dvh - 54px); border-radius: 34px 34px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
.sheet-grab { flex: none; width: 36px; height: 5px; margin: 6px auto 0; border-radius: 3px; background: var(--ink3); }
.sheet-h { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 12px; }
.sheet-h .title { flex: 1 1 auto; text-align: center; font-size: 17px; font-weight: 600; }
.sheet-b { flex: 1 1 auto; min-height: 0; overflow: auto; padding-bottom: 24px; }
.scrim { position: fixed; inset: 0; z-index: 45; background: var(--backdrop); }

/* --------------------------------------------------------------- FÓRMULAS
   (salida de steps.js y math.js) */
.mline, .mchain { font-family: var(--math); font-size: 18px; line-height: 1.55; color: var(--ink); }
.mline { display: block; margin: 2px 0; }
.mf, .mi, .mbar, .msys, .mmat { vertical-align: middle; }
.mn { font-variant-numeric: lining-nums; }
.mu { font-family: var(--ui); font-size: 13px; color: var(--ink2); }
/* modo Fracción: el decimal al lado del valor exacto, «25/3 ≈ 8.3333»; normal aunque el resultado vaya en negritas */
.mapx { color: var(--ink2); white-space: nowrap; font-weight: 400; }
.mf { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 .12em; line-height: 1.2; font-size: .86em; }
.mf-n { padding: 0 .2em .1em; border-bottom: 1px solid currentColor; }
.mf-d { padding: .1em .2em 0; }
.mi { display: inline-flex; align-items: center; margin-right: .06em; }
.mi-s { font-size: 1.75em; line-height: 1; font-weight: 400; }
.mi-l { display: inline-flex; flex-direction: column; justify-content: space-between; height: 2.5em; margin-left: .05em; font-size: .66em; line-height: 1; }
.mdx { white-space: nowrap; }
.mbar { display: inline-flex; align-items: center; }
.mb-body { padding: 0 .1em; }
.mb-l, .mb-r { font-size: 1.6em; line-height: 1; font-weight: 300; color: var(--ink2); }
.mb-lim { height: 2.4em; }
.mchain { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 10px; row-gap: 10px; align-items: center; margin: 6px 0; overflow-x: auto; }
.mc-l { text-align: right; white-space: nowrap; }
.mc-r { display: block; min-width: 0; }
.mc-eq { color: var(--ink2); }
.msys { display: inline-flex; align-items: stretch; gap: 10px; }
.msys-b { width: 9px; border: 1.5px solid currentColor; border-right: 0; border-radius: 9px 0 0 9px; }
.msys-r { display: flex; flex-direction: column; gap: 8px; }
.msys-r > span { display: block; }
.mmat { display: inline-flex; align-items: stretch; vertical-align: middle; }
.mm-b { width: 6px; border: 1.5px solid currentColor; }
.mm-bl { border-right: 0; }
.mm-br { border-left: 0; }
.mm-g { display: grid; grid-template-columns: repeat(var(--nc), auto); gap: 6px 16px; padding: 4px 8px; align-items: center; justify-items: center; }
.mm-det .mm-b { width: 2px; border-top: 0; border-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
