/* Estilos del panel. Sin colores sueltos: todo sale de tokens.css. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

a {
  color: var(--invest);
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--invest);
  outline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--s-4);
  top: -60px;
  background: var(--invest);
  color: var(--on-invest);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-control);
  z-index: 10;
}

.skip-link:focus {
  top: var(--s-4);
}

/* ------------------------------------------------------------------ estructura */

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  padding: var(--s-7) var(--s-4);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: var(--s-7);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 0 var(--s-2);
}

.brand-name {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-sub,
.data-note {
  font-size: 13px;
  color: var(--ink-muted);
}

.data-note {
  padding: 0 var(--s-2);
  margin-top: auto;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.nav a {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-height: var(--touch);
  padding: 0 var(--s-3);
  border-radius: var(--r-control);
  color: var(--ink-muted);
  font-size: 15px;
  text-decoration: none;
  transition: background var(--t-state), color var(--t-state);
}

.nav a:hover {
  background: var(--surface);
  color: var(--ink);
}

.nav a[aria-current="page"] {
  background: var(--surface-raised);
  color: var(--ink);
  font-weight: 700;
}

.nav a[aria-current="page"] svg {
  color: var(--invest);
}

.logout {
  padding: 0 var(--s-2);
}

.main {
  min-width: 0;
  padding: var(--s-7) var(--s-7) 48px;
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-4);
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}

.page-sub {
  margin-top: var(--s-1);
  font-size: 14px;
  color: var(--ink-muted);
}

.bottom-nav,
.fab {
  display: none;
}

/* ------------------------------------------------------------------ controles */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--touch);
  padding: 0 var(--s-5);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  background: transparent;
  color: var(--ink);
  font: 700 15px var(--font-ui);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--t-state), border-color var(--t-state);
}

.btn:hover {
  background: var(--surface-raised);
}

.btn-primary {
  background: var(--invest);
  border-color: var(--invest);
  color: var(--on-invest);
}

.btn-primary:hover {
  background: var(--invest);
  border-color: var(--ink);
}

.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  min-height: var(--touch);
  color: var(--invest);
  font: 600 14px var(--font-ui);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 2px var(--s-2);
  border-radius: var(--r-tag);
  vertical-align: middle;
}

.tag-invest {
  background: var(--invest);
  color: var(--on-invest);
}

.tag-cetes {
  background: var(--cetes);
  color: var(--on-cetes);
}

.tag-muted {
  border: 1px solid var(--line-strong);
  color: var(--ink-muted);
}

.tag-danger {
  border: 1px solid var(--danger);
  color: var(--danger);
}

/* ------------------------------------------------------------------ tarjetas */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 22px;
  min-width: 0;
}

.card-dashed {
  border-style: dashed;
  border-color: var(--line-strong);
}

.card-title {
  font-size: 17px;
  font-weight: 700;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}

.card-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-muted);
}

.card-label-invest {
  color: var(--invest);
}

.card-label-cetes {
  color: var(--cetes);
}

.card-figure {
  margin-top: 10px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}

.card-note {
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink-muted);
}

.card-text {
  margin-top: var(--s-2);
  line-height: 1.55;
}

.muted {
  color: var(--ink-muted);
}

.positive {
  color: var(--invest);
}

.negative {
  color: var(--danger);
}

.figure-xl {
  font-size: 50px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.figure-lg {
  font-size: 40px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
}

/* Centavos atenuados solo en cifras grandes (>= 24 px). */
.figure-xl .cents,
.figure-lg .cents,
.card-figure .cents {
  color: var(--ink-faint);
  font-weight: 600;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-4);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-4);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  min-width: 0;
}

.empty {
  color: var(--ink-muted);
  line-height: 1.55;
}

.notice {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  font-size: 14px;
}

.notice-cetes {
  border-color: var(--cetes);
}

.notice-danger {
  border-color: var(--danger);
}

/* ------------------------------------------------------------------ barras (SVG) */

.bar {
  display: block;
  width: 100%;
  height: 8px;
  margin-top: var(--s-2);
  overflow: visible;
}

.bar-track {
  fill: var(--line);
}

.bar-fill {
  fill: var(--invest);
}

.bar-fill-cetes {
  fill: var(--cetes);
}

.bar-target {
  fill: var(--ink);
}

.bar-thin {
  height: 6px;
}

.split-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.split-row {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
}

/* ------------------------------------------------------------------ camino a $15M */

.path-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--s-4);
}

.path-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-muted);
}

.path-scale-note {
  font-size: 13px;
  color: var(--ink-muted);
  text-align: right;
}

.path-svg {
  display: block;
  width: 100%;
  height: 112px;
  margin-top: var(--s-5);
  overflow: visible;
  font-family: var(--font-ui);
}

.path-track {
  stroke: var(--line);
  stroke-width: 4;
  stroke-linecap: round;
}

.path-progress {
  stroke: var(--invest);
  stroke-width: 4;
  stroke-linecap: round;
}

.path-ms {
  fill: var(--surface);
  stroke: var(--line-strong);
  stroke-width: 2;
}

.path-ms-next {
  stroke: var(--cetes);
}

.path-ms-reached {
  fill: var(--invest);
  stroke: var(--invest);
}

.path-now {
  fill: var(--invest);
  stroke: var(--surface);
  stroke-width: 5;
}

.path-label {
  fill: var(--ink);
  font-size: 13px;
}

.path-sub {
  fill: var(--ink-muted);
  font-size: 13px;
}

.path-now-label {
  fill: var(--invest);
  font-size: 13px;
  font-weight: 700;
}

.path-row {
  display: none;
}

/* ------------------------------------------------------------------ inicio */

.home {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  grid-template-areas:
    "path amaia"
    "action amaia"
    "balances amaia"
    "split amaia"
    "notices amaia";
  grid-template-rows: auto auto auto auto 1fr; /* el alto extra de AMAIA va a la última fila */
  gap: var(--s-5);
  align-items: start;
}

.home-path {
  grid-area: path;
}

.home-amaia {
  grid-area: amaia;
}

.home-balances {
  grid-area: balances;
}

.home-split {
  grid-area: split;
}

.home-action {
  grid-area: action;
}

.home-notices {
  grid-area: notices;
}

.notice-row {
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--line);
}

.notice-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.notice-meta {
  font-size: 14px;
}

.notice-body {
  margin-top: var(--s-1);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-muted);
  white-space: pre-line;
}

.home-action:empty {
  display: none;
}

/* ------------------------------------------------------------------ AMAIA */

.amaia {
  background: var(--surface-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-card);
  padding: 22px;
  font-family: var(--font-amaia);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  overflow-y: auto; /* último recurso en pantallas muy bajas */
}

.amaia-head {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.amaia-mark {
  width: 44px;
  height: 44px;
  flex: none;
  color: var(--amaia-brasa);
}

.amaia-mark svg {
  width: 44px;
  height: 44px;
}

.amaia-name {
  font-size: 18px;
  font-weight: 600;
}

.amaia-sub {
  font-size: 13px;
  color: var(--ink-muted);
}

.amaia-move {
  background: var(--surface);
  border-radius: var(--r-card-sm);
  padding: var(--s-4);
}

.amaia-kicker {
  font-size: 13px;
  font-weight: 600;
  color: var(--amaia-accent);
}

.amaia-verdict {
  margin-top: var(--s-2);
  font-size: 26px;
  font-weight: 600;
}

.amaia-p {
  margin-top: 10px;
  font-size: 15px;
  line-height: 1.55;
}

.amaia-small {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-muted);
}

.amaia-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  padding: 0 var(--s-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--ink);
  font: 600 15px var(--font-amaia);
  text-decoration: none;
  cursor: pointer;
}

.pill-brasa {
  background: var(--amaia-brasa);
  border-color: var(--amaia-brasa);
  color: var(--amaia-on-brasa);
}

.why {
  border-top: 1px solid var(--line-strong);
  padding-top: var(--s-3);
}

.why summary {
  min-height: var(--touch);
  display: flex;
  align-items: center;
  font-weight: 600;
  cursor: pointer;
}

.why-list {
  margin: var(--s-2) 0 0;
  padding-left: var(--s-5);
  line-height: 1.55;
}

.why-list li + li {
  margin-top: var(--s-2);
}

/* ------------------------------------------------------------------ tablas */

.table-box {
  overflow-x: auto;
}

.table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 15px;
}

.table th {
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
  padding: 10px var(--s-3) 10px 0;
  border-bottom: 1px solid var(--line);
}

.table td {
  padding: 14px var(--s-3) 14px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.table tr:last-child td {
  border-bottom: none;
}

.table .num {
  text-align: right;
  white-space: nowrap;
}

.table .sub {
  display: block;
  font-size: 13px;
  color: var(--ink-muted);
}

.table tr.current td {
  background: var(--surface-raised);
}

.table-compact {
  min-width: 0;
}

.month-head {
  font-size: 15px;
  font-weight: 700;
  margin: var(--s-4) 0 var(--s-2);
}

.list-row {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.list-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.filters a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  padding: 0 var(--s-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.filters a[aria-current="true"] {
  background: var(--invest);
  border-color: var(--invest);
  color: var(--on-invest);
}

/* ------------------------------------------------------------------ formularios */

.form {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  max-width: 560px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.field label,
.field legend {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-muted);
}

.field input,
.field select,
.field textarea {
  min-height: var(--touch);
  padding: 0 var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  background: var(--bg);
  color: var(--ink);
  font: 400 15px var(--font-ui);
}

.field textarea {
  padding: var(--s-2) var(--s-3);
  min-height: 88px;
}

.field-hint {
  font-size: 13px;
  color: var(--ink-muted);
}

.field-error {
  font-size: 13px;
  color: var(--danger);
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.result {
  border-left: none;
}

.result-title {
  font-size: 17px;
  font-weight: 700;
}

.action-menu {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

/* ------------------------------------------------------------------ login y sin conexión */

.solo {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--s-4);
}

.solo-card {
  width: 100%;
  max-width: 400px;
}

.solo-card .brand {
  padding: 0;
  margin-bottom: var(--s-5);
}

/* ------------------------------------------------------------------ chat con AMAIA (T-007) */

/* La tarjeta de AMAIA tiene altura máxima: arriba la jugada (cede espacio solo si el
   historial ya está en su mínimo), en medio el historial con scroll propio y abajo el
   campo de texto, siempre visible. */
.amaia > * {
  flex-shrink: 0;
}

.amaia-intro {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  flex: 0 0.01 auto;
  min-height: 0;
  overflow-y: auto;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  flex: 1 1 auto;
  min-height: 0;
}

.chat > * {
  flex-shrink: 0;
}

.chat-log {
  list-style: none;
  margin: 0;
  padding: 0 var(--s-1) 0 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  flex: 1 1 auto;
  min-height: calc(var(--touch) * 3);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-log:focus-visible {
  outline-offset: var(--s-1);
}

.chat-msg {
  flex-shrink: 0;
  max-width: 92%;
  padding: 10px var(--s-3);
  border-radius: var(--r-card-sm);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.chat-msg p + p,
.chat-msg p + ul,
.chat-msg ul + p {
  margin-top: var(--s-2);
}

.chat-msg ul {
  margin: 0;
  padding-left: var(--s-5);
}

.chat-user {
  align-self: flex-end;
  background: var(--surface);
  border: 1px solid var(--line-strong);
}

.chat-assistant {
  align-self: flex-start;
  background: var(--surface);
}

.chat-notice {
  border: 1px solid var(--danger);
  color: var(--ink-muted);
}

.chat-form {
  display: flex;
  gap: var(--s-2);
  align-items: flex-end;
}

.chat-form textarea {
  flex: 1;
  min-height: var(--touch);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-control);
  background: var(--bg);
  color: var(--ink);
  font: 400 15px var(--font-ui);
  resize: vertical;
}

.chat-form button[disabled] {
  opacity: 0.6;
  cursor: progress;
}

.chat-thinking {
  display: none;
}

.chat:has(.htmx-request) .chat-thinking {
  display: block;
}

/* Altura máxima: la pantalla menos el margen superior y el encabezado de la página
   (≈ 4 × --s-7), para que el campo de texto se vea desde que carga. */
.amaia-page {
  max-width: 760px;
  max-height: calc(100vh - var(--s-7) * 4);
  max-height: calc(100dvh - var(--s-7) * 4);
}

@media (min-width: 1200px) {
  /* Escritorio: la columna de AMAIA acompaña el scroll y no pasa del alto de la pantalla. */
  .home-amaia {
    position: sticky;
    top: var(--s-7);
    max-height: calc(100vh - var(--s-7) * 4);
    max-height: calc(100dvh - var(--s-7) * 4);
  }
}

@media (max-width: 1199px) {
  /* Celular y tableta: tarjeta con altura máxima que deja ver la barra inferior. */
  .home-amaia {
    max-height: calc(100vh - var(--s-7) * 5);
    max-height: calc(100dvh - var(--s-7) * 5);
  }

  .amaia-page {
    max-height: calc(100vh - var(--s-7) * 8);
    max-height: calc(100dvh - var(--s-7) * 8);
  }
}

/* ------------------------------------------------------------------ glosario */


a.term {
  color: inherit;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.glossary-index {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-3);
  font-size: 14px;
}

.glossary {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.glossary-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card-sm);
  padding: var(--s-4);
  scroll-margin-top: var(--s-5);
}

.glossary-item:target {
  border-color: var(--amaia-accent);
}

.glossary-item dt {
  font-weight: 600;
  font-size: 16px;
}

.glossary-item dt .sub {
  display: block;
  font-weight: 400;
  font-size: 13px;
  color: var(--ink-muted);
}

.glossary-item dd {
  margin: var(--s-2) 0 0;
  line-height: 1.55;
}

.glossary-wam {
  margin-top: var(--s-2);
  color: var(--ink-muted);
}

/* ------------------------------------------------------------------ responsivo */

@media (max-width: 1199px) {
  .home {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "path"
      "amaia"
      "action"
      "balances"
      "split"
      "notices";
    grid-template-rows: none;
  }
}

@media (max-width: 899px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: var(--s-5) var(--s-4) 140px;
    gap: var(--s-4);
  }

  .page-title {
    font-size: 20px;
  }

  .figure-xl {
    font-size: 40px;
  }

  .figure-lg {
    font-size: 32px;
  }

  .card-figure {
    font-size: 22px;
  }

  .card {
    padding: var(--s-4);
  }

  .amaia {
    padding: var(--s-4);
  }

  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s-3);
  }

  .grid-3 > :last-child:nth-child(odd) {
    grid-column: span 2;
  }

  .grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }

  .page-head .btn-primary {
    display: none;
  }

  .path-svg .path-label,
  .path-svg .path-sub,
  .path-svg .path-now-label {
    display: none;
  }

  .path-svg {
    height: 56px;
    margin-top: 0;
  }

  .path-scale-note {
    display: none;
  }

  .path-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--ink-muted);
    margin-top: var(--s-2);
  }

  .path-row .now {
    color: var(--invest);
    font-weight: 700;
  }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 76px;
    background: var(--surface);
    border-top: 1px solid var(--line);
    z-index: 5;
  }

  .bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--s-1);
    font-size: 11px;
    color: var(--ink-muted);
    text-decoration: none;
  }

  .bottom-nav a[aria-current="page"] {
    color: var(--invest);
    font-weight: 700;
  }

  .fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: var(--s-5);
    bottom: 96px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: var(--invest);
    color: var(--on-invest);
    z-index: 6;
  }

  /* El botón flotante no tapa el campo del chat mientras está a la vista. */
  .chat-form-visible .fab {
    display: none;
  }
}

/* ------------------------------------------------------------------ hábito y opciones */

.habit {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--s-1);
  list-style: none;
  margin: var(--s-3) 0 0;
  padding: 0;
}

.habit li {
  height: 28px;
  border-radius: var(--r-tag);
  border: 1px solid var(--line-strong);
}

.habit li.done {
  background: var(--invest);
  border-color: var(--invest);
}

.form-row label {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: var(--touch);
  color: var(--ink);
  font-weight: 400;
}

.result-title svg {
  vertical-align: -4px;
  color: var(--invest);
}
