/* Cebivo responsive hardening — 2026-09-09
   Keeps the app usable while the browser window is continuously resized. */

html,
body,
#root {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

html {
  overflow-x: hidden;
}

body {
  min-width: 0;
  overflow-x: clip;
}

img,
svg,
canvas,
video {
  max-width: 100%;
}

.app-shell,
.main-column,
.content,
.dashboard-stack,
.reference-overview,
.metric-grid,
.account-grid,
.settings-grid,
.cards-layout,
.two-column,
.surface,
.surface > *,
.card-heading > *,
.page-heading > * {
  min-width: 0;
}

.content {
  container-type: inline-size;
}

.page-heading,
.heading-actions,
.card-heading,
.preference-row,
.photo-editor,
.modal-actions {
  max-width: 100%;
}

.page-heading {
  flex-wrap: wrap;
}

.heading-actions,
.card-heading {
  flex-wrap: wrap;
}

.card-heading > div,
.preference-heading > div,
.photo-editor > div,
.install-tip > div {
  min-width: 0;
}

.card-heading h2,
.card-heading p,
.settings-card h2,
.settings-card p,
.account-card h2,
.preference-row span,
.preference-row strong,
.install-tip strong,
.install-tip p,
.manage-row span {
  overflow-wrap: anywhere;
}

.monetary-value,
.amount,
.expense-total,
.bank-card-amount,
.account-card > strong,
.distribution-bars strong,
.budget-row strong {
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* Forms and controls must remain tappable/clickable even when space is tight. */
button,
input,
select,
textarea {
  min-width: 0;
}

.primary-button,
.secondary-button,
.danger-button,
.filter-button,
.icon-button,
.account-open,
.mobile-profile-trigger {
  flex-shrink: 0;
}

.field,
.setting-field,
.modal-form,
.modal-form label,
.settings-card form {
  min-width: 0;
  max-width: 100%;
}

.field input,
.setting-field input,
.setting-field select,
.modal-form input,
.modal-form select,
textarea {
  width: 100%;
  max-width: 100%;
}

/* Charts and large cards should shrink with the container, not force page overflow. */
.bar-chart-wrap,
.reference-chart,
.chart-card,
.shared-card-list,
.bank-card,
.credit-card-visual {
  min-width: 0;
  max-width: 100%;
}

.reference-chart .recharts-responsive-container,
.reference-chart svg,
.chart-card .recharts-responsive-container,
.chart-card svg {
  max-width: 100% !important;
}

/* Desktop auth stays 60/40, but content may scroll vertically on short windows. */
.auth-light {
  width: 100%;
  height: auto;
  min-height: 100svh;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
}

.auth-shell {
  width: 100%;
  height: auto;
  min-height: 100svh;
  max-height: none;
  overflow: visible;
  grid-template-columns: minmax(0, 3fr) minmax(340px, 2fr);
}

.auth-illustration {
  min-width: 0;
}

.auth-shell .auth-panel {
  width: 100%;
  height: auto;
  min-height: 100svh;
  max-height: none;
  overflow: visible;
}

.auth-shell .auth-card,
.auth-shell .auth-form,
.auth-shell .auth-form > *,
.auth-shell .consent-row,
.auth-shell .auth-message {
  min-width: 0;
  max-width: 100%;
}

.auth-shell .auth-message,
.auth-shell .consent-row > span,
.auth-switch,
.check-label {
  overflow-wrap: anywhere;
}

/* Prevent Cloudflare Turnstile from pushing very narrow screens sideways. */
.turnstile-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.turnstile-widget,
.turnstile-widget iframe {
  max-width: 100%;
}

/* Medium desktop / resized Chrome window. */
@media (max-width: 1200px) {
  .search-box {
    width: clamp(170px, 23vw, 220px);
  }

  .profile-copy {
    min-width: 0;
  }

  .profile-copy strong {
    max-width: 130px;
  }

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

  .reference-cards {
    grid-area: auto;
  }

  .reference-goals {
    grid-area: auto;
  }

  .reference-chart {
    grid-column: 1 / -1;
  }
}

/* Tablet / narrow browser: switch to the mobile navigation before the desktop
   sidebar becomes cramped. */
@media (max-width: 900px) {
  .content {
    width: 100%;
    padding-left: clamp(16px, 3vw, 22px);
    padding-right: clamp(16px, 3vw, 22px);
  }

  .topbar {
    min-width: 0;
  }

  .top-actions,
  .profile-button {
    min-width: 0;
  }

  .profile-copy strong {
    max-width: 100px;
  }

  .reference-overview,
  .cards-layout,
  .account-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .reference-chart {
    grid-column: 1 / -1;
  }

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

  .metric-card {
    min-width: 0;
  }

  .mobile-nav {
    width: 100%;
    min-width: 0;
  }

  .mobile-nav button {
    min-width: 0;
    min-height: 50px;
    touch-action: manipulation;
  }

  /* Auth becomes one-column at the same point the available form width becomes
     more important than preserving the illustration. */
  .auth-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-illustration {
    display: none;
  }

  .auth-shell .auth-panel {
    min-height: 100svh;
    padding-left: clamp(18px, 5vw, 30px);
    padding-right: clamp(18px, 5vw, 30px);
  }
}

/* Small tablet / large phone. */
@media (max-width: 700px) {
  .auth-light,
  .auth-shell,
  .auth-shell .auth-panel {
    height: auto;
    min-height: 100svh;
    max-height: none;
  }

  .auth-light,
  .auth-shell,
  .auth-shell .auth-panel,
  .auth-shell .auth-card {
    overflow: visible;
  }

  .auth-shell .auth-panel {
    align-items: center;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  .auth-shell .auth-card {
    width: min(100%, 420px);
    max-height: none;
  }

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

  .auth-register .auth-form > * {
    grid-column: 1;
  }
}

@media (max-width: 620px) {
  .content {
    padding-left: 16px;
    padding-right: 16px;
  }

  .page-heading {
    gap: 12px;
    align-items: center;
  }

  .heading-actions {
    margin-left: auto;
  }

  .reference-overview,
  .cards-layout,
  .account-grid,
  .settings-grid,
  .metric-grid,
  .two-column,
  .overview-grid,
  .overview-grid.lower {
    grid-template-columns: minmax(0, 1fr);
  }

  .reference-cards,
  .reference-goals,
  .reference-chart {
    grid-area: auto;
    grid-column: auto;
  }

  .surface,
  .reference-overview > article {
    max-width: 100%;
  }

  .metric-card {
    width: 100%;
  }

  .transaction-row {
    grid-template-columns: 32px minmax(0, 1fr) minmax(0, auto);
  }

  .transaction-copy,
  .transaction-copy strong,
  .transaction-copy span {
    min-width: 0;
    max-width: 100%;
  }

  .transaction-copy strong {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .transaction-row .amount {
    max-width: min(34vw, 130px);
    text-align: right;
  }

  .bank-card,
  .credit-card-visual {
    width: 100%;
    min-width: 0;
  }

  .budget-row > div:first-child,
  .budget-row p,
  .bank-card-footer,
  .bank-card-details dl > div {
    min-width: 0;
    flex-wrap: wrap;
  }

  .modal-backdrop {
    padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  }

  .modal-card {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .modal-head,
  .modal-form {
    padding: 18px;
  }
}

/* Very narrow Chrome windows / small phones. */
@media (max-width: 480px) {
  .content {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar {
    padding-left: 12px;
    padding-right: 12px;
    gap: 8px;
  }

  .top-actions .profile-copy {
    display: none;
  }

  .top-actions .profile-button {
    gap: 0;
    padding-left: 0;
  }

  .page-heading h1 {
    font-size: clamp(18px, 6vw, 20px);
  }

  .card-heading {
    align-items: flex-start;
  }

  .surface,
  .reference-overview > article,
  .list-card,
  .chart-card,
  .spending-card,
  .recent-card,
  .goals-mini-card,
  .centered-card,
  .table-card,
  .settings-grid .settings-card {
    padding-left: 16px;
    padding-right: 16px;
  }

  .photo-editor {
    align-items: flex-start;
  }

  .preference-row {
    align-items: flex-start;
  }

  .preference-row > strong,
  .preference-row .language-picker {
    margin-left: 0;
  }

  .distribution-bars > div,
  .account-summary .distribution-bars > div {
    grid-template-columns: minmax(64px, 1fr) minmax(46px, 1.4fr) minmax(78px, auto);
    gap: 6px;
  }

  .distribution-bars > div > span,
  .distribution-bars > div > strong {
    overflow-wrap: anywhere;
  }

  .install-tip {
    grid-template-columns: 38px minmax(0, 1fr) 28px;
    gap: 10px;
  }

  .auth-shell .auth-panel {
    padding-left: 16px;
    padding-right: 16px;
  }

  .auth-shell .auth-form {
    gap: 12px;
    margin-top: 18px;
  }

  .auth-shell .auth-heading h2 {
    font-size: 19px;
  }

  .auth-shell .auth-heading p,
  .auth-shell .auth-form > label,
  .auth-shell .auth-message {
    overflow-wrap: anywhere;
  }

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

  .modal-actions .primary-button,
  .modal-actions .secondary-button,
  .modal-actions .danger-button {
    width: 100%;
  }
}

/* Icon-only bottom navigation when the browser becomes extremely narrow.
   Labels remain in the accessibility tree. */
@media (max-width: 340px) {
  .content {
    padding-left: 12px;
    padding-right: 12px;
  }

  .mobile-nav {
    padding-left: 4px;
    padding-right: 4px;
  }

  .mobile-nav button {
    min-height: 52px;
    position: relative;
    place-items: center;
    padding: 4px 2px;
  }

  .mobile-nav button span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .mobile-nav button svg {
    width: 22px;
    height: 22px;
  }

  .page-heading {
    gap: 8px;
  }

  .heading-actions .primary-button {
    width: 40px;
    min-width: 40px;
    padding: 0;
    font-size: 0;
  }

  .surface,
  .reference-overview > article,
  .list-card,
  .chart-card,
  .spending-card,
  .recent-card,
  .goals-mini-card,
  .centered-card,
  .table-card,
  .settings-grid .settings-card {
    padding-left: 14px;
    padding-right: 14px;
  }

  .distribution-bars > div,
  .account-summary .distribution-bars > div {
    grid-template-columns: minmax(54px, 1fr) minmax(38px, 1fr) minmax(68px, auto);
    font-size: 11px;
  }

  .transaction-row {
    grid-template-columns: 30px minmax(0, 1fr) minmax(0, auto);
    gap: 7px;
  }

  .transaction-row .amount {
    max-width: 92px;
    font-size: 12px;
  }

  .auth-shell .auth-panel {
    padding-left: 12px;
    padding-right: 12px;
  }

  .auth-shell .field,
  .auth-shell .auth-submit {
    min-height: 44px;
  }

  .turnstile-wrap {
    justify-content: flex-start;
  }
}

/* Short landscape windows: never trap form controls below an invisible edge. */
@media (max-height: 720px) {
  .auth-light,
  .auth-shell,
  .auth-shell .auth-panel {
    height: auto;
    min-height: 100svh;
    max-height: none;
    overflow: visible;
  }

  .auth-shell .auth-panel {
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .auth-shell .auth-form {
    gap: 10px;
    margin-top: 14px;
  }

  .auth-shell .auth-switch {
    margin-top: 12px;
    padding-top: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}

/* Month navigation: keep the existing Cebivo date treatment; only the controls are interactive. */
.date-month-control {
  position: relative;
  gap: 6px;
  white-space: nowrap;
}

.month-nav-button,
.month-label-button {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: inherit;
  cursor: pointer;
  margin: 0;
  padding: 0;
  font: inherit;
}

.month-nav-button {
  display: inline-grid;
  place-items: center;
  width: 20px;
  min-width: 20px;
  height: 20px;
  line-height: 1;
  font-size: 19px;
  border-radius: 0;
}

.month-label-button {
  white-space: nowrap;
  line-height: 1.2;
}

.month-nav-button:hover,
.month-label-button:hover {
  color: var(--foreground);
}

.month-nav-button:focus-visible,
.month-label-button:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.month-picker-input {
  position: absolute !important;
  width: 1px !important;
  min-width: 1px !important;
  height: 1px !important;
  opacity: 0;
  pointer-events: none;
  clip-path: inset(50%);
  overflow: hidden;
}

@media (max-width: 390px) {
  .date-month-control {
    gap: 4px;
  }

  .month-nav-button {
    width: 18px;
    min-width: 18px;
  }
}

/* Cebivo month picker: minimal, borderless controls with a lightweight month/year surface. */
.date-pill.date-month-control {
  position: relative;
  overflow: visible;
}

.month-label-button {
  font-weight: 600;
  transition: color 160ms ease, opacity 160ms ease;
}

.month-picker-popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 120;
  width: 252px;
  max-width: calc(100vw - 28px);
  padding: 14px 14px 12px;
  background: var(--card);
  color: var(--foreground);
  border: 0;
  border-radius: 14px;
  box-shadow: 0 18px 44px rgba(11, 31, 27, 0.14), 0 2px 10px rgba(11, 31, 27, 0.06);
  transform-origin: top right;
  animation: cebivo-month-picker-in 140ms ease-out;
}

.month-picker-year {
  display: grid;
  grid-template-columns: 30px 1fr 30px;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.month-picker-year strong {
  text-align: center;
  font-size: 14px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.month-year-nav,
.month-choice,
.month-current-link {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.month-year-nav {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--muted-foreground);
  font-size: 19px;
  line-height: 1;
  border-radius: 8px;
}

.month-year-nav:hover {
  color: var(--foreground);
  background: var(--accent);
}

.month-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px 6px;
}

.month-choice {
  position: relative;
  min-height: 36px;
  padding: 7px 4px 9px;
  border-radius: 8px;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 550;
  line-height: 1;
  text-align: center;
  transition: color 140ms ease, background 140ms ease;
}

.month-choice:hover {
  color: var(--foreground);
  background: var(--accent);
}

.month-choice.is-selected {
  color: var(--accent-foreground);
  font-weight: 750;
  background: transparent;
}

.month-choice.is-selected::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: var(--accent-foreground);
  transform: translateX(-50%);
}

.month-current-link {
  display: block;
  width: max-content;
  margin: 10px auto 0;
  padding: 4px 2px 1px;
  color: var(--accent-foreground);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.2;
}

.month-current-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.month-year-nav:focus-visible,
.month-choice:focus-visible,
.month-current-link:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

@keyframes cebivo-month-picker-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 700px) {
  .date-pill.date-month-control {
    display: flex;
    padding: 0;
    background: transparent;
    border: 0;
    font-size: 12px;
    gap: 4px;
  }

  .date-month-control > svg {
    display: none;
  }

  .month-picker-popover {
    width: min(244px, calc(100vw - 24px));
    top: calc(100% + 8px);
  }
}

@media (max-width: 390px) {
  .month-label-button {
    font-size: 11px;
  }

  .month-picker-popover {
    right: -4px;
    padding: 12px 12px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .month-picker-popover {
    animation: none;
  }
}

/* Month header optical alignment: keep the label exactly centered between equal arrow zones. */
.date-pill.date-month-control {
  display: grid;
  grid-template-columns: 22px minmax(92px, auto) 22px;
  align-items: center;
  column-gap: 6px;
}

.date-month-control > svg {
  display: none;
}

.date-month-control .month-nav-button {
  width: 22px;
  min-width: 22px;
  height: 22px;
  line-height: 22px;
  align-self: center;
  justify-self: center;
}

.date-month-control .month-label-button {
  min-width: 92px;
  height: 22px;
  line-height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  justify-self: center;
  text-align: center;
  padding: 0;
}

@media (max-width: 700px) {
  .date-pill.date-month-control {
    display: grid;
    grid-template-columns: 20px minmax(88px, auto) 20px;
    align-items: center;
    column-gap: 4px;
  }

  .date-month-control .month-nav-button {
    width: 20px;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
  }

  .date-month-control .month-label-button {
    min-width: 88px;
    height: 20px;
    line-height: 20px;
  }
}

@media (max-width: 390px) {
  .date-pill.date-month-control {
    grid-template-columns: 18px minmax(82px, auto) 18px;
    column-gap: 3px;
  }

  .date-month-control .month-nav-button {
    width: 18px;
    min-width: 18px;
  }

  .date-month-control .month-label-button {
    min-width: 82px;
  }
}
