/* Mobile-first touch and spacing refinements for the internal workbench. */
@media (max-width: 760px) {
  html { -webkit-text-size-adjust: 100%; }

  body {
    min-width: 320px;
    overflow-x: hidden;
  }

  .app {
    display: block;
    min-height: 100svh;
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .sidebar { display: none; }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 12;
    height: auto;
    min-height: 70px;
    padding: 13px 16px;
    gap: 10px;
  }

  .topbar h2 { font-size: 19px; line-height: 1.25; }
  .top-actions { gap: 6px; }
  .top-actions .user-chip { display: none; }
  .top-actions .outline {
    min-height: 40px;
    padding: 8px 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .page { padding: 16px 14px 18px; }
  .workspace-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .context-card { grid-column: auto; }
  .card { padding: 16px; border-radius: 14px; box-shadow: 0 8px 24px rgba(18,48,74,.06); }
  .card-title h3 { font-size: 15px; line-height: 1.4; }

  .customer-select-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin: 16px 0 10px;
  }

  .customer-select-row select,
  .customer-select-row .small { min-height: 44px; }
  .customer-select-row select { min-width: 0; }
  .customer-select-row .small { white-space: nowrap; }

  textarea {
    min-height: 210px;
    padding: 13px;
    font-size: 15px;
    line-height: 1.65;
  }

  .upload-row {
    display: grid;
    gap: 8px;
    margin: 10px 0 15px;
  }

  .file-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 1px dashed #9fc5c2;
    border-radius: 9px;
    background: #f4fbfa;
    font-size: 13px;
  }

  .upload-row .muted { padding-left: 2px; line-height: 1.5; }
  .primary, .outline, .small { min-height: 44px; }
  .tip { font-size: 12px; line-height: 1.6; }

  .reply-card.empty-state { min-height: 260px; }
  .reply-card:not(.empty-state) { min-height: 0; }
  .reply-head { align-items: flex-start; gap: 8px; }
  .reply-head h3 { font-size: 15px; line-height: 1.45; }
  .reply-head .risk { flex: 0 0 auto; }
  .reply-section { margin-top: 15px; }
  .reply-editor { min-height: 170px; font-size: 15px; }
  .chinese-copy { font-size: 14px; line-height: 1.7; }
  .reply-meta { grid-template-columns: 1fr; gap: 8px; }
  .reply-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .reply-actions .action { min-height: 42px; }
  .reply-actions .send { grid-column: 1 / -1; margin-left: 0; }

  .context-summary { grid-template-columns: 1fr 1fr; gap: 8px; }
  .context-summary div { min-height: 56px; }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
  }

  .section-heading h3 { font-size: 18px; }
  .section-heading .primary, .section-heading .outline { width: 100%; }
  .customer-row, .knowledge-row { grid-template-columns: 1fr; gap: 10px; padding: 14px; }
  .customer-row > *:last-child { justify-self: stretch; }
  .customer-row .outline, .knowledge-row .outline { width: 100%; }
  .knowledge-row > .status { justify-self: start; }
  .knowledge-filters { overflow-x: auto; padding-bottom: 2px; }
  .chip { min-height: 40px; white-space: nowrap; }

  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { min-height: 88px; padding: 14px; }
  .metric strong { font-size: 24px; }
  .analytics-grid { grid-template-columns: 1fr; gap: 12px; margin-top: 12px; }
  .analytics-grid .card { padding: 14px; }
  .bar-row { grid-template-columns: 88px minmax(0, 1fr) 25px; gap: 7px; }

  .modal { align-items: end; padding: 0; }
  .modal-box {
    width: 100%;
    max-height: 92svh;
    padding: 24px 16px calc(20px + env(safe-area-inset-bottom));
    border-radius: 20px 20px 0 0;
  }

  .form-grid { grid-template-columns: 1fr; gap: 10px; }
  .modal-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .modal-actions .primary, .modal-actions .outline { width: 100%; }

  .toast {
    left: 14px;
    right: 14px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    text-align: center;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 18;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: calc(66px + env(safe-area-inset-bottom));
    padding: 5px 8px env(safe-area-inset-bottom);
    background: rgba(255,255,255,.96);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(18,48,74,.08);
    backdrop-filter: blur(12px);
  }

  .mobile-nav .nav {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 3px;
    min-height: 52px;
    padding: 5px 3px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #78909c;
    font-size: 10px;
    line-height: 1;
  }

  .mobile-nav .nav span {
    display: block;
    width: auto;
    font-size: 18px;
    line-height: 1;
  }

  .mobile-nav .nav small { font-size: 10px; font-weight: 700; }
  .mobile-nav .nav.active, .mobile-nav .nav:hover { background: #e7f4f7; color: var(--teal); }
}

@media (max-width: 390px) {
  .page { padding-left: 12px; padding-right: 12px; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .topbar h2 { font-size: 17px; }
  .top-actions .outline { padding: 8px; font-size: 11px; }
  .customer-select-row { grid-template-columns: 1fr; }
  .customer-select-row .small { width: 100%; }
  .context-summary, .metric-grid, .reply-actions { grid-template-columns: 1fr; }
  .reply-actions .send { grid-column: auto; }
}

@media (min-width: 761px) {
  .mobile-nav { display: none; }
}
