/* ============================================================================
   Monai · components.css
   Cada bloque = 1 componente standalone de Angular. Ver ANGULAR.md §4.
   ========================================================================= */

/* --- Card ------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  min-width: 0;
}
.card.flush { padding: 0; gap: 0; overflow: hidden; }
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
}
.card-head .sub { font-size: var(--t-sm); color: var(--muted); margin-top: 2px; }
.card-pad { padding: var(--s-5); }

.grid { display: grid; gap: var(--s-4); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .grid.cols-3, .grid.side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 620px) {
  .grid.cols-2, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
}

/* --- Botones (M3 filled / tonal / outlined / text / icon) ------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 44px;
  padding: 0 var(--s-5);
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 620;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease-std),
              border-color var(--dur-1) var(--ease-std),
              transform var(--dur-1) var(--ease-std);
}
.btn:active { transform: scale(0.97); }
.btn-filled { background: var(--primary); color: var(--on-primary); }
.btn-filled:hover { background: color-mix(in oklab, var(--primary) 88%, var(--fg)); }
.btn-tonal { background: var(--primary-container); color: var(--on-primary-container); }
.btn-tonal:hover { background: color-mix(in oklab, var(--primary-container) 86%, var(--primary)); }
.btn-outlined { border-color: var(--border-strong); }
.btn-outlined:hover { background: var(--surface-2); }
.btn-text { padding: 0 var(--s-3); color: var(--primary); }
.btn-text:hover { background: var(--surface-2); }
.btn-danger { background: var(--neg-soft); color: var(--neg); }
.btn-sm { min-height: 36px; padding: 0 var(--s-4); font-size: 13.5px; }

.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 44px; height: 44px;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease-std), color var(--dur-1) var(--ease-std);
}
.btn-icon:hover { background: var(--surface-2); color: var(--fg); }
.btn-icon[aria-pressed='true'] { background: var(--primary-container); color: var(--on-primary-container); }

.fab {
  position: fixed;
  right: clamp(16px, 3vw, 32px);
  bottom: clamp(16px, 3vw, 32px);
  z-index: 35;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 56px;
  padding: 0 var(--s-5);
  border: 0;
  border-radius: var(--r-lg);
  background: var(--primary);
  color: var(--on-primary);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 650;
  box-shadow: var(--shadow-2);
  cursor: pointer;
}
@media (max-width: 1023px) { .fab { bottom: calc(var(--bottomnav-h) + 16px); } }

/* --- Chips / segmented / pills --------------------------------------------- */
.chiprow { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 var(--s-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg);
  font-size: 13.5px;
  font-weight: 560;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease-std);
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed='true'] {
  background: var(--primary-container);
  border-color: transparent;
  color: var(--on-primary-container);
  font-weight: 660;
}

.seg {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
}
.seg button {
  min-height: 38px;
  padding: 0 var(--s-4);
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 620;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease-std), color var(--dur-1) var(--ease-std);
}
.seg button[aria-selected='true'] {
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-1);
}

/* En pantallas táctiles ningún control interactivo baja de 44px de alto.
   En puntero fino se permite la densidad de 36-38px. */
@media (pointer: coarse) {
  .chip, .btn-sm, .seg button { min-height: 44px; }
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--t-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.pill.pos { background: var(--pos-soft); color: var(--pos); }
.pill.neg { background: var(--neg-soft); color: var(--neg); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.habit { background: var(--habit-soft); color: var(--habit); }

/* --- Stat tile ------------------------------------------------------------- */
.stat { gap: var(--s-2); }
.stat-label {
  font-size: var(--t-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(24px, 1.3rem + 1vw, 32px);
  font-weight: 620;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.stat-value.pos { color: var(--pos); }
.stat-value.neg { color: var(--neg); }
.stat-foot { display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-sm); color: var(--muted); }

/* --- Barras de progreso ---------------------------------------------------- */
.progress {
  height: 8px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width var(--dur-3) var(--ease-emph);
}
.progress.pos > i { background: var(--pos); }
.progress.warn > i { background: var(--warn); }
.progress.neg > i { background: var(--neg); }

/* --- Lista de movimientos --------------------------------------------------- */
.tx-list { display: flex; flex-direction: column; }
.tx {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-3);
  min-height: 60px;
  padding: var(--s-2) var(--s-5);
  border-bottom: 1px solid var(--border);
  background: transparent;
  border-left: 0; border-right: 0; border-top: 0;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease-std);
}
.tx:hover { background: var(--surface-2); }
.tx:last-child { border-bottom: 0; }
.tx-ico {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--muted);
}
.tx-main { min-width: 0; }
.tx-title {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tx-meta { font-size: var(--t-sm); color: var(--muted); }
.tx-amount {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 620;
  white-space: nowrap;
}
.tx-amount.pos { color: var(--pos); }
.tx-amount.neg { color: var(--fg); }

/* --- Tabla ----------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  font-size: var(--t-xs);
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table td.right, .table th.right { text-align: right; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* --- Formularios (M3 outlined field) ---------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label {
  font-size: var(--t-sm);
  font-weight: 620;
  color: var(--muted);
}
.input, .select, textarea.input {
  min-height: 46px;
  padding: 0 var(--s-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--fg);
  font-size: 15px;
  width: 100%;
  transition: border-color var(--dur-1) var(--ease-std);
}
textarea.input { padding: var(--s-3) var(--s-4); min-height: 90px; resize: vertical; }
.input:hover, .select:hover { border-color: var(--fg); }
.input:focus, .select:focus { outline: 2px solid var(--primary); outline-offset: -2px; border-color: var(--primary); }
.field .hint { font-size: var(--t-xs); color: var(--muted); }
.field .err { font-size: var(--t-xs); color: var(--neg); font-weight: 620; }
.input[aria-invalid='true'] { border-color: var(--neg); }

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 52px; height: 32px;
  flex: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  background: var(--surface-3);
  cursor: pointer;
  transition: background var(--dur-2) var(--ease-std);
  padding: 0;
}
.switch::after {
  content: '';
  position: absolute;
  left: 4px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform var(--dur-2) var(--ease-emph), background var(--dur-2) var(--ease-std);
}
.switch[aria-checked='true'] { background: var(--primary); border-color: transparent; }
.switch[aria-checked='true']::after { transform: translateX(20px); background: var(--on-primary); }

.setting-row {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-4) 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row .txt { min-width: 0; flex: 1; }
.setting-row .txt strong { display: block; font-size: 14.5px; font-weight: 620; }
.setting-row .txt span { font-size: var(--t-sm); color: var(--muted); }
.setting-row .ctl { margin-left: auto; }

/* --- Grilla de hábitos ------------------------------------------------------ */
.habit-grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.habit-grid {
  display: grid;
  gap: 6px;
  min-width: max-content;
  align-items: center;
}
.hg-corner, .hg-name {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  padding-right: var(--s-3);
}
.hg-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  font-size: var(--t-xs);
  color: var(--muted);
  font-weight: 700;
  min-width: 44px;
}
.hg-day .dow { text-transform: uppercase; letter-spacing: 0.04em; }
.hg-day .dnum { font-family: var(--font-mono); font-size: 12px; color: var(--fg); }
.hg-day.today .dnum {
  background: var(--primary);
  color: var(--on-primary);
  border-radius: var(--r-full);
  padding: 0 6px;
}
.hg-name {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 190px;
  max-width: 190px;
}
.hg-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.hg-label { min-width: 0; }
.hg-label strong { display: block; font-size: 14px; font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hg-label span { font-size: var(--t-xs); color: var(--muted); }

.hcell {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: transparent;
  cursor: pointer;
  padding: 0;
  transition: background var(--dur-1) var(--ease-std),
              border-color var(--dur-1) var(--ease-std),
              transform var(--dur-1) var(--ease-emph);
}
.hcell:hover:not(:disabled) { border-color: var(--border-strong); }
.hcell:active:not(:disabled) { transform: scale(0.9); }
.hcell[aria-pressed='true'] {
  background: var(--h-color, var(--habit));
  border-color: var(--h-color, var(--habit));
  color: var(--surface);
}
.hcell[data-state='partial'] {
  background: color-mix(in oklab, var(--h-color, var(--habit)) 32%, var(--surface));
  border-color: color-mix(in oklab, var(--h-color, var(--habit)) 55%, var(--border));
}
.hcell:disabled { opacity: 0.32; cursor: not-allowed; }
/* El único gesto animado deliberado del sistema: el tilde entra con rebote.
   Es la interacción firma del dominio de hábitos. @media reduced-motion la anula. */
.hcell svg {
  width: 22px; height: 22px;
  transform: scale(0.35) rotate(-12deg);
  opacity: 0;
  transition: transform var(--dur-3) cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity var(--dur-1) var(--ease-std);
}
.hcell[aria-pressed='true'] svg { transform: none; opacity: 1; }

.hg-streak {
  position: sticky; right: 0;
  min-width: 78px;
  display: flex; align-items: center; justify-content: flex-end;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  background: var(--surface);
  padding-left: var(--s-3);
}

/* Heatmap compacto (vista mes / año) */
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; }
.heat i {
  width: 13px; height: 13px;
  border-radius: 3px;
  background: var(--surface-3);
  display: block;
}
.heat i[data-l='1'] { background: color-mix(in oklab, var(--habit) 28%, var(--surface-3)); }
.heat i[data-l='2'] { background: color-mix(in oklab, var(--habit) 55%, var(--surface-3)); }
.heat i[data-l='3'] { background: color-mix(in oklab, var(--habit) 78%, var(--surface-3)); }
.heat i[data-l='4'] { background: var(--habit); }

/* --- Gráficos (SVG puro, sin librerías) ------------------------------------- */
.bars { display: flex; align-items: flex-end; gap: clamp(4px, 1vw, 10px); height: 168px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; min-width: 0; }
.bars .bar .stack { display: flex; align-items: flex-end; justify-content: center; gap: 3px; height: 132px; }
.bars .bar .stack i {
  display: block;
  width: 46%;
  max-width: 22px;
  min-height: 2px;
  border-radius: var(--r-xs) var(--r-xs) 0 0;
}
.bars .bar .seg-in { background: var(--pos); }
.bars .bar .seg-out { background: var(--neg); }
.bars .bar .lbl { text-align: center; font-size: var(--t-xs); color: var(--muted); font-weight: 640; }

.legend { display: flex; flex-wrap: wrap; gap: var(--s-3) var(--s-5); }
.legend span { display: inline-flex; align-items: center; gap: 7px; font-size: var(--t-sm); color: var(--muted); }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.donut-wrap { display: flex; align-items: center; gap: var(--s-6); flex-wrap: wrap; }
.donut { position: relative; width: 172px; height: 172px; flex: none; }
.donut svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.donut .mid {
  position: absolute; inset: 0;
  display: grid; place-content: center; text-align: center;
}
.donut .mid b { font-family: var(--font-mono); font-size: 20px; font-weight: 650; }
.donut .mid span { font-size: var(--t-xs); color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }

/* --- Diálogo / bottom sheet ------------------------------------------------- */
dialog.sheet {
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  color: var(--fg);
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  box-shadow: var(--shadow-2);
}
dialog.sheet::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
.sheet-head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-5) var(--s-5) var(--s-3);
}
.sheet-body { padding: 0 var(--s-5) var(--s-4); display: flex; flex-direction: column; gap: var(--s-4); }
.sheet-foot {
  display: flex; justify-content: flex-end; gap: var(--s-2);
  padding: var(--s-4) var(--s-5) var(--s-5);
}
@media (max-width: 560px) {
  dialog.sheet {
    width: 100vw; max-width: 100vw;
    margin: auto 0 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    border-bottom: 0;
  }
  .sheet-foot .btn { flex: 1; }
}

/* --- Toast ----------------------------------------------------------------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: clamp(20px, 4vh, 40px);
  transform: translate(-50%, 140%);
  z-index: 60;
  display: flex; align-items: center; gap: var(--s-3);
  max-width: calc(100vw - 32px);
  padding: var(--s-3) var(--s-5);
  border-radius: var(--r-full);
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  font-weight: 560;
  box-shadow: var(--shadow-2);
  transition: transform var(--dur-3) var(--ease-emph);
}
#toast[data-show='1'] { transform: translate(-50%, 0); }
@media (max-width: 1023px) { #toast { bottom: calc(var(--bottomnav-h) + 20px); } }

/* --- Estado vacío ----------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--s-3);
  padding: var(--s-12) var(--s-5);
  text-align: center;
  color: var(--muted);
}
.empty .ph {
  width: 76px; height: 76px;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
}

/* --- Placeholder de imagen honesto ------------------------------------------ */
.ph-img {
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  display: grid; place-items: center;
  color: var(--muted);
  font-size: var(--t-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* --- Tour (compatible con driver.js) ---------------------------------------- */
.tour-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: var(--scrim);
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-std);
}
.tour-overlay[data-on='1'] { opacity: 1; }
.tour-spot {
  position: fixed; z-index: 901;
  border-radius: var(--r-md);
  box-shadow: 0 0 0 4px var(--primary), 0 0 0 9999px var(--scrim);
  pointer-events: none;
  transition: all var(--dur-3) var(--ease-emph);
}
.tour-pop {
  position: fixed; z-index: 902;
  width: min(340px, calc(100vw - 24px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: var(--s-5);
  display: flex; flex-direction: column; gap: var(--s-3);
  transition: top var(--dur-3) var(--ease-emph), left var(--dur-3) var(--ease-emph);
}
.tour-pop h3 { font-size: 16px; }
.tour-pop p { font-size: 14px; color: var(--muted); }
.tour-foot { display: flex; align-items: center; gap: var(--s-2); margin-top: var(--s-1); }
.tour-progress {
  margin-right: auto;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: var(--muted);
  font-weight: 700;
}
