/* The workbench keeps its desktop tables, but presents their rows as readable cards on phones. */
.sidebar-close { display: none; }

@media (max-width: 860px) {
  #sidebar :is(button, a) { min-height: 44px; }

  #content .org-toolbar {
    flex-wrap: wrap;
    align-items: stretch;
  }

  #content .org-toolbar .org-search {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  #content .org-toolbar .org-status-filter,
  #content .org-toolbar .direct-filter {
    min-height: 44px;
  }

  #appShell > #sidebar.show {
    z-index: 80;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  .sidebar-close {
    display: grid;
    place-items: center;
    flex: none;
    width: 44px;
    height: 44px;
    margin-left: auto;
    border: 1px solid var(--shell-border, var(--line));
    border-radius: 10px;
    color: var(--shell-text, var(--text));
    background: color-mix(in srgb, var(--shell-accent, var(--primary)) 10%, transparent);
    font-size: 24px;
    cursor: pointer;
  }

  .sidebar-close:focus-visible,
  #mobileMenu:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
}

@media (max-width: 640px) {
  /* Light cloud tokens need stronger small-text contrast on compact screens. */
  html[data-theme="cloud"][data-scheme="light"] {
    --muted: #5d6c82 !important;
    --primary: #3459d1 !important;
    --cyan: #087d96 !important;
    --success: #12705a !important;
    --warning: #9a5b08 !important;
    --danger: #bb3f52 !important;
  }

  html[data-theme="cloud"][data-scheme="light"] #content .protocol-badge {
    color: #0a6075;
  }

  /* Keep off-canvas overlays and decorative art out of horizontal page scrolling. */
  html, body { overflow-x: clip; }

  .app-shell .topbar .user-menu {
    flex: 0 0 44px;
    width: 44px;
    max-width: 44px;
  }

  .app-shell .topbar .user-trigger {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    min-height: 44px;
    padding: 3px;
    gap: 0;
  }

  .app-shell .topbar .user-trigger > svg,
  .app-shell .topbar .user-trigger > i {
    display: none;
  }

  .app-shell .topbar .user-trigger .avatar {
    flex: 0 0 36px;
  }

  .app-shell .topbar #userDropdown {
    width: min(280px, calc(100vw - 20px));
  }

  .app-shell .topbar :is(#mobileMenu, #notifyBtn),
  dialog.modal[open] .close-btn {
    min-width: 44px;
    min-height: 44px;
  }

  #content,
  #content .section-card,
  #content .org-main-panel,
  #content .table-wrap,
  #content .file-table-wrap,
  #content .task-management-table {
    min-width: 0;
    max-width: 100%;
  }

  #content .mobile-card-table {
    display: block;
    width: 100%;
    min-width: 0;
    border-collapse: separate;
  }

  #content .mobile-card-table colgroup,
  #content .mobile-card-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  #content .mobile-card-table tbody {
    display: grid;
    gap: 10px;
    padding: 9px;
  }

  #content .mobile-card-table tbody tr {
    display: grid;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
  }

  #content .mobile-card-table tbody tr.hidden,
  #content .mobile-card-table tbody tr[hidden] {
    display: none;
  }

  #content .mobile-card-table tbody td {
    position: static;
    display: grid;
    grid-template-columns: minmax(76px, 28%) minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    overflow: visible;
    border-bottom: 1px solid var(--line);
    box-shadow: none;
    white-space: normal;
    overflow-wrap: anywhere;
    text-overflow: clip;
  }

  #content .mobile-card-table tbody td:last-child {
    border-bottom: 0;
  }

  #content .mobile-card-table tbody td::before {
    content: attr(data-mobile-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
    line-height: 1.5;
  }

  #content .mobile-card-table tbody td[colspan] {
    display: block;
  }

  #content .mobile-card-table tbody td[colspan]::before {
    content: none;
  }

  #content .mobile-card-table .member-credentials,
  #content .mobile-card-table .table-actions,
  #content .mobile-card-table .file-name-cell {
    min-width: 0;
  }

  #content .mobile-card-table .table-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  #content .mobile-card-table .person-cell,
  #content .mobile-card-table .row-action,
  #content .mobile-card-table .credential-action {
    min-height: 44px;
  }

  #content .mobile-card-table .credential-action {
    min-width: 44px;
    padding: 6px;
  }

  #content .mobile-card-table .member-actions {
    width: auto;
    flex-wrap: wrap;
  }

  #content .mobile-card-table .member-actions .row-action {
    min-width: 56px;
    padding: 8px;
  }

  #content .mobile-card-table .interactive-row {
    cursor: pointer;
  }

  #content .mobile-card-table .interactive-row:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }

  #content :is(.primary-btn, .secondary-btn, .row-action),
  dialog.modal[open] :is(.primary-btn, .secondary-btn, .close-btn, .modal-actions button) {
    min-height: 44px;
  }

  #content button { min-height: 44px; }

  #content :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select),
  dialog.modal[open] :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select) {
    min-height: 44px;
    max-width: 100%;
  }

  dialog.modal[open] {
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  dialog.modal[open] .modal-actions,
  dialog.modal[open] .global-variable-modal-actions {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 360px) {
  .app-shell .topbar {
    gap: 6px;
    padding-inline: 8px;
  }
  .app-shell .topbar .topbar-brand { display: none; }
  #content .hero-ui-card-left { display: none; }
}
