/* Loaded after page styles: phone/tablet layouts without hiding overflowing data. */
.mobile-nav-toggle, .mobile-account, .mobile-table-tools-toggle, .mobile-more-records, .mobile-actions-toggle,
table .mobile-row-toggle-cell { display: none; }
@media screen and (max-width: 850px) {
  body { overflow-wrap: anywhere; }
  .main, .guest, .content, .attendance-wide, .payroll-wide { width: 100%; min-width: 0; margin-left: 0; }
  .content { padding: 16px 12px; }
  .sidebar { position: static; width: 100%; padding: 14px 18px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; border: 0; border-bottom: 1px solid #e7edf6; background: #fff; box-shadow: 0 3px 16px #20365306; }
  .sidebar .brand { min-width: 0; margin: 0; gap: 10px; }
  .sidebar .brand span { font-size: 18px; letter-spacing: 0; }
  .sidebar .brand small { margin-top: 4px; font-size: 10px; letter-spacing: 1px; font-weight: 400; }
  .sidebar .brand-icon { width: 34px; height: 34px; border-radius: 7px; }
  .mobile-nav-toggle:not([hidden]) { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 13px; min-height: 44px; border: 0; border-radius: 12px; background: #edf4ff; color: #2463bd; font-size: 13px; font-weight: 600; }
  .mobile-nav-toggle[aria-expanded="true"] { background: #2463bd; color: #fff; }
  .mobile-nav-toggle:focus-visible { outline: 2px solid #2463bd; outline-offset: 3px; }
  .mobile-menu-icon { position: relative; width: 16px; height: 20px; flex: 0 0 16px; }
  .mobile-menu-icon::before, .mobile-menu-icon::after { content: ""; position: absolute; left: 0; width: 16px; height: 2px; border-radius: 2px; background: currentColor; }
  .mobile-menu-icon::before { top: 6px; }
  .mobile-menu-icon::after { top: 12px; }
  .mobile-nav-toggle[aria-expanded="true"] .mobile-menu-icon::before { top: 9px; transform: rotate(45deg); }
  .mobile-nav-toggle[aria-expanded="true"] .mobile-menu-icon::after { top: 9px; transform: rotate(-45deg); }
  .sidebar > .nav-label, .sidebar-foot { display: none; }
  .sidebar nav { display: grid; grid-column: 1 / -1; min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; overflow: visible; padding-top: 14px; border-top: 1px solid var(--line); }
  .sidebar.mobile-nav-ready:not(.mobile-nav-open) nav { display: none; }
  .sidebar nav .nav-label { grid-column: 1 / -1; margin: 12px 4px 4px; letter-spacing: 1px; }
  .sidebar nav a { min-width: 0; min-height: 44px; white-space: normal; padding: 10px 12px; margin: 0; background: #f7f9fc; border-radius: 9px; }
  .sidebar nav a.active { background: #e9f1fc; }
  .mobile-account { display: block; grid-column: 1 / -1; min-width: 0; border-top: 1px solid var(--line); padding-top: 14px; }
  .sidebar.mobile-nav-ready:not(.mobile-nav-open) .mobile-account { display: none; }
  .mobile-account-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
  .mobile-account-heading strong { font-size: 14px; }
  .mobile-account-heading small { margin-left: 8px; font-size: 11px; color: var(--muted); }
  .mobile-account-caption { flex-shrink: 0; font-size: 11px; color: var(--muted); }
  .mobile-account-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .mobile-account-actions a, .mobile-account-actions button { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 44px; margin: 0; padding: 8px 4px; border: 0; border-radius: 9px; background: #f3f6fa; color: #506680; font-size: 12px; text-decoration: none; }
  .mobile-account-actions form { margin: 0; }
  .mobile-account-actions button { color: #a44d49; background: #fff3f2; }
  .topbar { display: none; }
  .topbar > span { display: none; }
  .topbar > div { flex-wrap: wrap; gap: 18px; }
  .topbar a, .topbar .link { padding: 8px 0; }
  h1 { font-size: 22px; margin: 0 0 6px; }
  h2 { font-size: 17px; margin: 0 0 10px; }
  .page-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; margin-bottom: 12px; }
  .page-head > .actions { grid-column: 1 / -1; }
  .page-head p { margin: 4px 0; font-size: 12px; }
  .page-head, .section-head, .form-footer, .modal-heading, .attendance-member-head { flex-wrap: wrap; gap: 12px; }
  .page-head > *, .section-head > *, .card, form, fieldset, .dashboard-grid > *, .form-grid > * { min-width: 0; max-width: 100%; }
  .card { padding: 12px; margin-bottom: 12px; }
  input, select, textarea { max-width: 100%; min-width: 0; font-size: 16px; }
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select { min-height: 38px; padding: 7px 9px; line-height: 1.3; }
  button, .button { min-height: 38px; padding: 7px 10px; font-size: 13px; white-space: normal; max-width: 100%; }
  img, video, canvas, iframe { max-width: 100%; }
  pre { white-space: pre-wrap; overflow-wrap: anywhere; }
  .actions, .holiday-actions, .attendance-review-filters, .attendance-detail-toolbar, .payroll-row-actions,
  .sales-month-toolbar, .plan-toolbar, .resource-row-actions, .announcement-toolbar, .tax-import-actions { flex-wrap: wrap; }
  .search { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; overflow: visible; gap: 8px; flex-wrap: wrap !important; }
  .search input, .search select, .search button, .search .button { width: 100% !important; max-width: none; min-width: 0; }
  .search input[name="q"] { grid-column: 1 / -1; }
  .search input[type="search"], .search > :only-child { grid-column: 1 / -1; }
  .attendance-review-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
  .attendance-review-filters .inline-filter { display: block; min-width: 0; margin: 0; font-size: 12px; }
  .attendance-review-filters .inline-filter select, .attendance-review-filters .inline-filter input { width: 100%; margin: 4px 0 0; }
  .attendance-review-filters .attendance-employee-search { grid-column: 1 / -1; }
  .attendance-review-filters:has([data-payroll-employee-search]) .attendance-employee-search { grid-column: auto; }
  .actions { gap: 6px; margin: 10px 0; }
  .actions .inline-filter { margin: 0; }
  .mobile-actions:not(.mobile-actions-open) > :not(.primary):not(.mobile-actions-toggle) { display: none; }
  .mobile-actions-toggle { display: inline-block; }
  .attendance-detail-toolbar { margin-bottom: 8px; }
  .notice { padding: 10px 12px; margin-bottom: 12px; font-size: 12px; }
  .search.salary-filter button[type="submit"] { display: block; }
  .attendance-employee-search, .sales-settings-form label, .plan-toolbar input { min-width: 0; width: 100%; }
  .announcement-search { width: 100%; min-width: 0; flex-wrap: wrap; }
  .announcement-search input, .announcement-search select { width: 100%; min-width: 0; max-width: none; }
  .list-pagination, .server-page-jump, .pagination { flex-wrap: wrap; overflow: visible; gap: 6px; }
  .list-pagination select { width: auto; }
  .form-grid, .dashboard-grid, .attendance-season-grid, .member-options, .stage-row,
  .payslip-basis-summary, .payslip-review-actions, .wecom-sync-row, .wecom-view, .wecom-person-view,
  .wecom-auto-settings, .wecom-bot-binding, .kpi-settings-grid, .kpi-page .kpi-source-form { grid-template-columns: minmax(0, 1fr) !important; }
  .span-two { grid-column: 1 / -1; }
  .stage-row { display: grid; }
  .stats, .salary-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stats, .salary-stats { margin: 12px 0; gap: 8px; }
  .stat { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 6px; padding: 8px 10px; border-radius: 9px; }
  .stat > span { font-size: 11px; }
  .stat strong.amount { margin-top: 2px; font-size: 18px; }
  .notification-setting-labels { display: none !important; }
  .notification-setting-row { min-width: 0; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; padding: 16px 0; }
  .notification-setting-row input, .notification-setting-row select { width: 100%; }
  .notification-setting-row > strong { align-self: center; }
  .notification-item { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .notification-settings-list { overflow: visible; }
  .app-modal { padding: 12px; }
  .modal-panel, .employee-wecom-dialog { width: 100%; max-width: calc(100vw - 24px); padding: 16px; max-height: calc(100dvh - 24px); overflow-y: auto; }
  .permission-grid, .attendance-picker-departments, .reward-picker-list, .directory-grid,
  .choice-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); }
  .directory-layout { grid-template-columns: minmax(0, 1fr) 26px; }
  .company-strip { display: grid; grid-template-columns: minmax(0, 1fr); overflow: visible; }
  .company-card { min-width: 0; }
  .mindmap, .mind-branch, .mind-children { display: block; min-height: 0; overflow: visible; }
  .mindmap ul { padding-left: 12px; min-width: 0; }
  .mindmap > ul { padding-left: 0; }
  .mindmap li { padding: 8px 0 8px 8px; }
  .mindmap ul::before, .mindmap li::before { display: none; }
  .mindmap .mind-node, .mindmap .mind-person, .mindmap .mind-root { min-width: 0; width: 100%; white-space: normal; padding: 12px; }
  .department-people { padding: 8px 0; }
  .mindmap .department-people ul { padding-left: 0; }
  .login-wrap { display: block; margin: 0 auto; }
  .login-story, .login-form { padding: 24px; }
  .login-story h1 { font-size: 30px; }
  .login-story p, .login-orbit { display: none; }
  .wall-container { width: 100%; padding: 14px; }
  .wall-reply, .wall-post-actions { flex-wrap: wrap; }
  .wall-reply input { width: 100%; }

  /* Every record reads vertically. Existing form fields stay in their forms. */
  .mobile-table-region { width: 100%; min-width: 0; max-width: 100%; height: auto !important; min-height: 0 !important; max-height: none !important; overflow: visible !important; }
  table.mobile-table { display: block; width: 100%; min-width: 0 !important; max-width: 100%; table-layout: auto; }
  table.mobile-table > thead { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }
  .mobile-table-tools-toggle { display: block; margin: 0 0 12px; }
  table.mobile-table > thead.mobile-table-controls { display: none; }
  table.mobile-table.mobile-tools-open > thead.mobile-table-controls { display: block; position: static; width: 100%; height: auto; overflow: visible; clip-path: none; }
  table.mobile-table.mobile-tools-open > thead > tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
  table.mobile-table.mobile-tools-open > thead > tr > th { display: none; }
  table.mobile-table.mobile-tools-open > thead > tr > th.mobile-header-control { display: block; position: static; width: 100%; min-width: 0; white-space: normal; padding: 8px; }
  table.mobile-table .mobile-header-control select { min-width: 0; width: 100%; font-size: 16px; }
  table.mobile-table > caption { display: block; }
  table.mobile-table > tbody, table.mobile-table > tfoot { display: block; width: 100%; }
  table.mobile-table > tbody > tr, table.mobile-table > tfoot > tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 12px; width: 100%; margin-bottom: 10px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: white; }
  table.mobile-table > tbody > tr[hidden] { display: none !important; }
  table.mobile-table > tbody > tr > td, table.mobile-table > tfoot > tr > td {
    display: block; position: static !important; width: 100% !important; min-width: 0 !important; max-width: none;
    height: auto; padding: 6px 0; border: 0; border-bottom: 1px solid #eef2f7; text-align: left; font-size: 13px; line-height: 1.5;
    white-space: normal; overflow-wrap: anywhere; box-shadow: none !important;
  }
  table.mobile-table > tbody > tr > td:last-child { border-bottom: 0; }
  .attendance-detail-panel:not(.is-detail-visible) table.mobile-table .attendance-detail-item { display: none; }
  table.mobile-table > tbody > tr > td::before { content: attr(data-mobile-label); display: block; font-size: 11px; font-weight: 400; color: var(--muted); margin-bottom: 2px; }
  table.mobile-table > tbody > tr > td.mobile-wide-cell { grid-column: 1 / -1; }
  table.mobile-table > tbody > tr.mobile-compact-row:not(.mobile-row-expanded) > td.mobile-secondary-cell { display: none; }
  .is-grid-editing table.mobile-table > tbody > tr.mobile-compact-row > td.mobile-secondary-cell { display: block; }
  table.mobile-table > tbody > tr > td.mobile-identity-cell { font-size: 15px; font-weight: 600; }
  table.mobile-table > tbody > tr > td.mobile-identity-cell::before { display: none; }
  table.mobile-table > tbody > tr.mobile-compact-row { position: relative; }
  table.mobile-table > tbody > tr > td.mobile-selection-cell { position: absolute !important; top: 8px; left: auto !important; right: 10px; width: 22px !important; padding: 0; border: 0; }
  table.mobile-table > tbody > tr > td.mobile-selection-cell::before { display: none; }
  table.mobile-table td.mobile-selection-cell input { width: 18px; height: 18px; margin: 0; }
  table.mobile-table > tbody > tr > td.mobile-action-cell { grid-column: 1 / -1; border: 0; }
  table.mobile-table > tbody > tr > td.mobile-action-cell::before { display: none; }
  table.mobile-table > tbody > tr > td.mobile-row-toggle-cell { display: block; grid-column: 1 / -1; padding: 0; border: 0; }
  table.mobile-table > tbody > tr.mobile-has-action > td.mobile-action-cell { grid-column: 1; }
  table.mobile-table > tbody > tr.mobile-has-action > td.mobile-row-toggle-cell { grid-column: 2; align-self: center; }
  table.mobile-table td .mobile-row-toggle { width: 100%; min-height: 36px; padding: 6px; border: 0; background: #f7f9fc; color: var(--green); font-size: 12px; }
  table.mobile-table > tbody > tr.mobile-page-excluded { display: none !important; }
  .mobile-more-records:not([hidden]) { display: block; width: 100%; margin-top: 8px; }
  table.mobile-table > tbody > tr > td.mobile-wide-cell::before { display: none; }
  table.mobile-table > tbody > tr > td input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  table.mobile-table > tbody > tr > td select { width: 100% !important; min-width: 0 !important; max-width: 100%; margin: 0; font-size: 16px; }
  table.mobile-table td .salary-adjust-cell { flex-wrap: wrap; height: auto; min-height: 44px; }
  table.mobile-table td .salary-adjust-cell input[type="number"] { min-height: 44px; background: #f8faff; border: 1px solid var(--line); border-radius: 8px; }
  .sales-detail-row td, .attendance-correction-inline, .payroll-objection-inline { min-width: 0; white-space: normal; }
  .attendance-correction-inline { flex-wrap: wrap; }
  .correction-inline-reason { max-width: 100%; white-space: normal; }
  .correction-inline-reply { width: 100%; min-width: 0; }
  .grid-fill-handle { display: none !important; }
  .calendar-scroll, .holiday-calendar-scroll { max-width: 100%; overflow: visible; }
  .calendar-grid, .wecom-calendar { min-width: 0; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
  .wecom-day { min-width: 0; padding: 4px 2px; font-size: 12px; }
}
@media screen and (max-width: 380px) {
  .sidebar { padding: 12px 14px; gap: 10px; }
  .notification-setting-row { grid-template-columns: minmax(0, 1fr); }
  .content { padding: 16px 10px; }
}
