/* Phone layouts share the desktop palette, controls and data. */
.mobile-only { display: none !important; }

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

#app { padding: var(--safe-top) var(--safe-right) 0 var(--safe-left); }
.sidebar { left: var(--safe-left); top: var(--safe-top); bottom: var(--safe-bottom); }
dialog {
  inset: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  max-width: calc(100% - var(--safe-left) - var(--safe-right) - 28px);
  max-height: min(90dvh, calc(100dvh - var(--safe-top) - var(--safe-bottom) - 24px));
}

.more-list { display: grid; gap: 8px; max-width: 520px; }
.more-item {
  display: flex; align-items: center; gap: 12px; min-height: 54px; width: 100%;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: white; color: var(--green); text-align: left; font-weight: 600;
}
.more-item > span:not(.avatar) { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.more-item small { display: block; margin-top: 4px; color: #60736a; font-weight: 400; }
.more-item > svg:last-child { width: 15px; }
.more-admin-heading, .more-logout { margin-top: 22px; margin-bottom: 10px; }
.more-logout { max-width: 520px; }

@media (max-width: 600px) {
  html { overscroll-behavior-y: none; }
  .mobile-only { display: revert !important; }
  .desktop-only, .mobile-only[hidden] { display: none !important; }

  #app:has(> .app-shell) { padding-top: 0; }
  .app-shell .sidebar {
    position: static;
    grid-template-columns: 1fr auto;
    padding: calc(8px + var(--safe-top)) 16px 8px;
  }
  .app-shell .sidebar-nav, .app-shell .topbar, .app-shell .sidebar .profile { display: none; }
  .mobile-menu-button.mobile-only {
    display: inline-flex !important; align-items: center; gap: 6px; min-height: 44px;
    padding: 0 10px; border: 1px solid var(--line); border-radius: 8px;
    background: var(--mint); color: var(--green); font-weight: 650;
  }
  dialog:has(.mobile-menu-links) { margin: 12px auto auto; }
  .more-item[aria-current="page"] { background: var(--mint); }
  .app-shell .page { padding: 20px 16px calc(26px + var(--safe-bottom)); }
  .page-heading { margin-bottom: 18px; gap: 10px; }
  .page-heading .eyebrow { margin-bottom: 6px; }
  .page-heading p { max-width: none; font-size: 13px; color: #60736a; }
  .page-heading > .button { font-size: 13px; }
  .page-heading > .mobile-only.button { display: inline-flex !important; }
  .section-heading h2 { font-size: 18px; }
  .section-heading a { font-size: 12px; }
  .button, .text-button, .icon-button, summary { min-height: 44px; }
  .checkbox { min-height: 44px; }
  .checkbox input { flex-shrink: 0; accent-color: var(--green); }
  input:not([type="checkbox"], [type="radio"]), select, textarea { min-height: 44px; font-size: 16px; }
  #toast { bottom: calc(18px + var(--safe-bottom)); }
  .auth-story { min-height: 0; padding: 16px; }
  .auth-story .brand { margin: 0; }
  .auth-story > :not(.brand) { display: none; }
  .auth-form { padding: 24px 16px 52px; }
  .auth-card { padding: 22px; }
  .auth-help .text-button { padding-inline: 8px; }
  dialog.mobile-sheet {
    inset: auto 0 0; width: 100%; max-width: none; margin: 0;
    max-height: min(85dvh, calc(100dvh - var(--safe-top) - 12px));
    padding: 20px calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left));
    border-radius: 18px 18px 0 0;
  }
  dialog.mobile-sheet .form-actions { display: grid; grid-template-columns: 1fr; }
  dialog.mobile-sheet .form-actions button[type="submit"] { grid-row: 1; }
  dialog.mobile-sheet .form-actions .button { font-size: 14px; }

  .page-home .page-heading { padding: 12px 14px; background: var(--mint); border-radius: 12px; }
  .page-home .page-heading .eyebrow, .page-home .page-heading p, .page-home .welcome-banner { display: none; }
  .home-cards.mobile-only { display: grid !important; gap: 10px; }
  .home-card {
    min-width: 0; border: 1px solid var(--line); border-radius: 12px; background: white;
    overflow-wrap: anywhere;
  }
  .home-card-main {
    display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 10px;
    width: 100%; min-height: 64px; padding: 10px 12px; border: 0; border-radius: inherit;
    color: inherit; background: transparent; text-align: left; cursor: pointer;
  }
  .home-card-main small, .home-earnings-values small { display: block; margin-bottom: 3px; color: #53675e; font-weight: 500; }
  .home-card-main strong { font-size: 15px; }
  .home-card-main strong small { margin: 3px 0 0; }
  .home-card-main > svg, .home-card-heading svg, .home-card-link svg { width: 16px; color: var(--green); }
  .home-duty-summary { cursor: auto; }
  .home-card-link {
    display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px;
    margin: 0 12px; border-top: 1px solid var(--line); color: var(--green); font-size: 13px; font-weight: 650;
  }
  .home-card summary { list-style: none; cursor: pointer; }
  .home-card summary::-webkit-details-marker { display: none; }
  .home-card details[open] > summary > svg, .home-earnings[open] .home-card-heading svg { transform: rotate(90deg); }
  .home-earnings summary { padding: 12px; }
  .home-card-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 650; }
  .home-earnings-values { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .home-earnings-values strong { font-size: 19px; color: var(--green); }
  .home-card-detail { padding: 0 12px 10px; color: #53675e; font-size: 13px; }
  .home-card-detail .home-card-link { margin: 8px 0 0; }
  .news-body { font-size: 14px; }
  .news-meta > span:last-child { font-size: 12px; color: #60736a; }
  .news-card { overflow-wrap: anywhere; }
  .news-card .news-body { color: #53675e; }

  .laundry-panel .calendar-toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .laundry-panel .segmented button, .duty-mobile-filter button { flex: 1; justify-content: center; min-height: 44px; font-size: 13px; color: #53675e; }
  .laundry-day-view { padding: 0 12px 14px; }
  .laundry-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-bottom: 16px; }
  .laundry-days button {
    display: grid; justify-items: center; align-content: center; gap: 3px; min-height: 50px; padding: 2px;
    border: 1px solid var(--line); border-radius: 8px; background: white; color: #53675e; font-size: 11px;
  }
  .laundry-days strong { font-size: 15px; }
  .laundry-days [aria-pressed="true"], .duty-mobile-filter [aria-pressed="true"] { background: var(--green); color: white; border-color: var(--green); }
  .laundry-day-view h2 { margin: 0 2px 10px; font-size: 17px; }
  .laundry-slots { display: grid; gap: 7px; }
  .laundry-slot {
    display: grid; grid-template-columns: 7.2em minmax(0, 1fr) auto; align-items: center; gap: 6px;
    min-height: 54px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
    color: var(--green); background: #f7faf7; font-size: 13px; text-align: left;
  }
  .laundry-slot > span { overflow-wrap: anywhere; }
  .laundry-slot small { display: block; font-size: 11px; }
  .laundry-slot svg { width: 16px; }
  .laundry-slot.free { border: 1px dashed #91ac96; }
  .laundry-slot.mine { background: var(--mint); border-color: #b1cabb; }
  .laundry-slot.occupied { background: #e5d8c5; border-color: #b59d7b; color: #513e26; }
  .laundry-slot.past { background: #f2f4f2; color: #60736a; }
  .laundry-day-view summary { padding-block: 12px; font-weight: 600; color: #53675e; }
  .laundry-panel .calendar-legend { display: none; }

  .page-meetings { display: flex; flex-direction: column; }
  .page-meetings .duty-admin-tools { order: 1; }
  .page-meetings .duty-fullscreen-trigger { display: none; }
  .duty-toolbar-actions, .draft-actions { flex-wrap: wrap; justify-content: flex-start; }
  .duty-toolbar > label { min-width: 0; }
  .duty-toolbar input[type="month"] {
    display: block; min-width: 0; max-width: 100%;
    -webkit-appearance: none; appearance: none;
  }
  .duty-toolbar input[type="month"]::-webkit-date-and-time-value { text-align: left; }
  .registration-actions { flex-shrink: 1; }
  .duty-layout > .duty-holidays { order: 1; }
  .duty-mobile-filter.mobile-only { display: flex !important; margin: 0 12px 10px; }
  .duty-mobile-day.mobile-only { display: flex !important; margin: 0 12px 12px; }
  .duty-filter-empty { padding: 0 12px 12px; }
  .duty-calendar-panel .table-scroll { padding: 0 12px 10px; }
  .duty-calendar, .duty-calendar tbody { display: block; min-width: 0; width: 100%; }
  .duty-calendar thead { display: none; }
  .duty-calendar tbody tr {
    display: grid; grid-template-columns: max-content 1fr; gap: 6px 8px;
    margin-bottom: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 10px;
  }
  .duty-calendar tbody th.duty-weekday, .duty-calendar tbody th.duty-date {
    width: auto; border: 0; padding: 3px; background: transparent; text-align: left;
  }
  .duty-calendar tbody .duty-weekday span, .duty-calendar tbody .duty-date strong { font-size: 14px; margin: 0; }
  .duty-calendar .today-day .duty-date strong { padding: 0; background: transparent; color: inherit; }
  .duty-calendar .duty-today-label.mobile-only {
    display: inline-flex !important; margin: 0 0 0 8px; padding: 3px 7px; border-radius: 5px;
    background: var(--mint); color: var(--green); font-size: 11px; font-weight: 650;
  }
  .duty-calendar tbody td {
    position: relative; display: grid; grid-column: 1 / -1;
    grid-template-columns: 7.4em minmax(0, 1fr); align-items: center; gap: 6px;
    min-height: 47px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 7px; background: white;
    font-size: 12px; text-align: left;
  }
  .duty-calendar tbody td::before { content: attr(data-time); color: #53675e; font-weight: 600; }
  .duty-calendar tbody td:has(.own-assignment) { background: var(--mint); }
  .duty-calendar td .duty-assignment { display: flex; align-items: center; padding: 0; }
  .duty-calendar .own-assignment { box-shadow: none; background: transparent; }
  .duty-calendar .duty-assignment strong { overflow-wrap: anywhere; white-space: normal; }
  .duty-calendar .duty-assignment:has(.duty-assignment-remove) { padding-right: 40px; }
  .duty-assignment-remove { width: 40px; height: 40px; right: -3px; }
  .duty-slot-status { color: #53675e; }
  .clickable-slot .duty-slot-status { color: var(--green); font-weight: 650; }
  .duty-slot-action { position: absolute; inset: 0; z-index: 1; border: 0; border-radius: inherit; background: transparent; }
  .duty-sidebars .duty-roster ol { grid-template-columns: 1fr; }
  .duty-sidebars .participant-main { min-height: 44px; }
  .duty-calendar .mobile-filtered, .duty-calendar [data-mobile-filtered], .users-table .mobile-filtered { display: none; }

  .mobile-card-table, .mobile-card-table tbody, .mobile-card-table tfoot {
    display: block; width: 100%; min-width: 0 !important;
  }
  .mobile-card-table thead { display: none; }
  .mobile-card-table tr {
    display: grid; gap: 0; margin-bottom: 10px; padding: 5px 10px;
    background: white; border: 1px solid var(--line); border-radius: 9px;
  }
  .mobile-card-table tr > th, .mobile-card-table tr > td {
    min-width: 0; padding: 8px 2px; border-bottom: 1px solid var(--line);
    text-align: left; overflow-wrap: anywhere; white-space: normal;
  }
  .mobile-card-table tr > :last-child { border: 0; }
  .mobile-card-table td[data-label] { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 8px; align-items: center; }
  .mobile-card-table td[data-label]::before { content: attr(data-label); color: #53675e; font-weight: 600; }
  .mobile-card-table input, .mobile-card-table select { min-width: 0; max-width: 100%; }
  .log-records tr > th { padding: 0; }
  .log-records tr:not(.log-expanded) > td:not([colspan]) { display: none; }
  .log-record-toggle.mobile-only {
    display: flex !important; justify-content: space-between; align-items: center; gap: 8px;
    width: 100%; min-height: 50px; padding: 5px 2px; border: 0; background: none; color: inherit; text-align: left;
  }
  .log-record-toggle strong { font-size: 14px; }
  .log-record-toggle > span:last-child { font-size: 19px; }
  .log-record-toggle[aria-expanded="true"] > span:last-child { transform: rotate(180deg); }
  .log-notes { max-width: none; }
  .payroll-deductions-table [data-deduction-reason] { grid-column: 1 / -1; }
  .payroll-deductions-table .deduction-error { grid-column: 1 / -1; }
  .room-groups-table tr { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 10px; }
  .room-groups-table th, .room-groups-table td:last-child { grid-column: 1 / -1; }
  .room-groups-table td:not(:last-child) { grid-template-columns: minmax(0, 1fr); }
  .room-groups-table input { max-width: none; }
  .active-users { padding: 0; border: 0; background: transparent; }
  .users-table tr { margin-bottom: 6px; padding: 0 12px; }
  .users-table tr > td:first-child { padding: 0; }
  .users-table tr:not(.user-expanded) > td:first-child { border-bottom: 0; }
  .users-table tr:not(.user-expanded) > td + td, .users-table td:empty { display: none; }
  .user-row-toggle.mobile-only {
    display: flex !important; width: 100%; min-height: 54px; align-items: center;
    gap: 10px; padding: 6px 0; border: 0; background: none; color: #243a35; text-align: left;
  }
  .user-row-toggle .avatar { width: 32px; height: 32px; }
  .user-row-toggle > span:not(.avatar) { flex: 1; min-width: 0; }
  .user-row-toggle strong { font-size: 14px; overflow-wrap: anywhere; }
  .user-row-toggle small { display: block; margin-top: 2px; font-size: 12px; color: #60736a; }
  .user-row-toggle svg { width: 16px; color: var(--green); }
  .user-row-toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
  .active-users .user-position { min-width: 0; min-height: 44px; font-size: 16px; }
  .active-users .user-delete {
    width: auto; height: auto; min-height: 44px; padding: 0 8px;
    border-radius: 7px; background: transparent; color: #923a31; font-size: 13px; font-weight: 600;
  }
  .active-users .user-delete:hover { background: #f9e7e4; }
  .pending-users-list .user-name, .pending-users-list .user-name > span { min-width: 0; overflow-wrap: anywhere; }
  #mobile-user-search { margin-bottom: 12px; }

  .mobile-foldable { min-width: 0; }
  .mobile-foldable:has(.mobile-section-toggle[aria-expanded="false"]) > :not(h2) { display: none; }
  .mobile-section-toggle.mobile-only {
    display: flex !important; justify-content: space-between; align-items: center; gap: 10px;
    width: 100%; min-height: 44px; padding: 5px 0; border: 0; background: transparent;
    color: var(--green); text-align: left; font-size: 17px; font-weight: 650;
  }
  .mobile-section-toggle > span { font-size: 22px; }
  .mobile-section-toggle[aria-expanded="true"] span { transform: rotate(90deg); }
  .mobile-foldable h2:has([aria-expanded="false"]) { margin: 0; }
  .notification-template-group { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; }
  .personal-settings-grid { gap: 10px; }
  .personal-settings-grid > .mobile-foldable { padding: 8px 14px 12px; }
  .personal-settings-grid form > button[type="submit"] { width: 100%; }

  .duty-entry-name-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .duty-entry-save {
    position: sticky; bottom: 0; z-index: 2; background: white;
    padding-bottom: calc(10px + var(--safe-bottom));
  }
}
