/* Mobile application shell and responsive workspaces */
/* Laptop/tablet widths hide the right rail, but must keep account and branch
   controls. Wide workspaces already render these controls in their own header. */
@media (min-width: 761px) and (max-width: 1200px) {
  .shell:not(.is-wide-workspace) {
    grid-template-columns: 216px minmax(0, 1fr);
    grid-template-rows: 54px minmax(0, 1fr);
  }

  .shell.is-sidebar-collapsed:not(.is-wide-workspace) {
    grid-template-columns: 68px minmax(0, 1fr);
  }

  .shell:not(.is-wide-workspace) > .right-panel {
    display: none;
  }

  .shell:not(.is-wide-workspace) > .workspace {
    grid-row: 2;
    min-height: 0;
    max-height: calc(100dvh - 54px);
  }

  .shell:not(.is-wide-workspace) > .mobile-topbar {
    display: flex;
    grid-column: 2;
    grid-row: 1;
    align-items: center;
    justify-content: flex-end;
    min-width: 0;
    padding: 6px var(--page-x);
    background: var(--bg-main);
    position: relative;
    z-index: 50;
  }

  .shell:not(.is-wide-workspace) .mobile-logo {
    display: none;
  }

  .shell:not(.is-wide-workspace) .mobile-topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    min-width: 0;
  }
}

@media (min-width: 761px) and (max-width: 900px) {
  .shell:not(.is-wide-workspace):not(.is-sidebar-collapsed) {
    grid-template-columns: 78px minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  :root {
    --page-x: 10px;
    --page-y: 10px;
    --control-h: 38px;
    --work-bottom-gap: 86px;
  }

  html,
  body {
    min-width: 0;
    overflow-x: hidden;
  }

  .shell,
  .shell.is-sidebar-collapsed,
  .shell.is-wide-workspace,
  .shell.is-sidebar-collapsed.is-wide-workspace,
  .shell.is-journal-shell,
  .shell.is-schedule-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: 100%;
    min-height: 100dvh;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .sidebar,
  .right-panel,
  .shell.is-schedule-shell .sidebar,
  .shell.is-schedule-shell .right-panel,
  .shell.is-journal-shell .sidebar,
  .shell.is-journal-shell .right-panel {
    display: none !important;
  }

  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    grid-column: 1;
    grid-row: 1;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
    min-height: 54px;
    padding: 8px 12px;
    background: #fff;
    border-bottom: 1px solid var(--border-light);
  }

  .mobile-logo {
    width: 122px;
    height: 34px;
    object-fit: contain;
    object-position: left center;
  }

  .mobile-topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
  }

  .mobile-topbar-actions > .team-notification-root,
  .mobile-topbar-actions > .messages-icon-btn,
  .mobile-topbar-actions > .account-profile-wrap {
    display: grid;
    width: 32px;
    min-width: 32px;
    height: 32px;
    place-items: center;
    flex: 0 0 32px;
  }

  .mobile-topbar .icon-btn,
  .mobile-topbar .account-profile-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    min-width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    place-items: center;
    line-height: 0;
  }

  .mobile-topbar .icon-btn svg {
    display: block;
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    transform: none !important;
  }

  /* The bell drawing is optically a little higher than the chat bubble,
     even though both SVGs share the same view box. */
  .mobile-topbar .team-notification-root .icon-btn svg {
    transform: translateY(0.5px) !important;
  }

  /* The speech bubble path includes its lower tail, so its visible mass sits
     below the SVG's mathematical centre. Lift only the drawing itself. */
  .mobile-topbar .messages-icon-btn svg {
    transform: translateY(-1.5px) !important;
  }

  .mobile-topbar .notify-dot {
    top: 1px;
    right: 1px;
  }

  .mobile-topbar .team-notifications-popover {
    position: fixed;
    top: calc(58px + env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    left: max(10px, env(safe-area-inset-left));
    width: auto;
    max-height: calc(100dvh - 76px - env(safe-area-inset-top));
  }

  .mobile-topbar .team-notification-list {
    max-height: min(316px, calc(100dvh - 196px - env(safe-area-inset-top)));
  }

  .mobile-branch {
    max-width: 86px;
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: var(--weight-medium);
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .mobile-topbar .topbar-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    min-width: 26px;
    height: 26px;
    margin: 0;
    font-size: 10px;
    line-height: 1;
  }

  .mobile-topbar .account-popover {
    position: fixed;
    top: 58px;
    right: 10px;
    width: min(300px, calc(100vw - 20px));
  }

  .mobile-topbar .account-popover::before {
    right: 16px;
  }

  .mobile-bottom-nav {
    position: fixed;
    right: var(--page-x);
    bottom: max(10px, env(safe-area-inset-bottom));
    left: var(--page-x);
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding: 5px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--border-light);
    border-radius: 18px;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.16);
    backdrop-filter: blur(16px);
  }

  .mobile-bottom-nav button {
    display: grid;
    min-width: 0;
    min-height: 48px;
    place-items: center;
    gap: 3px;
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    border-radius: 13px;
    transition: color 0.16s ease, background-color 0.16s ease, transform 0.12s ease;
  }

  .mobile-bottom-nav button:active {
    transform: scale(0.97);
  }

  .mobile-bottom-nav button span {
    display: grid;
    width: 22px;
    height: 22px;
    place-items: center;
    color: currentColor;
  }

  .mobile-bottom-nav svg {
    display: block;
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .mobile-bottom-nav svg path,
  .mobile-bottom-nav svg circle,
  .mobile-bottom-nav svg rect,
  .mobile-bottom-nav svg line,
  .mobile-bottom-nav svg polyline {
    fill: none;
    stroke: currentColor;
  }

  .mobile-bottom-nav strong {
    max-width: 100%;
    overflow: hidden;
    font-size: 10px;
    font-weight: var(--weight-semibold);
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .mobile-bottom-nav button.is-active {
    color: var(--primary);
    background: var(--primary-soft);
  }

  .workspace,
  .shell.is-wide-workspace .workspace,
  .workspace.is-journal-workspace,
  .workspace.is-schedule-workspace {
    grid-column: 1;
    grid-row: 2;
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 0;
    height: auto;
    max-height: none;
    padding-bottom: 86px;
    overflow: visible;
  }

  .workspace > .clients-page,
  .workspace > .analytics-page,
  .workspace > .settings-page,
  .workspace > .client-card-page,
  .workspace > .schedule-page,
  .workspace > .journal-page {
    display: block;
    min-height: auto;
    height: auto;
    max-height: none;
    padding: 10px 10px 92px;
    overflow: visible;
  }

  .workspace > .clients-page {
    margin-right: 0 !important;
    margin-left: 0 !important;
    padding-right: var(--page-x) !important;
    padding-left: var(--page-x) !important;
  }

  .workspace > .analytics-page {
    margin: 0 !important;
    padding: 10px var(--page-x) 92px !important;
  }

  .settings-mobile-shell {
    display: block;
    min-width: 0;
    padding: 0 var(--page-x) 92px;
  }

  .settings-mobile-shell .mobile-section-switcher {
    margin: 10px 0 12px;
  }

  .settings-mobile-shell .settings-page {
    margin: 0 !important;
    padding: 0 !important;
    background: transparent;
  }

  .team-mobile-shell {
    display: block;
    min-width: 0;
  }

  .team-mobile-shell .mobile-section-switcher {
    margin-inline: var(--page-x);
  }

  .team-workspace {
    padding: 10px;
  }

  /* The client card is a dedicated mobile screen, with the same gutters as
     the journal and schedule rather than a nested desktop panel. */
  .workspace > .client-card-page {
    margin: 0 !important;
    padding: 10px var(--page-x) 92px !important;
    background: transparent;
  }

  .view-toolbar,
  .journal-toolbar,
  .client-base-toolbar,
  .page-header {
    display: flex;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    min-height: auto;
    padding: 0 0 10px;
  }

  .toolbar-group,
  .journal-toolbar .toolbar-title-group,
  .journal-toolbar-actions,
  .page-actions {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    gap: 8px;
  }

  .journal-toolbar .journal-title,
  .schedule-heading,
  .page-title {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    font-size: 17px;
    line-height: 1.15;
  }

  .journal-toolbar .staff-filter,
  .staff-filter,
  .staff-filter-trigger,
  .journal-toolbar-search,
  .toolbar-search,
  .client-base-search,
  .page-actions .btn,
  .toolbar-group .btn:not(.icon-only),
  .clients-page .page-actions {
    width: 100%;
    max-width: none;
    min-width: 0;
    flex: 1 1 100%;
  }

  .journal-toolbar .day-nav-btn,
  .journal-toolbar .date-inline,
  .schedule-nav-btn,
  .btn.icon-only.day-nav-btn {
    width: 38px !important;
    min-width: 38px !important;
    height: 38px;
    min-height: 38px;
    flex: 0 0 38px;
  }

  .schedule-toolbar-primary {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .schedule-month-switcher {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) 38px;
    align-items: center;
    gap: 8px;
    width: 100%;
  }

  .schedule-month-switcher .schedule-heading {
    width: auto;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    font-size: 20px;
    line-height: 1.15;
    text-align: center;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .schedule-toolbar-primary .staff-filter,
  .schedule-toolbar-primary .staff-filter-trigger {
    width: 100%;
  }

  .journal-toolbar .compact-primary,
  .btn.primary,
  .btn.success,
  .btn {
    min-height: 38px;
    border-radius: 10px;
  }

  .journal,
  .schedule-stage {
    display: none;
  }

  /* Day timeline: one two-axis scroll area, a pinned ruler and staff header.
     Keep real event heights and the same five-minute slots as desktop. */
  .shell.is-journal-shell:has(.journal-day-grid) {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .workspace.is-journal-workspace:has(.journal-day-grid) {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    padding: 0 0 calc(68px + env(safe-area-inset-bottom));
  }
  .workspace > .journal-page:has(.journal-day-grid) {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100%;
    min-height: 0;
    overflow: hidden;
    padding: 6px 0 0;
  }
  .journal-page:has(.journal-day-grid) .journal-toolbar { padding: 0 8px 8px; }
  .journal-page:has(.journal-day-grid) .toolbar-title-group {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) 38px 38px;
    align-items: center;
    gap: 6px;
  }
  .journal-page:has(.journal-day-grid) .journal-title {
    width: auto;
    min-width: 0;
    font-size: 14px;
    text-align: center;
  }
  .journal-page:has(.journal-day-grid) .staff-filter { grid-column: 1 / -1; }
  .journal-page:has(.journal-day-grid) .staff-filter-trigger {
    min-height: 38px;
    justify-content: space-between;
  }
  .journal-page:has(.journal-day-grid) .staff-filter-trigger > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .journal-page:has(.journal-day-grid) .staff-filter-menu {
    max-height: min(420px, 60dvh);
    overflow-y: auto;
  }
  .journal-page:has(.journal-day-grid) #open-journal-week { display: none; }
  .journal-page:has(.journal-day-grid) .journal-toolbar-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .journal-page:has(.journal-day-grid) .journal-toolbar-search { min-width: 0; }
  .journal-page:has(.journal-day-grid) .journal-toolbar-actions .compact-primary {
    width: auto;
    padding: 0 10px;
  }
  .journal.journal-day-grid {
    display: grid;
    height: 100%;
    min-height: 0;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }
  .journal-day-grid .journal-body-scroll {
    overflow: auto;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
    scrollbar-width: thin;
  }
  .journal-day-grid .journal-head-row,
  .journal-day-grid .journal-body-row {
    grid-template-columns: 46px repeat(var(--master-count), minmax(180px, 1fr));
    min-width: calc(46px + var(--master-count) * 180px);
  }
  .journal-day-grid .time-head { padding: 8px 3px; font-size: 10px; }
  .journal-day-grid .master-head {
    height: 78px;
    min-height: 78px;
    padding: 6px;
    gap: 3px;
    flex-direction: column;
    justify-content: center;
    text-align: center;
  }
  .journal-day-grid .master-head > div { min-width: 0; max-width: 100%; }
  .journal-day-grid .master-avatar { width: 28px; height: 28px; min-width: 28px; flex: 0 0 28px; }
  .journal-day-grid .master-name { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .journal-day-grid .master-hours { font-size: 10px; }
  .journal-day-grid .time-slot { padding: 4px 3px; font-size: 11px; }
  .journal-day-grid .journal-scroll-indicator { right: calc(46px - 100vw); }
  .journal-day-grid .journal-scroll-indicator::before { left: 41px; border-left-width: 5px; }
  .journal-day-grid .journal-scroll-indicator::after { left: 46px; background: rgba(20, 184, 166, .55); }
  .journal-day-grid .journal-scroll-indicator span { left: 0; padding: 2px 3px; font-size: 10px; }
  .journal-day-grid .appointment-card { padding: 2px 4px; gap: 2px; border-radius: 6px; justify-content: flex-start; }
  .journal-day-grid .appointment-card.is-inline { justify-content: center; padding: 0 3px; }
  .journal-day-grid .appointment-card-top,
  .journal-day-grid .appointment-card-inline { gap: 2px; min-height: 14px; height: 14px; }
  .journal-day-grid .appointment-card-top-right,
  .journal-day-grid .appointment-quality-markers { gap: 2px; flex: 0 0 auto; }
  .journal-day-grid .appointment-time { font-size: 10px; line-height: 14px; }
  .journal-day-grid .appointment-quality-marker,
  .journal-day-grid .appointment-paid-marker { width: 14px; height: 14px; font-size: 10px; }
  .journal-day-grid .appointment-quality-marker svg { width: 10px; height: 10px; }
  .journal-day-grid .appointment-card .appointment-status-badge {
    height: 14px;
    min-height: 14px;
    padding: 0 3px;
    font-size: 0;
    line-height: 14px;
  }
  .journal-day-grid .appointment-status-badge::after { content: attr(data-mobile-label); font-size: 9px; }
  .journal-day-grid .appointment-client { font-size: 12px; line-height: 15px; }
  .journal-day-grid .appointment-meta { font-size: 11px; line-height: 14px; }
  .journal-day-grid .slot-action-popover { max-width: 172px; left: 4px; right: 4px; }
  /* Touch browsers can retain :hover after a tap or swipe. Do not leave a
     second, stale time guide in the grid; keyboard focus still has its cue. */
  .journal-day-grid .slot-button:hover:not(:focus-visible) { background: transparent; outline: none; }
  .journal-day-grid .slot-button:hover:not(:focus-visible)::after { color: transparent; background: transparent; }

  .mobile-journal-list,
  .mobile-schedule-list {
    display: grid;
    gap: 10px;
  }

  .mobile-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
  }

  .mobile-section-head > div {
    display: grid;
    min-width: 0;
    gap: 3px;
  }

  .mobile-section-head strong {
    overflow: hidden;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: var(--weight-bold);
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .mobile-section-head span,
  .mobile-card-meta,
  .mobile-schedule-card small {
    color: var(--text-secondary);
    font-size: 12px;
  }

  .mobile-card-list {
    display: grid;
    gap: 8px;
  }

  .mobile-schedule-month-card {
    display: grid;
    gap: 10px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
  }

  .mobile-schedule-month-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .mobile-schedule-month-head > div {
    display: grid;
    gap: 2px;
  }

  .mobile-schedule-month-head strong {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: var(--weight-bold);
  }

  .mobile-schedule-month-head span {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: var(--weight-semibold);
  }

  .mobile-schedule-legend {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
  }

  .mobile-schedule-legend i {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
  }

  .mobile-schedule-weekdays,
  .mobile-schedule-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 5px;
  }

  .mobile-schedule-weekdays span {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: var(--weight-bold);
    text-align: center;
  }

  .mobile-schedule-calendar-day {
    display: grid;
    place-items: center;
    align-content: center;
    min-width: 0;
    min-height: 48px;
    gap: 2px;
    padding: 4px 1px;
    color: var(--text-primary);
    font: inherit;
    background: #f8fafc;
    border: 1px solid transparent;
    border-radius: 10px;
  }

  button.mobile-schedule-calendar-day {
    cursor: pointer;
  }

  .mobile-schedule-calendar-day > span {
    font-size: 14px;
    font-weight: var(--weight-bold);
    line-height: 1;
  }

  .mobile-schedule-calendar-day small {
    overflow: hidden;
    max-width: 100%;
    color: var(--text-muted);
    font-size: 8px;
    font-weight: var(--weight-semibold);
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-topbar .organization-switcher {
    max-width: 108px;
    min-width: 0;
  }

  .mobile-topbar .organization-switcher select {
    width: 100%;
    max-width: 108px;
    min-height: 32px;
    padding-right: 22px;
    padding-left: 4px;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: var(--weight-semibold);
    text-overflow: ellipsis;
    background-color: transparent;
    background-position: right 4px center;
  }

  .mobile-topbar .organization-switcher-label {
    max-width: 108px;
    font-size: 11px;
    line-height: 32px;
  }

  .mobile-schedule-calendar-day.is-working {
    background: rgba(24, 183, 168, 0.1);
  }

  .mobile-schedule-calendar-day.is-working small {
    color: var(--primary);
  }

  .mobile-schedule-calendar-day.is-off {
    color: var(--text-muted);
    background: #fbfcfd;
  }

  .mobile-schedule-calendar-day.is-muted {
    opacity: 0.35;
  }

  .mobile-schedule-calendar-day.is-selected {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--primary);
  }

  .mobile-schedule-calendar-day.is-today > span {
    color: var(--primary);
  }

  .mobile-week-journal-list,
  .mobile-week-days,
  .mobile-week-day {
    display: grid;
    gap: 10px;
  }

  .mobile-week-summary,
  .mobile-week-day-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
  }

  .mobile-week-summary {
    padding: 4px 4px 2px;
  }

  .mobile-week-summary strong,
  .mobile-week-day-head strong {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: var(--weight-bold);
  }

  .mobile-week-summary span,
  .mobile-week-day-head span,
  .mobile-week-empty {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: var(--weight-semibold);
  }

  .mobile-week-day {
    padding: 12px;
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
  }

  .mobile-week-empty {
    padding: 12px;
    text-align: center;
    background: var(--surface-soft);
    border-radius: 10px;
  }

  .mobile-appointment-card,
  .mobile-schedule-card,
  .mobile-empty-card {
    position: relative;
    display: grid;
    width: 100%;
    min-width: 0;
    gap: 5px;
    padding: 13px 14px;
    text-align: left;
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
  }

  .mobile-appointment-card {
    --appointment-status-color: #3b82f6;
    padding-bottom: 19px;
  }

  .mobile-appointment-card::after {
    position: absolute;
    right: 14px;
    bottom: 9px;
    left: 14px;
    height: 5px;
    content: "";
    background: var(--event-color, var(--surface-soft));
    border-radius: 999px;
  }

  .mobile-appointment-card.is-blocked {
    min-height: 52px;
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .mobile-appointment-card.is-blocked::after {
    display: none;
  }

  .mobile-appointment-card-head,
  .mobile-appointment-card-top-right {
    display: flex;
    min-width: 0;
    align-items: center;
  }

  .mobile-appointment-card-head {
    justify-content: space-between;
    gap: 8px;
  }

  .mobile-appointment-card-top-right {
    flex: 0 0 auto;
    gap: 6px;
  }

  .mobile-card-time {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: var(--weight-semibold);
  }

  .mobile-card-title {
    overflow: hidden;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: var(--weight-bold);
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .mobile-appointment-card .status-badge {
    position: static;
  }

  .mobile-appointment-card .appointment-quality-markers {
    display: inline-flex;
    min-height: 24px;
    margin: 0;
  }

  .mobile-appointment-card .appointment-quality-marker {
    width: 24px;
    min-height: 24px;
    height: 24px;
    padding: 0;
  }

  .appointment-quality-notice {
    align-items: flex-start;
    flex-direction: column;
  }

  .mobile-schedule-card {
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;
  }

  .mobile-schedule-card.is-static {
    cursor: default;
  }

  .mobile-schedule-card .client-initial {
    width: 42px;
    height: 42px;
  }

  .mobile-schedule-card strong {
    display: block;
    overflow: hidden;
    color: var(--text-primary);
    font-size: 14px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .mobile-schedule-card em {
    color: var(--primary);
    font-size: 11px;
    font-style: normal;
    font-weight: var(--weight-semibold);
  }

  .mobile-schedule-card.is-off {
    background: #FAFBFD;
  }

  .mobile-schedule-card.is-off em {
    color: var(--text-muted);
  }

  .mobile-schedule-card.is-selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(24, 183, 168, 0.14), var(--shadow-soft);
  }

  .mobile-schedule-actions {
    display: grid;
  }

  .mobile-schedule-actions .btn {
    width: 100%;
  }

  .mobile-schedule-editor-hint {
    padding: 12px 14px;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.45;
    background: #f7fafc;
    border: 1px dashed var(--border-light);
    border-radius: 14px;
  }

  .mobile-schedule-editor {
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
  }

  .mobile-schedule-editor-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px;
    border-bottom: 1px solid var(--border-light);
  }

  .mobile-schedule-editor-head strong {
    color: var(--text-primary);
    font-size: 15px;
    font-weight: var(--weight-bold);
  }

  .mobile-schedule-editor-head .btn {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .mobile-schedule-editor .schedule-tools-panel {
    min-height: 0;
    padding: 14px;
    background: transparent;
  }

  .mobile-schedule-editor .schedule-empty-panel {
    max-width: none;
    padding-top: 0;
  }

  .clients-page > .client-base-toolbar.view-toolbar {
    padding: 0 0 10px;
  }

  .clients-page .page-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  #clear-client-bulk-selection {
    display: none;
  }

  .clients-workspace.table-card,
  .table-card,
  .settings-table {
    margin: 0;
    overflow: visible;
  }

  .clients-workspace.table-card {
    background: transparent;
    border-color: transparent;
    border-radius: 0;
    box-shadow: none;
  }

  .client-register-head {
    display: none;
  }

  .client-register-body {
    display: grid;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .client-register .client-register-row,
  .client-register.is-finance-hidden .client-register-row {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) minmax(0, max-content);
    grid-template-areas: "select person person" "select phone status";
    min-width: 0;
    align-items: center;
    gap: 7px 10px;
    min-height: auto;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
  }

  .client-register-row > span:first-child {
    grid-area: select;
    padding: 0;
  }

  .client-register.is-selection-hidden .client-register-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, max-content);
    grid-template-areas: "person person" "phone status";
  }

  .client-register.is-selection-hidden .client-register-row > span:first-child {
    display: none;
  }

  .client-register-person {
    grid-area: person;
    min-height: auto;
    padding: 0;
  }

  .client-register-person > span {
    min-width: 0;
  }

  .client-register-person strong {
    font-size: 14px;
  }

  .client-phone-cell {
    grid-area: phone;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: auto;
    justify-items: start;
    padding: 0;
    font-size: 12px;
  }

  .client-register-row .client-register-cell:nth-child(4) {
    grid-area: status;
    min-height: auto;
    justify-items: end;
    padding: 0;
  }

  .client-register-row .client-status {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .client-register-row .client-register-cell:nth-child(n+5) {
    display: none;
  }

  .profile-settings-head,
  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .profile-settings-actions {
    width: 100%;
    justify-content: stretch;
  }

  .profile-settings-actions .btn {
    flex: 1 1 auto;
  }

  .client-card-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "back actions"
      "main main";
    align-items: center;
    gap: 12px;
    padding: 14px;
  }

  .client-card-hero .panel-back {
    grid-area: back;
    justify-self: start;
  }

  .client-card-hero .client-card-main {
    grid-area: main;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px 10px;
  }

  .client-card-hero .client-card-actions {
    grid-area: actions;
    width: auto;
  }

  .client-name-row {
    display: contents;
  }

  .client-name-row h1 {
    grid-column: 1 / -1;
    grid-row: 1;
    font-size: 22px;
    line-height: 1.15;
  }

  .client-name-row .client-status {
    grid-column: 1;
    grid-row: 2;
  }

  .client-card-meta {
    display: contents;
  }

  .client-card-meta span:first-child {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .client-card-meta span:nth-child(n + 2) {
    display: none;
  }

  .client-card-hero .client-card-actions .btn {
    width: 42px;
    min-width: 42px;
    padding: 0;
  }

  .client-tabs {
    display: none;
  }

  .client-tabs-mobile {
    display: grid;
    gap: 6px;
    width: 100%;
    margin-top: 12px;
  }

  .client-tabs-mobile label {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: var(--weight-bold);
  }

  .client-tabs-mobile .select {
    width: 100%;
    font-weight: var(--weight-semibold);
  }

  .client-card-metrics,
  .form-grid.two,
  .quick-client-grid,
  .client-data-grid,
  .medical-grid,
  .analytics-kpis,
  .analytics-grid {
    grid-template-columns: 1fr;
  }

  .client-card-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .client-tab-panel,
  .panel-section.profile-settings-card,
  .client-section-card,
  .medical-card {
    padding: 14px;
  }

  .client-tab-panel {
    padding: 14px 0 0;
  }

  .settings-service-filters,
  .employees-filters {
    grid-template-columns: 1fr;
    padding: 0 0 10px;
    background: transparent;
    border: 0;
  }

  .settings-table-head {
    display: none;
  }

  .settings-table-body {
    display: grid;
    gap: 8px;
  }

  .settings-row,
  .employees-table .settings-row,
  .services-table .settings-row,
  .access-table .settings-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    min-height: auto;
    padding: 13px;
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
  }

  .settings-row > span {
    white-space: normal;
  }

  .system-admin-shell {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }

  .system-admin-sidebar {
    position: static;
    width: auto;
    min-height: auto;
    padding: 18px 14px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--border-light);
  }

  .system-admin-workspace {
    padding: 14px;
  }

  .system-admin-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .system-admin-header h1 {
    font-size: 28px;
  }

  .system-admin-header > strong {
    width: 42px;
    height: 42px;
  }

  .system-admin-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .system-admin-card {
    padding: 14px;
  }

  .system-org-row {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .system-org-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .modal {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 24px);
    border-radius: 18px;
  }

  /* A visit is a full mobile workflow, not a cropped desktop dialog. */
  .modal-backdrop {
    align-items: stretch;
    padding: 0;
    overflow: hidden;
  }

  .appointment-modal {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 0;
    border-radius: 0;
  }

  .appointment-modal .modal-header,
  .appointment-modal .modal-footer {
    flex: 0 0 auto;
  }

  .appointment-modal .modal-body {
    min-height: 0;
    flex: 1 1 auto;
    padding: 14px 16px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .appointment-modal .modal-title {
    font-size: 19px;
  }

  .appointment-modal .modal-footer {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    padding: 10px 16px max(12px, env(safe-area-inset-bottom));
    background: #fff;
  }

  .appointment-modal .modal-footer-left {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 10px;
    overflow: visible;
  }

  .appointment-modal .modal-footer-left > * {
    min-width: 0;
  }

  .appointment-modal .modal-footer-left [data-appointment-sale] {
    grid-column: 1 / -1;
    min-height: 38px;
  }

  .appointment-modal .modal-footer-left .btn,
  .appointment-modal .modal-footer-left .link-button {
    width: 100%;
    min-height: 34px;
    white-space: normal;
  }

  .appointment-modal .modal-footer-right,
  .appointment-modal .modal-footer-right .btn {
    width: 100%;
  }

  .visit-quick-actions-section {
    display: block;
    padding: 0;
    background: transparent;
    border: 0;
  }

  .visit-quick-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
  }

  .visit-quick-actions .btn {
    min-width: 0;
    padding: 0 8px;
    font-size: 12px;
  }

  .appointment-modal .appointment-history-anchor {
    display: none;
  }

  .appointment-time-grid,
  .appointment-service-grid,
  .appointment-client-layout,
  .appointment-note-grid,
  .appointment-photo-inline {
    grid-template-columns: minmax(0, 1fr);
  }

  /* iOS date controls have an intrinsic width: let the actual field, not
     the native date renderer, determine their size. Keep the native picker. */
  .appointment-modal .appointment-time-grid > .field { min-width: 0; }
  .appointment-modal input[type="date"] {
    display: block;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 38px;
    -webkit-appearance: none;
    appearance: none;
    text-align: left;
  }
  .appointment-modal input[type="date"]::-webkit-date-and-time-value {
    min-height: 1.2em;
    text-align: left;
  }

  .problem-empty-state {
    min-height: 240px;
    padding: 22px 16px;
  }

  .appointment-note-grid .field.wide {
    grid-column: auto;
  }

  .appointment-client-layout .appointment-confirm-row {
    width: fit-content;
  }

  .visit-status-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .appointment-quality-notice-items {
    width: 100%;
  }

  .modal-body {
    max-height: calc(100dvh - 178px);
  }

  .appointment-photo-inline,
  .visit-problem-inline,
  .sale-summary-grid,
  .sale-payment-grid,
  .sale-item-row,
  .block-time-fields {
    grid-template-columns: 1fr;
  }

  .visit-problem-inline {
    align-items: stretch;
    gap: 8px;
  }

  .visit-problem-inline-tags { min-height: 34px; }

  .appointment-service-row {
    position: relative;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    padding-right: 42px;
  }

  .appointment-service-row > .field:first-child {
    grid-column: 1 / -1;
  }

  .appointment-service-remove {
    position: absolute;
    right: 0;
    bottom: 0;
  }

  .appointment-services-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .appointment-services-summary {
    justify-items: start;
    text-align: left;
  }

  .appointment-sale-summary {
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 13px;
  }

  .appointment-sale-summary-values {
    grid-column: 1 / -1;
    gap: 8px;
  }

  .appointment-sale-summary-open {
    font-size: 0;
  }

  .appointment-sale-summary-open svg {
    width: 18px;
    height: 18px;
  }

  .sale-item-row {
    gap: 8px;
  }

  .sale-item-remove {
    width: 100%;
  }

  .sale-items-head,
  .sale-payments-history > div {
    align-items: flex-start;
    flex-direction: column;
  }

  .sale-items-head .btn {
    width: 100%;
  }

  .sale-payment-layer {
    padding: 12px;
  }

  .sale-payment-dialog {
    width: min(100%, 520px);
    padding: 22px 18px;
    border-radius: 16px;
  }

  .sale-payment-methods {
    grid-template-columns: 1fr;
  }

  .sale-payment-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .sale-payment-actions .btn {
    width: 100%;
  }

  .client-balance-row {
    align-items: flex-start;
  }

  .client-balance-card .client-tab-head {
    align-items: stretch;
    flex-direction: column;
  }

  .client-balance-card .client-tab-head .btn {
    width: 100%;
  }

  .appointment-cancel-confirmation-layer {
    padding: 12px;
  }

  .appointment-cancel-confirmation {
    width: min(470px, calc(100vw - 24px));
    padding: 22px 18px 18px;
  }

  .appointment-cancel-confirmation-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .appointment-cancel-confirmation-actions .btn {
    width: 100%;
  }

  .service-delete-confirmation-layer {
    padding: 12px;
  }

  .service-delete-confirmation {
    width: min(500px, calc(100vw - 24px));
    padding: 22px 18px 18px;
  }

  .service-delete-confirmation-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .service-delete-confirmation-actions .btn {
    width: 100%;
  }

  .client-medical-card-reminder {
    align-items: flex-start;
    flex-direction: column;
  }

  .client-medical-card-reminder-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .master-visit-summary {
    grid-template-columns: 1fr;
  }

  .master-visit-summary .is-wide {
    grid-column: auto;
  }

  .master-visit-notes {
    grid-template-columns: 1fr;
  }

  .master-visit-quick-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 10px;
  }

  .master-visit-quick-actions .btn {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding-inline: 10px;
    white-space: normal;
  }

  .master-visit-footer {
    padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  }

  .master-visit-footer .btn {
    width: 100%;
  }

  /* Client card: keep medical information readable instead of squeezing desktop pairs. */
  .client-overview-columns,
  .client-data-list,
  .medical-section-grid,
  .medical-side-grid,
  .medical-nails {
    grid-template-columns: minmax(0, 1fr);
  }

  .medical-specialists .medical-check-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .medical-specialists .medical-check-grid span {
    overflow: visible;
    line-height: 1.25;
    white-space: normal;
    text-overflow: clip;
  }

  .problem-followup-list > div {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  /* Only the visit subflows with an explicit return action stack their long header/footer actions. */
  .visit-quick-modal .modal-header,
  .visit-photo-modal .modal-header,
  .visit-problem-modal .modal-header,
  .visit-quick-modal .modal-footer,
  .visit-photo-modal .modal-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .visit-quick-modal .modal-header > div,
  .visit-photo-modal .modal-header > div,
  .visit-problem-modal .modal-header > div {
    min-width: 0;
  }

  .visit-quick-modal [data-return-to-appointment],
  .visit-photo-modal [data-return-to-appointment],
  .visit-problem-modal [data-return-to-appointment],
  .visit-quick-modal .modal-footer .btn,
  .visit-photo-modal .modal-footer .btn {
    width: 100%;
  }

  /* Employee and position settings are full mobile workflows, just like a visit. */
  .master-modal,
  .positions-modal {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 0;
    border-radius: 0;
  }

  .master-modal-head,
  .positions-modal .modal-header,
  .master-modal .modal-footer,
  .positions-modal .modal-footer {
    flex: 0 0 auto;
  }

  .master-modal .master-modal-body,
  .positions-modal .modal-body {
    min-height: 0;
    flex: 1 1 auto;
    padding: 16px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .master-modal-head {
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
  }

  .master-modal-title {
    min-width: 0;
  }

  .master-modal-title > div {
    min-width: 0;
  }

  .master-modal-title h2,
  .master-modal-title p {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  .master-modal-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 10px 16px;
  }

  .master-modal-tabs button {
    min-height: 38px;
    padding: 0 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid var(--border-light);
    border-radius: 10px;
  }

  .master-modal-tabs button.is-active {
    background: var(--primary-soft);
    border-bottom-color: var(--primary);
  }

  .master-modal .master-profile-layout,
  .master-modal .master-schedule-calendar {
    grid-template-columns: minmax(0, 1fr);
  }

  .master-modal .master-profile-layout {
    gap: 18px;
  }

  .master-modal .master-avatar-upload {
    height: 174px;
  }

  .master-modal .master-calendar-panel {
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .master-modal .master-calendar-weekdays,
  .master-modal .master-calendar-grid {
    min-width: 504px;
  }

  .master-modal .modal-footer,
  .positions-modal .modal-footer {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 10px 16px max(12px, env(safe-area-inset-bottom));
    background: #fff;
  }

  .master-modal .modal-footer .btn,
  .positions-modal .modal-footer .btn {
    width: 100%;
  }

  .master-modal .modal-footer .btn:only-child,
  .positions-modal .modal-footer .btn:only-child {
    grid-column: 1 / -1;
  }

  .service-modal .service-master-table {
    margin: 0;
    overflow: visible;
    border: 0;
  }

  .service-modal .service-master-head {
    display: none;
  }

  .service-modal .service-master-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px;
    grid-template-areas:
      "person person remove"
      "duration price remove";
    gap: 9px;
    padding: 12px;
    border: 1px solid var(--border-light);
    border-radius: 12px;
  }

  .service-modal .service-master-row .settings-person { grid-area: person; }
  .service-modal .service-master-row [data-service-master-duration] { grid-area: duration; }
  .service-modal .service-master-row .service-price-input { grid-area: price; }
  .service-modal .service-master-row .service-remove-master { grid-area: remove; }

  .dictionary-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .dictionary-form .btn {
    width: 100%;
  }

  .incoming-form > .btn[type="submit"] {
    width: 100%;
  }

  .dictionary-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .dictionary-row-actions {
    justify-content: flex-start;
  }

  /* Preserve every day in analytics while making the chart itself scrollable. */
  .analytics-line-bars {
    min-width: calc(var(--day-count) * 44px);
  }

  .analytics-comparison-grid {
    grid-template-columns: 1fr;
  }

  .analytics-donut-wrap {
    grid-template-columns: minmax(0, 1fr);
  }

  .analytics-legend span {
    min-width: 0;
  }

  .analytics-legend b {
    overflow-wrap: anywhere;
  }

  /* Sale actions must never compete for one narrow footer row. */
  .sale-modal-footer .modal-footer-right {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .sale-modal-footer .modal-footer-right .btn {
    width: 100%;
  }

  .sale-payment-layer {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .sale-payment-dialog {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }

  .appointment-change-history {
    width: min(320px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
  }
}
