/* The phone app layout, used below 761px and inside the desktop phone preview */
@media screen and (max-width: 760px) {
  .app-body { --tabs: calc(60px + env(safe-area-inset-bottom, 0px)); }
  /* 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; }

  /* Title bar */
  .m-bar { position: sticky; top: var(--bar); z-index: 12; display: flex; align-items: center; gap: 8px; min-height: 60px; padding: 8px 12px 8px 18px; background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
  .m-bar h1 { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 700 23px/1.25 var(--display); letter-spacing: -.015em; outline: none; }
  .m-bar > div { display: flex; gap: 4px; }
  .m-app--sub .m-bar { padding-left: 6px; }
  .m-app--sub .m-bar h1 { font-size: 19px; }
  .m-icon { position: relative; display: inline-grid; place-items: center; flex: none; width: 44px; height: 44px; border: 0; border-radius: 99px; background: none; color: var(--ink); cursor: pointer; }
  .m-icon:active { background: var(--soft); }
  .m-icon .icon { width: 22px; height: 22px; }
  .m-icon .dot { top: 3px; right: 2px; }

  .content.m-content { width: auto; margin: 0; max-width: none; min-height: 0; padding: 14px 16px calc(var(--tabs) + 34px); }
  .content.m-content > * + * { margin-top: 14px; }
  .m-app--fab .content.m-content { padding-bottom: calc(var(--tabs) + 94px); }

  /* Bottom tab bar and add button */
  .m-tabs { position: fixed; z-index: 14; left: 0; right: 0; bottom: 0; height: var(--tabs); padding: 0 4px env(safe-area-inset-bottom, 0px); background: var(--surface); border-top: 1px solid var(--line); }
  .m-tabs ul { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: 100%; }
  .m-tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 100%; color: var(--ink-2); font-size: 11.5px; font-weight: 650; text-decoration: none; white-space: nowrap; }
  .m-tabs i { font-style: normal; position: relative; display: grid; place-items: center; width: 44px; height: 25px; border-radius: 99px; transition: background-color .18s; }
  .m-tabs i .icon { width: 18px; height: 18px; }
  .m-tabs i .dot { top: -4px; right: 3px; min-width: 16px; height: 16px; padding: 0 4px; font-size: 10.5px; line-height: 16px; }
  .m-tabs a.is-on { color: var(--accent-dark); font-weight: 750; }
  .m-tabs a.is-on i { background: var(--accent-tint); }
  .m-fab { position: fixed; z-index: 13; right: 16px; bottom: calc(var(--tabs) + 16px); display: grid; place-items: center; width: 56px; height: 56px; border: 0; border-radius: 18px; background: var(--accent); color: #fff; box-shadow: 0 12px 24px -8px rgba(142, 31, 72, .65); cursor: pointer; }
  .m-fab .icon { width: 26px; height: 26px; }
  .m-fab:active { transform: scale(.95); }

  /* Lists */
  .m-list { display: block; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
  .m-list > li + li { border-top: 1px solid var(--line); }
  .m-card { padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
  .m-group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; margin-top: 4px; }
  .m-group-head h2 { font: 700 18px/1.3 var(--display); }
  .m-count { padding: 0 2px 8px; color: var(--ink-2); font-size: 14px; }
  .m-row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; color: var(--ink); text-decoration: none; }
  .m-row:active, .m-proj:active { background: var(--accent-tint); }
  .m-row > .icon:last-child { color: var(--ink-2); }
  .m-row-main { display: grid; flex: 1; min-width: 0; gap: 2px; line-height: 1.35; overflow-wrap: anywhere; }
  .m-row-main > strong, .m-line strong { font-size: 16px; }
  .m-row-main > span:not(.m-row-meta, .m-line) { color: var(--ink-2); font-size: 14px; }
  .m-line { display: flex; justify-content: space-between; gap: 10px; }
  .m-line b { font-size: 16px; white-space: nowrap; font-variant-numeric: tabular-nums; }
  .m-row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 4px; }
  .m-row-meta small { font-size: 13px; color: var(--ink-2); }
  .m-proj { display: grid; gap: 6px; padding: 14px 16px; color: var(--ink); text-decoration: none; }
  .m-proj-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
  .m-proj-top strong { font-size: 16.5px; line-height: 1.3; }
  .m-sub, .m-proj small { font-size: 13.5px; color: var(--ink-2); }
  .m-proj .meter { margin-block: 3px; }

  /* Home */
  .m-hero { position: relative; display: grid; padding: 18px 20px; border-radius: 18px; background: var(--navy); color: #fff; text-decoration: none; }
  .m-hero span, .m-hero small { color: #e6cfda; font-size: 14px; padding-right: 30px; }
  .m-hero strong { font: 700 36px/1.2 var(--display); letter-spacing: -.02em; }
  .m-hero .icon { position: absolute; right: 16px; top: 50%; margin-top: -11px; width: 22px; height: 22px; }
  .m-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .m-tile { display: grid; align-content: start; gap: 2px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; color: var(--ink); text-decoration: none; }
  .m-tile strong { font: 700 24px/1.2 var(--display); }
  .m-tile span { color: var(--ink-2); font-size: 13px; line-height: 1.3; }
  .m-todo a { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 11px 12px 11px 14px; color: var(--ink); text-decoration: none; }
  .m-todo a > .icon { color: var(--ink-2); }
  .m-more-btn { width: 100%; min-height: 44px; margin-top: 4px; color: var(--accent-dark); }
  .m-card .feed li:first-child { padding-top: 0; }
  .m-card .feed li:last-child { border-bottom: 0; padding-bottom: 0; }

  /* Search and chips */
  .m-searchbar { display: flex; gap: 8px; }
  .m-search { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; min-height: 46px; padding: 0 16px; background: var(--surface); border: 1px solid var(--line-2); border-radius: 99px; color: var(--ink-2); }
  .m-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-tint); }
  .m-search input { flex: 1; min-width: 0; height: 44px; border: 0; background: none; font-size: 16px; color: var(--ink); outline: none; }
  .m-searchbar .m-filter { width: 46px; height: 46px; background: var(--surface); border: 1px solid var(--line-2); }
  .m-chips { position: relative; display: flex; gap: 8px; margin-inline: -16px; padding: 2px 16px; overflow-x: auto; scrollbar-width: none; }
  .m-chips::-webkit-scrollbar { display: none; }
  .m-chip { display: inline-flex; align-items: center; gap: 7px; flex: none; min-height: 40px; padding: 0 15px; border: 1px solid var(--line-2); border-radius: 99px; background: var(--surface); color: var(--ink); font-size: 14.5px; font-weight: 650; white-space: nowrap; cursor: pointer; }
  .m-chip.is-on { background: var(--navy); border-color: var(--navy); color: #fff; }

  /* Shared screens, made roomy */
  .m-me { display: flex; align-items: center; gap: 14px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
  .m-me .avatar { width: 52px; height: 52px; font-size: 17px; }
  .m-me div { display: grid; line-height: 1.4; }
  .m-me strong { font-size: 18px; }
  .m-me span:not(.avatar) { color: var(--ink-2); font-size: 14px; }
  .m-menu :is(a, button) { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 54px; padding: 0 16px; border: 0; background: none; color: var(--ink); font-size: 16px; font-weight: 600; text-align: left; text-decoration: none; cursor: pointer; }
  .m-menu :is(a, button):active { background: var(--accent-tint); }
  .m-menu span { flex: 1; }
  .m-menu em { font-style: normal; font-size: 13px; font-weight: 700; color: var(--danger); }
  .m-menu .icon:last-child { color: var(--ink-2); }

  .m-title { display: grid; justify-items: start; gap: 5px; }
  .m-title h2 { font: 700 23px/1.22 var(--display); letter-spacing: -.012em; overflow-wrap: anywhere; }
  .m-title p { color: var(--ink-2); font-size: 14.5px; }
  .m-title > span:not(.badge) { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

  .card { padding: 16px; border-radius: 16px; }
  .card h2 { font-size: 17px; }
  .subtabs { margin-inline: -16px; padding-inline: 8px; }
  .subtabs a { padding: 0 12px; height: 46px; }
  .stats, .stats-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); border-radius: 16px; }
  .stat { padding: 12px 10px; }
  .stat-name { font-size: 13px; line-height: 1.3; min-height: 2.6em; }
  .stat-value { font-size: 19px; }
  .stat-sub { font-size: 13px; line-height: 1.3; }

  .mile { grid-template-columns: 28px minmax(0, 1fr) auto; gap: 8px 12px; }
  .mile-status { grid-column: 2; }
  .mile-status select { width: 100%; min-height: 44px; font-size: 16px; }
  .mile-tools { grid-column: 3; }
  .mile-tools .icon-btn, .post-tools .icon-btn { width: 44px; height: 44px; }
  .mile > .badge { grid-column: 2 / -1; justify-self: start; }
  .mile:not(:last-child)::before { top: 28px; }
  .mile-dot { align-self: start; margin-top: 2px; }
  .mile > .mile-dot { grid-row: 1 / span 2; }
  .facts-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .internal { flex-wrap: wrap; }
  .internal > .icon { display: none; }
  .internal > div { flex: 1 1 100%; }
  .internal .btn { min-height: 44px; }
  .reply-form { flex-wrap: wrap; }
  .reply-form .field { flex: 1 1 100%; }
  .reply-form .btn { margin-left: auto; }
  .composer > .btn, .composer-foot .btn { width: 100%; justify-self: stretch; }
  .check { min-height: 44px; }

  .decision { padding: 16px; }
  .decision > .icon { display: none; }
  .decision > div:not(.decision-actions) { flex-basis: 100%; }
  .decision-actions { width: 100%; }
  .decision-actions .btn { flex: 1 1 130px; min-height: 48px; padding-inline: 8px; }
  .decision-actions .btn .icon { display: none; }
  .version-rail { margin-inline: -16px; padding: 0 16px 6px; scrollbar-width: none; scroll-snap-type: x proximity; }
  .version-rail::-webkit-scrollbar { display: none; }
  .version { flex: 0 0 82%; scroll-snap-align: start; scroll-margin-left: 16px; }
  .version:only-child { flex-basis: 100%; }

  .sheet { padding: 20px 16px; border-radius: 8px 8px 16px 16px; }
  .sheet-head { flex-direction: column-reverse; gap: 14px; }
  .sheet-no { display: flex; align-items: baseline; justify-content: space-between; text-align: left; }
  .sheet-no h2 { font-size: 24px; }
  .sheet-no p { font-weight: 700; color: var(--ink); }
  .sheet-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 16px; }
  .sheet-meta div:first-child { grid-column: 1 / -1; }
  .lines thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .lines, .lines tbody { display: block; }
  .lines tr { display: grid; grid-template-columns: repeat(3, minmax(0, auto)); justify-content: space-between; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .lines th, .lines td { display: block; border: 0; padding: 0; text-align: left; }
  .lines tbody th { grid-column: 1 / -1; }
  .lines td::before { content: attr(data-label); display: block; font-size: 13px; color: var(--ink-2); }
  .lines td:last-child { text-align: right; font-weight: 700; }
  .inv-layout { display: flex; flex-direction: column; gap: 14px; }
  .content.m-content > .inv-layout { margin-top: 0; }
  .inv-layout > * { width: 100%; }
  .inv-actions .btn { min-height: 48px; }

  .req-layout { display: flex; flex-direction: column; gap: 14px; }
  .req-layout > * { width: 100%; }
  .req-main { gap: 14px; }
  .thread li { padding: 12px; gap: 10px; }
  .thread .avatar, .replies .avatar { width: 30px; height: 30px; font-size: 11.5px; }
  .triage-more .btn { flex: 1; min-height: 44px; }
  .triage .btn { min-height: 48px; }

  .client-list { gap: 10px; }
  .client-row { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 16px; border-radius: 16px; }
  .client-note, .client-actions { grid-column: 1; grid-row: auto; }
  .client-actions { display: flex; }
  .client-actions .btn { flex: 1; min-height: 44px; }

  .card .m-list { border: 0; border-radius: 0; margin-inline: -16px; }
  .card-head .btn-small { min-height: 40px; }
  .as-table summary { min-height: 44px; display: flex; align-items: center; }

  .field input:not([type="file"]), .field select { min-height: 44px; font-size: 16px; }
  .field textarea { font-size: 16px; }
  .btn, .btn-small { min-height: 44px; }
  .xc-hits .xc-tip { max-width: 150px; }

  /* Popups slide up from the bottom */
  dialog, dialog.is-wide { position: fixed; inset: auto 0 0 0; width: 100%; max-width: 100%; margin: 0; max-height: calc(100dvh - var(--bar, 0px) - 40px); border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  dialog form { max-height: calc(100dvh - var(--bar, 0px) - 40px); }
  dialog[open] { animation: m-up .24s cubic-bezier(.2, .8, .2, 1); }
  dialog .modal-head { position: relative; padding-top: 22px; }
  dialog .modal-head .icon-btn { width: 44px; height: 44px; }
  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 .modal-foot > .btn { flex: 1; min-height: 48px; }
  .m-sheet ul { max-height: 62vh; overflow-y: auto; padding: 6px 8px 14px; }
  .m-sheet li button { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 6px 12px; border: 0; border-radius: 12px; background: none; font-size: 16px; font-weight: 600; text-align: left; cursor: pointer; }
  .m-sheet li button:active { background: var(--accent-tint); }
  .m-sheet li button span { display: grid; min-width: 0; line-height: 1.35; }
  .m-sheet li small { color: var(--ink-2); font-size: 13.5px; font-weight: 500; }
  .m-sheet li button.is-danger { color: var(--danger); }

  .toasts { left: 12px; right: 12px; max-width: none; bottom: calc(var(--tabs, 0px) + 84px); }
  .signin { padding: 28px 16px 40px; }
  .roles { grid-template-columns: minmax(0, 1fr); }
}
@media screen and (max-width: 620px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .line-row { grid-template-columns: 76px minmax(0, 1fr) 44px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
  .line-row .line-text { grid-column: 1 / -1; }
  .line-sum { grid-column: 1 / 3; text-align: left; height: 32px; line-height: 32px; font-size: 15px; }
  .line-del { grid-column: 3; width: 44px; height: 44px; }
}
@media screen and (max-width: 350px) {
  .m-row .filetype { display: none; }
  .m-tile { padding: 10px 8px; }
  .stats, .stats-3 { grid-template-columns: minmax(0, 1fr); }
  .stat-name { min-height: 0; }
}
/* Sideways rows: smooth swiping by finger, and a clean drag with a mouse (assets/js/touch.js) */
.m-chips, .subtabs, .version-rail, .content > .tabs, .card > .tabs, .topnav ul { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.m-chips > *, .subtabs > *, .version-rail > *, .tabs > *, .topnav li { user-select: none; -webkit-user-select: none; }
.subtabs a, .topnav a { -webkit-user-drag: none; }
.is-gliding { scroll-snap-type: none !important; }
@media screen and (max-width: 760px) {
  /* Filter chips on shared screens stay on one swipeable line */
  .content.m-content .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .content.m-content .card > .tabs { margin-inline: -16px; padding-inline: 16px; }
  .content.m-content .tab { min-height: 40px; }
}
body.is-grabbing, body.is-grabbing * { cursor: grabbing !important; }
@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 screen and (min-width: 900px) {
  .view-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 99px; background: rgba(255, 255, 255, .14); }
  .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: #f6e9ef; font-size: 13px; font-weight: 700; cursor: pointer; }
  .view-switch button .icon { width: 15px; height: 15px; }
  .view-switch button[aria-pressed="true"] { background: #fff; color: var(--navy); }

  .app-body.is-preview { background: #ece4e8; }
  .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: 340px; }
  .preview-notes h2 { font: 700 clamp(26px, 2.6vw, 34px)/1.15 var(--display); letter-spacing: -.02em; }
  .preview-notes > p { margin-top: 10px; color: var(--ink-2); font-size: 16px; }
  .preview-notes ul { margin-top: 22px; border-top: 1px solid var(--line-2); }
  .preview-notes li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-2); font-size: 15px; }
  .preview-notes li .icon { margin-top: 3px; color: var(--accent); }

  .device { --h: 844px; flex: none; width: 414px; padding: 11px; border-radius: 56px; background: #1a1015; box-shadow: 0 40px 70px -30px rgba(26, 16, 21, .65), inset 0 0 0 2px #4a3a42; }
  .device-screen { position: relative; display: flex; flex-direction: column; width: 392px; height: var(--h); border-radius: 45px; overflow: hidden; background: var(--bg); }
  .device-status { display: flex; align-items: center; justify-content: space-between; flex: none; height: 42px; padding: 2px 30px 0 34px; background: var(--bg); font-size: 14px; }
  .device-island { position: absolute; top: 9px; left: 50%; width: 108px; height: 25px; margin-left: -54px; border-radius: 99px; background: #1a1015; }
  .device-signal { display: flex; align-items: flex-end; gap: 2px; height: 12px; }
  .device-signal i { width: 3px; border-radius: 1px; background: var(--ink); height: 4px; }
  .device-signal i:nth-child(2) { height: 6px; }
  .device-signal i:nth-child(3) { height: 9px; }
  .device-signal i:nth-child(4) { height: 12px; }
  .device-signal em { width: 24px; height: 12px; margin-left: 5px; border: 1.5px solid var(--ink); border-radius: 4px; background: linear-gradient(var(--ink), var(--ink)) 2px 50% / 15px 6px no-repeat; }
  .device iframe { flex: 1; width: 100%; min-height: 0; border: 0; background: var(--bg); }
  /* Space under the tab bar so the rounded corners never touch its labels */
  .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); }
  .signin .role-top, .signin .role-top > span:last-child { display: contents; }
}

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