/* Phone layout. Loaded after each page's inline styles so these win at equal specificity. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body {
  max-width: 100%;
  overflow-x: clip;
}
body {
  font-size: 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: env(safe-area-inset-top);
  background: #4f46e5;
}
.topbar header,
.topbar nav { position: static; }

header {
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: nowrap;
  gap: 8px;
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-left: calc(18px + env(safe-area-inset-left));
  padding-right: calc(18px + env(safe-area-inset-right));
}
.topbar header { padding-top: 14px; }
header h1 { min-width: 0; flex: 0 0 auto; white-space: nowrap; }
header span {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  flex: 1 1 auto;
  justify-content: flex-end;
}
header small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
header button { flex: 0 0 auto; white-space: nowrap; }

nav {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-left: calc(6px + env(safe-area-inset-left));
  padding-right: calc(6px + env(safe-area-inset-right));
}
nav::-webkit-scrollbar { display: none; height: 0; }
nav button {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 14px;
  font-size: 16px;
}

main {
  width: 100%;
  max-width: min(1000px, 100%);
  padding: 16px;
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.auth { max-width: min(380px, 100%); }
main.legal { max-width: min(720px, 100%); }

.card, #taxout, #remlog {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: clip;
  -webkit-overflow-scrolling: touch;
}
.row, .grid, .no-print { max-width: 100%; min-width: 0; }
.row > * { min-width: 0; }
.no-print { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

table { width: max-content; min-width: 100%; }
td, th, p, li, small, h1, h2, .banner, .stripe { overflow-wrap: anywhere; }
img, svg, video, canvas { max-width: 100%; }
img.th { width: 48px; height: 48px; max-width: 48px; }

button, a.b, summary, label.b {
  min-height: 44px;
  min-width: 44px;
}
button.b, button.s, button.sm, a.b, label.b {
  padding: 10px 14px;
  font-size: 16px;
  line-height: 1.2;
  max-width: 100%;
  white-space: normal;
}
a.b, label.b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
summary { display: flex; align-items: center; cursor: pointer; }

input:not([type=checkbox]):not([type=radio]):not([type=hidden]),
select, textarea {
  font-size: 16px;
  max-width: 100%;
}
input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=file]),
select {
  min-height: 44px;
}
textarea { min-height: 88px; }
input[type=file] { font-size: 16px; min-height: 44px; }
label:has(> input[type=checkbox]),
label:has(> input[type=radio]) {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
}

dialog {
  width: min(480px, calc(100vw - 16px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: auto;
  overscroll-behavior: contain;
  margin: auto;
}
dialog .row { flex-wrap: wrap; }
dialog .row > button, dialog .row > .b { flex: 1 1 auto; }

@media print {
  html, body { overflow: visible !important; }
  .topbar, header { position: static; }
  .card, #taxout, #remlog { overflow: visible !important; }
  table { width: 100% !important; }
}
