/*
 * Project-specific CSS only. Tabler covers typography, colour, spacing and components; the rules
 * below exist because Tabler has no bottom-navigation component for the mobile shell.
 */

.app-bottom-nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  /* Ticket 032: pin the bar to the viewport width. With only `inset-inline: 0` the browser can
     resolve the shrink-to-fit width beyond 100vw (measured 471 px at a 360 px viewport on
     Finances), which pushes `Más` off-screen and creates page-level horizontal overflow. */
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  z-index: 1030;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  background: var(--tblr-bg-surface);
  border-top: 1px solid var(--tblr-border-color);
  padding-bottom: env(safe-area-inset-bottom);
}

.app-bottom-nav-link {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.125rem;
  /* Comfortable touch target on phones. */
  min-height: 3.5rem;
  padding: 0.375rem 0.25rem;
  color: var(--tblr-secondary);
  text-decoration: none;
  font-size: 0.6875rem;
  line-height: 1;
}

.app-bottom-nav-link i {
  font-size: 1.375rem;
}

.app-bottom-nav-link:hover,
.app-bottom-nav-link:focus-visible {
  color: var(--tblr-primary);
}

.app-bottom-nav-link:focus-visible {
  outline: 2px solid var(--tblr-primary);
  outline-offset: -2px;
}

.app-bottom-nav-link.active {
  color: var(--tblr-primary);
  font-weight: 600;
}

/* Ticket 039: the center action is raised and unmistakably primary while every control keeps an
   equal-width slot, including at 320 px. */
.app-bottom-nav-capture {
  position: relative;
  transform: translateY(-0.5rem);
  color: var(--tblr-primary);
  font-weight: 600;
}

.app-bottom-nav-capture-icon {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  border: 0.25rem solid var(--tblr-bg-surface);
  border-radius: 50%;
  background: var(--tblr-primary);
  color: var(--tblr-primary-fg);
  box-shadow: var(--tblr-box-shadow);
}

.app-bottom-nav-capture .app-bottom-nav-capture-icon i {
  font-size: 1.5rem;
}

.app-bottom-nav-capture:hover .app-bottom-nav-capture-icon,
.app-bottom-nav-capture:focus-visible .app-bottom-nav-capture-icon {
  filter: brightness(0.9);
  color: var(--tblr-primary-fg);
}

/* Shared account entry point: the same partial is used in the desktop sidebar and mobile header. */
.app-account-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.5rem;
  border-radius: var(--tblr-border-radius);
  color: var(--tblr-body-color);
  text-decoration: none;
}

.app-account-link:hover {
  background: var(--tblr-bg-surface-secondary);
  color: var(--tblr-body-color);
}

.app-account-copy {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
}

.app-account-name {
  overflow: hidden;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-account-hint {
  color: var(--tblr-secondary);
  font-size: 0.75rem;
}

.app-account-chevron {
  flex: 0 0 auto;
  color: var(--tblr-secondary);
}

@media (max-width: 991.98px) {
  .app-account-link {
    max-width: 12rem;
    padding-block: 0.25rem;
  }

  .app-account-hint,
  .app-account-chevron {
    display: none;
  }
}

/* `Más` is a button (opens the offcanvas menu), not a link; it must look identical to its siblings. */
button.app-bottom-nav-link {
  background: none;
  border: 0;
  font: inherit;
  cursor: pointer;
}

/* Group headings inside the shared destination list (sidebar and `Más` menu, ticket 028). */
.app-nav-group-title {
  padding: 0.75rem 0.75rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.25rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tblr-secondary);
  list-style: none;
}

.app-nav-group-title:first-child {
  padding-top: 0.25rem;
}

.navbar-nav .app-nav-group-title + .nav-item .nav-link {
  padding-top: 0.25rem;
}

/* The `Más` sheet stays narrow so a phone keeps most of the page visible behind it. */
.app-more-menu {
  --bs-offcanvas-width: 20rem;
  max-width: 85vw;
}

/* Desktop sidebar: destinations scroll independently on short screens while brand, identity and
   logout remain pinned (ticket 028). The aside is fixed-height, so the whole chain below it must
   be constrained for the inner list to scroll instead of overflowing the viewport. */
@media (min-width: 992px) {
  .navbar-vertical .container-fluid {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
  }

  .navbar-vertical .navbar-collapse.show {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
  }

  .app-sidebar-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }
}

/* Keep page content clear of the fixed bottom navigation. */
@media (max-width: 991.98px) {
  .page-body {
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
  }
}

/*
 * Ticket 032: guarantee a visible focus indicator on every interactive control. The browser sweep
 * found buttons that match :focus-visible without any outline or shadow, so keyboard users could
 * not see where they were. Inputs and selects already show Tabler's focus styling; this rule
 * covers buttons, links and focusable scroll regions.
 */
button:focus-visible,
a:focus-visible,
[tabindex="0"]:focus-visible,
.btn:focus-visible,
.nav-link:focus-visible {
  outline: 2px solid var(--tblr-primary);
  outline-offset: 2px;
}

/* Tabler sizes its empty-state icon for inline SVG; the icon webfont needs an explicit size. */
.empty-icon .ti {
  font-size: 3rem;
  color: var(--tblr-secondary);
}

/*
 * Shared validation summary (ticket 027). The container always exists so unobtrusive client
 * validation can fill it, but it is never visible —nor announced— without a real error.
 * Pages render it with: <div class="alert alert-danger app-validation-summary" role="alert"
 * asp-validation-scope="Input"></div> (see FormValidationSummaryTagHelper).
 */
.app-validation-summary.validation-summary-valid {
  display: none;
}

.app-validation-summary.validation-summary-errors {
  margin-bottom: 0.75rem;
}

.app-validation-summary.validation-summary-errors ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.app-validation-summary.validation-summary-errors li + li {
  margin-top: 0.125rem;
}

/*
 * Shared progressive-disclosure panels (ticket 029). The toggle and the collapsible body are
 * rendered by CollapsiblePanelTagHelper; Bootstrap collapse keeps aria-expanded in sync.
 */
.app-collapsible {
  margin-bottom: 0.75rem;
}

.app-collapsible .app-collapsible-toggle {
  margin-bottom: 0.75rem;
}

.app-collapsible .app-collapsible-toggle .ti {
  margin-inline-end: 0.25rem;
}

/*
 * Compact purchase research list (ticket 030). The same option markup is a comparison table on
 * desktop and stacks as prioritized cards on phones, so no horizontal page overflow occurs.
 */
.app-purchase-options td[data-label]::before {
  content: attr(data-label);
}

@media (max-width: 767.98px) {
  .app-purchase-options thead {
    display: none;
  }

  .app-purchase-options,
  .app-purchase-options tbody,
  .app-purchase-options tr,
  .app-purchase-options td {
    display: block;
    width: 100%;
  }

  .app-purchase-options tr {
    border: 1px solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius);
    margin-bottom: 0.5rem;
    padding: 0.5rem;
  }

  .app-purchase-options tr.table-success {
    border-color: var(--tblr-success);
  }

  .app-purchase-options td {
    border: 0;
    padding: 0.25rem 0;
  }

  .app-purchase-options td[data-label]::before {
    display: block;
    font-size: 0.6875rem;
    line-height: 1.25rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--tblr-secondary);
  }

  /* Expansion and action targets keep a practical 44 px touch height on phones. */
  .app-purchase-summary-actions .btn {
    min-height: 2.75rem;
  }
}

/*
 * Compact financial overviews (ticket 031). Summary flex rows need to shrink below their
 * content width so long Spanish descriptions wrap instead of overflowing the page.
 */
.min-width-0 {
  min-width: 0;
}

/*
 * Ticket 031: installment schedules stack as labeled cards on phones (same pattern as the
 * purchase options table from 030) so the schedule never forces page-level horizontal overflow.
 */
.app-stacked-table td[data-label]::before {
  content: attr(data-label);
}

@media (max-width: 767.98px) {
  .app-stacked-table thead {
    display: none;
  }

  .app-stacked-table,
  .app-stacked-table tbody,
  .app-stacked-table tr,
  .app-stacked-table td {
    display: block;
    width: 100%;
  }

  .app-stacked-table tr {
    border: 1px solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius);
    margin-bottom: 0.5rem;
    padding: 0.5rem;
  }

  .app-stacked-table td {
    border: 0;
    padding: 0.25rem 0;
  }

  .app-stacked-table td[data-label]::before {
    display: block;
    font-size: 0.6875rem;
    line-height: 1.25rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--tblr-secondary);
  }

  /* Expansion and action targets keep a practical 44 px touch height on phones, and the
     action cluster takes its own row so icon+label buttons never overflow a 320 px viewport. */
  .app-summary-actions {
    flex: 1 1 100%;
  }

  .app-summary-actions .btn {
    min-height: 2.75rem;
  }
}

/*
 * Ticket 031: genuine comparison tables (statement movements) stay tables inside a labeled,
 * keyboard-focusable scroll region (role="region" + tabindex="0", arrow keys scroll once
 * focused). The hint below the region makes the horizontal overflow evident on phones.
 */
.app-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Contain absolutely-positioned descendants (tooltips, .visually-hidden table headers): without
     a positioning context they escape this scroll clip and create page-level horizontal overflow
     (ticket 032 finding on the Finances expenses table). */
  position: relative;
}

/*
 * Ticket 032: Tabler cards are flex columns, so a scroll-region table that is a direct card child
 * grows to its content width instead of clipping. Reset the flex minimum so the region actually
 * scrolls (Finances expenses; applies to any future direct-child scroll region).
 */
.card > .table-responsive {
  min-width: 0;
}

.app-table-scroll-cue {
  margin-top: 0.25rem;
}

/*
 * Ticket 032: practical 44 px touch targets on phones. Ordinary controls (buttons, selects, inputs)
 * get a 2.75rem minimum height below tablet; icon-only buttons also get a 2.75rem minimum width so
 * the whole target —not just the glyph— is comfortably tappable. The `-sm` variants used by the bulk
 * grids keep 2.5rem (40 px): the rows carry their own visible label per column, the layout stays
 * scannable and they remain keyboard-accessible; this is the documented compact exception.
 */
@media (max-width: 767.98px) {
  .btn {
    min-height: 2.75rem;
  }

  .btn-icon {
    min-width: 2.75rem;
  }

  .form-control,
  .form-select {
    min-height: 2.75rem;
  }

  .btn-sm,
  .form-control-sm,
  .form-select-sm {
    min-height: 2.5rem;
  }

  /* Ticket 032: the `Más` sheet close affordance is icon-only; it needs the same target size. */
  .app-more-menu .btn-close {
    width: 2.75rem;
    height: 2.75rem;
  }
}

/*
 * Ticket 032: shared collapsible filters (FiltersPanelTagHelper). Phones collapse the filter form
 * behind a labeled toggle; from tablet up the toggle disappears and the body is always visible.
 */
.app-filters-toggle {
  margin-bottom: 0.5rem;
}

.app-filters-toggle .app-filters-chevron {
  transition: transform 0.15s ease-in-out;
}

.app-filters-toggle[aria-expanded="true"] .app-filters-chevron {
  transform: rotate(180deg);
}

.app-filters-active {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  color: var(--tblr-secondary);
}

.app-filters-active .app-filters-clear {
  white-space: nowrap;
}

@media (max-width: 767.98px) {
  .app-filters-body {
    margin-bottom: 0.5rem;
  }
}

@media (min-width: 768px) {
  .app-filters-toggle {
    display: none;
  }

  /* The body is authored to be permanently visible on wide screens regardless of the phone state. */
  .app-filters-body {
    display: block !important;
  }
}

/*
 * Ticket 032: Inbox-style rows keep their primary text usable on phones. The row wraps so the badge
 * stays inline with the text while the action cluster takes its own full-width line, and the text
 * column is allowed to shrink so long notes wrap instead of fragmenting.
 */
@media (max-width: 767.98px) {
  .app-row-with-actions {
    flex-wrap: wrap;
  }

  .app-row-with-actions .app-row-main {
    flex: 1 1 100%;
    min-width: 0;
  }

  .app-row-with-actions .app-row-actions {
    flex: 1 1 100%;
    justify-content: flex-start;
  }
}

/*
 * Backlog 035: edit mode on the shopping list must be visible at a glance. The quick-add card turns
 * into the active editor (accented edge) and the row being edited gets the same accent plus a subtle
 * surface change, so panel and row read as the same operation on both columns.
 */
.app-editing-panel {
  border-inline-start: 3px solid var(--tblr-primary);
}

.app-item-editing {
  border-inline-start: 3px solid var(--tblr-primary);
  background: var(--tblr-bg-surface-secondary);
}

/* Ticket 038: the browser-only dictation control is revealed by site.js after support detection. */
.app-voice-controls[hidden] {
  display: none !important;
}

.app-voice-button.app-voice-listening {
  color: var(--tblr-danger);
  border-color: var(--tblr-danger);
  background: var(--tblr-danger-lt);
}

.app-voice-button.app-voice-listening .ti-microphone {
  animation: app-voice-pulse 1.2s ease-in-out infinite;
}

.app-voice-status {
  min-width: 0;
}

@keyframes app-voice-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.18);
    opacity: 0.65;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-voice-button.app-voice-listening .ti-microphone {
    animation: none;
  }
}

/*
 * Ticket 040: the activity trail groups every entry of one operation inside a connected block.
 * The group reads as a unit (accented edge, indented entries) on desktop and simply stacks on
 * phones; no entry text ever forces horizontal overflow because descriptions wrap.
 */
.app-activity-group {
  border-inline-start: 3px solid var(--tblr-border-color);
}

.app-activity-entries {
  margin-inline-start: 0.75rem;
  display: grid;
  gap: 0.5rem;
}

.app-activity-entry {
  min-width: 0;
}

.app-activity-description {
  overflow-wrap: anywhere;
}

.app-activity-json summary {
  cursor: pointer;
  user-select: none;
}

.app-activity-json-block {
  padding: 0.5rem;
  border-radius: var(--tblr-border-radius);
  background: var(--tblr-bg-surface-secondary);
  font-size: 0.75rem;
  overflow-x: auto;
  max-height: 16rem;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-inline-end: 0.5rem;
}

/* Provenance affordances ("Generó: …", "Desde nota") sit inside metadata lines. */
.app-provenance-link {
  white-space: nowrap;
}

/* Ticket 040: the row a provenance focus link points at is highlighted without edit mode. */
.app-focus-highlight {
  border-inline-start: 3px solid var(--tblr-primary);
  background: var(--tblr-active-bg, var(--tblr-bg-surface-secondary));
  animation: app-focus-fade 1.6s ease-out 1;
}

@keyframes app-focus-fade {
  0% {
    background: var(--tblr-primary-lt);
  }

  100% {
    background: var(--tblr-bg-surface);
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-focus-highlight {
    animation: none;
  }
}
