/* ============================================================
   飞镖俱乐部管理软件 · 手机版（窄屏）外观层
   只在屏幕宽度 <= 820px 时生效，电脑端完全不受影响。
   和 ui-v2.css 一样只做外观与布局，不改业务逻辑；
   如需回退，删除 index.html 里的 mobile.css / mobile.js 引用即可。
   ============================================================ */

/* 桌面端不显示手机专用元素 */
.m-menu-btn,
.m-tabbar,
.m-drawer-mask,
.m-sheet-mask,
.m-sheet-close,
.m-drawer-actions {
  display: none;
}

/* 触屏设备（平板横屏等）加大可点区域，但不改变电脑版布局 */
@media (hover: none) and (pointer: coarse) {
  input,
  select,
  textarea,
  .input,
  .select {
    font-size: 16px;
  }
  .btn {
    min-height: 40px;
  }
  .btn.small {
    min-height: 34px;
    padding: 6px 10px;
  }
  .qty-btn {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }
  .tab {
    min-height: 36px;
  }
}

@media (max-width: 820px) {
  /* ---------- 登录页：手机上更紧凑，键盘弹出也点得到按钮 ---------- */
  .login-wrap {
    min-height: 100dvh;
    padding: 16px;
    align-items: center;
  }
  .login-card {
    width: 100%;
    max-width: 400px;
    padding: 22px 18px 20px;
    border-radius: 16px;
  }
  .login-logo {
    width: 64px;
    height: 64px;
    margin-bottom: 10px;
    border-radius: 16px;
  }
  .login-card h1 {
    font-size: 18px;
  }
  .login-card input {
    margin-top: 10px;
    padding: 12px 13px;
    font-size: 16px;
  }
  .login-card .btn {
    margin-top: 14px;
  }
  .login-beian {
    margin-top: 14px;
    padding-top: 10px;
    font-size: 11px;
  }

  html {
    -webkit-text-size-adjust: 100%;
  }
  body {
    font-size: 15px;
  }

  /* ---------- 一、外壳：内容占满整屏，底部给标签栏留位置 ---------- */
  #main-view {
    min-height: 100dvh;
  }
  .app-shell {
    display: block;
    min-height: 0;
    padding-bottom: calc(66px + env(safe-area-inset-bottom));
  }
  .main-area {
    display: block;
  }
  .content {
    padding: 10px 10px 16px;
  }
  .content > .view {
    padding: 0;
  }
  .panel {
    padding: 12px;
    border-radius: 14px;
  }
  .row > * {
    min-width: 0;
    flex: 1 1 100%;
  }
  .row {
    gap: 8px;
  }

  /* ---------- 二、侧栏变成抽屉 ---------- */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 90;
    width: 86%;
    max-width: 320px;
    height: 100dvh;
    padding: 14px 12px calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
    transform: translateX(-104%);
    transition: transform .22s cubic-bezier(.32, .72, 0, 1);
    box-shadow: 0 0 40px rgba(0, 0, 0, .45);
  }
  body.m-drawer-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 13px;
  }
  .nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .nav-group-title {
    display: block;
  }
  .nav-item {
    padding: 11px 10px;
    font-size: 14px;
  }
  .sidebar-foot {
    display: block;
  }

  .m-drawer-mask {
    position: fixed;
    inset: 0;
    z-index: 89;
    background: rgba(8, 10, 14, .5);
    backdrop-filter: blur(2px);
  }
  body.m-drawer-open .m-drawer-mask {
    display: block;
  }

  /* 抽屉底部：手机上把「修改密码 / 退出登录」等收到这里 */
  .m-drawer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px 0 0;
    margin-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, .08);
  }
  .m-drawer-actions button {
    min-height: 42px;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 10px;
    background: rgba(255, 255, 255, .05);
    color: var(--ui-side-ink);
    font-size: 13px;
  }
  .m-drawer-actions button.m-danger {
    color: #ff9c8c;
    border-color: rgba(255, 120, 100, .3);
  }

  /* ---------- 三、顶栏：紧凑一行 ---------- */
  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    gap: 8px;
    flex-wrap: nowrap;
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top));
  }
  .topbar-title {
    flex: 1;
  }
  .topbar-title h1 {
    font-size: 16px;
  }
  .topbar-title span {
    display: none;
  }
  .topbar-right {
    width: auto;
    margin-left: 0;
    flex-wrap: nowrap;
    gap: 6px;
  }
  .topbar-clock b {
    font-size: 13px;
  }
  .topbar-clock span {
    display: none;
  }
  .topbar-right > #btn-boc-pay,
  .topbar-right > #btn-pwd,
  .topbar-right > #btn-shift,
  .topbar-right > #btn-logout {
    display: none !important;
  }
  .m-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
    border-color: var(--ui-line);
    border-radius: 11px;
    background: var(--ui-surface);
    font-size: 17px;
    line-height: 1;
  }
  .m-menu-btn:focus,
  .m-tab:focus {
    outline: none;
  }
  .m-menu-btn:focus-visible,
  .m-tab:focus-visible,
  .m-sheet-close:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
  }
  #btn-refresh {
    min-height: 40px;
  }

  /* ---------- 四、底部标签栏 ---------- */
  .m-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--ui-line);
    background: rgba(255, 255, 255, .97);
    backdrop-filter: blur(14px);
    box-shadow: 0 -6px 22px rgba(15, 17, 21, .07);
  }
  .m-tabbar .m-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 100%;
    min-height: 50px;
    padding: 4px 2px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--ui-muted);
    font-size: 11px;
    text-align: center;
    cursor: pointer;
  }
  .m-tabbar .m-tab .m-tab-icon {
    font-size: 19px;
    line-height: 1.1;
  }
  .m-tabbar .m-tab.active {
    background: var(--ui-accent-soft);
    color: var(--ui-accent-ink);
    font-weight: 600;
  }
  .m-tabbar .m-tab:active {
    background: var(--ui-surface-2);
  }

  /* ---------- 五、表格全部改成可横向滑动，不再撑破页面 ---------- */
  .panel {
    min-width: 0;
  }
  table.data {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  table.data th,
  table.data td {
    white-space: nowrap;
  }
  /* 手机上不显示的列（编号、进度条等），由 mobile.js 打标记 */
  table.data th[data-m-hidden],
  table.data td[data-m-hidden] {
    display: none;
  }
  table.data td {
    vertical-align: middle;
  }

  /* 列表型表格在手机上变成一张张卡片（由 mobile.js 打标记） */
  table.data.m-cards {
    display: block;
    overflow: visible;
    white-space: normal;
  }
  table.data.m-cards thead {
    display: none;
  }
  table.data.m-cards tbody {
    display: block;
  }
  table.data.m-cards tr {
    display: block;
    margin-bottom: 8px;
    padding: 11px 12px;
    border: 1px solid var(--ui-line);
    border-radius: 14px;
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow);
  }
  table.data.m-cards tr.clickable:active {
    background: var(--ui-surface-2);
  }
  table.data.m-cards td {
    position: static;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 3px 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    white-space: normal;
    text-align: left;
    vertical-align: baseline;
  }
  table.data.m-cards td::before {
    content: attr(data-m-label);
    flex: 0 0 auto;
    color: var(--ui-muted);
    font-size: 12px;
  }
  table.data.m-cards td .m-cell {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
    text-align: right;
  }
  table.data.m-cards td[data-m-title] {
    display: block;
    padding: 0 0 8px;
    margin-bottom: 6px;
    border-bottom: 1px dashed var(--ui-line);
    font-size: 16px;
  }
  table.data.m-cards td[data-m-title]::before {
    display: none;
  }
  table.data.m-cards td[data-m-title] .m-cell {
    display: block;
    font-weight: 600;
    text-align: left;
  }
  table.data.m-cards td[data-m-actions] {
    display: block;
    padding-top: 9px;
    margin-top: 7px;
    border-top: 1px solid var(--ui-line);
  }
  table.data.m-cards td[data-m-actions]::before {
    display: none;
  }
  table.data.m-cards td[data-m-actions] .m-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    text-align: left;
  }
  table.data.m-cards td[data-m-actions] .m-cell > * {
    flex: 1 1 auto;
  }
  table.data.m-cards td[data-m-hidden] {
    display: none;
  }
  table.data.m-cards td[data-m-plain] {
    display: block;
    padding: 2px 0;
  }
  table.data.m-cards td[data-m-plain]::before {
    display: none;
  }
  table.data.m-cards td[data-m-plain] .m-cell {
    display: block;
    text-align: left;
  }

  /* 小统计表：平铺列表（不用卡片边框），避免卡片套卡片 */
  table.data.m-flat tr {
    margin: 0;
    padding: 5px 0;
    border: 0;
    border-bottom: 1px dashed var(--ui-line);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  table.data.m-flat tr:last-child {
    border-bottom: 0;
  }
  table.data.m-flat td[data-m-title] {
    padding: 0 0 2px;
    margin: 0;
    border-bottom: 0;
    font-size: 14px;
  }
  table.data.m-flat td {
    padding: 1px 0;
  }
  table.data.m-flat td[data-m-actions] {
    padding-top: 5px;
    margin-top: 3px;
    border-top: 0;
  }
  /* ---------- 六、手指友好：按钮 / 输入框尺寸 ---------- */
  input,
  select,
  textarea,
  .input,
  .select {
    font-size: 16px; /* 低于 16px 时 iOS 会自动放大整页 */
  }
  .input,
  .select,
  textarea.input {
    min-height: 42px;
    padding: 9px 11px;
  }
  .btn {
    min-height: 42px;
    padding: 10px 14px;
  }
  .btn.small {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 13px;
  }
  /* 加号 / 减号：手机上的最小可点区域 */
  .qty-btn,
  .cart-row .qty-btn,
  #view-sales .menu-item .qty-btn {
    width: 40px;
    height: 40px;
    font-size: 17px;
  }
  .qty-val {
    min-width: 30px;
    font-size: 15px;
  }
  .tab {
    min-height: 38px;
    padding: 8px 14px;
  }
  .tabs {
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-bottom: 4px;
  }
  .tabs .tab {
    flex: 0 0 auto;
  }
  .machine .set-status {
    min-width: 40px;
    min-height: 34px;
    padding: 5px 9px;
    font-size: 13px;
  }
  .machine .set-status + .machine-name {
    padding-left: 42px;
  }

  /* ---------- 七、经营概览 ---------- */
  .dash-main-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .dash-todo {
    grid-template-columns: 1fr;
  }
  .stat-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .stat .value {
    font-size: 19px;
  }

  /* ---------- 八、收银台 ---------- */
  #view-pos.active {
    display: block;
  }
  #view-pos .panel {
    margin-bottom: 10px;
  }
  #view-pos .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 7px;
  }
  .machine {
    min-height: 84px;
    padding: 9px 8px;
  }
  .machine-time {
    font-size: 18px;
  }
  .pos-statusbar {
    gap: 6px;
    padding: 9px 10px;
  }
  .pos-statusbar .count-chip {
    font-size: 12px;
  }
  /* 底部两个面板改成页签切换，不用一直往下翻 */
  #view-pos .m-pos-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 5px;
    border: 1px solid var(--ui-line);
    border-radius: 14px;
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow);
  }
  #view-pos .m-pos-tabs button {
    min-height: 42px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--ui-muted);
    font-size: 14px;
  }
  #view-pos .m-pos-tabs button.active {
    background: var(--ui-accent);
    color: var(--ui-accent-ink);
    font-weight: 600;
  }
  #view-pos .pos-sessions-panel,
  #view-pos .pos-scan-panel {
    display: none !important;
  }
  #view-pos[data-m-panel="sessions"] .pos-sessions-panel,
  #view-pos[data-m-panel="scan"] .pos-scan-panel {
    display: block !important;
  }

  /* 选中机器后，「开台收费」从底部弹出，不用再滚到页面下方找 */
  #view-pos.m-sheet-open .pos-open-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 86;
    max-height: 78dvh;
    margin: 0;
    padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
    border-width: 1px 0 0;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -14px 44px rgba(8, 10, 14, .34);
    animation: mSheetUp .22s cubic-bezier(.32, .72, 0, 1);
  }
  #view-pos.m-sheet-open .pos-open-panel .panel-head {
    position: sticky;
    top: -14px;
    z-index: 2;
    margin: -6px -4px 8px;
    padding: 8px 4px;
    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-line);
  }
  .m-sheet-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 56px;
    height: 32px;
    margin-left: auto;
    padding: 0 10px;
    border: 1px solid var(--ui-line-strong);
    border-radius: 999px;
    background: var(--ui-surface);
    color: var(--ui-muted);
    font-size: 13px;
  }
  .m-sheet-mask {
    position: fixed;
    inset: 0;
    z-index: 85;
    background: rgba(8, 10, 14, .42);
  }
  #view-pos.m-sheet-open .m-sheet-mask {
    display: block;
  }
  .dur-presets .btn {
    flex: 1 1 40%;
  }

  /* ---------- 九、点单销售 ---------- */
  /* 手机上菜单与购物车不再并排挤在一起：菜单铺满，购物车变成底部弹层 */
  #view-sales .row {
    display: block;
  }
  #view-sales .row > .panel {
    width: 100%;
  }
  #view-sales .row > .panel:first-child {
    margin-bottom: 12px;
  }
  #view-sales.active {
    padding-bottom: 58px;
  }
  #view-sales .row > .panel:last-child {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 86;
    max-height: 78dvh;
    margin: 0;
    padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
    visibility: hidden;
    transform: translateY(101%);
    transition: transform .24s cubic-bezier(.32, .72, 0, 1), visibility .24s;
    box-shadow: 0 -14px 44px rgba(8, 10, 14, .34);
  }
  #view-sales.m-sheet-open .row > .panel:last-child {
    visibility: visible;
    transform: translateY(0);
  }
  #view-sales.m-sheet-open .m-sheet-mask {
    display: block;
  }
  #view-sales .row > .panel:last-child .panel-head {
    position: sticky;
    top: -14px;
    z-index: 2;
    margin: -6px -4px 8px;
    padding: 8px 4px;
    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-line);
  }
  .m-cart-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(66px + env(safe-area-inset-bottom));
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-top: 1px solid var(--ui-line);
    background: rgba(255, 255, 255, .97);
    backdrop-filter: blur(14px);
    box-shadow: 0 -6px 22px rgba(15, 17, 21, .08);
  }
  .m-cart-bar .m-cart-info {
    flex: 1;
    min-width: 0;
    color: var(--ui-muted);
    font-size: 13px;
  }
  .m-cart-bar .m-cart-info b {
    color: var(--ui-accent);
    font-size: 16px;
    font-variant-numeric: tabular-nums;
  }
  .m-cart-bar .btn {
    flex: none;
    min-width: 108px;
  }

  #view-sales .menu-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
  }
  #view-sales .menu-item {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 10px;
  }
  #view-sales .menu-item b {
    max-width: 100%;
    font-size: 14px;
  }
  #view-sales .menu-item .muted {
    font-size: 12px;
  }
  #view-sales .menu-item .foot {
    justify-content: space-between;
  }
  .cart-bar {
    position: sticky;
    bottom: calc(66px + env(safe-area-inset-bottom));
    z-index: 30;
    gap: 8px;
    padding: 10px 12px;
    box-shadow: 0 -6px 22px rgba(15, 17, 21, .12);
  }
  .cart-bar .total {
    font-size: 15px;
  }
  .cart-bar .btn {
    flex: 1;
  }

  /* ---------- 十、排班表 / 设置等宽表格页 ---------- */
  #view-schedule table.data th:first-child,
  #view-schedule table.data td:first-child,
  #view-stock table.data th:first-child,
  #view-stock table.data td:first-child,
  #view-members table.data th:first-child,
  #view-members table.data td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--ui-surface);
    box-shadow: 1px 0 0 var(--ui-line);
  }
  #view-schedule table.data td[data-sched] {
    min-width: 54px;
    height: 40px;
  }
  #view-schedule table.data td[data-sched] .pill {
    font-size: 12px;
  }
  .settings-subnav {
    top: 56px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .settings-subnav button {
    flex: 0 0 auto;
    min-height: 42px;
  }

  /* ---------- 十一、弹窗、列表、会员条 ---------- */
  /* 弹窗要盖在底部弹层和标签栏之上 */
  .modal-mask {
    z-index: 200;
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 88dvh;
    border-radius: 20px 20px 0 0;
  }
  .modal-head,
  .modal-body,
  .modal-foot {
    padding-left: 14px;
    padding-right: 14px;
  }
  .modal-foot {
    position: sticky;
    bottom: 0;
    background: var(--ui-surface);
  }
  .modal-foot .btn {
    flex: 1;
  }
  .list li {
    align-items: flex-start;
  }
  .feed-item {
    padding: 10px 0;
  }
  .logo-editor {
    flex-direction: column;
  }
  .payment-row {
    flex-wrap: wrap;
  }
  .payment-row .select {
    width: 100%;
  }
  .member-toolbar {
    margin-left: 0;
    width: 100%;
  }
  .member-toolbar .input {
    max-width: none;
  }
}

@keyframes mSheetUp {
  from {
    transform: translateY(24px);
    opacity: .4;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
  #view-pos.m-sheet-open .pos-open-panel {
    animation: none;
  }
}
