/* Errandry on a phone: top bar, five tabs, rows instead of tables, sheets for popups */
@media (max-width: 760px) {
  :root { --tabs: calc(64px + env(safe-area-inset-bottom, 0px)); }
  body.app-body { font-size: 15.5px; }
  .app-body .demo-bar { position: static; }
  .m-bar { position: sticky; top: 0; z-index: 12; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 0 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
  .m-bar span { flex: 1; min-width: 0; font: 700 19px/1.2 var(--head); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .m-bar small { color: var(--ink-2); font-size: 12.5px; text-align: right; }
  .m-back { display: grid; place-items: center; width: 44px; height: 44px; margin-left: -10px; color: var(--ink); }
  .m-back .icon { width: 24px; height: 24px; }
  .m-tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 14; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: var(--tabs); padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--surface); border-top: 1px solid var(--line); }
  .m-tabs a { position: relative; display: grid; place-content: center; justify-items: center; gap: 3px; color: var(--ink-2); font-size: 12px; font-weight: 700; text-decoration: none; }
  .m-tabs a .icon { width: 22px; height: 22px; }
  .m-tabs a.is-active { color: var(--accent-dark); }
  .m-tabs a.is-active .icon { width: 46px; height: 28px; padding: 3px 12px; border-radius: 99px; background: var(--accent-tint); }
  .m-tabs a:not(.is-active) .icon { margin: 3px 0; }
  .m-tabs .badge { position: absolute; top: 5px; left: calc(50% + 8px); font-size: 12px; min-width: 18px; height: 18px; }
  .fab { position: fixed; right: 16px; bottom: calc(var(--tabs) + 14px); z-index: 13; display: grid; place-items: center; width: 56px; height: 56px; border: 0; border-radius: 18px; background: var(--accent); color: #fff; box-shadow: 0 12px 24px -10px rgba(74, 44, 2, .7); }
  .fab .icon { width: 26px; height: 26px; }
  .jump { position: fixed; right: 14px; bottom: calc(var(--tabs) + 14px); z-index: 13; display: flex; align-items: center; gap: 8px; min-height: 50px; padding: 0 18px; border: 0; border-radius: 99px; background: var(--navy); color: #fff; font-weight: 700; box-shadow: 0 12px 24px -10px rgba(44, 36, 26, .7); }
  .main.m-main { padding: 16px 14px calc(var(--tabs) + 86px); }
  .main > * + * { margin-top: 14px; }
  .page-head h1 { font-size: 24px; }
  .page-head p { font-size: 14.5px; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; min-height: 46px; white-space: nowrap; }
  .head-actions .pill { justify-self: start; }
  .head-new { display: none; }
  .head-actions:has(> .head-new:only-child) { display: none; }
  .btn { min-height: 46px; white-space: nowrap; }
  .btn-small { min-height: 40px; }
  .crumb { display: none; }
  .main > .crumb + * { margin-top: 0; }
  .card { padding: 14px; }
  .two, .two.wide-left, .detail, .browse, .searchhead { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .searchhead h1 { font-size: 25px; }
  .searchhead { gap: 10px; }
  .cats { display: flex; gap: 10px; overflow-x: auto; margin-inline: -14px; padding: 2px 14px !important; scrollbar-width: none; }
  .cat { display: grid; grid-template-columns: minmax(0, 1fr); flex: none; width: 138px; }
  .cat img { height: auto; min-height: 0; aspect-ratio: 16 / 9; }
  .cat b { font-size: 14.5px; }
  .m-filterbar { display: flex; gap: 8px; margin-bottom: -4px; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .listing { gap: 14px; }
  .banner { height: 170px; }
  .banner.short { height: 130px; }
  .bookpanel { padding: 14px; scroll-margin-top: 66px; }
  .dayb { width: 62px; }
  .slot { min-height: 50px; }
  .listing-more { grid-column: 1; }
  .stats, .stats.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats > div { padding: 11px 12px; border-top: 1px solid var(--line); }
  .stats > div:nth-child(odd) { border-left: 0; }
  .stats > div:nth-child(-n+2) { border-top: 0; }
  .stats.three > div:last-child { grid-column: 1 / -1; }
  .stats dt, .stats small { font-size: 13px; }
  .stats dd { font-size: 21px; }
  .blist a { gap: 10px; padding: 10px; align-items: flex-start; }
  .blist .thumb { width: 54px; height: 54px; }
  .blist-side { gap: 4px; }
  .blist a { display: grid; grid-template-columns: 54px minmax(0, 1fr); }
  .blist a > .thumb { grid-row: span 2; }
  .blist-side { grid-column: 2; display: flex; justify-content: space-between; align-items: center; }
  .tight .blist a { grid-template-columns: minmax(0, 1fr); }
  .tight .blist-side { grid-column: 1; }
  .todo a { gap: 10px; padding: 10px; }
  .agenda a { grid-template-columns: 68px minmax(0, 1fr); row-gap: 2px; }
  .agenda .pill { grid-column: 2; justify-self: start; }
  .rows { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
  .rows li + li { border-top: 1px solid var(--line); }
  .rows li > * { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 62px; padding: 10px 13px; color: var(--ink); text-decoration: none; }
  .row-main { display: grid; min-width: 0; line-height: 1.35; }
  .row-main small { color: var(--ink-2); font-size: 13px; }
  .row-side { display: grid; justify-items: end; gap: 4px; flex: none; text-align: right; font-variant-numeric: tabular-nums; }
  .row-side small { color: var(--ink-2); font-size: 12.5px; }
  .toolbar { display: grid; grid-template-columns: minmax(0, 1fr); }
  .toolbar .tabs, .main > .tabs:not(.cats) { margin-inline: -14px; padding-inline: 14px; max-width: calc(100% + 28px) !important; }
  .tab { min-height: 44px; }
  .inline-search input, .toolbar select { height: 46px; min-height: 46px; }
  .track li { font-size: 12px; }
  .track i { width: 30px; height: 30px; }
  .track li + li::before { top: 14px; right: calc(50% + 17px); width: calc(100% - 34px); }
  .nextstep .actions .btn, .card > .actions .btn { flex: 1 1 140px; }
  .profile-head { align-items: flex-start; gap: 12px; }
  .avatar.big { width: 54px; height: 54px; font-size: 20px; }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .pane { padding: 14px; }
  .pane-head { flex-wrap: wrap; }
  .pane .thread { min-height: 0; max-height: none; }
  .thread { max-height: none; }
  .composer input { min-height: 46px; }
  .composer .btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .field input, .field select, .field textarea { min-height: 46px; font-size: 16px; }
  .pair { grid-template-columns: minmax(0, 1fr); }
  .daychecks { gap: 4px; }
  .daychecks span { font-size: 12.5px; }
  .week7 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .weekchart .xc { --xc-h: 170px; }
  .weekchart .xc-frame { grid-template-columns: 34px minmax(0, 1fr); column-gap: 4px; }
  .weekchart .xc-xlabels span:nth-child(odd) { visibility: hidden; }
  .weekchart .xc-xlabels span { font-size: 12px; white-space: nowrap; overflow: visible; }
  .xc-ticks b, .xc-yaxis b, .xc-axisname, .xc-label, .xc-val, .xc-legend { font-size: 12px !important; }
  .xc-colbar em { font-size: 12px !important; }
  .xc-row { grid-template-columns: 96px minmax(0, 1fr) 62px !important; column-gap: 8px !important; }
  .xc-xaxis { grid-template-columns: 96px minmax(0, 1fr) 62px !important; column-gap: 8px !important; }
  .xc-ticks b:nth-child(even) { display: none; }
  .badge, .pill, .dayb small, .dayb em, .slot small { font-size: 12px; }
  .ledger.sum { max-width: none; }
  .who { display: flex; gap: 12px; align-items: center; }
  .who div { display: grid; }
  .who small { color: var(--ink-2); font-size: 13.5px; }
  .morelist { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
  .morelist li + li { border-top: 1px solid var(--line); }
  .morelist a, .morelist button { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 0 14px; border: 0; background: none; color: var(--ink); font-weight: 700; text-align: left; text-decoration: none; cursor: pointer; }
  .morelist span { flex: 1; }

  /* Popups slide up from the bottom */
  dialog { position: fixed; inset: auto 0 0 0; width: 100%; max-width: 100%; margin: 0; max-height: calc(100dvh - 40px); border-radius: 20px 20px 0 0; }
  dialog form { max-height: calc(100dvh - 40px); }
  dialog[open] { animation: m-up .24s cubic-bezier(.2, .8, .2, 1); }
  dialog .modal-head { position: relative; padding-top: 20px; }
  dialog .modal-head::before { content: ""; position: absolute; top: 8px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 99px; background: var(--line-2); }
  dialog .icon-btn { width: 44px; height: 44px; }
  dialog .modal-foot > .btn { flex: 1; min-height: 50px; }
  dialog .modal-foot > .btn[type="submit"] { flex: 1.7; white-space: normal; }
  .toasts { left: 12px; right: 12px; max-width: none; bottom: calc(var(--tabs) + 82px); }

  /* Role screen: all three roles are visible at once */
  .signin { padding: 22px 16px 32px; }
  .signin .roles { gap: 10px; margin-top: 18px; }
  .signin h1 { margin-top: 18px; font-size: 24px; text-wrap: balance; }
  .signin-sub { font-size: 14.5px; }
  .signin .role-points { display: none; }
  .signin .role { display: grid; grid-template-columns: 46px minmax(0, 1fr) 10px; grid-template-areas: "ico title go" "ico name go" "ico short go"; align-content: center; align-items: center; column-gap: 14px; height: auto; min-height: 100px; padding: 14px; }
  .signin .role::after { content: ""; grid-area: go; width: 8px; height: 8px; border: solid currentColor; border-width: 2px 2px 0 0; transform: rotate(45deg); opacity: .55; }
  .signin .role-icon { grid-area: ico; }
  .signin .role-title { grid-area: title; margin: 0; font-size: 18px; }
  .signin .role-name { grid-area: name; font-size: 14px; }
  .signin .role-short { grid-area: short; display: block; font-size: 13.5px; line-height: 1.35; color: var(--ink-2); }
}
@media (max-width: 380px) {
  .slots { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .m-bar small { display: none; }
  .stats dd { font-size: 19px; }
  .week7 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .daychecks { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 761px) { .m-filterbar { display: flex; } }
body.is-grabbing, body.is-grabbing * { cursor: grabbing !important; }
.tabs, .table-wrap { -webkit-overflow-scrolling: touch; }
@keyframes m-up { from { transform: translateY(40px); opacity: .4; } }

/* Desktop and phone switch in the demo bar */
.view-switch { display: none; }
.preview { display: none; }
@media (min-width: 900px) {
  .view-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 99px; background: rgba(74, 44, 2, .13); }
  .view-switch button { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 13px; border: 0; border-radius: 99px; background: none; color: #4a2c02; font-size: 13.5px; font-weight: 700; cursor: pointer; }
  .view-switch button .icon { width: 15px; height: 15px; }
  .view-switch button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 3px rgba(74, 44, 2, .25); }

  .app-body.is-preview { background: #ece7df; }
  .is-preview #app, .is-preview > dialog, .is-preview .toasts { display: none; }
  .is-preview .preview { display: flex; align-items: center; justify-content: center; gap: clamp(32px, 6vw, 96px); min-height: calc(100vh - var(--bar)); padding: 20px 32px; }
  .preview-notes { max-width: 360px; }
  .preview-notes h2 { font: 700 clamp(28px, 2.8vw, 38px)/1.12 var(--head); }
  .preview-notes > p { margin-top: 10px; color: var(--ink-2); font-size: 17px; }
  .preview-notes ul { margin-top: 20px; border-top: 1px solid var(--line-2); }
  .preview-notes li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-2); }
  .preview-notes li .icon { margin-top: 2px; color: var(--accent); }

  .device { --h: 844px; flex: none; width: 414px; padding: 11px; border-radius: 56px; background: #141517; box-shadow: 0 40px 70px -30px rgba(20, 21, 23, .65), inset 0 0 0 2px #45474c; }
  .device-screen { position: relative; display: flex; flex-direction: column; width: 392px; height: var(--h); border-radius: 45px; overflow: hidden; background: var(--surface); isolation: isolate; }
  .device-status { display: flex; align-items: center; justify-content: space-between; flex: none; height: 44px; padding: 0 30px; background: var(--surface); font-size: 15px; font-weight: 700; }
  .device-status::after { content: ""; width: 25px; height: 12px; border: 1.5px solid var(--ink); border-radius: 4px; background: linear-gradient(var(--ink), var(--ink)) 2px 50% / 16px 6px no-repeat; }
  .device-island { position: absolute; top: 10px; left: 50%; width: 108px; height: 26px; margin-left: -54px; border-radius: 99px; background: #141517; }
  .device iframe { flex: 1; width: 100%; min-height: 0; border: 0; background: var(--bg); }
  .device-home { flex: none; height: 12px; background: var(--surface); }
}

@media (max-width: 760px) {
  /* Role screen: both roles are visible at once, each as one large row */
  .signin .roles { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 22px; }
  .signin h1 { margin-top: 22px; font-size: 25px; text-wrap: balance; }
  .signin-sub { margin-inline: auto; font-size: 15px; text-wrap: balance; }
  .signin .role-points, .signin .role-org { display: none; }
  .signin .role { display: grid; grid-template-columns: 46px minmax(0, 1fr) 10px; grid-template-areas: "ico title go" "ico name go" "ico short go"; align-content: center; align-items: center; column-gap: 14px; row-gap: 1px; height: auto; min-height: 104px; padding: 16px; text-align: left; }
  .signin .role::after { content: ""; grid-area: go; width: 8px; height: 8px; border: solid currentColor; border-width: 2px 2px 0 0; transform: rotate(45deg); opacity: .55; }
  .signin .role-icon { grid-area: ico; align-self: center; }
  .signin .role-title { grid-area: title; margin: 0; font-size: 18px; line-height: 1.25; }
  .signin .role-name { grid-area: name; font-size: 14px; line-height: 1.35; }
  .signin .role-short { grid-area: short; display: block; font-size: 13.5px; line-height: 1.35; color: var(--ink-2); }
}

/* Desktop and Mobile switch sits in the exact middle of the bar */
@media (min-width: 900px) {
  .app-body .demo-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .app-body .demo-bar > p { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .app-body .demo-bar > .view-switch { justify-self: center; }
  .app-body .demo-bar > nav { justify-self: end; }
}
