/* The phone app layout, used below 761px and inside the desktop phone preview. */
@media (max-width: 760px) {
  /* Inside the preview it should feel like a phone: dragging moves the screen instead of selecting text */
  .is-embed { user-select: none; -webkit-user-select: none; }
  .is-embed :is(input, textarea) { user-select: text; -webkit-user-select: text; }
  .app-body.is-embed { --bar: 0px; }
  .is-embed .demo-bar { display: none; }
  html:has(.is-embed) { scrollbar-width: none; }
  html:has(.is-embed)::-webkit-scrollbar { display: none; }
  .m-app { min-height: calc(100vh - var(--bar)); padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  .app-body { --bar: 40px; }
  .m-top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 52px; padding: 0 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
  .m-top .brand { font-size: 19px; }
  .m-top > span { padding: 3px 10px; border-radius: 99px; background: var(--accent-tint); color: var(--accent-dark); font-size: 12.5px; font-weight: 800; }
  .page { padding: 14px 12px 76px; }
  .page > * + * { margin-top: 12px; }
  .page-head h1 { font-size: 23px; }
  .page-head p { font-size: 14px; }
  .page-actions .btn-primary { display: none; }
  .page-actions:empty { display: none; }
  .btn { min-height: 44px; }
  .btn-small { min-height: 40px; }
  .m-tabs { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 5px 2px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line-2); }
  .m-tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 50px; padding-top: 3px; color: var(--ink-2); font-size: 12px; font-weight: 700; text-decoration: none; white-space: nowrap; }
  .m-tabs a > span { position: relative; display: grid; place-items: center; width: 46px; height: 26px; border-radius: 99px; }
  .m-tabs .icon { width: 21px; height: 21px; }
  .m-tabs a.is-active { color: var(--accent-dark); }
  .m-tabs a.is-active > span { background: var(--accent-tint); }
  .m-tabs .nav-count { position: absolute; top: -3px; right: -1px; }
  .fab { position: fixed; z-index: 25; right: 14px; bottom: calc(78px + env(safe-area-inset-bottom)); 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(14, 60, 30, .7); cursor: pointer; }
  .fab .icon { width: 25px; height: 25px; }
  .toasts { left: 12px; right: 12px; bottom: auto; top: 60px; max-width: none; }

  .grid-2, .grid-main, .tpl-list { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .card { padding: 13px 13px; }
  .card-flush { padding: 0; }
  .card-head a { display: inline-flex; align-items: center; min-height: 32px; }
  .summary { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary li:nth-child(odd) { border-left: 0; }
  .summary li:nth-child(n+3) { border-top: 1px solid var(--line); }
  .summary a, .summary div { padding: 10px 13px; }
  .summary strong { font-size: 23px; }
  .pipe { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pipe button { clip-path: none; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
  .toolbar { gap: 8px; }
  .toolbar .searchfield { flex: 1 1 100%; }
  .toolbar .filter, .toolbar .filter select { width: 100%; }
  .searchfield input, .filter select, .filter input { min-height: 44px; font-size: 16px; }
  .tab { min-height: 40px; }
  .toolbar .tabs, .page > .tabs { margin: 0 -12px; padding: 0 12px; max-width: calc(100% + 24px); }
  .toolbar .tabs { flex: 1 0 calc(100% + 24px); width: calc(100% + 24px); }

  .m-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
  .m-list li + li { border-top: 1px solid var(--line); }
  .m-row { display: flex; align-items: center; gap: 10px; min-height: 66px; padding: 10px 13px; color: inherit; text-decoration: none; }
  .m-row-main { display: grid; flex: 1; min-width: 0; line-height: 1.35; }
  .m-row-main > span { font-size: 13.5px; }
  .m-row-main small { color: var(--ink-2); font-size: 12.5px; }
  .m-row-end { flex: none; }
  .appts li { gap: 9px; }
  .appts a { min-height: 40px; align-content: center; }
  .appts time { width: 62px; font-size: 13px; }
  .appts li:has(.btn) { flex-wrap: wrap; row-gap: 4px; }
  .appts li:has(.btn) .appt-end { width: 100%; padding-left: 71px; justify-content: flex-start; }
  .appts.follows li:has(.btn) { flex-wrap: nowrap; }
  .appts.follows li:has(.btn) .appt-end { width: auto; padding: 0; flex-direction: column; align-items: flex-end; }
  .clip { max-width: 100%; }
  .facts > div, .record .facts > div { grid-template-columns: 100px minmax(0, 1fr); }
  .back { min-height: 40px; }
  .mini { min-height: 48px; }
  .xc { --xc-label: minmax(72px, 100px); --xc-value: 58px; }
  .xc-xlabels span { font-size: 12px; line-height: 1.2; }
  .xc-yaxis b, .xc-ticks b, .xc-colbar em, .xc-v .xc-colbar em, .xc-tip, .xc-axisname { font-size: 12px; }
  .xc-frame { grid-template-columns: 34px minmax(0, 1fr); column-gap: 6px; }
  .slim th, .slim td { padding-right: 6px; font-size: 13px; }

  /* Inbox: conversations as rows, then one full thread */
  .sim-row .btn { width: 100%; }
  #results .threads { margin: 0 -12px; background: var(--surface); border-block: 1px solid var(--line); }
  .thread { min-height: 76px; }
  .m-thread > * + * { margin-top: 10px; }
  .m-thread-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 8px; }
  .m-thread-head .back { grid-column: 1 / -1; justify-self: start; }
  .m-thread-head h1 { font-size: 21px; }
  .segment { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: var(--radius-lg); background: var(--soft); }
  .segment button { min-height: 40px; border: 0; border-radius: var(--radius); background: none; font-weight: 700; font-size: 14px; color: var(--ink-2); cursor: pointer; }
  .segment button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); }
  .m-thread .messages { margin-inline: -12px; padding: 12px; overflow: visible; }
  .m-thread .composer { position: sticky; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 4; margin: 0 -12px; padding: 10px 12px 12px; }
  .m-app.in-chat .page { padding-bottom: 0; }
  .composer textarea { font-size: 16px; }
  .msg { max-width: 86%; }
  .m-thread .record { padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
  .stages li { font-size: 12px; }

  .cal-bar p { flex: 1 1 100%; font-size: 14px; }
  .cal-nav .btn, .icon-btn { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }

  .m-menu { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
  .m-menu li + li { border-top: 1px solid var(--line); }
  .m-menu a, .m-menu button { display: flex; align-items: center; gap: 13px; width: 100%; min-height: 56px; padding: 0 14px; border: 0; background: none; color: inherit; font-weight: 700; text-align: left; text-decoration: none; cursor: pointer; }
  .m-menu span { flex: 1; }
  .m-menu .icon { color: var(--accent); }
  .m-menu a > .icon:last-child { color: var(--ink-2); width: 16px; }

  /* Popups rise from the bottom edge */
  dialog, dialog.is-side { width: 100%; max-width: 100%; height: auto; max-height: calc(100dvh - 52px); margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .field input:not([type="checkbox"]), .field select, .field textarea { font-size: 16px; min-height: 44px; }
  .field-row.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dlg-actions .btn { flex: 1; }
  .checks { grid-template-columns: minmax(0, 1fr); }
  .checks-days { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .check { min-height: 42px; }
  .slots button { min-height: 44px; }
  .slots { max-height: 150px; }

  /* 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); }
  .signin { padding: 24px 14px 32px; }
}
@media (max-width: 359px) {
  .field-row, .field-grid, .field-row.three { grid-template-columns: minmax(0, 1fr); }
  .m-tabs a > span { width: 40px; }
  .facts > div, .record .facts > div { grid-template-columns: 88px minmax(0, 1fr); }
}
.preview, .view-switch { display: none; }
@media (min-width: 900px) {
  .view-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 99px; background: rgba(15, 61, 31, .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: #0f3d1f; 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(15, 61, 31, .25); }

  .app-body.is-preview { background: #e6eae7; }
  .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); }
}

/* 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; }
}
