/* Task 5: planning surfaces for neighborhood and budget decisions. */
html,
body {
  max-width: 100%;
  overflow-x: clip;
}

.planning-budget-layout {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(300px, 5fr);
  gap: 24px;
  align-items: start;
}

.planning-budget-layout .calc-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
}

#budgetTicket {
  position: sticky;
  top: 156px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: var(--surface);
}

#budgetTicket.is-updating {
  opacity: .72;
}

.budget-quick {
  margin: 0 0 26px;
  padding: clamp(18px, 3vw, 28px);
  border-top-width: 1px;
  border-top-color: var(--line);
}

.budget-quick-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.budget-quick-head h2,
.budget-quick-head p {
  margin: 0;
}

.budget-quick-head h2 {
  margin-top: 4px;
}

.budget-quick-head p,
.budget-estimate-note {
  color: var(--muted);
  line-height: 1.5;
}

.budget-quick-controls {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.budget-quick-controls label,
.currency-toggle legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.budget-quick-controls label {
  display: grid;
  gap: 5px;
}

.budget-quick-controls select {
  min-width: 112px;
}

.currency-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 116px;
  padding: 0;
  border: 0;
}

.currency-toggle legend {
  grid-column: 1 / -1;
  margin-bottom: 5px;
}

.currency-toggle button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

.currency-toggle button:first-of-type {
  border-radius: 4px 0 0 4px;
}

.currency-toggle button:last-of-type {
  margin-left: -1px;
  border-radius: 0 4px 4px 0;
}

.currency-toggle button[aria-pressed="true"] {
  position: relative;
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.budget-estimate-table th:not(:first-child),
.budget-estimate-table td:not(:first-child) {
  text-align: right;
}

.budget-estimate-table td {
  vertical-align: middle;
}

.estimate-route {
  display: grid;
  gap: 3px;
}

.estimate-route small,
.estimate-cell small {
  color: var(--muted);
  font-size: 11px;
}

.estimate-cell {
  display: grid;
  gap: 3px;
  justify-items: end;
}

.estimate-cell b {
  font-variant-numeric: tabular-nums;
}

.budget-estimate-note {
  margin: 12px 0 0;
  font-size: 12.5px;
}

.budget-advanced {
  grid-column: 1 / -1;
  padding: 0;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 92%, var(--soft));
}

.budget-advanced > summary {
  min-height: 48px;
  padding: 14px 16px;
  font-weight: 750;
  cursor: pointer;
}

.budget-advanced > .hint {
  margin: -4px 16px 14px;
}

.budget-advanced > .calc-grid {
  padding: 0 16px 16px;
}

.budget-advanced .control.is-edited {
  position: relative;
  border-color: color-mix(in srgb, var(--accent) 56%, var(--line));
  box-shadow: inset 3px 0 0 var(--accent);
}

.budget-advanced .control.is-edited::before {
  content: "Editado";
  position: absolute;
  top: 9px;
  right: 10px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.use-estimate {
  min-height: 44px;
  margin-top: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.use-estimate:hover,
.use-estimate:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.budget-fit-matrix {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.budget-fit-head,
.budget-fit-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.2fr) repeat(3, minmax(128px, 1fr));
  align-items: center;
}

.budget-fit-head {
  min-height: 38px;
  padding: 0 14px;
  background: var(--soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.budget-fit-head span:not(:first-child) {
  text-align: right;
}

.budget-fit-row {
  min-height: 60px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
}

.budget-fit-row.is-current {
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}

.budget-fit-option,
.budget-fit-cell {
  min-width: 0;
}

.budget-fit-option {
  display: grid;
  gap: 2px;
}

.budget-fit-option span {
  color: var(--muted);
  font-size: 12px;
}

.budget-fit-option em {
  color: var(--accent);
  font-style: normal;
  font-weight: 800;
}

.budget-fit-cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.fit-mark {
  display: inline-grid;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
}

.fit-amount {
  min-width: 0;
  font-size: 13px;
  font-weight: 750;
}

.budget-fit-legend {
  display: flex;
  gap: 8px 18px;
  flex-wrap: wrap;
  margin: 10px 2px 0;
  font-size: 12px;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

.table-scroll:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 76%, white);
  outline-offset: 3px;
}

.table-scroll > .t {
  min-width: 560px;
}

/* Las comparaciones cortas caben completas: no necesitan un carril de scroll. */
.table-scroll.table-fit {
  overflow: visible;
}

.table-fit > .t {
  min-width: 0;
  width: 100%;
  table-layout: fixed;
}

.table-fit th,
.table-fit td {
  white-space: normal;
  overflow-wrap: anywhere;
}

.scenario-note {
  margin: 9px 2px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.scenario-note a {
  color: var(--accent);
  font-weight: 750;
}

#cmpTable th,
#cmpTable td {
  white-space: normal;
  overflow-wrap: anywhere;
}

.table-scroll > #rTable {
  min-width: 0;
  width: 100%;
  table-layout: fixed;
}

#rTable th:first-child,
#rTable td:first-child {
  width: 61%;
}

#rTable th:last-child,
#rTable td:last-child {
  width: 39%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.neighborhood-compare {
  margin: 20px 0 24px;
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 92%, var(--soft));
}

.compare-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.compare-head h2 {
  margin: 4px 0 8px;
}

.compare-count {
  flex: none;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.neighborhood-compare-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.compare-neighborhood {
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}

.compare-neighborhood h3,
.compare-neighborhood p {
  margin: 0;
}

.compare-neighborhood p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.compare-neighborhood dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.compare-neighborhood dl > div {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 8px;
}

.compare-neighborhood dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.compare-neighborhood dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.compare-toggle,
.compare-remove {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.compare-toggle[aria-pressed="true"],
.compare-remove[aria-pressed="true"] {
  background: var(--accent);
  color: var(--surface);
}

.bcard {
  cursor: default;
}

.bcard:hover {
  transform: none;
  box-shadow: none;
}

.bcard.is-selected,
.bcard.is-highlighted,
.compare-neighborhood.is-highlighted {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 32%, transparent);
}

.bcard-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bcard .more {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

@media (max-width: 900px) {
  .planning-budget-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  #budgetTicket {
    position: static;
  }
}

@media (max-width: 640px) {
  .budget-fit-matrix {
    max-width: 100%;
    overflow: hidden;
  }

  .budget-quick-head,
  .budget-quick-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .budget-quick-controls label,
  .budget-quick-controls select,
  .currency-toggle {
    width: 100%;
  }

  .budget-estimate-table,
  .budget-estimate-table tbody,
  .budget-estimate-table tr,
  .budget-estimate-table td {
    display: block;
    width: 100%;
  }

  .budget-estimate-table thead {
    display: none;
  }

  .budget-estimate-table tr {
    padding: 14px;
    border-bottom: 1px solid var(--line);
  }

  .budget-estimate-table td {
    display: grid;
    grid-template-columns: minmax(88px, .7fr) minmax(0, 1.3fr);
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border: 0;
  }

  .budget-estimate-table td:first-child {
    display: block;
    padding-top: 0;
  }

  .budget-estimate-table td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .06em;
    text-align: left;
    text-transform: uppercase;
  }

  .budget-fit-head {
    display: none;
  }

  .budget-fit-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px 14px;
    padding: 14px;
  }

  .budget-fit-option {
    grid-column: 1 / -1;
  }

  .budget-fit-cell {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    justify-content: stretch;
    text-align: left;
  }

  .budget-fit-cell::before {
    content: attr(data-city);
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
  }

  .fit-amount {
    overflow-wrap: anywhere;
    text-align: left;
  }

  #cmpTable th,
  #cmpTable td {
    padding-right: 6px;
    padding-left: 6px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .planning-budget-layout,
  .planning-budget-layout .calc-grid,
  .neighborhood-compare-grid {
    grid-template-columns: minmax(0, 1fr);
    max-width: 100%;
  }

  .neighborhood-compare {
    padding: 16px;
  }

  .compare-head,
  .bcard-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .carousel,
  .map-wrap,
  #cityMap,
  #budgetTicket,
  .table-scroll {
    max-width: 100%;
    min-width: 0;
  }

  .table-scroll > .t {
    width: max-content;
    min-width: 540px;
  }

  .table-scroll.table-fit > .t {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
  }

  .table-scroll > #budgetEstimateTable,
  .table-scroll > #rTable,
  .table-scroll > #rOnce,
  .table-scroll > #cmpTable {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
  }
}

@media (prefers-reduced-motion: reduce) {
  #budgetTicket {
    transition: none;
  }
}
