/* Phone and small-tablet layout. Kept separate so the desktop layout stays intact. */
@media (max-width: 760px) {
  :root { color-scheme: dark; }
  html, body { min-width: 320px; width: 100%; overflow-x: hidden; }
  body { font-size: 14px; -webkit-text-size-adjust: 100%; }
  .app { display: block; min-height: 100vh; min-height: 100dvh; }
  .main { width: 100%; min-width: 0; margin: 0; padding-top: 63px; }
  .topbar { position: fixed; inset: 0 0 auto; width: 100%; height: 63px; padding: 0 14px; gap: 11px; }
  .menu-toggle { display: grid; width: 42px; height: 42px; min-width: 42px; font-size: 19px; }
  .crumb { min-width: 0; }
  .crumb b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
  .page { width: 100%; max-width: none; margin: 0; padding: 22px 16px calc(40px + env(safe-area-inset-bottom)); }
  .sidebar { position: fixed; z-index: 1002; inset: 0 auto 0 0; width: min(310px, 86vw); height: 100vh; height: 100dvh; padding: max(14px, env(safe-area-inset-top)) 13px max(14px, env(safe-area-inset-bottom)); transform: translateX(-105%); transition: transform .22s ease; box-shadow: 18px 0 55px #0009; overscroll-behavior: contain; }
  .sidebar.open { transform: translateX(0); }
  .brand { min-height: 61px; height: auto; }
  .side-scroll { min-height: 0; overscroll-behavior: contain; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 1001; display: block; width: 100%; height: 100%; padding: 0; border: 0; background: #050405b8; backdrop-filter: blur(3px); }
  .sidebar-backdrop[hidden] { display: none; }
  body.mobile-menu-open { overflow: hidden; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .page-heading h1 { font-size: clamp(25px, 7vw, 34px); line-height: 1.12; overflow-wrap: anywhere; }
  .page-heading p { font-size: 13px; line-height: 1.55; }
  .hero { grid-template-columns: minmax(0, 1fr); min-height: 0; padding: 22px 18px 8px; }
  .hero h1 { font-size: clamp(32px, 9vw, 43px); }
  .hero p { font-size: 13px; line-height: 1.65; }
  .hero-visual { min-height: 145px; height: 145px; overflow: hidden; }
  .hero-visual svg { width: min(165px, 50vw); }
  .grid.two, .grid.three, .public-profile-grid, .employee-profile-grid, .orders-layout, .mis-browser, .mis-form-info-grid { grid-template-columns: minmax(0, 1fr); }
  .shortcut-grid, .staff-grid, .education-grid, .med-grid, .bind-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 16px; }
  .section { margin-top: 22px; scroll-margin-top: 76px; }
  .section-title { align-items: flex-start; flex-direction: column; gap: 6px; }
  .section-title h2, .card-head h2, .card h2 { line-height: 1.25; overflow-wrap: anywhere; }
  .button, .tab, .radio-pill { min-height: 42px; }
  .hero-actions, .orders-form-actions, .mis-form-actions { width: 100%; }
  input, select, textarea { max-width: 100%; font-size: 16px !important; }
  .field input, .field select, .field textarea, .orders-fields input, .orders-fields select, .orders-fields textarea, .mis-form .field input, .mis-form .field select, .mis-form .field textarea { min-height: 44px; }
  .form-grid > *, .orders-fields > *, .mis-form-grid > *, .staff-detail > *, .employee-profile-grid > *, .employee-career-card > *, .promotion-review-actions > * { min-width: 0; }
  .staff-detail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .promotion-review-actions { flex-wrap: wrap; }
  .promotion-review-actions > * { flex: 1 1 140px; }
  .table-wrap, .table-scroll, [data-table-scroll] { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  textarea { resize: vertical; }
  .modal-backdrop, .app-dialog-backdrop { align-items: end; padding: 10px 10px max(10px, env(safe-area-inset-bottom)); overflow-y: auto; }
  .modal, .app-dialog { width: 100%; max-width: 560px; max-height: min(92dvh, 900px); overflow-y: auto; padding: 18px; border-radius: 18px 18px 12px 12px; }
  .gate { min-height: 100vh; min-height: 100dvh; padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom)); }
  .gate-panel { width: min(100%, 460px); max-height: calc(100dvh - 36px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow-y: auto; padding: 28px 20px 20px; border-radius: 18px; }
  .gate h1 { font-size: clamp(26px, 8vw, 34px); line-height: 1.15; }
  .gate-sub { font-size: 14px; }
  .gate-foot { font-size: 9px; }
  .vk-login-widget { min-height: 52px; }
  .vk-login-widget iframe, .vk-login-widget > * { max-width: 100% !important; }
  .account-form { grid-template-columns: minmax(0, 1fr); }
  .account-form .field:first-child { grid-column: auto; }
  .metric-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .messenger-shell { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .messenger-list-panel { max-height: 250px; min-height: 0; border-right: 0; border-bottom: 1px solid #5e3438; }
  .chat-list { max-height: 150px; min-height: 70px; }
  .messenger-sidebar-foot { display: none; }
  .messenger-thread { min-height: min(68dvh, 620px); }
  .message-list { min-height: 240px; padding: 12px; }
  .message-bubble-row { max-width: 96%; }
  .message-bubble { min-width: 0; max-width: calc(100vw - 100px); }
  .message-author { flex-wrap: wrap; }
  .message-author time { margin-left: 0; }
  .message-composer { padding: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .message-composer input { min-height: 44px; font-size: 16px !important; }
  .compose-icon, .send-message { width: 44px; height: 44px; flex: 0 0 44px; }
  .messenger-attach-wrap .compose-icon { display: grid; }
  .chat-media-image, .chat-media-video, .chat-media-audio, .chat-file-card, .chat-location-card { width: min(100%, 360px); max-width: 78vw; }
  .messenger-image-viewer { padding: 52px 10px 16px; }
  .messenger-image-viewer img { max-width: 96vw; max-height: 84dvh; }
  .messenger-image-close { top: max(10px, env(safe-area-inset-top)); right: 12px; }
  .toast { width: calc(100% - 28px); max-width: 520px; bottom: max(14px, env(safe-area-inset-bottom)); text-align: center; line-height: 1.4; }
  .audit-table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
}

@media (max-width: 560px) {
  .page { padding: 17px 12px calc(34px + env(safe-area-inset-bottom)); }
  .page-heading { margin-bottom: 14px; }
  .shortcut-grid, .staff-grid, .education-grid, .med-grid, .bind-steps, .metric-row { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 14px; border-radius: 14px; }
  .card-head { flex-wrap: wrap; }
  .view-tabs, .mis-tabs, .rp-section-nav { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 5px; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
  .view-tabs > *, .mis-tabs > *, .rp-section-nav > * { flex: 0 0 auto; }
  .rp-body { padding: 0 9px 10px; }
  .rp-row { flex-wrap: wrap; }
  .rp-tag { min-width: 42px; }
  .rp-text { min-width: calc(100% - 60px); font-size: 13px; overflow-wrap: anywhere; }
  .copy-btn { min-height: 36px; margin-left: auto; }
  .orders-fields, .mis-form-grid, .staff-edit-fields, .bb-profile-fields, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .orders-wide, .field.full { grid-column: auto; }
  .orders-form-actions > *, .mis-form-actions > *, .hero-actions > * { flex: 1 1 100%; }
  .orders-preview { min-height: 180px; padding: 12px; font-size: 12px; overflow-wrap: anywhere; }
  .mis-card { padding: 16px; }
  .mis-card h2 { font-size: 22px; }
  .mis-list { height: min(37dvh, 330px); min-height: 170px; }
  .mis-toolbar { align-items: stretch; flex-direction: column; }
  .mis-toolbar input { width: 100%; min-width: 0; }
  .employee-vk-cover { height: 150px; }
  .employee-vk-cover-overlay { gap: 8px; }
  .employee-vk-media-actions { max-width: 72%; }
  .employee-vk-identity { align-items: flex-start; }
  .employee-profile-card dl > div { grid-template-columns: minmax(0, 1fr); gap: 3px; }
  .employee-profile-card dd { max-width: none; margin: 0; }
  .staff-import-row { grid-template-columns: 20px minmax(0, 1fr); }
  .staff-detail { grid-template-columns: minmax(0, 1fr); }
  .staff-import-person, .staff-import-row select { grid-column: 2; }
  .staff-import-modal footer { align-items: stretch; flex-direction: column; }
  .rp-editor-step { grid-template-columns: minmax(0, 1fr); }
  .rp-editor-step select, .rp-editor-step textarea, .rp-step-actions { grid-column: 1; grid-row: auto; }
  .rp-step-actions { flex-direction: row; }
  .rp-step-actions .button { width: 40px; height: 40px; }
  .gate-panel { padding: 24px 16px 18px; }
  .gate-foot { flex-wrap: wrap; gap: 6px 12px; }
  .app-dialog { grid-template-columns: 32px minmax(0, 1fr); gap: 0 10px; padding: 16px; }
  .app-dialog-icon { width: 32px; height: 32px; }
  .app-dialog footer { flex-direction: column-reverse; }
  .app-dialog footer .button { width: 100%; flex: none; }
  .messenger-list-top { padding: 13px 12px 9px; }
  .messenger-search { margin-inline: 10px; }
  .thread-head { padding: 10px; }
  .thread-head b { font-size: 13px; }
  .thread-actions button { width: 38px; height: 38px; }
  .chat-location-card { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
