@media (max-width: 767px), (max-width: 959px) and (max-height: 500px) and (pointer: coarse) and (orientation: landscape) {
  .app-dialog.ticket-workflow-dialog {
    position: fixed;
    inset: auto;
    top: calc(var(--workflow-viewport-top, 0px) + max(8px, env(safe-area-inset-top)));
    left: calc(var(--workflow-viewport-left, 0px) + max(8px, env(safe-area-inset-left)));
    width: calc(var(--workflow-viewport-width, 100vw) - max(8px, env(safe-area-inset-left)) - max(8px, env(safe-area-inset-right)));
    max-height: calc(var(--workflow-viewport-height, 100dvh) - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
    margin: 0;
    overflow-y: auto;
    scroll-padding-block: 8px;
  }
  .ticket-workflow-dialog .app-dialog-actions { position: static; min-width: 0; box-shadow: none; }
  .ticket-workflow-dialog .app-dialog-actions > button { min-width: 0; white-space: normal; }
  .topbar:has(+ .page-content .ticket-create-panel) { min-height: 0; gap: 6px; padding: 6px 8px; }
  .topbar:has(+ .page-content .ticket-create-panel) h1 { margin: 0; font-size: 18px; line-height: 1.2; }
  .topbar:has(+ .page-content .ticket-create-panel) .muted { margin-top: 2px; font-size: 12px; line-height: 1.3; }
  .topbar:has(+ .page-content .ticket-create-panel) .mobile-menu-toggle { flex: 0 0 40px; width: 40px; height: 40px; min-height: 40px; padding: 8px; }
  .ticket-create-panel,
  .ticket-detail .ticket-intake-editor,
  .ticket-detail .detail-comments {
    padding: 12px;
  }

  .ticket-create-form,
  .ticket-detail .ticket-intake-form .ticket-create-form {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .ticket-create-form :is(.ticket-create-writing, .ticket-create-options, .ticket-option-list) {
    min-width: 0;
    gap: 10px;
  }

  .ticket-create-form .ticket-create-options { padding: 10px; }

  .ticket-create-form :is(.ticket-create-writing-heading, .ticket-create-options-heading) {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    min-width: 0;
    gap: 8px;
  }

  .ticket-create-form .ticket-create-section-title {
    min-width: 0;
    margin: 0;
    font-size: 15px;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }

  .ticket-create-form .ticket-create-writing > label,
  .ticket-create-form .ticket-option-list > label:not(.ticket-legal-approval-toggle),
  .ticket-create-form .legal-party-fields > label,
  .ticket-create-form .ticket-editor-field {
    min-width: 0;
    gap: 4px;
    font-size: 13px;
    line-height: 1.35;
  }

  .ticket-create-form .ticket-create-writing > label > input,
  .ticket-create-form .ticket-option-list > label > input:not([type="checkbox"]),
  .ticket-create-form .ticket-option-list > label > select,
  .ticket-create-form .legal-party-fields :is(input, select),
  .ticket-create-form .requester-selector-filters :is(input, select) {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    height: 40px;
    min-height: 40px;
    padding: 7px 10px;
    font-size: 16px;
    line-height: 1.35;
  }

  .ticket-create-form .ticket-editor-field > .advanced-rich-editor > .rich-editor-content {
    min-height: 128px;
    padding: 10px 12px;
  }

  .ticket-create-form .ticket-attachments-picker {
    min-width: 0;
    gap: 6px 8px;
    padding-top: 0;
  }

  .ticket-create-form .ticket-attachments-picker > .ticket-attachment-button {
    flex-basis: 40px;
    width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .ticket-create-form .ticket-attachments-note {
    font-size: 12px;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }

  .ticket-create-form .ticket-attachments-list { min-width: 0; gap: 6px; }
  .ticket-create-form .ticket-attachments-list:empty { display: none; }
  .ticket-create-form .ticket-attachments-existing { padding: 8px; }
  .ticket-create-form .ticket-attachment-item { gap: 6px; padding: 4px 6px; }

  .ticket-create-form .ticket-attachment-name {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .ticket-create-form .ticket-attachment-remove {
    flex-basis: 40px;
    width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .ticket-create-form :is(.ticket-people, .legal-parties) {
    min-width: 0;
    gap: 8px;
    margin-top: 0;
    padding-top: 10px;
  }

  .ticket-create-form :is(.ticket-people h3, .legal-parties-heading h3) {
    font-size: 13px;
    line-height: 1.35;
  }

  .ticket-create-form .ticket-legal-approval-toggle {
    min-height: 40px;
    gap: 8px;
    font-size: 12px;
    line-height: 1.35;
  }

  .ticket-create-form .legal-parties-heading {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  .ticket-create-form .legal-parties-heading p { font-size: 11px; line-height: 1.4; }

  .ticket-create-form .legal-parties-list {
    max-height: none;
    gap: 10px;
    padding-right: 0;
    overflow: visible;
  }

  .ticket-create-form .legal-party-card { gap: 8px; padding: 10px; }
  .ticket-create-form .legal-party-fields { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .ticket-create-form .legal-party-fields > label:last-child { grid-column: auto; }
  .ticket-create-form .requester-selector-filters { grid-template-columns: minmax(0, 1fr); gap: 8px; }

  .ticket-create-form .legal-parties-heading .ghost-button,
  .ticket-create-form .legal-party-remove,
  .ticket-create-form .person-selector-toggle {
    width: auto;
    max-width: 100%;
    min-height: 40px;
    padding: 6px 10px;
    font-size: 12px;
    white-space: normal;
  }

  .ticket-create-form .ticket-create-actions { width: 100%; margin-top: 0; padding-top: 10px; }
  .ticket-create-form .ticket-create-actions > .primary-button { width: 100%; min-width: 0; min-height: 42px; }

  .ticket-detail .ticket-intake-form { gap: 12px; }

  .ticket-detail .ticket-intake-header {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 0 0 10px;
  }

  .ticket-detail .ticket-intake-header-copy h3 { font-size: 16px; }
  .ticket-detail .ticket-intake-header-copy p { margin-top: 4px; font-size: 12px; }
  .ticket-detail .ticket-intake-toolbar { gap: 8px; }
  .ticket-detail .ticket-intake-actions { min-width: 0; flex-wrap: wrap; }
  .ticket-detail .ticket-intake-actions > button { min-width: 0; min-height: 42px; white-space: normal; }

  .ticket-detail .detail-comments > .detail-card-heading {
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 8px;
  }

  .ticket-detail .detail-comments > .detail-card-heading h3 { font-size: 14px; }
  .ticket-detail .detail-chat-status { margin: 0 0 8px; line-height: 1.4; }

  /* Only the empty history loses its reserved height. */
  .ticket-detail .detail-thread.chat-thread:has(> .detail-conversation-empty) {
    height: auto;
    min-height: 0;
    padding: 10px 12px;
  }

  .ticket-detail .detail-thread > .detail-conversation-empty {
    grid-template-columns: 24px minmax(0, 1fr);
    align-items: center;
    justify-items: start;
    width: 100%;
    min-width: 0;
    gap: 4px 8px;
    margin: 0;
    padding: 0;
    text-align: start;
  }

  .ticket-detail .detail-conversation-empty > .detail-icon {
    grid-column: 1;
    grid-row: 1 / span 2;
    width: 22px;
    height: 22px;
    margin: 0;
  }

  .ticket-detail .detail-conversation-empty > strong { grid-column: 2; font-size: 13px; line-height: 1.35; }
  .ticket-detail .detail-conversation-empty > p { grid-column: 2; max-width: none; font-size: 12px; line-height: 1.4; }

  .ticket-detail .detail-comment-form {
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    scroll-margin-block: 12px;
  }

  .ticket-detail .detail-composer-heading > .detail-internal-tag {
    box-sizing: border-box;
    max-width: 100%;
    margin: 0 0 0 auto;
    padding: 4px 6px;
    font-size: 10px;
    line-height: 1.3;
    letter-spacing: .02em;
    white-space: normal;
  }

  .ticket-detail .detail-comment-form .chat-keyboard-help { margin: 0; font-size: 11px; }

  .ticket-detail .detail-comment-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px 12px;
  }

  .ticket-detail .detail-comment-preferences { min-width: 0; gap: 4px; }
  .ticket-detail .detail-internal-toggle { min-width: 0; min-height: 40px; gap: 6px; line-height: 1.35; }
  .ticket-detail .detail-internal-toggle input { flex-basis: 18px; width: 18px; height: 18px; }
  .ticket-detail .detail-internal-toggle > span { min-width: 0; overflow-wrap: anywhere; }
  .ticket-detail .detail-visibility { line-height: 1.4; overflow-wrap: anywhere; }

  .ticket-detail .detail-comment-controls > .chat-send {
    width: auto;
    min-width: 88px;
    max-width: 100%;
    min-height: 42px;
    margin-left: 0;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.35;
    white-space: normal;
  }
}
