/* MiAgroPlus UI — componentes del sistema de diseño MiAgroPlus (CSS puro, sin build).
   Mobile-first: la base es móvil; @media (min-width) amplía. Requiere miagroplus-tokens.css.
   Prefijo de clases: ma-  */

/* ---------- Base ---------- */
.ma, .ma *, .ma *::before, .ma *::after { box-sizing: border-box; }
.ma { font-family: var(--font-sans); font-size: 16px; line-height: 24px; color: var(--ink); background: var(--surface); -webkit-font-smoothing: antialiased; }
.ma-num { font-variant-numeric: tabular-nums; }
.ma-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ma-icon { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ma-icon--sm { width: 20px; height: 20px; }
.ma :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

span.ma-icon { display: inline-block; }
span.ma-icon > svg { display: block; width: 100%; height: 100%; }
.ma [hidden] { display: none !important; }

/* ---------- Button ---------- */
.ma-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: var(--target-min); padding: 0 var(--space-5); border-radius: var(--radius-md); border: 1.5px solid transparent; font: 600 16px/20px var(--font-sans); text-decoration: none; cursor: pointer; transition: background-color .15s, border-color .15s, box-shadow .15s; -webkit-tap-highlight-color: transparent; }
.ma-btn--primary { background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-sm); }
.ma-btn--primary:hover { background: var(--brand-hover); }
.ma-btn--secondary { background: var(--surface-raised); color: var(--ink); border-color: var(--line-strong); }
.ma-btn--secondary:hover { background: var(--surface-sunken); }
.ma-btn--ghost { background: transparent; color: var(--brand-text); padding: 0 var(--space-3); }
.ma-btn--ghost:hover { background: var(--brand-soft); }
.ma-btn--danger { background: var(--surface-raised); color: var(--danger); border-color: var(--danger); }
.ma-btn--danger:hover { background: var(--danger-soft); }
.ma-btn--lg { min-height: var(--control-h); font-size: 17px; padding: 0 var(--space-6); }
.ma-btn--block { width: 100%; }
.ma-btn[disabled], .ma-btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; box-shadow: none; }
.ma-btn[aria-busy="true"] { cursor: wait; }
.ma-spin { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: ma-spin .8s linear infinite; }
@keyframes ma-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ma-spin { animation-duration: 2.4s; } }

/* ---------- Top bar ---------- */
.ma-topbar { position: sticky; top: 0; z-index: var(--z-topbar); display: flex; align-items: center; gap: var(--space-3); height: var(--topbar-h); padding: 0 var(--space-4); background: var(--nav); color: var(--on-nav); }
.ma-topbar__brand { display: flex; align-items: center; gap: var(--space-2); color: inherit; text-decoration: none; font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }
.ma-topbar__brand img { width: 32px; height: 32px; }
.ma-topbar__spacer { flex: 1; }
.ma-topbar__company { display: inline-flex; align-items: center; gap: var(--space-2); max-width: 55vw; min-height: 40px; padding: 0 var(--space-3); border-radius: var(--radius-full); background: var(--ink-soft); color: var(--on-nav); font-size: 14px; font-weight: 600; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ma-topbar__company small { color: var(--on-nav-muted); font-weight: 500; }
.ma-topbar__iconbtn { position: relative; display: inline-grid; place-items: center; width: var(--target-min); height: var(--target-min); border: 0; border-radius: var(--radius-md); background: transparent; color: inherit; text-decoration: none; cursor: pointer; }
.ma-topbar__iconbtn:hover { background: var(--ink-soft); }
.ma-topbar__iconbtn:last-child { margin-right: calc(var(--space-3) * -1); }
.ma-topbar__badge { position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--radius-full); background: var(--danger); color: #fff; font-size: 10px; line-height: 16px; text-align: center; font-weight: 700; }
.ma-support { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) var(--space-4); background: var(--warning-fill); color: #041818; font-size: 14px; }
.ma-support button { min-height: 40px; background: none; border: 0; font: 700 14px var(--font-sans); color: inherit; text-decoration: underline; cursor: pointer; }

/* ---------- Bottom navigation (móvil, < 1024px) ---------- */
.ma-bottomnav { position: sticky; bottom: 0; z-index: var(--z-drawer); display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; min-height: var(--bottomnav-h); padding: 0 var(--space-1) env(safe-area-inset-bottom); background: var(--surface-raised); border-top: 1px solid var(--line); box-shadow: var(--shadow-md); }
.ma-bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 64px; color: var(--ink-muted); font-size: 12px; line-height: 16px; font-weight: 600; text-decoration: none; text-align: center; }
.ma-bottomnav a[aria-current="page"] { color: var(--brand-text); }
.ma-bottomnav a[aria-current="page"] .ma-icon { background: var(--brand-soft); border-radius: var(--radius-full); width: 56px; padding: 2px 16px; box-sizing: content-box; margin: 0 -16px; }
.ma-bottomnav__main { position: relative; top: -14px; }
.ma-bottomnav__main .ma-bottomnav__fab { display: grid; place-items: center; width: 56px; height: 56px; border-radius: var(--radius-full); background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-md); border: 4px solid var(--surface-raised); box-sizing: content-box; }
.ma-bottomnav__main span:last-child { color: var(--ink); }
@media (min-width: 1024px) { .ma-bottomnav--auto { display: none; } }

/* ---------- Side navigation (escritorio, ≥ 1024px) ---------- */
.ma-sidenav { width: var(--rail-w); padding: var(--space-4) var(--space-3); background: var(--surface-raised); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.ma-sidenav__group { margin: var(--space-4) var(--space-3) var(--space-1); font-size: 12px; line-height: 16px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); }
.ma-sidenav a { display: flex; align-items: center; gap: var(--space-3); min-height: var(--target-min); padding: 0 var(--space-3); border-radius: var(--radius-md); color: var(--ink); font-size: 15px; font-weight: 500; text-decoration: none; }
.ma-sidenav a:hover { background: var(--surface-sunken); }
.ma-sidenav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); font-weight: 700; }
.ma-sidenav a[aria-current="page"] .ma-icon { color: var(--brand-strong); }
.ma-sidenav__cta { margin-bottom: var(--space-3); }
@media (max-width: 1023.98px) { .ma-sidenav--auto { display: none; } }

/* ---------- Page header ---------- */
.ma-pagehead { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-6); }
.ma-pagehead__back { display: inline-flex; align-items: center; gap: var(--space-1); align-self: flex-start; min-height: 40px; margin-left: calc(var(--space-2) * -1); padding: 0 var(--space-2); border-radius: var(--radius-sm); color: var(--brand-text); font-weight: 600; font-size: 15px; text-decoration: none; }
.ma-pagehead__back:hover { background: var(--brand-soft); }
.ma-pagehead h1 { margin: 0; font-size: 26px; line-height: 32px; font-weight: 700; letter-spacing: -0.01em; }
.ma-pagehead p { margin: 0; color: var(--ink-muted); }
.ma-pagehead__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); }
@media (min-width: 768px) {
  .ma-pagehead { display: grid; grid-template-columns: 1fr auto; column-gap: var(--space-4); align-items: end; }
  .ma-pagehead__back { grid-column: 1 / -1; }
  .ma-pagehead__actions { grid-row: 2 / span 2; grid-column: 2; margin: 0; }
}

/* ---------- Tabs ---------- */
.ma-tabs { display: flex; gap: var(--space-1); overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); margin: 0 calc(var(--space-4) * -1); padding: 0 var(--space-4); scroll-snap-type: x proximity; }
.ma-tabs::-webkit-scrollbar { display: none; }
.ma-tabs a { flex: none; display: inline-flex; align-items: center; min-height: var(--target-min); padding: 0 var(--space-4); border-bottom: 3px solid transparent; color: var(--ink-muted); font-weight: 600; font-size: 15px; text-decoration: none; white-space: nowrap; scroll-snap-align: start; }
.ma-tabs a:hover { color: var(--ink); }
.ma-tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--brand-strong); }
@media (min-width: 768px) { .ma-tabs { margin: 0; padding: 0; flex-wrap: wrap; } }

/* ---------- Card, Stat card ---------- */
.ma-card { background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: var(--space-4); }
@media (min-width: 768px) { .ma-card { padding: var(--space-6); } }
.ma-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); }
.ma-stat { display: flex; flex-direction: column; gap: var(--space-1); min-height: 120px; padding: var(--space-4); background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); color: var(--ink); text-decoration: none; }
a.ma-stat:hover { border-color: var(--line-strong); }
.ma-stat__label { display: flex; align-items: center; gap: var(--space-2); font-size: 14px; line-height: 20px; font-weight: 600; color: var(--ink-muted); }
.ma-stat__chip { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--brand-text); }
.ma-stat__chip--warn { background: var(--warning-soft); color: var(--warning); }
.ma-stat__value { margin-top: auto; font-size: 32px; line-height: 38px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.ma-stat__hint { font-size: 13px; line-height: 18px; color: var(--ink-muted); }
.ma-stat--hero { background: var(--nav); border-color: var(--nav); color: var(--on-nav); grid-column: 1 / -1; }
.ma-stat--hero .ma-stat__label, .ma-stat--hero .ma-stat__hint { color: var(--on-nav-muted); }
.ma-stat--hero .ma-stat__value { font-size: 40px; line-height: 44px; }

/* ---------- Quick actions ---------- */
.ma-quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
@media (min-width: 768px) { .ma-quick { grid-template-columns: repeat(4, 1fr); } }
.ma-quick a { display: flex; flex-direction: column; gap: var(--space-3); min-height: 112px; padding: var(--space-4); border-radius: var(--radius-lg); background: var(--surface-raised); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 600; font-size: 16px; line-height: 22px; }
.ma-quick a:hover { border-color: var(--brand-strong); background: var(--brand-soft); }
.ma-quick .ma-icon { width: 28px; height: 28px; color: var(--brand-strong); }

/* ---------- Fields ---------- */
.ma-form { display: flex; flex-direction: column; gap: var(--space-5); max-width: var(--form-max); }
.ma-field { display: flex; flex-direction: column; gap: 6px; }
.ma-field__label { font-size: 15px; line-height: 20px; font-weight: 600; color: var(--ink); }
.ma-field__opt { font-weight: 500; color: var(--ink-muted); }
.ma-field__help { font-size: 14px; line-height: 20px; color: var(--ink-muted); margin: 0; }
.ma-input, .ma-select, .ma-textarea { width: 100%; min-height: var(--control-h); padding: 0 var(--space-4); border: 1.5px solid var(--line-strong); border-radius: var(--radius-md); background: var(--surface-raised); color: var(--ink); font: 400 16px/24px var(--font-sans); transition: border-color .15s, box-shadow .15s; }
.ma-textarea { padding: var(--space-3) var(--space-4); min-height: 112px; resize: vertical; }
.ma-select { appearance: none; padding-right: 44px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2357534e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; background-size: 20px; }
.ma-input::placeholder, .ma-textarea::placeholder { color: var(--ink-subtle); }
.ma-input:focus, .ma-select:focus, .ma-textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--brand-soft), 0 0 0 1px var(--focus) inset; }
.ma-input[readonly] { background: var(--surface-sunken); }
.ma-affix { position: relative; display: flex; align-items: stretch; }
.ma-affix .ma-input { padding-right: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.ma-affix__unit { position: absolute; right: 0; top: 0; bottom: 0; display: grid; place-items: center; min-width: 56px; padding: 0 var(--space-3); color: var(--ink-muted); font-weight: 600; border-left: 1px solid var(--line); pointer-events: none; }
.ma-field--error .ma-input, .ma-field--error .ma-select, .ma-field--error .ma-textarea { border-color: var(--danger); }
.ma-field__error { display: flex; gap: 6px; align-items: flex-start; margin: 0; font-size: 14px; line-height: 20px; font-weight: 600; color: var(--danger); }
.ma-field__error::before { content: "!"; display: inline-grid; place-items: center; flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%; background: var(--danger); color: var(--surface-raised); font-size: 12px; font-weight: 800; }
.ma-check { display: flex; align-items: center; gap: var(--space-3); min-height: var(--target-min); cursor: pointer; font-size: 16px; }
.ma-check input { width: 24px; height: 24px; accent-color: var(--brand-strong); margin: 0; }
.ma-grid-2 { display: grid; gap: var(--space-5); }
@media (min-width: 640px) { .ma-grid-2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Choice cards (radio grande) ---------- */
.ma-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); border: 0; padding: 0; margin: 0; }
.ma-choices legend { font-size: 15px; font-weight: 600; margin-bottom: var(--space-2); padding: 0; }
.ma-choice { position: relative; display: flex; align-items: center; gap: var(--space-3); min-height: 64px; padding: var(--space-3) var(--space-4); border: 1.5px solid var(--line-strong); border-radius: var(--radius-md); background: var(--surface-raised); cursor: pointer; font-weight: 600; }
.ma-choice input { position: absolute; opacity: 0; }
.ma-choice .ma-icon { color: var(--ink-muted); }
.ma-choice::after { content: ""; margin-left: auto; width: 22px; height: 22px; flex: none; border-radius: 50%; border: 2px solid var(--line-strong); }
.ma-choice:has(input:checked) { border-color: var(--brand-strong); background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand-strong) inset; }
.ma-choice:has(input:checked) .ma-icon { color: var(--brand-strong); }
.ma-choice:has(input:checked)::after { border: 7px solid var(--brand-strong); background: var(--surface-raised); }
.ma-choice:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Stepper (formularios largos por pasos) ---------- */
.ma-steps { display: flex; flex-direction: column; gap: var(--space-2); }
.ma-steps__text { display: flex; flex-wrap: wrap; gap: 2px var(--space-3); justify-content: space-between; font-size: 14px; line-height: 20px; color: var(--ink-muted); font-weight: 600; }
.ma-steps__text strong { color: var(--ink); }
.ma-steps__bar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; }
.ma-steps__bar span { height: 6px; border-radius: var(--radius-full); background: var(--line); }
.ma-steps__bar span.is-done, .ma-steps__bar span.is-current { background: var(--brand-strong); }

/* ---------- Sticky actions (pie de formulario) ---------- */
.ma-actions { position: sticky; bottom: 0; display: flex; flex-direction: column-reverse; gap: var(--space-2); padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom)); margin: 0 calc(var(--space-4) * -1); background: var(--surface-raised); border-top: 1px solid var(--line); }
@media (min-width: 640px) { .ma-actions { position: static; flex-direction: row-reverse; justify-content: flex-start; margin: 0; padding: var(--space-4) 0 0; background: none; } }

/* ---------- Search & filters ---------- */
.ma-search { position: relative; }
.ma-search .ma-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-muted); pointer-events: none; }
.ma-search .ma-input { padding-left: 48px; }
.ma-chips { display: flex; gap: var(--space-2); overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.ma-chip { flex: none; display: inline-flex; align-items: center; gap: var(--space-1); min-height: 40px; padding: 0 var(--space-4); border: 1.5px solid var(--line-strong); border-radius: var(--radius-full); background: var(--surface-raised); color: var(--ink); font: 600 14px var(--font-sans); cursor: pointer; white-space: nowrap; }
.ma-chip[aria-pressed="true"] { background: var(--nav); border-color: var(--nav); color: var(--on-nav); }

/* ---------- Record list (móvil) ---------- */
.ma-records { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.ma-record { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--space-3); padding: var(--space-4); background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); color: var(--ink); text-decoration: none; }
a.ma-record:hover { border-color: var(--line-strong); }
.ma-record__title { font-size: 17px; line-height: 24px; font-weight: 600; }
.ma-record__amount { font-size: 17px; line-height: 24px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.ma-record__meta { font-size: 14px; line-height: 20px; color: var(--ink-muted); }
.ma-record__side { text-align: right; }

/* ---------- Data table (escritorio; en móvil se apila) ---------- */
.ma-tablewrap { background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.ma-table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 22px; }
.ma-table th { background: var(--surface-sunken); color: var(--ink-muted); font-size: 13px; line-height: 18px; font-weight: 700; text-align: left; padding: var(--space-3) var(--space-4); }
.ma-table td { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--line); vertical-align: middle; }
.ma-table .is-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ma-table tbody tr:hover { background: var(--surface-sunken); }
.ma-table__actions { text-align: right; white-space: nowrap; }
@media (max-width: 767.98px) {
  .ma-table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .ma-table--stack tr { display: block; padding: var(--space-3) var(--space-4); border-top: 1px solid var(--line); }
  .ma-table--stack tr:first-child { border-top: 0; }
  .ma-table--stack td { display: flex; justify-content: space-between; gap: var(--space-4); padding: 4px 0; border: 0; }
  .ma-table--stack td::before { content: attr(data-label); color: var(--ink-muted); font-weight: 600; font-size: 14px; }
  .ma-table--stack .is-num { text-align: right; }
  .ma-table--stack .ma-table__actions { justify-content: flex-end; padding-top: var(--space-2); }
  .ma-table--stack .ma-table__actions::before { content: none; }
}

/* ---------- Alert ---------- */
.ma-alert { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--line); font-size: 15px; line-height: 22px; color: var(--ink); background: var(--info-soft); }
.ma-alert strong { display: block; }
.ma-alert .ma-icon { margin-top: -1px; }
.ma-alert--success { background: var(--brand-soft); border-color: var(--brand-strong); }
.ma-alert--success .ma-icon { color: var(--brand-strong); }
.ma-alert--warning { background: var(--warning-soft); border-color: var(--warning); }
.ma-alert--warning .ma-icon { color: var(--warning); }
.ma-alert--error { background: var(--danger-soft); border-color: var(--danger); }
.ma-alert--error .ma-icon { color: var(--danger); }

/* ---------- Badge ---------- */
.ma-badge { display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 0 10px; border-radius: var(--radius-full); font-size: 13px; line-height: 18px; font-weight: 700; background: var(--surface-sunken); color: var(--ink-muted); white-space: nowrap; }
.ma-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.ma-badge--ok { background: var(--brand-soft); color: var(--brand-text); }
.ma-badge--pending { background: var(--warning-soft); color: var(--warning); }
.ma-badge--error { background: var(--danger-soft); color: var(--danger); }
.ma-badge--plain::before { content: none; }

/* ---------- Empty state ---------- */
.ma-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-3); padding: var(--space-12) var(--space-6); background: var(--surface-raised); border: 1.5px dashed var(--line-strong); border-radius: var(--radius-lg); }
.ma-empty__icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: var(--radius-full); background: var(--mint); color: var(--brand-text); }
.ma-empty__icon .ma-icon { width: 32px; height: 32px; }
.ma-empty h2 { margin: 0; font-size: 20px; line-height: 28px; font-weight: 700; }
.ma-empty p { margin: 0; max-width: 36ch; color: var(--ink-muted); font-size: 16px; }

/* ---------- Confirm sheet (hoja inferior en móvil, modal centrado ≥640px) ---------- */
.ma-sheet-backdrop { position: fixed; inset: 0; z-index: var(--z-modal); display: flex; align-items: flex-end; justify-content: center; background: var(--overlay); }
.ma-sheet-backdrop--inline { position: relative; inset: auto; min-height: 100%; }
.ma-sheet { width: 100%; max-height: 90vh; overflow-y: auto; background: var(--surface-raised); border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--shadow-lg); padding: var(--space-2) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom)); }
.ma-sheet__grip { width: 40px; height: 4px; margin: 0 auto var(--space-4); border-radius: var(--radius-full); background: var(--line-strong); }
.ma-sheet h2 { margin: 0 0 var(--space-1); font-size: 20px; line-height: 28px; font-weight: 700; }
.ma-sheet__lead { margin: 0 0 var(--space-4); color: var(--ink-muted); font-size: 15px; }
.ma-summary { margin: 0 0 var(--space-4); padding: 0; }
.ma-summary div { display: flex; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) 0; border-top: 1px solid var(--line); font-size: 15px; }
.ma-summary dt { color: var(--ink-muted); }
.ma-summary dd { margin: 0; font-weight: 600; text-align: right; }
.ma-summary .is-total { font-size: 18px; }
.ma-summary .is-total dd { font-weight: 800; font-variant-numeric: tabular-nums; }
.ma-sheet__actions { display: flex; flex-direction: column-reverse; gap: var(--space-2); }
@media (min-width: 640px) {
  .ma-sheet-backdrop { align-items: center; padding: var(--space-6); }
  .ma-sheet { max-width: 520px; border-radius: var(--radius-lg); padding: var(--space-6); }
  .ma-sheet__grip { display: none; }
  .ma-sheet__actions { flex-direction: row-reverse; justify-content: flex-start; }
}

/* =====================================================================
   Estructura de la aplicación (layout de templates/layouts/base.html)
   ===================================================================== */
html { -webkit-text-size-adjust: 100%; }
body.ma { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
.ma [x-cloak] { display: none !important; }
.ma-shell { flex: 1; display: flex; width: 100%; }
.ma-main { flex: 1; min-width: 0; width: 100%; max-width: calc(var(--content-max) + 2 * var(--space-10)); margin: 0 auto; padding: var(--space-4) var(--space-4) calc(var(--bottomnav-h) + var(--space-8)); }
@media (min-width: 768px) { .ma-main { padding: var(--space-6) var(--space-6) calc(var(--bottomnav-h) + var(--space-8)); } }
@media (min-width: 1024px) { .ma-main { padding: var(--space-8) var(--space-10) var(--space-10); } }
.ma-main--narrow { max-width: 480px; padding-top: var(--space-8); }
.ma-app--form .ma-main { padding-bottom: var(--space-4); }

.ma-sidenav--auto { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; flex: none; }
.ma-bottomnav--auto { position: fixed; left: 0; right: 0; bottom: 0; }
@media (max-width: 1023.98px) { .ma-app--form .ma-bottomnav--auto { display: none; } }
.ma-bottomnav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 64px; padding: 0; border: 0; background: none; color: var(--ink-muted); font: 600 12px/16px var(--font-sans); cursor: pointer; }
.ma-bottomnav .ma-bottomnav__main { top: -14px; color: var(--ink); }

.ma-topbar__brand img { border-radius: 7px; }
.ma-topbar__link { color: var(--on-nav); font-weight: 600; font-size: 15px; text-decoration: none; padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); }
.ma-topbar__link:hover { background: var(--ink-soft); }
.ma-topbar__link--cta { background: var(--brand); color: var(--on-brand); }
.ma-topbar__link--cta:hover { background: var(--brand-hover); }
@media (max-width: 479.98px) { .ma-topbar__brand span { display: none; } }

.ma-menu { position: relative; }
.ma-menu__panel { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; padding: var(--space-2); background: var(--surface-raised); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); z-index: var(--z-modal); }
.ma-menu__panel a, .ma-menu__panel button { display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: var(--target-min); padding: 0 var(--space-3); border: 0; border-radius: var(--radius-md); background: none; color: var(--ink); font: 500 15px var(--font-sans); text-align: left; text-decoration: none; cursor: pointer; }
.ma-menu__panel a:hover, .ma-menu__panel button:hover { background: var(--surface-sunken); }
.ma-menu__meta { padding: var(--space-2) var(--space-3); font-size: 13px; line-height: 18px; color: var(--ink-muted); border-bottom: 1px solid var(--line); margin-bottom: var(--space-1); word-break: break-all; }

.ma-footer { padding: var(--space-4); text-align: center; font-size: 13px; color: var(--ink-muted); }
@media (max-width: 1023.98px) { .ma-app--auth .ma-footer { padding-bottom: calc(var(--bottomnav-h) + var(--space-4)); } }

/* Alertas de mensajes */
.ma-messages { list-style: none; margin: 0 0 var(--space-5); padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }

/* Pestañas: submenú desplegable de un item agrupador */
.ma-tabs { margin-bottom: var(--space-6); }
.ma-tabs button { flex: none; display: inline-flex; align-items: center; gap: var(--space-1); min-height: var(--target-min); padding: 0 var(--space-4); border: 0; border-bottom: 3px solid transparent; background: none; color: var(--ink-muted); font: 600 15px var(--font-sans); white-space: nowrap; cursor: pointer; }
.ma-tabs button[aria-current="true"] { color: var(--ink); border-bottom-color: var(--brand-strong); }
.ma-tabs .ma-menu { position: static; }
.ma-tabs .ma-menu__panel { position: fixed; left: var(--space-4); right: var(--space-4); top: calc(var(--topbar-h) + 52px); }
@media (min-width: 768px) {
  .ma-tabs { overflow: visible; }
  .ma-tabs .ma-menu { position: relative; }
  .ma-tabs .ma-menu__panel { position: absolute; left: 0; right: auto; top: calc(100% + 6px); }
}
.ma-tabs .ma-menu__panel a { border-bottom: 0; min-height: var(--target-min); font-weight: 500; color: var(--ink); }
.ma-tabs .ma-menu__panel a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); font-weight: 700; }

/* Hojas (Registrar / Más) */
.ma-sheet-backdrop.hidden { display: none; }
.ma-sheet__group { margin: var(--space-3) 0 var(--space-1); font-size: 12px; line-height: 16px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); }
.ma-sheet__group:first-of-type { margin-top: 0; }
.ma-sheet__list { list-style: none; margin: 0 0 var(--space-2); padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.ma-sheet__list a { display: flex; align-items: center; gap: var(--space-3); min-height: 56px; padding: 0 var(--space-3); border-radius: var(--radius-md); color: var(--ink); font-size: 16px; font-weight: 600; text-decoration: none; }
.ma-sheet__list a:hover { background: var(--surface-sunken); }
.ma-sheet__list .ma-icon { color: var(--brand-strong); }
.ma-sheet__list small { display: block; font-size: 13px; line-height: 18px; font-weight: 500; color: var(--ink-muted); }
.ma-sheet__close { display: flex; justify-content: flex-end; }

/* Formularios: tarjeta, campos deshabilitados/calculados, select múltiple */
.ma-formcard { background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: var(--space-4); max-width: var(--form-max); }
@media (min-width: 768px) { .ma-formcard { padding: var(--space-6) var(--space-8); } }
.ma-formcard--wide { max-width: none; }
.ma-form-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-5); }
@media (min-width: 640px) { .ma-formcard--wide .ma-form-grid { grid-template-columns: 1fr 1fr; column-gap: var(--space-5); } .ma-form-grid .ma-field--full { grid-column: 1 / -1; } }
.ma-input:disabled, .ma-select:disabled, .ma-textarea:disabled { background: var(--surface-sunken); color: var(--ink-muted); border-style: dashed; cursor: not-allowed; opacity: 1; }
.ma-select[multiple] { height: auto; min-height: 140px; padding: var(--space-2); background-image: none; }
.ma-select[multiple] option { padding: 6px var(--space-2); border-radius: 6px; }
.ma-input[type="file"] { padding: var(--space-3); min-height: auto; }
.ma-input[type="date"], .ma-input[type="datetime-local"], .ma-input[type="time"] { appearance: none; -webkit-appearance: none; }
.ma-field__req { color: var(--danger); }
.ma-field .ma-check { min-height: var(--target-min); font-weight: 600; font-size: 15px; }
.ma-checkbox { width: 24px; height: 24px; accent-color: var(--brand-strong); margin: 0; flex: none; }
.ma-field ul, .ma-field div[id^="id_"] > div { list-style: none; padding: 0; margin: 0; }
.ma-field input[type="radio"] { width: 22px; height: 22px; accent-color: var(--brand-strong); vertical-align: middle; margin: 0 var(--space-2) 0 0; }
.ma-field div[id^="id_"] > div > label { display: flex; align-items: center; min-height: var(--target-min); font-size: 16px; cursor: pointer; }

/* Secciones de formulario (sin pasos) y pasos */
.ma-formsection + .ma-formsection { margin-top: var(--space-8); }
.ma-formsection__title { margin: 0 0 var(--space-4); padding-bottom: var(--space-2); border-bottom: 1px solid var(--line); font-size: 17px; line-height: 24px; font-weight: 700; color: var(--ink); }
form[data-pasos].is-stepped > section[data-paso] > h2,
form[data-pasos].is-stepped > section[data-paso] > .ma-formsection__title { display: none; }
form[data-pasos].is-stepped > section[data-paso] { margin-top: 0; }
form[data-pasos].is-stepped > section[data-paso][hidden] { display: none; }
.ma-steps { margin-bottom: 0; }
.ma-steps__title { margin: var(--space-2) 0 0; font-size: 20px; line-height: 28px; font-weight: 700; }
.ma-actions { margin-top: var(--space-6); }
@media (max-width: 639.98px) { .ma-actions { margin-left: calc(var(--space-4) * -1); margin-right: calc(var(--space-4) * -1); margin-bottom: calc(var(--space-4) * -1); border-radius: 0 0 var(--radius-lg) var(--radius-lg); } }
.ma-actions .ma-btn { min-height: var(--control-h); }
@media (max-width: 639.98px) { .ma-actions .ma-btn { width: 100%; } }

/* Listados: tarjetas en móvil, tabla desde 768px */
.ma-listbar { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-5); }
.ma-listbar form { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.ma-listbar .ma-search { flex: 1 1 260px; }
.ma-listbar .ma-field { flex: 0 1 240px; }
@media (min-width: 768px) { .ma-listbar { flex-direction: row; align-items: flex-end; justify-content: space-between; } }
.ma-only-mobile { display: block; }
.ma-only-desktop { display: none; }
@media (min-width: 768px) { .ma-only-mobile { display: none; } .ma-only-desktop { display: block; } }
.ma-record--static { display: block; }
.ma-record__head { display: flex; justify-content: space-between; gap: var(--space-3); }
.ma-record__data { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2) var(--space-4); margin: var(--space-3) 0 0; }
.ma-record__data div { min-width: 0; }
.ma-record__data dt { font-size: 13px; line-height: 18px; color: var(--ink-muted); }
.ma-record__data dd { margin: 0; font-size: 15px; line-height: 22px; font-weight: 500; overflow-wrap: anywhere; }
.ma-record__data .is-num { font-variant-numeric: tabular-nums; }
.ma-record__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--line); }
.ma-record__actions .ma-btn { min-height: 44px; flex: 1 1 auto; }
.ma-tablewrap { overflow-x: auto; }
.ma-table__actions .ma-btn { min-height: 40px; padding: 0 var(--space-3); }
.ma-table__actions .ma-btn + .ma-btn { margin-left: var(--space-1); }
.ma-btn--danger-ghost { background: transparent; color: var(--danger); border-color: transparent; }
.ma-btn--danger-ghost:hover { background: var(--danger-soft); }
.ma-pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-5); font-size: 15px; color: var(--ink-muted); }

/* Detalle */
.ma-detail { display: grid; grid-template-columns: 1fr; gap: var(--space-4) var(--space-6); margin: 0; }
@media (min-width: 640px) { .ma-detail { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1280px) { .ma-detail { grid-template-columns: 1fr 1fr 1fr; } }
.ma-detail dt { font-size: 14px; line-height: 20px; color: var(--ink-muted); }
.ma-detail dd { margin: 2px 0 0; font-size: 16px; line-height: 24px; font-weight: 600; white-space: pre-line; overflow-wrap: anywhere; }
.ma-cardactions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-6); padding-top: var(--space-4); border-top: 1px solid var(--line); }
@media (max-width: 639.98px) { .ma-cardactions .ma-btn { flex: 1 1 100%; } }

/* Inicio */
.ma-home { display: flex; flex-direction: column; gap: var(--space-8); }
.ma-home h1 { margin: 0; font-size: 26px; line-height: 32px; font-weight: 700; letter-spacing: -0.01em; }
@media (min-width: 768px) { .ma-home h1 { font-size: 32px; line-height: 38px; font-weight: 800; letter-spacing: -0.02em; } }
.ma-home__lead { margin: var(--space-1) 0 0; color: var(--ink-muted); }
.ma-sectiontitle { margin: 0 0 var(--space-3); font-size: 20px; line-height: 28px; font-weight: 700; }

/* Auth (login/registro) — tarjeta centrada */
.ma-app--guest .ma-main > .bg-white { border-radius: var(--radius-lg); }

/* Vista de impresión (roadmap de octubre, Fase D3 — "reimpresión de
   cuadros comparativos" sobre el Panel de Costo Consolidado, 2026-10-04):
   `.ma-no-print` oculta cualquier elemento de interacción (botones,
   nav) al imprimir; sin depender de ninguna librería de PDF, usa el
   diálogo de impresión nativo del navegador (`window.print()`). */
@media print {
  .ma-topbar, .ma-sidenav, .ma-sidenav--auto, .ma-tabs, .ma-messages,
  .ma-support, .ma-bottomnav, .ma-bottomnav--auto, .ma-no-print {
    display: none !important;
  }
  .ma-shell, .ma-main { margin: 0; padding: 0; max-width: none; }
  body { background: #fff; }
}
