/*
 * 设备适配层
 *
 * style.css 保留桌面端的业务组件样式，这里只负责把工作台重新排布到
 * 平板和触屏手机。报价编辑器（.qe/.qp/.qcard）由 quote-responsive.css
 * 维护，避免两个断点同时修改表格列宽。
 */

:root {
  --mobile-nav-h: 0px;
}
.sidebar-footer { opacity: 1; color: var(--text-2); }
.ai-chat-fab { box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }

.sidebar-backdrop { display: none; }
.sidebar-backdrop[hidden] { display: none; }
.mobile-subnav { display: none; }

/* 地区内容只在侧栏内滚动，不参与分配地图高度。 */
.supplier-map { grid-template-rows: minmax(0, 1fr); }
.supplier-map > .globe-card,
.supplier-map > .region-panel { min-width: 0; }
.supplier-map > .region-panel { overflow-y: auto; }
.supplier-map .region-list { min-height: 0; }
.supplier-map .region-panel > :not(.region-list) { flex-shrink: 0; }
.supplier-map .globe-tools .btn { white-space: nowrap; }
@media (min-width: 721px) {
  .supplier-map > .globe-card,
  .supplier-map > .region-panel { min-height: 0; }
}

/* 合作项目：编辑空间随屏幕展开，价格操作保持在对应行内。 */
.project-form-modal .modal-header,
.project-form-modal .modal-footer { flex-shrink: 0; }
.project-form-modal .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.project-form-modal .form-grid > * { min-width: 0; }
.project-price-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.project-form-modal .price-entry-top { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto; }
.price-entry-actions { display: flex; align-items: center; gap: 8px; }
.price-entry-actions .price-entry-delete { margin-bottom: 0; }
.project-form-modal [data-private-price][hidden] { display: none !important; }
.private-prices-hidden .price-entry-values { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.project-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.project-card-actions .btn { min-height: 36px; }
@media (max-width: 720px) {
  .project-form-modal .form-grid { grid-template-columns: minmax(0, 1fr); }
  .project-form-modal .form-grid .span-2 { grid-column: 1; }
  .project-form-modal .price-entry-top { grid-template-columns: minmax(0, 1fr); }
  .project-form-modal .price-entry-top .form-item { grid-column: 1; grid-row: auto; }
  .price-entry-actions { justify-content: flex-end; }
  .project-card-actions .btn,
  .price-entry-actions .btn,
  .price-entry-actions .icon-btn { min-height: 44px; }
  .price-entry-actions .icon-btn { min-width: 44px; }
}

/* 平板：保留侧栏，但收窄导航并收回桌面端的大留白。 */
@media (min-width: 721px) and (max-width: 1100px) {
  :root {
    --sidebar-w: 76px;
    --sidebar-w-collapsed: 76px;
  }

  .sidebar,
  .layout.collapsed .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 890;
    width: var(--sidebar-w);
  }

  .main {
    margin-left: var(--sidebar-w);
    width: calc(100% - var(--sidebar-w));
  }

  .brand {
    justify-content: center;
    padding: 0 10px;
  }

  .brand-name,
  .nav-text,
  .sidebar-footer {
    display: none;
  }

  .nav {
    padding: 12px 8px;
  }

  .nav-item {
    justify-content: center;
    padding: 12px 8px;
  }

  .nav-sub-group { display: none; }

  .layout.nav-open .sidebar {
    width: 240px;
    background: var(--card);
    box-shadow: 8px 0 28px rgba(0, 0, 0, .14);
  }

  .layout.nav-open .brand {
    justify-content: flex-start;
    padding: 0 18px;
  }

  .layout.nav-open .brand-name,
  .layout.nav-open .nav-text,
  .layout.nav-open .sidebar-footer,
  .layout.nav-open .nav-sub-group {
    display: block;
  }

  .layout.nav-open .nav-item {
    justify-content: flex-start;
    padding: 12px 14px;
  }

  .layout.nav-open .sidebar-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 880;
    border: 0;
    background: rgba(20, 20, 22, .28);
    cursor: pointer;
  }

  .nav-sub {
    padding: 10px 12px;
    white-space: normal;
  }

  .nav-sub::before {
    display: none;
  }

  .content {
    padding: 32px clamp(20px, 4vw, 40px) 104px;
  }

  .topbar {
    padding: 0 clamp(14px, 3vw, 24px);
  }

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

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

  .card {
    padding: 26px 24px;
    margin-bottom: 20px;
  }

  .supplier-map {
    grid-template-columns: minmax(0, 1fr) 260px;
    min-height: 440px;
  }

  .supplier-map .globe-tools { left: 12px; right: 12px; gap: 6px; justify-content: flex-end; }
  .supplier-map .globe-tools .btn { padding: 8px; gap: 4px; font-size: 12px; min-height: 44px; }

  .modal {
    max-width: calc(100vw - 32px);
  }

  .ai-chat-win {
    width: min(58vw, 680px);
    min-width: 360px;
  }
}

/* 手机：导航变为可横向滑动的底部栏，所有一级模块仍然可达。 */
@media (max-width: 720px) {
  :root {
    --topbar-h: 56px;
    --mobile-nav-h: calc(72px + env(safe-area-inset-bottom));
    --sidebar-w: 0px;
    --sidebar-w-collapsed: 0px;
  }

  html {
    min-width: 0;
  }

  body {
    min-width: 0;
    min-height: 100svh;
  }

  .layout {
    display: block;
    height: 100vh;
    height: 100dvh;
  }

  .sidebar,
  .layout.collapsed .sidebar {
    position: fixed;
    inset: auto 0 0;
    z-index: 880;
    width: 100%;
    height: var(--mobile-nav-h);
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--glass-border);
    border-right: 0;
    background: var(--glass-strong);
    box-shadow: 0 -8px 28px rgba(0, 0, 0, .08);
  }

  .brand,
  .sidebar-footer {
    display: none;
  }

  .nav,
  .layout.collapsed .nav {
    display: flex;
    align-items: stretch;
    gap: 0;
    width: 100%;
    height: 100%;
    padding: 6px max(6px, env(safe-area-inset-left)) 6px max(6px, env(safe-area-inset-right));
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .nav-item,
  .layout.collapsed .nav-item {
    flex: 1 0 58px;
    min-width: 58px;
    min-height: 60px;
    justify-content: center;
    flex-direction: column;
    gap: 3px;
    padding: 7px 6px;
    margin: 0;
    border-radius: 10px;
    font-size: 11px;
    line-height: 1.2;
  }

  .nav-text,
  .layout.collapsed .nav-text {
    display: block;
    overflow: hidden;
    max-width: 68px;
    text-overflow: ellipsis;
  }

  .nav-icon {
    width: auto;
    height: 22px;
    font-size: 18px;
  }

  .nav-sub-group,
  .layout.collapsed .nav-sub-group {
    display: none;
  }

  .mobile-subnav:not([hidden]) {
    display: flex;
    flex: 0 0 48px;
    align-items: center;
    gap: 4px;
    min-width: 0;
    padding: 0 10px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--border);
    background: var(--card);
  }

  .mobile-subnav-link {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    min-height: 44px;
    padding: 8px 12px;
    margin: 0;
    color: var(--text-2);
    white-space: nowrap;
    font-size: 14px;
    border-bottom: 2px solid transparent;
  }

  .mobile-subnav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
  }

  .mobile-subnav-link:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -3px;
  }

  .main {
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  .topbar {
    height: var(--topbar-h);
    padding: 0 12px;
    gap: 8px;
  }

  #toggle-sidebar {
    display: none;
  }

  .breadcrumb {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 14px;
  }

  .topbar-right {
    gap: 2px;
  }

  .search,
  .topbar .user-meta {
    display: none;
  }

  .user-btn {
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
    padding: 4px;
  }

  .content {
    width: 100%;
    min-height: 0;
    padding: 20px 12px calc(var(--mobile-nav-h) + 24px);
  }

  .page-header {
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 20px;
  }

  .page-header > div:first-child,
  .page-header > div:last-child {
    flex: 1 1 100%;
    width: 100%;
  }

  .page-title {
    font-size: 26px;
  }

  .page-desc {
    margin-top: 6px;
    font-size: 14px;
  }

  .card {
    padding: 20px 16px;
    margin-bottom: 16px;
    border-radius: 14px;
  }

  .card-title {
    font-size: 18px;
    margin-bottom: 14px;
  }

  .grid,
  .grid-4,
  .grid-3,
  .grid-2 {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    margin-bottom: 12px;
  }

  .stat-value {
    font-size: 28px;
  }

  .toolbar,
  .card-header,
  .list-toolbar {
    align-items: stretch;
  }

  .toolbar .btn,
  .card-header .btn,
  .page-header .toolbar .btn {
    min-height: 44px;
  }

  .page-header .toolbar {
    width: 100%;
  }

  .page-header .toolbar .btn {
    flex: 1 1 auto;
  }

  .card-header {
    flex-wrap: wrap;
  }

  .card-header > * {
    min-width: 0;
  }

  .form-row,
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .form-grid .span-2 {
    grid-column: span 1;
  }

  .input,
  select.input,
  textarea.input {
    min-height: 44px;
    font-size: 16px;
  }

  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }

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

  .tabs {
    gap: 2px;
    margin: 0 0 18px;
    padding: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 12px 14px;
    font-size: 15px;
  }

  .list-toolbar > .toolbar {
    width: 100%;
    margin-left: 0;
  }

  .list-toolbar > .toolbar .btn {
    flex: 1 1 auto;
  }

  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 3px;
    margin-bottom: 10px;
    -webkit-overflow-scrolling: touch;
  }

  .chip {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 8px 14px;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-item,
  .filter-item .input,
  .filter-bar > .btn {
    width: 100%;
  }

  .table-scroll {
    width: 100%;
    margin: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .table-scroll > .table {
    width: max-content;
    min-width: 100%;
  }

  .table th,
  .table td {
    padding: 12px 8px;
    font-size: 14px;
  }

  .row-actions {
    gap: 6px;
  }

  .row-actions .btn-sm {
    min-height: 40px;
    padding: 7px 10px;
  }

  .settings-section {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    padding: 20px 0;
  }

  .settings-section .form-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .settings-status {
    margin-left: 0;
  }

  .info-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  .supplier-map {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
    gap: 12px;
  }

  .globe-card {
    height: min(70svh, 520px);
    min-height: 340px;
    flex: none;
  }

  .globe-tools {
    top: 10px;
    right: 10px;
    left: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .globe-hint {
    left: 10px;
    right: 10px;
    bottom: 10px;
    white-space: normal;
  }

  .region-panel {
    min-height: 260px;
    max-height: 360px;
  }

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

  .route-planner-float {
    top: 64px;
    width: calc(100% - 20px);
    max-height: calc(100% - 78px);
  }

  .modal-mask {
    align-items: flex-end;
    padding: 8px 8px 0;
  }

  .modal {
    width: calc(100vw - 16px) !important;
    max-width: none;
    max-height: calc(100svh - 16px);
    border-radius: 18px 18px 0 0;
  }

  .modal-header {
    padding: 16px 18px;
  }

  .modal-body {
    padding: 18px;
  }

  .modal-footer {
    flex-direction: column-reverse;
    padding: 12px 18px max(12px, env(safe-area-inset-bottom));
  }

  .modal-footer .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .ai-chat-host {
    right: 12px;
    bottom: calc(var(--mobile-nav-h) + 10px);
    z-index: 850;
  }

  body:has(.qe-layout) .ai-chat-host {
    bottom: calc(var(--mobile-nav-h) + 190px);
  }

  body:has(.qe-layout):has(.qe-side details[open]) .ai-chat-host {
    bottom: calc(var(--mobile-nav-h) + 250px);
  }

  .ai-chat-fab {
    min-height: 44px;
    padding: 11px 16px;
  }

  .ai-chat-win {
    top: calc(var(--topbar-h) + 8px);
    right: 8px;
    bottom: calc(var(--mobile-nav-h) + 8px);
    width: calc(100vw - 16px);
    min-width: 0;
    max-width: none;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
  }

  .ai-chat-head {
    padding: 12px 16px;
  }

  .ai-chat-body {
    padding: 16px;
  }

  .ai-msg,
  .ai-draft {
    max-width: 94%;
  }

  .ai-chat-input {
    gap: 6px;
    padding: 10px 12px 6px;
  }

  .ai-chat-input textarea {
    min-width: 0;
    font-size: 16px;
  }

}

@media (max-width: 380px) {
  :root {
    --mobile-nav-h: calc(68px + env(safe-area-inset-bottom));
  }

  .nav-item,
  .layout.collapsed .nav-item {
    min-width: 58px;
    padding-inline: 6px;
  }

  .nav-sub {
    padding-inline: 8px;
  }

  .content {
    padding-inline: 10px;
  }

  .card {
    padding-inline: 14px;
  }
}

@media (orientation: landscape) and (max-width: 720px) {
  :root {
    --mobile-nav-h: calc(60px + env(safe-area-inset-bottom));
  }

  .globe-card {
    height: min(78svh, 440px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
