/* NODO Metro — sistema de diseño mobile-first (Metro reinterpretado)
   Reglas: grilla de 8px, 3 tamaños de texto, tap target 44px+, 1 acento por módulo. */

:root {
  /* Tokens */
  --m-u: 8px;                       /* unidad base */
  --m-tile: 96px;                   /* tile 1x1 (se recalcula en JS/CSS según ancho) */
  --m-gap: 8px;
  --m-font: "Segoe UI", "Segoe UI Variable", Inter, system-ui, sans-serif;
  --m-fs-title: 32px;               /* título / número grande, weight 300 */
  --m-fs-body: 16px;
  --m-fs-micro: 12px;
  --m-ease: cubic-bezier(.1, .9, .2, 1);
  --m-dur: 180ms;                   /* nunca >200ms */

  /* Acento por módulo (cambiar con data-accent en cualquier contenedor) */
  --m-accent: #2c64a8;
  --m-accent-ink: #fff;

  /* Tema oscuro (default) */
  --m-bg: #101114;
  --m-surface: #1b1d22;
  --m-surface-2: #262930;
  --m-ink: #f2f3f5;
  --m-muted: #9aa0ab;
  --m-line: #343842;
  --m-ok: #3fae56;
  --m-warn: #e0b000;
  --m-danger: #e04848;
}
[data-theme="light"] {
  --m-bg: #f3f4f6;
  --m-surface: #ffffff;
  --m-surface-2: #e8eaee;
  --m-ink: #1e1e1e;
  --m-muted: #5f6672;
  --m-line: #c9ced6;
}
[data-accent="azul"]     { --m-accent: #2c64a8; }
[data-accent="cian"]     { --m-accent: #00a3c4; }
[data-accent="verde"]    { --m-accent: #2a8a3a; }
[data-accent="lima"]     { --m-accent: #8cbf26; --m-accent-ink: #14210a; }
[data-accent="naranja"]  { --m-accent: #e8710a; }
[data-accent="rojo"]     { --m-accent: #c4262e; }
[data-accent="magenta"]  { --m-accent: #b4009e; }
[data-accent="violeta"]  { --m-accent: #6a4fc4; }
[data-accent="amarillo"] { --m-accent: #ffe79a; --m-accent-ink: #1e1e1e; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--m-bg); color: var(--m-ink);
  font: 300 var(--m-fs-body)/1.4 var(--m-font);
  overscroll-behavior: none;
}

/* ---------- Tipografía ---------- */
.m-title { font-size: var(--m-fs-title); font-weight: 300; line-height: 1.1; margin: 0; letter-spacing: -.5px; }
.m-body  { font-size: var(--m-fs-body); }
.m-micro { font-size: var(--m-fs-micro); color: var(--m-muted); text-transform: lowercase; }
.m-num   { font-variant-numeric: tabular-nums; font-family: Consolas, monospace; }

/* ---------- App shell ---------- */
.m-app { display: flex; flex-direction: column; height: 100dvh; max-width: 480px; margin: 0 auto; position: relative; overflow: hidden; }
.m-header { padding: 24px 16px 8px; }
.m-header .m-micro { display: block; margin-bottom: 4px; }
.m-view { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px 16px 88px; -webkit-overflow-scrolling: touch; }
.m-page { animation: m-in var(--m-dur) var(--m-ease); }
@keyframes m-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

/* ---------- Tiles ---------- */
.m-tiles {
  display: grid; gap: var(--m-gap);
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: calc((min(100vw, 480px) - 32px - 3 * var(--m-gap)) / 4);
  grid-auto-flow: dense;
}
.m-tile {
  position: relative; overflow: hidden; border: 0; padding: 8px; text-align: left;
  background: var(--m-accent); color: var(--m-accent-ink);
  font: inherit; cursor: pointer; display: flex; flex-direction: column; justify-content: space-between;
  transition: transform var(--m-dur) var(--m-ease);
  grid-column: span 2; grid-row: span 1;
}
.m-tile.s1 { grid-column: span 1; }              /* 1x1 */
.m-tile.w2 { grid-column: span 2; }              /* 2x1 */
.m-tile.w4 { grid-column: span 4; }              /* 4x1 */
.m-tile.h2 { grid-row: span 2; }                 /* 2x2 si se combina con w2 */
.m-tile:active { transform: perspective(400px) scale(.96); }   /* "tilt" Metro */
.m-ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; stroke-linejoin: miter; vertical-align: middle; }
.m-tile__icon .m-ico { width: 32px; height: 32px; }
.m-tile__icon { line-height: 1; }
.m-tile__label { font-size: var(--m-fs-micro); }
.m-tile__badge { position: absolute; top: 8px; right: 8px; font-size: var(--m-fs-body); font-weight: 600; }
.m-tile__value { font-size: var(--m-fs-title); font-weight: 300; line-height: 1; }
.m-tile.neutral { background: var(--m-surface-2); color: var(--m-ink); }
/* Live tile: dos caras que se voltean */
.m-tile.live > .face { position: absolute; inset: 0; padding: 8px; display: flex; flex-direction: column; justify-content: space-between;
  transition: transform 400ms var(--m-ease); backface-visibility: hidden; }
.m-tile.live > .face.back { background: var(--m-surface-2); color: var(--m-ink); transform: translateY(100%); }
.m-tile.live.flipped > .face.front { transform: translateY(-100%); }
.m-tile.live.flipped > .face.back  { transform: none; }

/* ---------- Pivot (pestañas tipográficas) ---------- */
.m-pivot { display: flex; gap: 16px; overflow-x: auto; padding: 0 16px; scrollbar-width: none; }
.m-pivot::-webkit-scrollbar { display: none; }
.m-pivot button {
  background: none; border: 0; padding: 8px 0; min-height: 44px; font: inherit;
  font-size: var(--m-fs-title); font-weight: 300; color: var(--m-muted); cursor: pointer; white-space: nowrap;
  transition: color var(--m-dur);
}
.m-pivot button[aria-selected="true"] { color: var(--m-ink); }

/* ---------- Lista con swipe ---------- */
.m-list { list-style: none; margin: 0; padding: 0; }
.m-item { position: relative; overflow: hidden; border-bottom: 1px solid var(--m-line); touch-action: pan-y; }
.m-item__actions { position: absolute; inset: 0 0 0 auto; display: flex; }
.m-item__actions button { border: 0; width: 80px; color: #fff; font: inherit; font-size: var(--m-fs-micro); cursor: pointer; }
.m-item__actions .edit { background: var(--m-accent); color: var(--m-accent-ink); }
.m-item__actions .del  { background: var(--m-danger); }
.m-item__row { position: relative; background: var(--m-bg); min-height: 64px; padding: 8px 0; display: flex; align-items: center; gap: 16px;
  transition: transform var(--m-dur) var(--m-ease); }
.m-item__main { flex: 1; min-width: 0; }
.m-item__title { font-size: var(--m-fs-body); font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-item__amount { text-align: right; font-size: var(--m-fs-body); }

/* ---------- Campos ---------- */
.m-field { display: block; margin-bottom: 16px; }
.m-field > span { display: block; font-size: var(--m-fs-micro); color: var(--m-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .5px; }
.m-field > span.req::after { content: " *"; color: var(--m-accent); }
.m-input {
  width: 100%; min-height: 48px; padding: 8px 16px; font: 300 var(--m-fs-body) var(--m-font);
  color: var(--m-ink); background: transparent; border: 2px solid var(--m-line); border-radius: 0; outline: 0;
}
.m-input:focus { border-color: var(--m-accent); background: var(--m-surface); }
.m-field.error .m-input { border-color: var(--m-danger); }
.m-field .m-err { color: var(--m-danger); font-size: var(--m-fs-micro); margin-top: 4px; }
.m-field .m-err::before { content: "!"; display: inline-grid; place-items: center; width: 14px; height: 14px; margin-right: 6px; border: 1.5px solid var(--m-danger); border-radius: 50%; font-size: 10px; font-weight: 700; }

/* Toggle plano */
.m-switch { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.m-switch input { appearance: none; width: 48px; height: 24px; border: 2px solid var(--m-ink); position: relative; margin: 0; cursor: pointer; }
.m-switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; background: var(--m-ink); transition: transform var(--m-dur) var(--m-ease); }
.m-switch input:checked { background: var(--m-accent); border-color: var(--m-accent); }
.m-switch input:checked::after { transform: translateX(24px); background: var(--m-accent-ink); }

/* ---------- Botones ---------- */
.m-btn { min-height: 48px; padding: 8px 24px; font: 400 var(--m-fs-body) var(--m-font); cursor: pointer; border: 2px solid var(--m-ink);
  background: transparent; color: var(--m-ink); border-radius: 0; transition: transform var(--m-dur) var(--m-ease); }
.m-btn:active { transform: scale(.96); }
.m-btn.primary { background: var(--m-accent); border-color: var(--m-accent); color: var(--m-accent-ink); }   /* 1 por pantalla */
.m-btn.danger  { border-color: var(--m-danger); color: var(--m-danger); }
.m-btn.block { width: 100%; }

/* ---------- App bar inferior ---------- */
.m-appbar { position: absolute; left: 0; right: 0; bottom: 0; height: 64px; background: var(--m-surface); border-top: 1px solid var(--m-line);
  display: flex; justify-content: space-around; align-items: center; }
.m-appbar button { background: none; border: 0; color: var(--m-ink); min-width: 64px; min-height: 48px; font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.m-appbar .ico { width: 40px; height: 40px; border: 2px solid var(--m-ink); border-radius: 50%; display: grid; place-items: center; }
.m-appbar .ico .m-ico { width: 20px; height: 20px; }
.m-appbar span.lbl { font-size: var(--m-fs-micro); color: var(--m-muted); }

/* ---------- KPI y estado ---------- */
.m-kpi { border-left: 4px solid var(--m-accent); padding: 8px 16px; background: var(--m-surface); }
.m-kpi.ok { border-color: var(--m-ok); } .m-kpi.warn { border-color: var(--m-warn); } .m-kpi.bad { border-color: var(--m-danger); }
.m-kpi .delta { display: flex; align-items: center; gap: 4px; }
.m-kpi .delta .m-ico { width: 14px; height: 14px; }
.m-kpi .delta.up { color: var(--m-ok); } .m-kpi .delta.down { color: var(--m-danger); }

/* ---------- Toast y diálogo ---------- */
.m-toast { position: absolute; left: 16px; right: 16px; bottom: 80px; padding: 16px; background: var(--m-ink); color: var(--m-bg);
  animation: m-up var(--m-dur) var(--m-ease); z-index: 10; }
@keyframes m-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.m-dialog-bg { position: absolute; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 20; padding: 24px; }
.m-dialog { background: var(--m-surface); padding: 24px; width: 100%; }
.m-dialog .m-actions { display: flex; gap: 8px; margin-top: 24px; }
.m-dialog .m-actions .m-btn { flex: 1; }

/* ---------- Rejilla de datos (estilo DevExpress, compacta) ---------- */
.m-grid { width: 100%; border-collapse: collapse; font-size: var(--m-fs-micro); }
.m-grid th { text-align: left; padding: 8px; background: var(--m-surface-2); border-bottom: 2px solid var(--m-accent); font-weight: 600; position: sticky; top: 0; }
.m-grid td { padding: 8px; border-bottom: 1px solid var(--m-line); min-height: 44px; }
.m-grid .n { text-align: right; font-family: Consolas, monospace; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
