/* Small-screen adaptations for GranaNexo 2.6.1. Theme colors stay owned by #app. */
@media (max-width: 600px) {
  #app {
    --mobile-gutter: clamp(12px, 4vw, 20px);
    --mobile-left: max(var(--mobile-gutter), env(safe-area-inset-left, 0px));
    --mobile-right: max(var(--mobile-gutter), env(safe-area-inset-right, 0px));
    --mobile-bottom: env(safe-area-inset-bottom, 0px);
    min-height: 100vh;
    min-height: 100dvh;
  }
  #app > header {
    padding: max(8px, env(safe-area-inset-top, 0px)) var(--mobile-right) 8px var(--mobile-left);
    min-height: 60px;
  }
  #app > header > .row:first-child,
  #app > header > .row:first-child > :last-child { min-width: 0; }
  #app > header > .row:last-child, #app > header .logo { flex-shrink: 0; }
  #app .account-label { max-width: min(47vw, 100%); }
  #app > main {
    padding: 14px var(--mobile-right) calc(104px + var(--mobile-bottom)) var(--mobile-left);
  }
  #app > main.auth-shell {
    padding: max(20px, env(safe-area-inset-top, 0px)) var(--mobile-right)
      max(20px, var(--mobile-bottom)) var(--mobile-left);
  }
  #app .auth-shell > .card { padding: clamp(17px, 5vw, 25px); }

  #app button { min-block-size: 44px; }
  #app .iconbtn, #app .period button, #app .item button[data-a="pay"] {
    min-inline-size: 44px;
  }
  #app .item button[data-a="pay"] { padding-inline: 8px; }
  #app input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]), #app select, #app textarea {
    min-block-size: 44px;
    font-size: 16px; /* Keep text in view when focusing fields in mobile Safari. */
  }
  #app label, #app .badge { line-height: 1.4; }
  #app label { font-size: 14px; }
  #app .muted, #app .note, #app .legend { font-size: 13px; }
  #app .account-label { font-size: 12px; }
  #app h3 { font-size: 15px; line-height: 1.35; }
  #app .amount { font-size: 14px; }
  #app .note, #app .legend, #app .share-actions,
  #app .card h2, #app .credit strong, #app .split strong, #app .item h3 {
    overflow-wrap: anywhere;
  }

  #app > nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    padding: 7px max(5px, env(safe-area-inset-right, 0px))
      max(8px, var(--mobile-bottom)) max(5px, env(safe-area-inset-left, 0px));
  }
  #app > nav button {
    min-inline-size: 0;
    inline-size: 100%;
    padding: 2px 1px;
    gap: 3px;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 12px;
    line-height: 1.25;
  }
  #app > nav .new {
    inline-size: 46px;
    block-size: 46px;
    margin-top: -7px;
  }
  #app .toast { bottom: calc(82px + var(--mobile-bottom)); }

  #app .spacebar { gap: 8px; padding: 8px; }
  #app .spacebar select { font-size: 16px; }
  #app .spacebar button { flex-shrink: 0; }
  #app .quick { inline-size: 100%; min-inline-size: 0; text-align: center; overflow-wrap: anywhere; }
  #app .quick span { max-inline-size: 100%; }
  #app .tabs {
    flex-wrap: wrap;
    overflow: visible;
  }
  #app .tabs > button {
    flex: 1 1 7rem;
    min-inline-size: 0;
    padding-inline: 8px;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 14px;
  }
  #app dialog {
    width: min(94%, 460px);
    max-height: min(90vh, 42rem);
    max-height: min(calc(var(--nexo-visible-height, 100dvh) - max(10px, env(safe-area-inset-top, 0px))
      - max(10px, var(--mobile-bottom))), 42rem);
    padding: 15px;
    overflow: auto;
    overscroll-behavior-y: contain;
    scroll-padding-block: 16px 22px;
  }
  #app .modalhead { margin-bottom: 12px; }
  #app .modalhead h2 { min-width: 0; overflow-wrap: anywhere; }
  #app .card > .row, #app .credit > .between, #app .item { gap: 8px; }
  #app .share-actions > button, #app .chips > button { min-block-size: 44px; }
  #app .spending-chart { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
  #app .spending-chart .donut { inline-size: 124px; block-size: 124px; justify-self: center; }
  #app .spending-chart .donutinner {
    inline-size: 98px; block-size: 98px; padding: 6px; text-align: center;
  }
  #app .spending-chart .donutinner strong { font-size: 13px; overflow-wrap: anywhere; max-inline-size: 100%; }
  #app .spending-chart .legend { font-size: 14px; }
  #app .spending-chart .legend > .between { gap: 10px; align-items: start; }
  #app .spending-chart .legend strong, #app .spending-chart .dot { flex: none; }
  #app dialog form > label { display: block; min-inline-size: 0; }
  #app dialog form :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]) {
    box-sizing: border-box; min-inline-size: 0; max-inline-size: 100%;
  }
  #app .f22-actions > button, #app .f23-actions > button { max-inline-size: 100%; white-space: normal; overflow-wrap: anywhere; }
  #app form .write-progress { overflow-wrap: anywhere; }
}

@media (max-width: 370px) {
  #app {
    --mobile-gutter: 11px;
  }
  #app .grid4 { gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #app .grid2 { gap: 8px; }
  #app .card { padding: 12px; }
  #app .hero, #app .credit { padding: 15px; }
  #app .item { gap: 7px; }
  #app .item .cat { inline-size: 32px; block-size: 32px; font-size: 16px; }
  #app .item .amount { white-space: normal; overflow-wrap: anywhere; }
  #app .item > :last-child:not(button) { max-inline-size: 44%; }
  #app .item > strong.amount { max-inline-size: 34%; }
  #app .card.between > strong { max-inline-size: 46%; overflow-wrap: anywhere; text-align: end; }
  #app .tabs > button { padding-inline: 8px; }
  #app #search > .secondary { padding-inline: 8px; }
}

@media (max-height: 450px) and (orientation: landscape) and (max-width: 950px) {
  #app > header { position: static; }
  #app dialog { max-height: 88dvh; }
  #app > nav { padding-block-start: 3px; }
  #app > nav .new { margin-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #app dialog { scroll-behavior: auto; }
}

/* Keep zoomable forms and long labels usable on a compact installed screen. */
@media (max-width: 600px) {
  #app .auth-shell .muted { font-size: 14px; line-height: 1.5; }
  #app form input, #app form select, #app form textarea { scroll-margin-block: 16px; }
  #app button:focus-visible, #app :is(input,select,textarea,a):focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
  }
  #app .auth-shell a, #app .legal-links a, #app .docs-links a {
    min-block-size: 44px;
    display: inline-flex;
    align-items: center;
  }
}

@media (max-width: 600px) {
  #app { min-inline-size: 0; }
  #app > header > .row:first-child { flex: 1 1 auto; }
  #app > header > .row:last-child { gap: 5px; }
  #app > header .brand { overflow-wrap: anywhere; }
  #app .account-label { max-inline-size: min(100%, 47vw); }
  #app > main > *, #app .stack > *, #app .grid2 > *, #app .grid4 > *,
  #app dialog > *, #app dialog .row > *, #app .between > *, #app #search > input,
  #app #chat > input { min-inline-size: 0; }
  #app .stack, #app .modal-list { grid-template-columns: minmax(0, 1fr); }
  #app .between > button, #app #search > button, #app #chat > button,
  #app dialog .row > button { flex: 0 0 auto; max-inline-size: 100%; }
  #app .card p, #app .hero .big, #app .card > .between > strong,
  #app .credit .between strong, #app .metric, #app .amount,
  #app dialog .formerror, #app dialog .result, #app .syncbar,
  #app .checkline > span, #app .share-row span {
    overflow-wrap: anywhere;
  }
  #app .amount { white-space: normal; }
  #app dialog, #app dialog form, #app .tabs { max-inline-size: 100%; }
  #app dialog .row:not(.modalhead), #app .card > .row, #app .syncbar,
  #app .advice .row { flex-wrap: wrap; }
  #app #search, #app #chat { flex-wrap: nowrap; }
  #app .item > :last-child:not(button) { min-inline-size: 0; max-inline-size: 44%; }
  #app input[type="file"] { inline-size: 100%; max-inline-size: 100%; }
  #app input[type="checkbox"], #app input[type="radio"] {
    inline-size: 20px; block-size: 20px; flex: 0 0 auto;
  }
  #app .checkline, #app .share-row label.row, #app dialog summary {
    min-block-size: 44px;
  }
  #app .docs-links { gap: 3px 14px; }
  #app .gn-action, #app .share-actions > button {
    max-inline-size: 100%; overflow-wrap: anywhere; white-space: normal;
    min-inline-size: 44px; text-align: start;
  }
}

@media (max-width: 360px) {
  #app > header .secondary { padding-inline: 9px; }
  #app .period { padding-inline: 5px; }
  #app .spacebar { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  #app dialog .grid2 { grid-template-columns: minmax(0, 1fr); }
  #app .item > strong.amount { max-inline-size: 32%; }
  #app .card > .between > button { padding-inline: 6px; }
}
