/* Small-screen adaptations for Somar 2.4. 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(94px + 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"]), #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: nowrap;
    font-size: clamp(10px, 3.05vw, 12px);
  }
  #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 {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: inline proximity;
  }
  #app .tabs > button {
    flex: 1 0 auto;
    scroll-snap-align: start;
    padding-inline: 10px;
  }
  #app dialog {
    width: min(94%, 460px);
    max-height: min(90vh, 42rem);
    max-height: min(calc(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; }
}

@media (max-width: 370px) {
  #app {
    --mobile-gutter: 11px;
  }
  #app .grid4 { gap: 5px; }
  #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 .donut { inline-size: 84px; block-size: 84px; }
  #app .donutinner { inline-size: 64px; block-size: 64px; text-align: center; }
  #app .donutinner .muted, #app .donutinner strong { font-size: 11px; overflow-wrap: anywhere; max-inline-size: 63px; }
  #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 .tabs, #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 {
    min-block-size: 44px;
    display: inline-flex;
    align-items: center;
  }
}
