/**
 * 全站响应式：手机 / 平板 / 窄屏
 * 在 scrollbar.css 之后引入
 */

/* 移动端：关毛玻璃、关背景动画，避免 GPU 卡死白屏 */
@media (max-width: 900px) {
  .sidebar,
  .top-bar,
  .data-panel,
  .login-box,
  .login-card,
  .panel,
  .wallet-hero,
  .modal-content,
  .toast,
  .sidebar-backdrop,
  #uiDialogOverlay {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  .sidebar-backdrop {
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  /* user / cloud / finance / salary 等页的旋转光晕 */
  body::before,
  body::after {
    display: none !important;
    animation: none !important;
    filter: none !important;
  }

  .list-view {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after {
    animation: none !important;
  }

  .sidebar {
    transition: none !important;
  }
}

/* —— 通用页面容器（iframe 子页） —— */
@media (max-width: 900px) {
  .panel {
    max-width: 100% !important;
    padding: 16px 12px !important;
    border-radius: 20px;
  }

  .hero {
    padding: 16px !important;
    border-radius: 14px;
  }

  .hero h2 {
    font-size: 17px;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)) !important;
    gap: 10px !important;
  }

  .stat-card,
  .mini-stat {
    padding: 12px !important;
  }

  .stat-value,
  .mini-stat-value {
    font-size: 18px !important;
  }

  .header {
    flex-direction: column;
    align-items: stretch !important;
    gap: 12px;
    text-align: left;
  }

  .header .actions {
    justify-content: flex-start;
    width: 100%;
    flex-wrap: wrap;
  }

  .controls {
    padding: 14px !important;
  }

  .ctrl-row {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .ctrl-row input[type="text"],
  .ctrl-row input[type="number"],
  .ctrl-row input[type="date"],
  .ctrl-row select {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  section .row:not(.row-inline),
  .panel .row:not(.rate-panel .row):not(.row-inline) {
    flex-direction: column;
    align-items: stretch !important;
  }

  section .row:not(.row-inline) > input,
  section .row:not(.row-inline) > select,
  section .row:not(.row-inline) > button,
  .panel .row:not(.row-inline) > input,
  .panel .row:not(.row-inline) > select,
  .panel .row:not(.row-inline) > button {
    width: 100% !important;
    max-width: 100% !important;
  }

  section .row.row-inline {
    flex-direction: row !important;
    flex-wrap: wrap;
    align-items: center !important;
  }

  section .row.row-inline > label {
    flex: 0 0 auto;
  }

  section .row.row-inline > input {
    flex: 1 1 140px;
    width: auto !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  section .row.row-inline > button {
    width: auto !important;
    flex: 0 0 auto;
  }

  .rate-panel .row {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .list-view {
    border-radius: 12px;
    -webkit-overflow-scrolling: touch;
  }

  .list-table {
    font-size: 12px;
  }

  .list-table th,
  .list-table td {
    padding: 8px 10px;
  }

  .list-table-user {
    min-width: 720px;
  }

  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }

  .card-view {
    grid-template-columns: 1fr !important;
  }

  .pager {
    gap: 6px;
  }

  .btn,
  button.btn {
    min-height: 40px;
  }

  .toast {
    left: 12px;
    right: 12px;
    transform: none;
    max-width: calc(100vw - 24px);
    text-align: center;
  }
}

@media (max-width: 480px) {
  .panel {
    padding: 12px 10px !important;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .stat-value,
  .mini-stat-value {
    font-size: 16px !important;
  }

  .logo {
    font-size: 28px !important;
  }
}

/* —— 主框架 index.html —— */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-right: 8px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--txt, #e5eefb);
  cursor: pointer;
  flex-shrink: 0;
}

.mobile-menu-btn svg {
  width: 22px;
  height: 22px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0, 0, 0, 0.55);
}

.sidebar-backdrop.show {
  display: block;
}

@media (max-width: 900px) {
  body.erp-frame {
    display: block;
    padding: 0 !important;
    min-height: 100%;
    min-height: 100dvh;
    overflow: hidden;
  }

  html.erp-frame,
  body.erp-frame {
    height: 100%;
    height: 100dvh;
  }

  body.erp-frame .main-content {
    margin-left: 0 !important;
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
    height: 100dvh;
    height: -webkit-fill-available;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  body.erp-frame .top-bar {
    padding-top: max(8px, env(safe-area-inset-top, 0));
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    width: 86vw;
    max-width: 260px;
    box-shadow: none;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.45);
    will-change: transform;
  }

  .top-bar {
    display: grid;
    grid-template-columns: 40px 1fr;
    grid-template-areas:
      "menu title"
      "actions actions";
    align-items: center;
    padding: 8px 12px;
    height: auto;
    min-height: 56px;
    gap: 8px 10px;
  }

  .mobile-menu-btn {
    grid-area: menu;
    margin-right: 0;
  }

  .top-bar h2 {
    grid-area: title;
    font-size: 16px;
    min-width: 0;
    margin-right: 0;
  }

  .top-bar-right {
    grid-area: actions;
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
  }

  .top-bar-time {
    display: none;
  }

  .studio-switch-wrap {
    flex: 1 1 auto;
    min-width: 0;
  }

  .studio-switch-wrap select {
    min-width: 0;
    max-width: 100%;
    width: 100%;
  }

  .top-bar-user span {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .dashboard {
    padding: 16px 12px;
  }

  .data-grid {
    grid-template-columns: 1fr !important;
    gap: 14px;
  }

  .mini-stats {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .mini-stats.mini-stats-5 {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .data-panel {
    padding: 16px;
  }

  .rank-table {
    font-size: 12px;
  }

  .rank-table th,
  .rank-table td {
    padding: 8px 6px;
  }

  body.sidebar-open {
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  .mini-stats,
  .mini-stats.mini-stats-5 {
    grid-template-columns: 1fr !important;
  }

  .btn-logout {
    padding: 8px 10px;
    font-size: 11px;
  }

  .top-bar-user {
    padding: 6px 10px;
  }
}

/* —— 云机 / 员工管理聚合页 —— */
@media (max-width: 768px) {
  .cloudmgmt-top,
  body > .top,
  .top {
    padding: 10px 12px !important;
  }

  .tabs .tab,
  .tab {
    flex: 1 1 auto;
    text-align: center;
    padding: 8px 12px !important;
    font-size: 12px !important;
  }

  .desc-cell {
    max-width: none !important;
  }
}

/* —— 员工/系统管理内嵌 —— */
@media (max-width: 900px) {
  section h2 {
    font-size: 17px;
  }

  table {
    font-size: 12px;
  }

  input[type="text"],
  input[type="password"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px; /* 避免 iOS 自动放大 */
  }

  /* 全屏 iframe 聚合页不加 padding，避免高度被撑破 */
  body:not(.erp-frame):not(.erp-embed) {
    padding: 12px !important;
  }

  body.erp-embed {
    padding: 0 !important;
    height: 100%;
    overflow: hidden;
  }

  section {
    padding: 14px !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  section table {
    min-width: 520px;
  }

  .filter-grid {
    grid-template-columns: 1fr !important;
  }

  .filter-grid > div {
    min-width: 0;
  }

  .filter-dates {
    grid-template-columns: 1fr !important;
    grid-column: 1 / -1 !important;
  }

  .filter-field-full {
    grid-column: 1 / -1 !important;
  }

  .filter-grid input[type="date"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .wallet-balances {
    grid-template-columns: 1fr !important;
  }

  .wallet-hero-top {
    flex-direction: column;
    align-items: stretch !important;
  }

  .wallet-actions {
    align-items: stretch !important;
    width: 100%;
  }

  .wallet-actions .btn-withdraw {
    width: 100%;
  }

  .modal {
    padding: 12px;
    align-items: flex-end;
  }

  .modal-box {
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
  }

  body.erp-frame .login-overlay {
    padding: 16px;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .login-card {
    padding: 28px 22px;
  }

  .login-card input {
    font-size: 16px;
  }

  .tabs {
    width: 100%;
    justify-content: stretch;
  }

  .tabs .tab,
  .tab {
    flex: 1 1 0;
    min-width: 0;
  }
}
