/* RS-IN ERP mobile shell and page-wide responsive overrides.
   Loaded last so desktop-oriented page styles cannot restore fixed widths on phones. */

.mobile-sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 990;
  border: 0;
  padding: 0;
  background: rgba(2, 20, 45, 0.5);
  backdrop-filter: blur(1px);
}

@media (max-width: 820px) {
  :root {
    --topbar-height: 60px;
    --mobile-page-padding: 10px;
  }

  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body.mobile-menu-open {
    overflow: hidden;
    touch-action: none;
  }

  .login-view {
    min-height: 100dvh;
    padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  }

  .login-panel {
    width: min(100%, 480px);
    min-height: auto;
    padding: 32px 22px;
  }

  .brand-row {
    gap: 10px;
    margin-bottom: 34px;
    font-size: 28px;
  }

  .erp-view,
  .erp-view.sidebar-collapsed {
    display: block;
    width: 100%;
    min-height: 100dvh;
    overflow-x: clip;
    background: none;
  }

  .main-area {
    width: 100%;
    min-width: 0;
  }

  .sidebar,
  .sidebar.collapsed {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    width: min(84vw, 310px) !important;
    height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(-105%);
    visibility: hidden;
    box-shadow: none;
    transition: transform 180ms ease, visibility 180ms ease, box-shadow 180ms ease;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    visibility: visible;
    box-shadow: 18px 0 48px rgba(2, 20, 45, 0.32);
  }

  .sidebar-logo {
    position: sticky;
    top: 0;
    z-index: 2;
    height: 60px;
    font-size: 27px;
  }

  .menu-list {
    padding: 10px 8px max(24px, env(safe-area-inset-bottom));
  }

  .menu-parent {
    min-height: 46px;
    padding-inline: 13px;
  }

  .menu-item {
    min-height: 42px;
    font-size: 14px;
  }

  .submenu {
    padding-left: 42px;
  }

  .topbar {
    top: 0;
    z-index: 40;
    width: 100%;
    height: 60px;
    min-height: 60px;
    gap: 8px;
    padding: 0 max(9px, env(safe-area-inset-right)) 0 max(9px, env(safe-area-inset-left));
  }

  .topbar-left {
    flex: 1 1 auto;
    min-width: 0;
    gap: 7px;
  }

  .topbar h1 {
    min-width: 0;
    overflow: hidden;
    font-size: 18px;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #sidebarToggle {
    flex: 0 0 42px;
    width: 42px;
    min-width: 42px;
    min-height: 44px;
    border-radius: 8px;
    font-size: 25px;
  }

  .topbar-right {
    flex: 0 0 auto;
    gap: 7px;
  }

  .account-box {
    display: none !important;
  }

  .avatar {
    display: block !important;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
  }


  .notification-button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .notification-button svg {
    width: 18px;
    height: 18px;
  }

  .notification-panel {
    position: fixed;
    top: 66px;
    right: max(8px, env(safe-area-inset-right));
    left: max(8px, env(safe-area-inset-left));
    width: auto;
    max-height: calc(100dvh - 78px);
  }

  .notification-panel > header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .notification-panel > header .notification-header-actions {
    margin-left: auto;
  }

  .notification-list {
    max-height: calc(100dvh - 150px);
  }

  .header-notification-toast {
    top: 68px;
    right: max(8px, env(safe-area-inset-right));
    width: calc(100vw - max(16px, env(safe-area-inset-left) + env(safe-area-inset-right)));
  }

  .logout-button {
    width: auto;
    min-width: 0;
    min-height: 38px;
    padding: 0 9px;
    font-size: 12px;
    white-space: nowrap;
  }

  .content {
    width: 100%;
    min-width: 0;
    padding: var(--mobile-page-padding) var(--mobile-page-padding) max(24px, env(safe-area-inset-bottom));
  }

  .page-actions {
    width: 100%;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 0 8px !important;
  }

  .action-buttons {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
  }

  .action-buttons > button:not([hidden]) {
    flex: 1 1 96px;
    width: auto;
    min-width: 0;
    min-height: 44px;
    padding-inline: 12px;
  }

  .dashboard-view,
  .module-view {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    gap: 10px;
  }

  .module-view :where(section, article, div, form, fieldset),
  .dashboard-view :where(section, article, div, form, fieldset) {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  .module-view :where(.card, .table-card, .panel-card, .section-card, .module-card, .process-card),
  .dashboard-view :where(.card, .table-card, .panel-card, .section-card, .module-card) {
    border-radius: 8px;
  }

  .module-view :where(.card-header, .card-head, .panel-header, .panel-head, .section-header, .section-head, .table-card-head, .toolbar-head),
  .dashboard-view :where(.card-header, .card-head, .panel-header, .panel-head, .section-header, .section-head) {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
  }

  /* Override the final desktop fixed-width search/filter declarations. */
  .module-view > .search-panel,
  .module-view > section.search-panel,
  .work-order-search,
  .product-match-search,
  .process-progress-search,
  .daily-production-search,
  .production-result-search,
  .shipment-filter-list-only,
  .inventory-filter,
  .material-flow-filter,
  .lot-issue-filter,
  .customer-product-search,
  .customer-search,
  .bom-toolbar.search-panel,
  .assembly-filter-card,
  .shipment-filter-card,
  .filter-panel,
  .filter-card,
  .module-filter {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: stretch !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    gap: 10px !important;
    padding: 12px !important;
    overflow: visible !important;
  }

  .module-view > .search-panel label,
  .module-view > section.search-panel label,
  .work-order-search label,
  .product-match-search label,
  .process-progress-search label,
  .daily-production-search label,
  .production-result-search label,
  .shipment-filter-list-only label,
  .inventory-filter label,
  .material-flow-filter label,
  .lot-issue-filter label,
  .customer-product-search label,
  .customer-search label,
  .bom-toolbar.search-panel label,
  .assembly-filter-card label,
  .shipment-filter-card label,
  .filter-panel label,
  .filter-card label,
  .module-filter label {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: stretch !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    gap: 6px !important;
    white-space: normal !important;
    flex: 1 1 100% !important;
  }

  .module-view > .search-panel :where(input, select, textarea),
  .module-view > section.search-panel :where(input, select, textarea),
  .work-order-search :where(input, select, textarea),
  .product-match-search :where(input, select, textarea),
  .process-progress-search :where(input, select, textarea),
  .daily-production-search :where(input, select, textarea),
  .production-result-search :where(input, select, textarea),
  .shipment-filter-list-only :where(input, select, textarea),
  .inventory-filter :where(input, select, textarea),
  .material-flow-filter :where(input, select, textarea),
  .lot-issue-filter :where(input, select, textarea),
  .customer-product-search :where(input, select, textarea),
  .customer-search :where(input, select, textarea),
  .bom-toolbar.search-panel :where(input, select, textarea),
  .assembly-filter-card :where(input, select, textarea),
  .shipment-filter-card :where(input, select, textarea),
  .filter-panel :where(input, select, textarea),
  .filter-card :where(input, select, textarea),
  .module-filter :where(input, select, textarea) {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 44px !important;
    min-height: 44px !important;
    font-size: 16px;
  }

  .module-view > .search-panel > button,
  .module-view > section.search-panel > button,
  .work-order-search > button,
  .product-match-search > button,
  .process-progress-search > button,
  .daily-production-search > button,
  .production-result-search > button,
  .shipment-filter-list-only > button,
  .inventory-filter > button,
  .material-flow-filter > button,
  .lot-issue-filter > button,
  .customer-product-search > button,
  .customer-search > button,
  .bom-toolbar.search-panel > button,
  .assembly-filter-card > button,
  .shipment-filter-card > button,
  .filter-panel > button,
  .filter-card > button,
  .module-filter > button {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 44px !important;
    min-height: 44px !important;
  }

  .search-actions,
  .filter-actions,
  .assembly-filter-actions,
  .form-actions,
  .employee-form-actions,
  .dialog-actions,
  .modal-actions {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: 100%;
    gap: 8px !important;
  }

  .search-actions > button,
  .filter-actions > button,
  .assembly-filter-actions > button,
  .form-actions > button,
  .employee-form-actions > button,
  .dialog-actions > button,
  .modal-actions > button {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: 44px !important;
  }

  .form-grid,
  .dialog-grid,
  .lot-dialog-grid,
  .detail-grid,
  .form-panels,
  .employee-form,
  .employee-form-grid,
  .customer-layout,
  .customer-product-layout,
  .process-master-layout,
  .process-editor-grid,
  .shipment-main-grid,
  .shipment-form-grid,
  .shipment-line-builder,
  .profile-grid,
  .user-profile-grid,
  .server-transfer-lock,
  .server-transfer-password-grid,
  .company-info-form,
  .community-layout,
  .community-side,
  .community-toolbar,
  .community-write-grid,
  .community-write-page-grid,
  .access-template-grid,
  .assembly-requirement-grid,
  .bom-manage-grid,
  .design-global-grid,
  .history-info-grid,
  .inbound-slip-grid,
  .lot-editor-grid,
  .lot-issue-register-grid,
  .outbound-slip-grid,
  .process-grid,
  .process-popup-grid,
  .result-detail-grid,
  .shipment-form-top-grid,
  .user-info-grid,
  .work-order-detail-grid,
  .hfr-detail-layout,
  .hfr-detail-grid,
  .hfr-summary-grid,
  .hfr-history-summary,
  .shipment-history-summary {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .summary-grid,
  .metric-grid,
  .kpi-grid,
  .dashboard-grid,
  .shipment-stat-grid,
  .inbound-stat-grid,
  .assembly-metrics,
  .progress-metric-grid,
  .studio-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Swipe tab bars instead of wrapping them into tall stacks. */
  .module-view :where(.tabs, .tab-list, .module-tabs, .page-tabs, .hfr-tabs, .hfr-company-tabs, .hfr-page-tabs),
  .hfr-company-nav {
    display: flex !important;
    width: 100%;
    max-width: 100%;
    gap: 7px !important;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .module-view :where(.tabs, .tab-list, .module-tabs, .page-tabs, .hfr-tabs, .hfr-company-tabs, .hfr-page-tabs) > *,
  .hfr-company-nav > * {
    flex: 0 0 auto;
    min-height: 44px;
    white-space: nowrap;
  }

  /* Preserve business columns, but confine horizontal scrolling to the card. */
  .module-view :where(.table-card, .table-scroll, .data-table-wrap, .rs-table-wrap, .table-wrap, .grid-scroll, .hfr-grid-scroll, .hfr-table-scroll, .matrix-scroll, .calendar-scroll),
  .dashboard-view :where(.table-card, .table-scroll, .data-table-wrap, .rs-table-wrap, .table-wrap, .grid-scroll, .matrix-scroll, .calendar-scroll) {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: auto;
    overscroll-behavior-inline: contain;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
  }

  .module-view table,
  .dashboard-view table {
    width: max-content;
    min-width: max(640px, 100%);
    font-size: 12px;
  }

  .module-view th,
  .module-view td,
  .dashboard-view th,
  .dashboard-view td {
    height: 42px;
    padding: 7px 9px;
  }

  .rs-col-resize,
  .hfr-col-resize,
  .hfr-resize-handle {
    display: none !important;
  }

  .process-flow-split {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

  .process-flow-fixed-pane,
  .process-flow-chain-pane {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    box-shadow: none !important;
  }

  .process-flow-chain-pane {
    margin-top: 10px;
  }

  .progress-fixed-table {
    width: 420px !important;
    min-width: 420px !important;
    max-width: none !important;
  }

  dialog,
  .modal,
  .dialog,
  .dialog-panel,
  .record-dialog,
  .rs-modal {
    width: calc(100vw - 16px) !important;
    min-width: 0 !important;
    max-width: calc(100vw - 16px) !important;
    max-height: calc(100dvh - 16px) !important;
    margin: auto !important;
    padding: 0 !important;
    border-radius: 10px !important;
  }

  .modal-body,
  .dialog-body,
  .record-dialog-body,
  .rs-modal-body,
  dialog form {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    max-height: calc(100dvh - 86px);
    overflow: auto;
    padding: 14px !important;
  }

  .modal-footer,
  .dialog-footer,
  .record-dialog-footer,
  .rs-modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    padding: 10px 14px max(10px, env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid var(--line);
  }

  .modal-footer button,
  .dialog-footer button,
  .record-dialog-footer button,
  .rs-modal-footer button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
  }

  #erpView input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  #erpView select,
  #erpView textarea,
  dialog input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  dialog select,
  dialog textarea {
    max-width: 100%;
    font-size: 16px;
  }

  .module-view :where(h2, h3, h4, p, dt, dd, label, .card-title, .panel-title) {
    overflow-wrap: anywhere;
  }
}

@media (max-width: 480px) {
  :root {
    --mobile-page-padding: 8px;
  }

  .topbar h1 {
    font-size: 16px;
  }

  .topbar-right {
    gap: 5px;
  }

  .logout-button {
    padding-inline: 7px;
    font-size: 11px;
  }

  .summary-grid,
  .metric-grid,
  .kpi-grid,
  .dashboard-grid,
  .shipment-stat-grid,
  .inbound-stat-grid,
  .assembly-metrics,
  .progress-metric-grid,
  .studio-summary-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .action-buttons > button:not([hidden]) {
    flex-basis: calc(50% - 4px);
  }
}
/* Mobile dashboard and HFR density refinement. */
@media (max-width: 820px) {
  .shipment-history-summary,
  .hfr-draft-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }

  .home-calendar {
    padding: 12px !important;
  }

  .home-card-head {
    gap: min(10vw, 36px) !important;
  }

  .calendar-cell {
    min-height: 64px !important;
    padding: 6px 4px !important;
    font-size: 12px !important;
  }

  .calendar-events {
    gap: 2px !important;
    margin-top: 3px !important;
  }

  .calendar-event {
    padding: 2px 3px !important;
    font-size: 9px !important;
  }

  .dashboard-calendar-help {
    margin-bottom: 0;
    font-size: 11px;
    line-height: 1.45;
  }
}

@media (max-width: 480px) {
  .shipment-history-summary,
  .hfr-draft-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* MOBILE LOGIN FIT AND VIEWPORT STABILITY START */
@media (max-width: 820px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  :where(button, a, [role="button"], .menu-parent, .menu-item) {
    touch-action: manipulation;
  }

  #loginView.login-view {
    width: 100%;
    height: 100dvh;
    min-height: 100svh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  #loginView .login-panel {
    width: min(100%, 460px);
    min-height: 0;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    overflow-x: hidden;
    overflow-y: auto;
    border-radius: 18px;
    scrollbar-width: thin;
  }

  #loginView .login-brand-side {
    min-height: 126px;
    padding: 18px 20px 12px;
  }

  #loginView .brand-mark {
    font-size: 26px;
  }

  #loginView .login-brand-lockup > span {
    display: none;
  }

  #loginView .login-brand-copy {
    padding: 12px 0 0;
  }

  #loginView .login-brand-copy h1 {
    font-size: clamp(19px, 5.6vw, 22px);
    line-height: 1.24;
    letter-spacing: -1px;
  }

  #loginView .login-form-side {
    padding: 0 8px 8px;
  }

  #loginView .login-form {
    padding: 19px 17px 17px;
    border-radius: 15px;
  }

  #loginView .login-form-header > span {
    margin-bottom: 7px;
    font-size: 9px;
  }

  #loginView .login-form-header h2 {
    font-size: 22px;
    letter-spacing: -1px;
  }

  #loginView .login-form-header p {
    margin: 6px 0 15px;
    font-size: 12px;
  }

  #loginView .login-form > label {
    margin-top: 11px;
  }

  #loginView .login-form > label > span {
    margin-bottom: 5px;
  }

  #loginView .login-input-field {
    min-height: 50px;
    border-radius: 10px;
  }

  #loginView .login-input-field input {
    min-height: 48px;
    font-size: 16px !important;
  }

  #loginView .password-field button {
    height: 48px;
  }

  #loginView .login-form > .login-remember-option {
    margin-top: 10px;
  }

  #loginView .login-button {
    min-height: 50px;
    margin-top: 14px;
    border-radius: 10px;
  }

  #loginView .login-hint {
    margin-top: 10px;
  }

  #loginView .login-security-note {
    margin-top: 8px;
  }
}

@media (max-width: 820px) and (max-height: 700px) {
  #loginView.login-view { align-items: flex-start; }
  #loginView .login-brand-side { min-height: 98px; padding: 14px 18px 9px; }
  #loginView .brand-mark { font-size: 23px; }
  #loginView .login-brand-copy { padding-top: 7px; }
  #loginView .login-brand-copy h1 { font-size: 17px; line-height: 1.18; }
  #loginView .login-form { padding: 15px 16px 14px; }
  #loginView .login-form-header > span,
  #loginView .login-security-note { display: none; }
  #loginView .login-form-header p { margin-bottom: 10px; }
  #loginView .login-form > label { margin-top: 8px; }
  #loginView .login-input-field { min-height: 47px; }
  #loginView .login-input-field input,
  #loginView .password-field button { min-height: 45px; height: 45px; }
  #loginView .login-button { min-height: 47px; margin-top: 10px; }
}
/* MOBILE LOGIN FIT AND VIEWPORT STABILITY END */
