/* Touch tablets retain the desktop information density without mouse-sized controls. */
@media screen and (min-width: 600px) and (max-width: 1440px) and (any-pointer: coarse) {
  html { font-size: 16px; scroll-padding-block: 96px 32px; }
  :root { --form-input-font-size: 16px; }
  body { -webkit-text-size-adjust: 100%; }
  body .app-layout { grid-template-columns: minmax(0, 1fr) !important; gap: 0 !important; }
  body .main-area { width: 100%; min-width: 0; }
  body .content {
    padding: 20px max(20px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)) !important;
  }
  body .topbar {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto !important;
    align-items: center;
    gap: 16px !important;
    margin: max(12px, env(safe-area-inset-top)) 16px 0 !important;
    padding: 12px 16px !important;
    min-height: 72px;
  }
  body .topbar-left { display: flex !important; align-items: center; gap: 12px; min-width: 0; }
  body .topbar-title { min-width: 0; font-size: 17px !important; line-height: 1.3; text-align: center; }
  body .topbar-right { flex-wrap: wrap; gap: 8px; }
  body .topbar-left .user-chip { display: none !important; }
  body #hamburgerBtn {
    display: inline-flex !important;
    position: static !important;
    align-items: center;
    justify-content: center;
    gap: 9px !important;
    width: auto !important;
    min-width: 48px !important;
    height: 48px !important;
    padding: 8px 12px !important;
  }
  body .sidebar-hamburger .ham-glyph { display: flex !important; flex: 0 0 28px; align-items: center; flex-direction: column; justify-content: center; gap: 4px; }
  body .sidebar-hamburger .ham-bar { display: block !important; width: 16px !important; height: 2px !important; }
  body .sidebar-hamburger .ham-label { display: inline !important; font-size: 14px !important; }
  body .sidebar {
    position: fixed !important;
    inset: 0 auto 0 0 !important;
    width: 310px !important;
    min-width: 0 !important;
    height: 100dvh !important;
    margin: 0 !important;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    border-radius: 0 8px 8px 0 !important;
    transform: translateX(-104%) !important;
    pointer-events: none !important;
    z-index: 125 !important;
  }
  body.menu-open .sidebar { transform: translateX(0) !important; pointer-events: auto !important; }
  body .sidebar-overlay { display: none !important; position: fixed; inset: 0; z-index: 120 !important; }
  body.menu-open .sidebar-overlay { display: block !important; }
  body .sidebar .menu-link { min-height: 48px !important; padding: 10px 12px !important; font-size: 15px !important; }
  body .sidebar .menu { gap: 5px !important; overscroll-behavior: contain; }
  body .sidebar .sidebar-footer { flex: 0 0 auto; }
  body.menu-open .sidebar .sidebar-dismiss {
    position: static;
    flex: 0 0 auto;
    width: auto;
    height: auto;
    min-height: 44px;
    margin: 8px 12px;
    padding: 8px 12px;
    clip-path: none;
    overflow: visible;
    border: 1px solid #7895b4;
    border-radius: 6px;
    color: #fff;
    background: #163b61;
    font-size: 14px;
  }
  body #navEdgeReveal { display: none !important; }

  /* Preserve state colours and icons; only increase touch area and legibility. */
  body .main-area :is(button, .btn, .mini-btn, .icon-btn, .topbar-action, summary) {
    min-height: 44px !important;
    min-width: 44px;
    touch-action: manipulation;
  }
  body .main-area :is(.btn, .mini-btn, .topbar-action, .phrase-btn) {
    font-size: 14px !important;
    line-height: 1.35 !important;
    white-space: normal !important;
  }
  body .main-area :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea) {
    min-height: 48px !important;
    font-size: 16px !important;
    scroll-margin-block: 96px 32px;
  }
  body .main-area :is(.field-group > span, .form-grid > label, .compact-form-grid > label) { font-size: 14px !important; line-height: 1.4; }
  body .main-area :is(.section-note, .form-hint, .micro-help, .field-group small) { font-size: 13px !important; line-height: 1.45; }
  body .main-area :is(.actions, .quick-actions, .filter-row, .td-actions) { gap: 10px; }
  body .main-area .quick-actions > * { flex-basis: auto; }
  body .table-wrap { overscroll-behavior-inline: contain; scrollbar-width: auto; }
  body .scroll-top-btn { width: 48px; height: 48px; bottom: max(16px, env(safe-area-inset-bottom)); }

  /* Home: keep the work entry points together instead of three phone-width bands. */
  body.page-dashboard .home-vnext { width: min(1280px, 100%); gap: 20px; }
  body.page-dashboard .home-hero { padding: 24px; }
  body.page-dashboard .home-hero-metrics.has-validity { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body.page-dashboard .home-procedure-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  body.page-dashboard .home-procedure-card { grid-template-columns: 40px minmax(0, 1fr) 16px; padding: 16px; min-height: 140px; gap: 10px; }
  body.page-dashboard .home-procedure-card :is(strong, h3) { font-size: 16px; }
  body.page-dashboard .home-procedure-card :is(small, p) { font-size: 13px; line-height: 1.4; }
  body.page-dashboard .home-secondary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body.page-dashboard .home-account-grid { grid-template-columns: 1fr; }
  body.page-dashboard .home-resume-main { align-items: center; }

  /* R.F.T.: one aligned toolbar, comfortably sized controls and spacious writing. */
  body.page-rft .rft-shell.rft-unified :is(.rft-casebar, .rft-turn-workspace) { padding-inline: 20px; }
  body.page-rft .rft-shell.rft-unified .rft-turn-tabs > a { min-height: 52px; font-size: 15px; }
  body.page-rft .rft-shell.rft-unified .rft-intervention-card-head { gap: 14px; padding: 16px; }
  body.page-rft .rft-shell.rft-unified .rft-intervention-card-head > strong { min-width: 0; }
  body.page-rft .rft-shell.rft-unified .rft-intervention-card-tools { grid-template-columns: 112px 132px auto; grid-auto-rows: 44px; gap: 8px; }
  body.page-rft .rft-shell.rft-unified :is(.rft-card-stralcio, .rft-card-collapse) { min-height: 44px !important; height: 44px !important; font-size: 14px !important; }
  body.page-rft .rft-shell.rft-unified .rft-card-icon-actions { grid-template-columns: repeat(3, 44px); gap: 8px; }
  body.page-rft .rft-shell.rft-unified :is(.rft-card-move, .rft-card-delete, .rft-checkpoint-person-edit, .rft-icon-btn) { width: 44px !important; height: 44px !important; }
  body.page-rft .rft-shell.rft-unified :is(.icon-btn:not(.rft-card-collapse), .rft-back) { width: 44px !important; min-width: 44px !important; height: 44px !important; min-height: 44px !important; }
  body.page-rft .rft-shell.rft-unified .rft-intervention-card-preview { font-size: 15px; line-height: 1.6; padding: 14px 16px; }
  body.page-rft .rft-shell.rft-unified [data-card-body] { font-size: 16px !important; line-height: 1.6 !important; }
  body.page-rft .rft-shell.rft-unified .rft-event-action { min-height: 48px !important; font-size: 14px; }
  body.page-rft .rft-shell .rft-date-manual .btn { min-height: 48px !important; height: auto !important; }
  body.page-rft .rft-shell.rft-unified .rft-context-drawer {
    width: min(820px, 100vw);
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
    overscroll-behavior: contain;
    scroll-padding-block: 100px 24px;
  }
  body.page-rft .rft-shell.rft-unified .rft-context-drawer-head { padding: max(20px, env(safe-area-inset-top)) 24px 20px; }
  body.page-rft .rft-shell.rft-unified .rft-context-drawer .rft-nominativi-stage { padding: 20px 24px 28px; }
  body.page-rft .rft-shell.rft-unified .rft-person-grid { gap: 16px; }
  body.page-rft .rft-shell.rft-unified .rft-nominativi-stage:not(.is-intervention-create) .rft-person-card-head { grid-template-columns: 44px minmax(0, 1fr) auto auto auto 44px !important; }
  body.page-rft .rft-shell.rft-unified .rft-person-steps button { min-height: 60px !important; font-size: 14px; padding-inline: 8px; }
  body.page-rft .rft-shell.rft-unified .rft-person-card-nav { padding-block: 16px; gap: 12px; }
  body.page-rft .rft-shell.rft-unified .rft-checkpoint-person-copy { grid-template-columns: minmax(0, 1fr) auto 44px; gap: 8px; }
  body.page-rft .rft-shell.rft-unified :is(.rft-schema-number, .rft-nom-people-stepper) { grid-template-columns: 44px minmax(64px, 1fr) 44px; height: 50px; }
  body.page-rft .rft-shell.rft-unified :is(.rft-schema-number, .rft-nom-people-stepper) button { width: 44px !important; height: 48px !important; }
  body.page-rft .rft-shell.rft-unified :is(.rft-schema-number, .rft-nom-people-stepper) input { width: 100% !important; max-width: 100% !important; }

  /* Atti Operativi: the final action row must not inherit 100% flex basis vertically. */
  body.page-dpl .dpl-page-shell { --dpl-control-h: 48px; width: min(1280px, 100%); }
  body.page-dpl .dpl-page-shell .dpl-step :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, .ts-control) { min-height: 48px !important; font-size: 16px !important; }
  body.page-dpl .dpl-page-shell .dpl-form.card { padding: 20px !important; }
  body.page-dpl .dpl-page-shell .dpl-step:not([data-step="4"]) { padding: 0 !important; }
  body.page-dpl .dpl-page-shell :is(.dpl-work-panel, .adaptive-section-body) { padding: 20px !important; }
  body.page-dpl .dpl-page-shell :is(.dpl-phase-actions, .adaptive-section-actions.split-actions) {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: space-between !important;
    align-items: center !important;
    min-height: 0 !important;
    height: auto !important;
    gap: 12px !important;
    padding: 16px !important;
  }
  body.page-dpl .dpl-page-shell :is(.dpl-phase-actions, .adaptive-section-actions) > * { flex: 0 1 auto !important; width: auto !important; }
  body.page-dpl .dpl-page-shell .dpl-phase-actions .quick-actions { flex: 0 1 auto !important; width: auto !important; }
  body.page-dpl .dpl-page-shell .dpl-phase-actions .quick-actions > * { flex: 0 1 auto !important; width: auto !important; }
  body.page-dpl .dpl-page-shell .dpl-phase-actions .dpl-nav-btn { width: auto !important; }
  body.page-dpl .dpl-page-shell :is(.dpl-phase-actions, .generate-row) .btn { min-height: 48px !important; height: auto !important; font-size: 15px !important; }
  body.page-dpl .dpl-page-shell :is(.dpl-grid-anagrafica, .dpl-grid-complementari, .dpl-grid-indirizzi, .domicilio-defender-grid) { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  body.page-dpl .dpl-page-shell .dpl-compile-progress-rail { scroll-padding-inline: 12px; overscroll-behavior-inline: contain; scrollbar-width: thin; }
  body.page-dpl .dpl-page-shell .dpl-progress-step { min-width: 200px; max-width: 260px; white-space: normal; }
  body.page-dpl .dpl-page-shell .dpl-compile-root :is(.mini-btn, .copy-btn, .phrase-btn) { min-height: 44px !important; height: auto !important; font-size: 14px !important; }
  body.page-dpl .dpl-page-shell .dpl-preset-btn { min-height: 44px !important; font-size: 14px !important; }
  body.page-dpl .dpl-page-shell .dpl-document-menu > summary { width: 44px; }

  /* Planning: keep navigation visible and scrolling inside the grids. */
  body.page-planning .planning-mobile-section-picker { display: none !important; }
  body.page-planning .planning-workspace-tabs {
    display: flex !important;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    padding-block: 4px 8px;
    overscroll-behavior-inline: contain;
  }
  body.page-planning .planning-workspace-tabs > a { flex: 0 0 auto; min-height: 48px; padding: 12px 16px; font-size: 14px; }
  body.page-planning .planning-team-primary-actions { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
  body.page-planning .planning-management-hub { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  body.page-planning .planning-control-actions { display: flex; flex-wrap: wrap; align-items: center; }
  body.page-planning .planning-direct-actions { width: auto; flex-wrap: wrap; }
  body.page-planning :is(.planning-control-primary, .planning-export-action) { width: auto; }
  body.page-planning .planning-control-actions .btn { flex: 0 1 auto; min-width: 0; }
  body.page-planning :is(.planning-month-grid-wrap, .planning-week-grid-wrap, .planning-grid-wrap) { max-width: 100%; overscroll-behavior-inline: contain; scroll-padding-inline: 170px 24px; }
  body.page-planning .planning-month-vnext .planning-month-grid-wrap { max-height: min(64dvh, 760px); }
  body.page-planning .planning-month-cell-display { min-height: 44px !important; font-size: 13px !important; }
  body.page-planning .planning-context-drawer { width: 440px; max-width: calc(100vw - 40px); max-height: calc(100dvh - 112px); }
  body.page-planning .planning-context-drawer > footer { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  body.page-planning .planning-week-edit-dialog.is-planning-week-edit-portal { width: min(520px, calc(100vw - 48px)); max-height: calc(100dvh - 48px); overflow-y: auto; padding: 24px; }
  body.page-planning .planning-week-edit-dialog.is-planning-week-edit-portal :is(select, input:not([type="hidden"]), button) { min-height: 48px; font-size: 16px; }
  body.page-planning .planning-week-edit-dialog .planning-week-edit-close { flex-basis: 44px; width: 44px; height: 44px; min-height: 44px; }
  body.page-planning .planning-week-edit-actions { gap: 12px; }

  /* Other forms and archives retain their established hierarchy. */
  body.page-set :is(.form-grid, .compact-form-grid),
  body.page-utente-dettaglio :is(.form-grid, .compact-form-grid) { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  body .relation-editor .relation-fields-grid { gap: 18px; }
  body .relation-editor .relation-form-actions { flex-direction: row; align-items: center; flex-wrap: wrap; padding: 16px; gap: 14px; }
  body .relation-editor .relation-form-action-buttons { width: auto; flex-wrap: wrap; }
  body .relation-editor .relation-form-actions .btn.primary { min-height: 48px !important; }
  body :is(.app-confirm-dialog, .field-error-dialog, .af-document-dialog) { max-width: calc(100vw - 48px); max-height: calc(100dvh - 48px); }
  body.page-rubriche .rft-shell .icon-btn { width: 44px !important; min-width: 44px !important; height: 44px !important; min-height: 44px !important; }
  body.page-manutenzione .maintenance-console-nav-link { min-height: 44px; font-size: 14px; touch-action: manipulation; }
  body :is(.login-card, .reset-card, .access-request-public, .offline-shell) :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea) { min-height: 48px; font-size: 16px; }
  body :is(.login-password-toggle, .login-submit, .login-btn, .offline-button, .offline-tabs button) { min-height: 48px; min-width: 44px; touch-action: manipulation; }
  body .offline-shell { padding-bottom: max(32px, env(safe-area-inset-bottom)); }

  @media (max-width: 1000px) {
    body.page-dashboard .home-hero { grid-template-columns: 1fr; gap: 20px; }
    body.page-dashboard .home-procedure-card { grid-template-columns: 1fr 16px; align-content: start; }
    body.page-dashboard .home-procedure-card > .dashboard-picture:first-child { grid-column: 1; }
    body.page-dashboard .home-procedure-card > .dashboard-picture:last-child { grid-column: 2; grid-row: 1 / span 2; }
    body.page-dashboard .home-procedure-card > div { grid-column: 1; }
    body.page-rft .rft-shell.rft-unified .rft-intervention-card-head { grid-template-columns: minmax(0, 1fr); }
    body.page-rft .rft-shell.rft-unified .rft-intervention-card-tools { justify-content: end; width: 100%; }
    body.page-rft .rft-shell.rft-unified .rft-intervention-card-head > strong { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
    body.page-rft .rft-shell.rft-unified .rft-intervention-card-head > strong small { display: inline; margin: 0; }
    body.page-rft .rft-shell.rft-unified .rft-context-drawer { border-left: 0; border-radius: 0; }
    body.page-rft .rft-shell.rft-unified .rft-nominativi-stage:not(.is-intervention-create) .rft-person-card-head { grid-template-columns: 44px minmax(0, 1fr) auto auto 44px !important; }
    body.page-dpl .dpl-page-shell .dpl-grid-document-validity { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    body.page-dpl .dpl-page-shell .dpl-grid-document-validity > :first-child { grid-column: 1 / -1; }
    body .relation-editor .relation-form-layout { grid-template-columns: minmax(0, 1fr); }
  }
  @media (max-width: 720px) {
    body .content { padding-inline: 16px !important; }
    body.page-dashboard .home-procedure-grid { grid-template-columns: 1fr; }
    body.page-dashboard .home-procedure-card { grid-template-columns: 44px minmax(0, 1fr) 16px; min-height: 96px; }
    body.page-dashboard .home-procedure-card > div { grid-column: 2; }
    body.page-dashboard .home-procedure-card > .dashboard-picture:last-child { grid-column: 3; grid-row: 1; }
    body.page-dashboard .home-secondary-grid { grid-template-columns: 1fr; }
    body.page-rft .rft-shell.rft-unified .rft-context-drawer .rft-nominativi-stage { padding-inline: 16px; }
    body.page-rft .rft-shell.rft-unified .rft-nominativi-stage:not(.is-intervention-create) .rft-person-card-head { grid-template-columns: 44px minmax(0, 1fr) 44px !important; }
    body.page-planning .planning-team-primary-actions { grid-template-columns: 1fr !important; }
  }
}
