/* ==========================================================================
   移动端自适应
   ------------------------------------------------------------------
   断点策略：
     ≤ 1024px  平板：侧栏收窄，双栏改单栏，图表竖排
     ≤ 900px   手机：侧栏变抽屉（汉堡菜单），表格改卡片式
     ≤ 640px   小屏：进一步压缩间距，按钮与输入框加大触控面积

   设计目标：手机上能完整浏览信息并完成操作，
   而不是只能看个大概的「只读版」。
   ========================================================================== */

/* ------------------------------ 平板及以下 ------------------------------ */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: 200px;
  }

  /* 双栏布局（新增/编辑订单）改单栏 */
  .layout-split {
    flex-direction: column;
  }
  .layout-split__side {
    width: 100%;
    flex: 0 0 auto;
  }

  /* 图表行改竖排 */
  .chart-row {
    flex-direction: column;
  }
  .chart-card--fixed {
    width: 100%;
    flex: 0 0 auto;
  }

  /* 统计卡片每行两个 */
  .stat-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--sp-6);
  }

  /* 汇率条换行排布 */
  .rate-bar {
    flex-wrap: wrap;
    gap: var(--sp-6);
  }
  .rate-bar__aux {
    padding-left: 0;
    border-left: none;
  }
  .rate-bar__right {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }
}

/* ------------------------------ 手机 ------------------------------ */
@media (max-width: 900px) {
  :root {
    --topbar-h: 52px;
    --page-pad: 12px;
  }

  /* 登录页背景换小图（省流量） */
  .login__bg {
    background-image: url('../assets/maldives-aerial-sm.jpg');
    /* 上移取景：让岛屿落在画面上半，标题落在天空与海交界处 */
    background-position: center 20%;
    background-size: cover;
  }
  /* 表单压在下半部分深蓝海域，避开岛屿主体 */
  .login__panel {
    justify-content: space-between;
    padding: 56px var(--sp-5) 40px;
  }
  .login__form {
    gap: var(--sp-5);
    max-width: 340px;
  }
  .login__form-bottom { gap: var(--sp-4); }
  .login__brand {
    gap: var(--sp-4);
    margin-bottom: 0;
  }
  .login__mark { width: 44px; height: 44px; }
  .login__mark::before { width: 22px; height: 22px; }
  .login__scrim {
    background:
      linear-gradient(180deg, rgba(4, 20, 38, 0.58) 0%, rgba(4, 20, 38, 0.30) 30%,
                      rgba(3, 18, 34, 0.50) 48%, rgba(3, 16, 32, 0.86) 78%, rgba(3, 16, 32, 0.95) 100%);
  }
  .login__title { font-size: 26px; letter-spacing: 1px; }

  /* --- 侧栏变抽屉 --- */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    flex: 0 0 260px;
    min-height: 100vh;
    height: 100vh;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 30px rgba(0, 0, 0, .28);
    overflow-y: auto;
  }
  .sidebar.is-open { transform: translateX(0); }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(6, 16, 28, .45);
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
  }
  .sidebar-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }
  /* 抽屉打开时锁定背景滚动 */
  body.nav-open { overflow: hidden; }

  /* --- 顶栏 --- */
  .topbar {
    padding: 0 var(--sp-5);
    gap: var(--sp-4);
  }
  .topbar__menu {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    margin-right: 2px;
    border-radius: var(--r-btn);
    color: var(--text-2);
  }
  .topbar__menu:hover { background: var(--primary-soft); }
  .topbar__title {
    font-size: 15px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar__right { gap: var(--sp-4); }
  .topbar__bell { display: none; }
  .topbar__user { font-size: 12px; }
  .topbar__role { display: none; }

  /* --- 页面容器 --- */
  .page {
    padding: var(--page-pad);
    gap: var(--sp-5);
  }
  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-4);
  }
  .page-head__title { font-size: 17px; }
  .page-head__actions {
    gap: var(--sp-3);
  }
  .page-head__actions .btn { flex: 1; min-width: 0; }

  /* --- 卡片 --- */
  .card {
    padding: var(--sp-6);
    gap: var(--sp-5);
  }
  .section-title { font-size: 14px; }

  /* --- 统计卡片：单列 --- */
  .stat-grid {
    grid-template-columns: 1fr;
    gap: var(--sp-4);
  }
  .stat { padding: var(--sp-5); gap: var(--sp-2); }
  .stat__value { font-size: 22px; }

  /* --- 汇率条：竖排 --- */
  .rate-bar {
    padding: var(--sp-5);
    gap: var(--sp-5);
  }
  .rate-bar__main { flex: 1 1 100%; }
  .rate-bar__value { font-size: 20px; }
  .rate-bar__aux {
    width: 100%;
    gap: var(--sp-6);
  }
  .rate-bar__aux-item + .rate-bar__aux-item {
    padding-left: var(--sp-6);
  }
  .rate-bar__right {
    width: 100%;
    flex-wrap: wrap;
    gap: var(--sp-4);
  }
  .rate-bar__meta {
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: var(--sp-3);
  }

  /* --- 表单：单列 --- */
  .form-row {
    flex-direction: column;
    gap: var(--sp-4);
  }
  .form-row > .field { width: 100%; }

  /* 输入框与选择器加大触控高度 */
  .input, .select { height: 38px; }
  .textarea { min-height: 80px; }

  /* --- 筛选栏：整行换行 --- */
  .filter-bar {
    flex-wrap: wrap;
    gap: var(--sp-3);
    padding: var(--sp-4);
  }
  .filter-bar__select,
  .filter-bar__select--wide,
  .filter-bar__date {
    width: 100%;
    flex: 1 1 100%;
  }
  .filter-bar__spacer { display: none; }
  .filter-bar .btn { flex: 1 1 auto; }

  /* --- 可折叠筛选面板：手机上默认收起 --- */
  .filter-collapse {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-card);
    overflow: hidden;
  }
  .filter-collapse__toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-5) var(--sp-6);
    font-size: var(--fs-body);
    font-weight: 500;
    color: var(--text-1);
    background: var(--surface);
  }
  .filter-collapse__arrow {
    margin-left: auto;
    color: var(--text-4);
    transition: transform .2s ease;
    font-size: 12px;
  }
  .filter-collapse.is-open .filter-collapse__arrow { transform: rotate(180deg); }
  .filter-collapse__body {
    display: none;
    padding: 0 var(--sp-4) var(--sp-4);
    flex-direction: column;
    gap: var(--sp-3);
  }
  .filter-collapse.is-open .filter-collapse__body { display: flex; }
  .filter-collapse__body .filter-bar {
    background: transparent;
    border: none;
    padding: 0;
  }

  /* --- 表格：卡片式 --- */
  .table-scroll {
    overflow-x: visible;
    -webkit-overflow-scrolling: touch;
  }
  .table,
  .table--wide {
    min-width: 0;
    display: block;
    table-layout: auto;
  }
  .table thead {
    display: none;              /* 表头隐藏，改用单元格上的 data-label */
  }
  .table tbody,
  .table tbody tr,
  .table tbody td {
    display: block;
    width: 100%;
  }
  .table tbody tr {
    border-bottom: 1px solid var(--border);
    padding: var(--sp-4) var(--sp-5);
    background: var(--surface);
  }
  .table tbody tr:last-child { border-bottom: none; }
  .table tbody tr:hover td { background: transparent; }
  .table tbody td {
    height: auto;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-5);
    padding: 5px 0;
    border-bottom: none;
    white-space: normal;
    word-break: break-word;
    font-size: var(--fs-body);
  }
  .table tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--text-4);
    font-size: var(--fs-sm);
  }
  /* 首列（通常是主键/编号）作为卡片标题突出显示 */
  .table tbody td:first-child {
    font-weight: 600;
    color: var(--text-1);
    padding-bottom: var(--sp-3);
    margin-bottom: var(--sp-2);
    border-bottom: 1px solid var(--border-soft);
  }
  .table tbody td:first-child::before { display: none; }
  /* 操作列按钮可点击区域加大 */
  .table__actions { display: flex; flex-wrap: wrap; gap: var(--sp-4); justify-content: flex-end; }
  .table__actions span {
    padding: 4px 2px;
  }
  .table__actions span + span { margin-left: 0; }
  /* 空状态的 colspan 不再撑破布局 */
  .table tbody td[colspan] { display: block; }

  /* --- 分页 --- */
  .table-footer {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
  }
  .table-footer__info { text-align: center; }
  .pagination {
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--sp-3);
  }
  .pagination__page {
    min-width: 32px;
    height: 32px;
  }

  /* --- 图表 --- */
  .chart-card { padding: var(--sp-5); gap: var(--sp-5); }
  .pie-body {
    flex-direction: column;
    align-items: stretch;
  }
  .line-chart { height: 180px; }
  .line-chart svg { height: 156px; }

  /* --- 金额卡（新增订单右侧栏） --- */
  .amount-card {
    position: static;
    width: 100%;
  }

  /* --- 价格明细表：改为卡片式，避免撑破手机视口 --- */
  .price-table { overflow-x: visible; }
  .price-table table {
    min-width: 0;
    display: block;
    table-layout: auto;
  }
  .price-table thead { display: none; }
  .price-table tbody,
  .price-table tbody tr,
  .price-table tbody td { display: block; width: 100%; }
  .price-table tbody tr {
    border-bottom: 1px solid var(--border);
    padding: var(--sp-3) 0;
  }
  .price-table tbody tr:last-child { border-bottom: none; }
  .price-table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: 4px 0;
    border-bottom: none;
    text-align: right;
  }
  .price-table tbody td:first-child {
    font-weight: 600;
    color: var(--text-1);
  }
  /* 首列作标题，其余列右对齐显示 */
  .price-table tbody td:first-child {
    display: block;
    margin-bottom: 2px;
  }
  .price-table tbody td:not(:first-child)::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--text-4);
    font-size: var(--fs-sm);
  }
  .price-table tbody td:last-child { justify-content: flex-end; }

  /* --- 房间/资源卡片 --- */
  .grid-cards {
    grid-template-columns: 1fr;
    gap: var(--sp-5);
  }
  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: var(--sp-3);
  }

  /* --- 消息提醒 --- */
  .notice-item {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-4);
  }
  .notice-item__right {
    width: 100%;
    justify-content: flex-end;
  }

  /* --- 弹窗：贴满屏幕 --- */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--r-modal) var(--r-modal) 0 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal__actions {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    padding-top: var(--sp-4);
    margin-top: var(--sp-4);
    border-top: 1px solid var(--border);
  }
  .modal__actions .btn { flex: 1; }

  /* --- 标签页 --- */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; }

  /* --- 设置行 --- */
  .setting-row {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-4);
  }
  .setting-row__control { width: 100%; }
  .setting-row__control--full { flex-direction: column; }

  /* --- 提示条 --- */
  .toast-host {
    left: var(--sp-4);
    right: var(--sp-4);
    bottom: var(--sp-4);
    align-items: center;
  }
  .toast { width: 100%; text-align: center; }
}

/* ------------------------------ 小屏手机 ------------------------------ */
@media (max-width: 640px) {
  :root {
    --fs-stat: 22px;
    --fs-stat-sm: 17px;
  }

  .page { padding: 10px; gap: var(--sp-4); }

  /* 顶部标题与按钮 */
  .page-head__title { font-size: 16px; }
  .page-head__subtitle { font-size: 12px; }

  /* 卡片内边距再压缩 */
  .card { padding: var(--sp-5); }

  /* 表单标签与输入更紧凑 */
  .field__label { font-size: 12px; }

  /* 表格卡片内边距 */
  .table tbody tr { padding: var(--sp-4); }

  /* 弹窗标题与描述 */
  .modal__title { font-size: 16px; }
  .modal__desc { font-size: 12px; }
}

/* ------------------------------ 横屏矮屏 ------------------------------ */
@media (max-height: 480px) and (orientation: landscape) {
  .login__panel { padding: var(--sp-5); }
  .login__brand { margin-bottom: 0; gap: var(--sp-3); }
  .login__mark { width: 38px; height: 38px; }
  .login__title { font-size: 22px; }
  .login__form { gap: var(--sp-4); max-width: 340px; }
  .login__field { height: 40px; }
}
