/* Device-adaptive refinements: tablet cards, touch targets, safe areas */

html {
  -webkit-text-size-adjust: 100%;
}

@media (max-width: 1080px) {
  .data-table {
    display: none;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-card:nth-child(2n) {
    border-right: 0;
  }

  .kpi-card:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .mobile-cards {
    display: block;
  }

  .list-toolbar {
    flex-wrap: wrap;
  }

  .search-box {
    flex: 1 1 100%;
    max-width: none;
  }

  .toolbar-filters {
    width: 100%;
    overflow-x: auto;
  }

  .sort-hint {
    display: none;
  }

  .refresh-btn {
    display: none;
  }

  .settings-mobile {
    display: block;
  }

  .user-list-card > .data-table {
    display: none;
  }
}

@media (max-width: 480px) {
  .page {
    padding-right: 11px;
    padding-left: 11px;
  }

  .page-head {
    gap: 13px;
  }

  .page-actions {
    gap: 7px;
  }

  .page-actions .btn {
    min-width: 0;
    padding: 0 10px;
    font-size: 13px;
  }

  .kpi-card {
    padding: 14px 12px;
  }

  .kpi-value {
    font-size: 27px;
  }

  .card-head h2 {
    font-size: 17.5px;
  }

  .chart-card,
  .fleet-card,
  .todo-card,
  .activity-card {
    padding: 15px 13px;
  }

  .mobile-card {
    padding: 13px 12px;
  }

  .login-form-wrap {
    max-width: 100%;
  }

  .toolbar-filters {
    flex-wrap: wrap;
    gap: 2px 3px;
    overflow: visible;
  }

  .filter-tab {
    height: 32px;
    padding: 0 6px;
  }
}

@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 42px;
    padding-right: 17px;
    padding-left: 17px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
  }

  .search-box {
    height: 42px;
  }

  .filter-tab {
    height: 36px;
  }

  .select-wrap {
    height: 38px;
  }

  .row-action {
    width: 33px;
    height: 33px;
  }

  .pager-btn {
    min-width: 32px;
    height: 32px;
  }

  .sidebar .nav-item {
    height: 46px;
  }

  .mobile-nav a,
  .mobile-nav button {
    min-height: 50px;
  }
}

@media (max-width: 1080px) {
  .page {
    padding-bottom: calc(94px + env(safe-area-inset-bottom));
  }

  .mobile-nav {
    bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

/* 独立记账是独立工具，不显示平台手机底栏，避免遮挡账本内容 */
@media (max-width: 1080px) {
  body[data-route="ledger"] .mobile-nav {
    display: none !important;
  }

  body[data-route="ledger"] .page {
    padding-bottom: 24px;
  }
}

@media (max-width: 620px) {
  .toolbar-filters {
    flex-wrap: wrap;
    overflow: visible;
  }

  .filter-tabs {
    width: 100%;
    flex-wrap: wrap;
    overflow: visible;
    row-gap: 2px;
  }

  .filter-tab {
    flex: 0 0 auto;
  }

  .mobile-card-foot {
    flex-wrap: wrap;
    gap: 7px;
  }
}

@media (display-mode: standalone) {
  .topbar {
    padding-top: env(safe-area-inset-top);
  }
}

/* Fallback when a phone browser uses a wide desktop layout viewport. */
html.force-mobile .app-main {
  margin-left: 0;
}

html.force-mobile .sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 80;
  display: flex;
  width: 280px;
  padding: 24px 16px 16px;
  border-right: 1px solid var(--line);
  box-shadow: 20px 0 60px rgba(26, 42, 70, 0.16);
  transform: translateX(-102%);
  transition: transform 0.24s ease;
}

html.force-mobile body.nav-open .sidebar {
  transform: translateX(0);
}

html.force-mobile .sidebar .brand {
  height: auto;
  padding: 0 8px 24px;
  border-bottom: 0;
}

html.force-mobile .sidebar .brand img {
  width: 40px;
  height: 40px;
}

html.force-mobile .sidebar .brand-copy strong {
  font-size: 22px;
}

html.force-mobile .sidebar .sidebar-nav {
  padding: 0;
}

html.force-mobile .sidebar .nav-item {
  height: 46px;
  font-size: 15px;
}

html.force-mobile .sidebar .drawer-close {
  position: absolute;
  top: 20px;
  right: 12px;
  display: inline-grid;
}

html.force-mobile .sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: 75;
  display: block;
  background: rgba(26, 42, 70, 0.38);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

html.force-mobile body.nav-open .sidebar-scrim {
  opacity: 1;
  visibility: visible;
}

html.force-mobile .topbar {
  height: 60px;
  padding: 0 16px;
}

html.force-mobile .topbar-left {
  gap: 8px;
}

html.force-mobile .topbar-brand {
  display: flex;
}

html.force-mobile .breadcrumb {
  display: none;
}

html.force-mobile .topbar .menu-btn {
  display: inline-grid;
}

html.force-mobile .date-chip {
  display: none;
}

html.force-mobile .profile-copy,
html.force-mobile .profile-chevron {
  display: none;
}

html.force-mobile .profile-trigger {
  height: 36px;
  padding: 2px;
}

html.force-mobile .page {
  padding: 22px 16px calc(94px + env(safe-area-inset-bottom));
}

html.force-mobile .page-head {
  flex-direction: column;
  align-items: flex-start;
  gap: 15px;
}

html.force-mobile .page-head h1 {
  font-size: 29px;
}

html.force-mobile .page-actions {
  width: 100%;
}

html.force-mobile .page-actions .btn {
  flex: 1;
}

html.force-mobile .kpi-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

html.force-mobile .kpi-card {
  padding: 15px 14px;
  border-right: 1px solid var(--line);
}

html.force-mobile .kpi-card:nth-child(2n) {
  border-right: 0;
}

html.force-mobile .kpi-card:nth-child(-n + 2) {
  border-bottom: 1px solid var(--line);
}

html.force-mobile .kpi-value {
  font-size: 28px;
}

html.force-mobile .dash-grid,
html.force-mobile .dash-lower {
  grid-template-columns: 1fr;
}

html.force-mobile .dash-grid > .todo-card-featured {
  order: -1;
}

html.force-mobile .data-table {
  display: none;
}

html.force-mobile .mobile-cards,
html.force-mobile .settings-mobile {
  display: block;
}

html.force-mobile .list-toolbar {
  flex-wrap: wrap;
}

html.force-mobile .search-box {
  flex: 1 1 100%;
  max-width: none;
}

html.force-mobile .toolbar-filters {
  width: 100%;
  overflow-x: auto;
}

html.force-mobile .sort-hint,
html.force-mobile .refresh-btn {
  display: none;
}

html.force-mobile .settings-grid,
html.force-mobile .settings-side {
  grid-template-columns: 1fr;
}

html.force-mobile .settings-stats {
  grid-template-columns: 1fr;
}

html.force-mobile .settings-stat {
  border-right: 0;
  border-bottom: 1px solid var(--line);
}

html.force-mobile .settings-stat:last-child {
  border-bottom: 0;
}

html.force-mobile .login-page {
  grid-template-columns: 1fr;
}

html.force-mobile .login-visual {
  display: none;
}

html.force-mobile .login-panel {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 30px 18px 52px;
  background: var(--bg);
}

html.force-mobile .login-mobile-brand {
  display: flex;
}

html.force-mobile .mobile-nav {
  position: fixed;
  right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  left: 12px;
  z-index: 60;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: 62px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(26, 42, 70, 0.08);
}

html.force-mobile .mobile-nav a,
html.force-mobile .mobile-nav button {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 2px;
  color: var(--ink-3);
  background: transparent;
}

html.force-mobile .mobile-nav em {
  font-size: 10px;
  font-style: normal;
}

html.force-mobile .mobile-nav a.active {
  color: var(--brand);
  background: var(--brand-soft);
}

html.force-mobile .mobile-nav a.active span {
  color: var(--brand);
}

/* Mobile login: one column, aligned brand and form, no clipped fields */
@media (max-width: 1080px) {
  .login-page {
    display: block;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
  }

  .login-panel {
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    width: 100%;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 28px 20px 48px;
    box-sizing: border-box;
  }

  .login-mobile-brand {
    display: flex;
    width: 100%;
    max-width: 392px;
    margin: 0 auto 34px;
    padding: 0;
    justify-content: flex-start;
  }

  .login-form-wrap {
    width: 100%;
    max-width: 392px;
    margin: 0 auto;
  }

  .login-panel-foot {
    position: static;
    margin-top: 28px;
    padding-top: 0;
    text-align: center;
  }
}

html.force-mobile .login-page {
  display: block;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

html.force-mobile .login-panel {
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  width: 100%;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 28px 20px 48px;
  box-sizing: border-box;
}

html.force-mobile .login-mobile-brand {
  display: flex;
  width: 100%;
  max-width: 392px;
  margin: 0 auto 34px;
  padding: 0;
  justify-content: flex-start;
}

html.force-mobile .login-form-wrap {
  width: 100%;
  max-width: 392px;
  margin: 0 auto;
}

html.force-mobile .login-panel-foot {
  position: static;
  margin-top: 28px;
  padding-top: 0;
  text-align: center;
}

.status-pill + .status-pill {
  margin-left: 4px;
}

.mobile-status-stack {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex-wrap: wrap;
}
