/* Phone layouts for the working tools. Keep document/print dimensions intact;
   only their surrounding controls adapt. Load after the feature styles. */
@media screen and (max-width: 767px) {
  /* A grid/flex child's intrinsic width must never set the page width. */
  :is(.jobs-page, .events-page, .firms-page, .colleges-page,
      .article-page, .article-editor-page, .network-content) {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  :is(.job-form-grid, .event-form-grid, .firm-form-grid, .college-form-grid,
      .citation-fields, .college-profile-grid, .firm-profile-grid,
      .article-editor-layout) {
    grid-template-columns: minmax(0, 1fr);
  }

  :is(.job-form-grid, .event-form-grid, .firm-form-grid, .college-form-grid,
      .citation-fields, .article-editor-layout) > * {
    min-width: 0;
    max-width: 100%;
  }

  :is(.job-form-grid, .event-form-grid, .firm-form-grid,
      .college-form-grid, .citation-fields) .wide {
    grid-column: 1 / -1;
  }

  :is(.job-modal, .event-modal, .firm-modal, .college-modal, .citation-modal,
      .profile-form, .article-editor-page, .firm-inline-editor,
      #firmPostForm, #firmMemberForm, #firmMemberEditForm, #firmSettingsForm)
      :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    min-width: 0;
    max-width: 100%;
    font-size: 16px;
    box-sizing: border-box;
  }

  :is(.job-form-grid, .event-form-grid, .firm-form-grid, .college-form-grid,
      .citation-fields, .profile-form, .firm-inline-editor)
      :is(input:not([type="checkbox"]):not([type="radio"]), select) {
    min-height: 46px;
    width: 100%;
  }

  :is(.job-form-grid, .event-form-grid, .firm-form-grid, .college-form-grid,
      .citation-fields) label {
    font-size: 13px;
    line-height: 1.5;
  }

  :is(.job-modal, .event-modal, .firm-modal, .college-modal,
      #firmPostForm, #firmMemberForm, #firmMemberEditForm, #firmSettingsForm)
      textarea {
    width: 100%;
    min-height: 128px;
    line-height: 1.6;
  }

  :is(.jobs-page-top, .events-page-top, .firms-page-top, .colleges-page-top) {
    position: relative;
    top: auto;
    height: auto;
    min-height: 56px;
    gap: 8px;
    flex-wrap: wrap;
    padding-block: 8px;
  }

  :is(.jobs-page-top, .events-page-top, .firms-page-top,
      .colleges-page-top) > button {
    min-height: 44px;
    max-width: 100%;
    white-space: normal;
  }

  body:is(.logged-in,.guest-workspace) :is(.jobs-hero, .events-hero, .firms-hero, .colleges-hero) {
    display: block;
    padding: 24px 20px;
    border-radius: 16px;
  }

  body:is(.logged-in,.guest-workspace) :is(.jobs-hero, .events-hero, .firms-hero, .colleges-hero) h1 {
    font-size: clamp(28px, 7.5vw, 34px) !important;
    line-height: 1.15 !important;
  }

  :is(.jobs-hero, .events-hero, .firms-hero, .colleges-hero) p {
    font-size: 14px;
    line-height: 1.6;
  }

  :is(.firms-hero, .colleges-hero) > label {
    width: 100%;
    min-width: 0;
    margin-top: 20px;
    box-sizing: border-box;
  }

  :is(.firms-hero, .colleges-hero) input {
    min-width: 0;
    font-size: 16px;
  }

  /* Careers and events retain their existing list-to-detail interaction. */
  body:is(.logged-in,.guest-workspace) :is(.jobs-page .jobs-toolbar, .events-toolbar) {
    position: relative;
    top: auto;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 8px;
    padding: 12px;
    border-radius: 12px;
  }

  :is(.jobs-toolbar, .events-toolbar) > *,
  :is(.jobs-toolbar, .events-toolbar) .custom-select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  :is(.job-search, .event-search) {
    min-width: 0;
    min-height: 48px;
  }

  :is(.job-search, .event-search) input { min-width: 0; }

  :is(.jobs-toolbar, .events-toolbar) :is(select, .custom-select-trigger) {
    min-height: 46px;
  }

  .jobs-page .job-card h3,
  #eventsList .event-card-copy h3 { font-size: 17px; line-height: 1.4; }

  .jobs-page .job-card :is(strong, p),
  .event-card-copy > :is(b, span) { font-size: 13px; line-height: 1.5; }

  .jobs-page .job-card footer,
  .event-card-copy footer { flex-wrap: wrap; gap: 8px; font-size: 12px; }

  .job-detail-head > div,
  .job-detail-identity,
  .event-detail-card,
  .event-detail-card header > div { min-width: 0; max-width: 100%; }

  .job-detail .company { overflow-wrap: anywhere; }
  .job-detail .company-website-link { min-height: 44px; align-items: center; font-size: 14px; }
  .job-facts { grid-template-columns: minmax(0, 1fr); }
  .job-fact > strong { font-size: 14px; }
  .job-detail-copy { font-size: 16px; line-height: 1.7; }
  .event-description { font-size: 16px; line-height: 1.7; }
  .event-date-tile { width: 46px; }

  #eventDetail .event-detail-card > header > .event-header-meta {
    width: 100%;
    min-width: 0;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }

  #eventDetail .event-registration-deadline { text-align: left; }
  #eventDetail .event-top-links a { width: 100%; justify-content: center; white-space: normal; }
  .event-brochure-preview iframe { height: 65dvh; min-height: 280px; }

  /* Directories, organisation profiles and their management controls. */
  :is(.firm-card-grid, .college-card-grid) {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  :is(.firms-directory-head, .colleges-directory-head) {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 24px;
  }

  :is(.firms-directory-head, .colleges-directory-head) h2 { font-size: 26px; }
  :is(.firm-card, .college-card) { min-height: 0; }
  :is(.firm-card, .college-card) h3 { font-size: 23px; line-height: 1.3; }
  :is(.firm-card-body, .college-card-body) { padding-inline: 18px; }
  :is(.firm-card-meta, .college-card-meta) { flex-wrap: wrap; font-size: 13px; }
  .college-programmes span { font-size: 11px; line-height: 1.4; }
  :is(.firm-directory-back, .college-directory-back) { min-height: 46px; font-size: 14px; }

  body.firm-detail-view .firm-profile-identity,
  .college-profile-identity {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    padding: 0 18px 20px;
  }

  :is(.firm-profile-name, .college-profile-copy) { min-width: 0; }
  body.firm-detail-view .firm-profile-name h1,
  .college-profile-identity h1 { font-size: 28px; line-height: 1.2; overflow-wrap: anywhere; }

  :is(.firm-profile-logo, .college-profile-logo) {
    width: 92px;
    height: 92px;
    margin-top: -40px;
  }

  body.firm-detail-view .firm-stats {
    flex-wrap: wrap;
    gap: 10px 0;
    overflow: visible;
  }

  body.firm-detail-view .firm-stats span { white-space: normal; font-size: 11px; }
  .college-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .college-stats b, .college-stats b:first-child { padding: 14px 8px; font-size: 22px; }
  .college-stats small { line-height: 1.4; font-size: 10px; }
  .college-profile-location { flex-wrap: wrap; font-size: 12px; }

  body.firm-detail-view .firm-actions,
  .college-actions {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 0;
    padding: 12px;
  }

  body.firm-detail-view .firm-actions button,
  .college-actions button {
    min-width: 0;
    width: 100%;
    min-height: 46px;
    padding: 10px;
    font-size: 13px;
    line-height: 1.4;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  body.firm-detail-view .firm-actions #followFirm { min-height: 46px; }
  body.firm-detail-view .firm-actions-public { padding: 0; }
  body.firm-detail-view .firm-profile-grid { display: block; }
  :is(.firm-profile-grid, .college-profile-grid) > * { min-width: 0; }

  body.firm-detail-view .firm-panel,
  .college-panel { padding: 22px 18px; margin-bottom: 14px; border-radius: 14px; }

  :is(.firm-panel, .college-panel) h2 { font-size: 23px; line-height: 1.3; }
  body.firm-detail-view .firm-about-copy, .college-about { font-size: 15px; line-height: 1.75; }
  body.firm-detail-view .firm-panel > .firm-tags,
  .college-programme-grid { grid-template-columns: minmax(0, 1fr); }
  .college-programme-grid small { max-width: 100%; font-size: 12px; }
  .college-person > div, .college-opportunity > div, .firm-job > div { min-width: 0; }
  .college-person small, .college-opportunity small { font-size: 12px; line-height: 1.5; }

  :is(.firm-job, .college-opportunity) button,
  .firm-field-edit,
  body.firm-detail-view .firm-member-edit { min-height: 44px; min-width: 44px; font-size: 13px; }

  .firm-field-edit { flex: 0 0 44px; }
  body.firm-detail-view .firm-team-member-copy strong { font-size: 14px; }
  body.firm-detail-view .firm-team-member-copy small { font-size: 12px; }
  body.firm-detail-view .firm-contact dd { font-size: 14px; }
  .firm-contact dd { min-width: 0; flex-wrap: wrap; }
  .firm-contact dd a { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }

  body.firm-detail-view .firm-post-composer { padding: 18px 14px; }
  body.firm-detail-view .firm-post-composer-head { display: block; }
  body.firm-detail-view .firm-post-message { grid-template-columns: 34px minmax(0, 1fr); gap: 10px; }
  body.firm-detail-view .firm-post-composer-footer { grid-template-columns: minmax(0, 1fr); padding-left: 0; }
  body.firm-detail-view .firm-post-composer-footer button { width: 100%; min-height: 46px; }
  body.firm-detail-view .firm-post-message textarea,
  body.firm-detail-view .firm-post-composer-footer input { min-width: 0; max-width: 100%; font-size: 16px; }

  #firmSettingsForm .firm-form-grid { grid-template-columns: minmax(0, 1fr); }
  #firmMemberForm { display: block; }
  #firmMemberForm > label,
  #firmMemberForm > label:first-of-type,
  #firmMemberForm > label:nth-of-type(2),
  #firmMemberForm > label:nth-of-type(3) { padding-inline: 18px; }
  .firm-member-results { left: 18px; right: 18px; max-height: 35dvh; }
  .firm-member-selection { height: auto; min-height: 64px; }
  .firm-member-selection button { min-height: 44px; font-size: 12px; }
  .firm-member-selection strong, .firm-member-result strong { font-size: 13px; }
  #firmMemberEditForm > label { margin-inline: 0; }
  .firm-member-edit-footer { flex-wrap: wrap; }
  .firm-member-edit-footer span { flex-basis: 100%; margin-left: 0; }

  /* Network cards keep both the identity and every action readable. */
  .network-tabs { padding-inline: 12px; overflow-x: auto; scrollbar-width: thin; }
  .network-tabs button { flex: 0 0 auto; min-height: 48px; padding-inline: 12px; font-size: 14px; }
  .network-content { padding: 12px; }
  .network-person { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 12px; padding: 16px; border-radius: 12px; }
  .network-person .avatar { width: 44px; height: 44px; }
  .network-person strong { font-size: 15px; line-height: 1.4; }
  .network-person small { font-size: 13px; line-height: 1.5; }
  .network-person .network-actions { grid-column: 1 / -1; display: flex; flex-direction: row; flex-wrap: wrap; margin-left: 0; gap: 8px; }
  .network-actions button { flex: 1 1 110px; min-height: 44px; padding: 10px 12px; font-size: 13px; border-radius: 8px; }

  #profilePage :is(.name-row, .section-heading, .credential-card-heading) { flex-wrap: wrap; }
  #profileOwnerActions, #profileMemberActions { flex-wrap: wrap; }
  #profileOwnerActions > button, #profileMemberActions > button { flex: 1 1 130px; min-width: 0; white-space: normal; }
  #profilePage .section-heading button,
  #profilePage .entry-actions button,
  #profilePage .profile-section-save > button { min-height: 44px; min-width: 44px; }
  #profilePage .profile-save-bar { flex-wrap: wrap; gap: 8px; }
  #profilePage .credential-card-heading strong { overflow-wrap: anywhere; }
  #profilePage .credential-card-heading small { max-width: 100% !important; text-align: left !important; }
  #profilePage .dossier-stats { gap: 10px 16px; }
  .verified-profile { flex-wrap: wrap; }
  .verified-profile small { margin-left: 0; }

  /* Reader actions and every editor command remain reachable on a phone. */
  .article-topbar {
    position: relative;
    top: auto;
    height: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 8px;
    padding: 10px 14px;
  }

  .article-topbar > button { min-height: 44px; text-align: left; }
  .article-topbar > div { flex: 1 1 100%; flex-wrap: wrap; }
  .article-topbar .outline-btn:not([hidden]) { display: inline-flex; flex: 1 1 110px; min-height: 44px; align-items: center; justify-content: center; margin: 0; font-size: 13px; white-space: normal; }
  .article-topbar .article-website-publish:after { content: none; }
  .article-hero { padding: 30px 18px; }
  .article-kicker { flex-wrap: wrap; line-height: 1.5; }
  .article-byline { flex-wrap: wrap; }
  .article-published { display: flex; flex-basis: 100%; margin-left: 0; text-align: left; gap: 4px; }
  .article-layout { padding-inline: 12px; }
  .article-content { padding: 26px 18px; font-size: 16px; line-height: 1.75; overflow-wrap: anywhere; }
  .article-content :is(img, video, iframe) { max-width: 100%; }
  .article-content :is(table, pre) { max-width: 100%; overflow-x: auto; display: block; }
  .article-contents a { display: flex; align-items: center; min-height: 44px; font-size: 13px; }

  .article-editor-top,
  .editor-focus-mode .article-editor-top {
    position: relative;
    top: auto;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 12px;
  }

  .article-editor-top > button { min-height: 44px; justify-self: start; }
  .article-editor-top .editor-top-status {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    min-width: 0;
  }

  .article-editor-top .editor-top-status > span {
    display: block;
    grid-column: 1 / -1;
    font-size: 12px;
    margin: 0;
  }

  .article-editor-top .editor-top-status > button,
  .article-editor-top #toggleEditorSeo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    width: 100%;
    min-height: 46px;
    margin: 0;
    padding: 8px;
    font-size: 13px;
    white-space: normal;
  }

  .article-editor-top .editor-zoom { display: flex; grid-column: 1 / -1; justify-self: start; height: 44px; }
  .article-editor-top .editor-zoom button { width: 44px; height: 44px; }
  .article-editor-top .editor-zoom strong { font-size: 12px; }
  .article-editor-shell, .editor-focus-mode .article-editor-shell { padding: 24px 12px; }
  .article-editor-layout, .editor-focus-mode .article-editor-layout { grid-template-columns: minmax(0, 1fr); }
  .article-editor-sidebar { order: 0; }
  .article-editor-intro > div { min-width: 0; }
  .article-workflow-nav { max-width: 100%; gap: 8px; padding: 8px; scroll-snap-type: x proximity; }
  .article-workflow-nav button { min-height: 52px; flex: 0 0 128px; padding: 8px; scroll-snap-align: start; }
  .article-workflow-nav > i { display: none; }
  .article-workflow-nav button > span { font-size: 12px; }
  .article-workflow-nav small { font-size: 10px; }

  .word-ribbon, .editor-focus-mode .word-ribbon {
    position: relative;
    inset: auto;
    width: 100%;
    max-width: 100%;
  }

  .word-tabs { height: auto; min-height: 46px; padding-inline: 8px; }
  .word-tabs button { flex: 0 0 auto; min-height: 46px; padding: 8px 12px; font-size: 13px; }
  .editor-toolbar { align-items: stretch; padding: 8px; scroll-padding-inline: 8px; }
  .editor-toolbar .ribbon-group { flex: 0 0 auto; padding: 0 8px 18px; }
  .editor-toolbar .ribbon-group button { min-width: 44px; min-height: 44px; height: auto; font-size: 13px; }
  .editor-toolbar .ribbon-font { width: 252px; }
  .editor-toolbar .ribbon-font select { min-height: 44px; font-size: 16px; }
  .editor-toolbar .ribbon-font select:first-child { min-width: 0; width: 166px; }
  .editor-toolbar .ribbon-font select:last-child { width: 66px; }
  .editor-toolbar .ribbon-paragraph { width: 208px; }
  .editor-toolbar .ribbon-styles { width: 200px; }
  .editor-toolbar .ribbon-insert { width: 270px; }
  .editor-toolbar .ribbon-group > small { display: block; font-size: 10px; }
  .editor-focus-mode .article-editor-card { padding-top: 0; }

  .article-editor-card > :is(.editor-title-label, .editor-standfirst-label,
      .article-outline-bar, .editor-body-label, .editor-counts) {
    width: calc(100% - 12px);
    padding-inline: 16px;
  }

  .article-editor-card > .editor-title-label { padding-top: 26px; }
  .article-editor-card input#articleEditorTitle { font-size: 26px; line-height: 1.35; }
  .article-outline-bar { gap: 10px; }
  .article-outline-bar button { min-height: 44px; min-width: 90px; font-size: 12px; }
  .editor-body-canvas .rich-article-body { min-height: 360px; font-size: 17px; }
  .editor-page-break { margin-inline: -16px; }
  .editor-page-break:after { left: 16px; right: 16px; }
  .editor-reference-panel { margin-inline: 12px; padding: 14px; }
  .editor-reference-panel > header { flex-wrap: wrap; }
  .editor-reference-panel button { min-height: 44px; min-width: 44px; }
  .editor-reference-panel ol li { grid-template-columns: 23px minmax(0, 1fr) 44px; gap: 6px; }
  .editor-side-card { padding: 18px; }
  .editor-side-card label { font-size: 13px; }
  .seo-advanced summary { min-height: 44px; }

  .citation-modal-body { display: block; max-height: none; overflow: visible; }
  .citation-modal-head { align-items: flex-start; gap: 10px; padding: 18px; }
  .citation-mark { width: 38px; height: 38px; border-radius: 10px; }
  .citation-modal-head > div:not(.citation-mark) { min-width: 0; }
  .citation-modal-head > button { flex: 0 0 44px; min-height: 44px; }
  .citation-builder, .citation-library { padding: 18px; }
  .citation-types { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .citation-types button { min-height: 60px; }
  .citation-types button span { font-size: 12px; }
  .citation-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .citation-actions button { width: 100%; min-height: 46px; margin: 0; }
  .citation-preview p, .citation-library-list p { overflow-wrap: anywhere; }
  .citation-preview button, .citation-library-list button { min-height: 44px; padding-inline: 8px; font-size: 12px; }
  .citation-library > a, .bibliography-btn { min-height: 44px; font-size: 12px; }
  .article-website-modal .modal-footer > div { grid-template-columns: minmax(0, 1fr); }

  /* Keep A4 preview scaling/zoom unchanged; resize its touch controls only. */
  .resume-studio { height: 100dvh; }
  .resume-studio-head { padding-top: max(12px, env(safe-area-inset-top)); }
  .resume-studio-head > button { width: 44px; height: 44px; }
  .resume-workflow-nav { min-width: 0; }
  .resume-workflow-nav button { min-width: 0; min-height: 44px; font-size: 12px; }
  .resume-workflow-nav button span { margin-right: 4px; }
  .resume-missing-card > header { flex-wrap: wrap; gap: 10px; }
  .resume-missing-list strong { font-size: 13px; }
  .resume-missing-list small { font-size: 12px; }
  .resume-template-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .resume-template-panel > * { flex-shrink: 0; }
  .resume-template-panel .template-panel-title { order: 0; padding: 10px 12px; }
  .resume-readiness-summary { order: 3; float: none; width: calc(100% - 24px); margin: 10px 12px; }
  .resume-contact-controls {
    order: 2;
    float: none;
    min-width: 0;
    width: calc(100% - 24px);
    height: auto;
    margin: 0 12px 10px;
    padding: 4px 8px;
    white-space: normal;
  }

  .resume-contact-controls label { min-height: 44px; padding-inline: 4px; gap: 6px; font-size: 12px; }
  .resume-contact-controls input { width: 18px; height: 18px; }
  .resume-template-list { order: 1; width: 100%; min-width: 0; overflow-x: auto; gap: 8px; }
  .resume-template-card { flex: 0 0 124px; min-width: 124px; }
  .resume-preview-stage { grid-template-rows: auto minmax(0, 1fr); }
  .preview-toolbar { flex-wrap: wrap; padding: 8px 10px; gap: 6px; }
  .preview-toolbar > span { font-size: 12px; }
  .preview-controls { width: 100%; justify-content: space-between; gap: 8px; }
  .preview-controls .photo-toggle { max-width: calc(100% - 132px); min-height: 44px; font-size: 12px; white-space: normal; }
  .photo-toggle > span { flex: 0 0 30px; }
  .zoom-controls { gap: 4px; }
  .preview-toolbar strong { min-width: 32px; font-size: 12px; }
  .resume-studio-footer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .resume-studio-footer button { min-height: 48px; font-size: 12px; white-space: normal; }
  .resume-full-toolbar { flex-wrap: wrap; height: auto; min-height: 56px; padding: 6px 8px; gap: 4px; }
  .resume-full-preview { padding-top: 70px; }

  .website-workflow-overlay { padding: 12px; }
  .website-workflow-card { max-height: calc(100dvh - 24px); padding: 48px 20px 24px; overflow-y: auto; box-sizing: border-box; }
  .website-workflow-card h2 { font-size: 28px; overflow-wrap: anywhere; }
  .website-workflow-card .primary-btn { width: 100%; min-width: 0; min-height: 48px; white-space: normal; }
  .website-workflow-close { width: 44px; height: 44px; right: 8px; top: 4px; }
  .website-workflow-countdown { gap: 6px; }
  .website-workflow-countdown b { min-width: 44px; font-size: 32px; }
}

@media screen and (max-width: 359px) {
  body.firm-detail-view .firm-actions,
  .college-actions { grid-template-columns: minmax(0, 1fr); }
  .network-person { padding: 12px; }
  .resume-workflow-nav button { padding-inline: 5px; font-size: 11px; }
  .resume-workflow-nav button span { display: none; }
  .resume-studio-heading h1 { font-size: 17px; }
  .citation-modal-head .citation-mark { display: none; }
  .article-editor-top .editor-top-status > button { font-size: 12px; }
}
