@supports (padding-top: env(safe-area-inset-top)) {
  .topbar {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .toast {
    bottom: max(18px, env(safe-area-inset-bottom));
    left: max(18px, env(safe-area-inset-left));
    top: auto;
  }
}

@media (max-width: 1024px) {
  .mobile-menu-btn { display: inline-flex; }
  .mobile-quick-btn, .btn-tool.mobile-quick-btn, .btn-tool.btn-primary.mobile-quick-btn { display: inline-flex; }
  .view-section > .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(285px, 84vw) !important;
    z-index: 1260;
    transform: translateX(-104%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
  }
  .workspace.sidebar-open .view-section.active > .sidebar { transform: translateX(0); }
  .contact-drawer.open {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(410px, 100vw);
    z-index: 1050;
    box-shadow: var(--shadow-lg);
  }
}

@media (max-width: 960px) {
  .topbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .topbar-left { order: 1; }
  .topbar-right { order: 2; margin-left: auto; }
  .app-switcher { order: 3; }
  .search-wrap { order: 4; flex: 1 1 100%; max-width: 100%; }
  .thread-list-pane { width: 350px; }
}

@keyframes mobileSlideInRight {
  from { transform: translateX(22%); opacity: 0.72; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes mobileSlideInLeft {
  from { transform: translateX(-18%); opacity: 0.72; }
  to { transform: translateX(0); opacity: 1; }
}

@media (max-width: 860px) {
  .mobile-back-btn, .btn-tool.mobile-back-btn { display: inline-flex; }
  #view-mail { touch-action: pan-y; overflow: hidden; }
  #view-mail, #view-mail * {
    -webkit-user-drag: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
  }
  #view-mail .reading-pane, #view-mail .msg-body, #view-mail .msg-body * {
    user-select: text;
    -webkit-user-select: text;
  }
  #view-mail .thread-list-pane {
    width: 100%;
    border-right: none;
    animation: mobileSlideInLeft 0.18s cubic-bezier(0.22, 1, 0.36, 1);
  }
  #view-mail .reading-pane { display: none; width: 100%; }
  #view-mail.mobile-reading-active .thread-list-pane,
  .workspace.mobile-reading #view-mail .thread-list-pane { display: none; }
  #view-mail.mobile-reading-active .reading-pane,
  .workspace.mobile-reading #view-mail .reading-pane {
    display: flex;
    width: 100%;
    animation: mobileSlideInRight 0.18s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .reading-toolbar { padding: 7px 10px; flex-wrap: nowrap; overflow-x: auto; gap: 6px; }
  .toolbar-actions { flex-wrap: nowrap; overflow-x: auto; width: 100%; gap: 6px; scrollbar-width: none; }
  .toolbar-actions::-webkit-scrollbar { display: none; }
  .toolbar-actions .btn-tool { flex-shrink: 0; white-space: nowrap; padding: 6px 10px; font-size: 13px; }
  .toolbar-actions .btn-tool .btn-label { display: none; }
  .reading-scroll { padding: 12px 12px 96px; gap: 12px; }
  .conversation-header { padding: 12px 14px; }
  .conversation-subject { font-size: 15.5px; line-height: 1.35; }
  .msg-header { padding: 11px 14px; }
  .msg-body { padding: 14px 14px; font-size: 13.5px; }
}

@media (max-width: 768px) {
  .modal-backdrop { padding: 0; }
  .modal-card, .inline-reply-card.maximized {
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    transform: none !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0;
    border: none;
  }
  .help-modal-header {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .help-search-bar-wrap { padding: 10px 14px 0; }
  .help-search-input { font-size: 16px !important; padding: 9px 32px 9px 34px; }
  .help-pills-bar { padding: 8px 14px; gap: 5px; }
  .help-pill { padding: 6px 10px; font-size: 12px; }
  .help-modal-body { padding: 12px 14px; -webkit-overflow-scrolling: touch; }
  .help-shortcuts-grid { grid-template-columns: 1fr !important; gap: 7px; }
  .help-shortcut-card { padding: 10px 12px; }
  .help-modal-footer { padding: 10px 14px max(14px, env(safe-area-inset-bottom)); }
  .help-footer-legend { display: none; }
  .help-modal-footer .btn-tool { width: 100%; min-height: 42px; font-size: 14px; font-weight: 600; justify-content: center; }
  .headers-meta-table { grid-template-columns: 90px 1fr; }
  .autocomplete-dropdown { left: 0; }
  .action-label { display: none; }
  .contacts-table thead { display: none; }
  .contacts-table, .contacts-table tbody { display: block; width: 100%; }
  .contacts-table tbody { padding: 8px 10px; }
  .contacts-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px 10px;
    padding: 11px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
  }
  .contacts-table td { display: block; padding: 2px 0; max-width: 100%; white-space: normal; border-bottom: none; }
  .contacts-table td[data-col="name"] { flex: 1 1 calc(100% - 60px); }
  .contacts-table td[data-col="email"],
  .contacts-table td[data-col="unit"],
  .contacts-table td[data-col="medium"],
  .contacts-table td[data-col="clearance"],
  .contacts-table td[data-col="groups"],
  .contacts-table td[data-col="pgp"] { width: 100%; padding-left: 34px; font-size: 12px; }
  .contacts-table td[data-col="source"] { padding-left: 34px; }
  .contacts-table td[data-col="actions"] { margin-left: auto; text-align: right; }
  .cal-toolbar, .contacts-toolbar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .cal-controls-wrap { width: 100%; justify-content: space-between; }
  .cal-view-label { display: none; }
  .cal-segment-btn { padding: 4px 7px; font-size: 11px; }
  .cal-dropdown-btn { padding: 4px 8px; font-size: 11.5px; }
  .cal-body { padding: 8px 6px; overflow-x: auto; }
  .cal-week-grid { min-width: 0; width: 100%; }
  .cal-week-row { grid-template-columns: 38px repeat(7, minmax(0, 1fr)) !important; }
  .cal-week-row .wk-month-abbr { display: none; }
  .cal-week-row .wk-hdr-cell { padding: 4px 2px !important; font-size: 10.5px !important; }
  .cal-week-row .wk-time-cell { padding: 4px 3px !important; font-size: 10px !important; }
  .cal-year-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important; }
  .day-full { display: none; }
  .day-short { display: inline; }
  .month-cell { min-height: 64px; padding: 4px; }
  .month-cell .cal-event-pill { padding: 2px 4px; font-size: 10px; }
}

@media (max-width: 680px) {
  .topbar { padding: 6px 10px; gap: 6px; }
  .topbar-left { gap: 6px; min-width: 0; }
  .mobile-menu-btn { width: 31px; height: 31px; font-size: 15px; }
  .brand img { height: 22px; }
  .topbar-right { gap: 5px; min-width: 0; }
  .top-icon-btn, .btn-topbar-help { padding: 4px 7px; font-size: 11.5px; }
  .account-picker { padding: 2px 7px 2px 3px; gap: 4px; }
  .avatar-sm { width: 22px; height: 22px; font-size: 9.5px; }
  .hide-mobile-text, .help-title-full, .pill-lbl-full { display: none; }
  .help-title-short, .pill-lbl-short { display: inline; }
  .app-switcher {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
  }
  .app-tab { justify-content: center; padding: 5px 4px; font-size: 11.5px; gap: 4px; }
  .search-input { padding: 6px 26px 6px 32px; font-size: 12.5px; }
  .pane-header { padding: 9px 12px; gap: 7px; }
  .filter-pills { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; padding-bottom: 2px; }
  .filter-pills::-webkit-scrollbar { display: none; }
  .filter-pill { flex-shrink: 0; white-space: nowrap; }
  .year-filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .year-filter-row .mini-select { width: 100%; min-width: 0; text-overflow: ellipsis; }
  .composer-dock { left: 8px; right: 8px; bottom: 0; flex-direction: column; align-items: stretch; }
  .composer-card { width: 100%; max-height: 82dvh; }
  .msg-header { flex-direction: column; gap: 6px; }
  .msg-date-wrap { width: 100%; justify-content: space-between; }
  .login-demo-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .help-topic-card { padding: 10px; }
  .help-topic-title { font-size: 13px; }
  .help-topic-summary, .help-step-item { font-size: 12px; }
  .help-tip-banner { font-size: 11.5px; padding: 6px 8px; }
}
