/* Phone-only refinements: desktop remains unchanged. */
@media (max-width: 640px) {
html { -webkit-text-size-adjust: 100%; } body { overflow-x: hidden; }
.topbar { min-height: 64px; height: 64px; padding: 7px 10px; gap: 8px; flex-wrap: nowrap; }
.brand-lockup { flex: 1 1 auto; min-width: 0; gap: 8px; } .brand-mark { width: 36px; height: 36px; border-radius: 11px; flex: 0 0 36px; }
.brand-lockup > div:last-child { min-width: 0; } .brand-lockup strong { overflow: hidden; display: block; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.brand-lockup span { overflow: hidden; max-width: 140px; margin-top: 2px; font-size: 7px; text-overflow: ellipsis; white-space: nowrap; }
.topbar-center, .topbar-actions .connection { display: none; } .topbar-actions { display: flex; flex: 0 0 auto; gap: 4px; align-items: center; }
.topbar-actions .button, .language-toggle { min-height: 36px; padding: 7px 8px; border-radius: 9px; font-size: 9px; white-space: nowrap; }
.language-toggle { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 700; }
.header-nav { top: 64px; } .header-nav-inner { min-height: 46px; padding: 5px 10px; gap: 4px; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scrollbar-width: none; }
.header-nav-inner::-webkit-scrollbar { display: none; } .header-nav-label, .header-project-chip { display: none; }
.header-nav-item { padding: 7px 9px; font-size: 10px; scroll-snap-align: start; } .header-nav-item > span { font-size: 12px; }
.main-content { padding: 18px 10px 34px; } .page-stack { width: 100%; } .page-intro, .page-header { gap: 12px; margin-bottom: 16px; }
.page-intro h1, .page-header h1 { font-size: 25px; line-height: 1.35; letter-spacing: -.45px; } .page-intro p, .page-header p { font-size: 12px; line-height: 1.75; } .intro-meta { padding: 6px 9px; font-size: 9px; }
.dashboard-overview { margin: 0 0 16px; padding: 11px; border-radius: 14px; } .overview-heading { margin-bottom: 10px; } .overview-heading h2 { font-size: 15px; } .overview-status { padding: 5px 7px; font-size: 8px; }
.overview-cards { gap: 6px; } .overview-card { min-height: 84px; padding: 9px; } .overview-card > span, .overview-card small { font-size: 9px; } .overview-card strong { font-size: 14px; }
.card-surface, .metric, .project-row, .database-card { border-radius: 13px; } .card-title-row, .visual-heading { gap: 9px; } .detail-card, .string-diagram, .options-card, .form-card, .table-card, .timeline-card, .database-card { padding: 13px; }
.accordion-head { min-height: 50px; padding: 13px 14px; font-size: 13px; } .accordion-body { padding: 13px; } .button { min-height: 42px; }
.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; } .action-row .button:first-child { grid-column: 1 / -1; } .toast { bottom: 14px; width: calc(100% - 24px); justify-content: center; }
.design-page .inputs-panel { border-radius: 13px; padding: 10px; } .side-panel-header { padding: 8px; } .inputs-panel .input-sidebar { gap: 5px; } .inputs-panel .input-list-item { min-height: 46px; padding: 7px; } .inputs-panel .input-list-item strong { font-size: 9px; }
.engineering-elevation { height: 210px; } .elevation-svg-label { font-size: 8px; } .options-card .table-wrap { margin-inline: -13px; padding-inline: 13px; }
}
@media (max-width: 380px) {
.topbar { padding-inline: 8px; } .brand-lockup span { display: none; } .topbar-actions .button, .language-toggle { padding-inline: 6px; font-size: 8px; } .header-nav-item { padding-inline: 8px; } .main-content { padding-inline: 8px; } .overview-card { padding: 8px; }
}
/* Internal pages and touch-first controls. */
@media (max-width: 640px) {
  button, input, select, textarea, .search-input { min-height: 44px; }
  input, select, textarea, .search-input { padding: 10px 11px; font-size: 16px; }
  textarea { min-height: 112px; }
  .form-grid.two, .form-grid.three, .cost-controls, .database-filters { grid-template-columns: 1fr; gap: 9px; }
  .field { margin-bottom: 10px; }
  .field > span, .field-hint { font-size: 11px; line-height: 1.55; }
  .page-header > .button, .page-header .action-row, .page-header .action-row .button { width: 100%; }
  .page-header .action-row { margin-top: 2px; }
  .project-row { min-height: 68px; padding: 12px; gap: 10px; }
  .project-avatar { width: 40px; height: 40px; flex: 0 0 40px; }
  .project-info strong { font-size: 13px; }
  .project-info small { font-size: 10px; line-height: 1.6; }
  .database-toolbar { gap: 10px; margin-bottom: 12px; }
  .tabs, .tool-tabs { width: 100%; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
  .tabs::-webkit-scrollbar, .tool-tabs::-webkit-scrollbar { display: none; }
  .tabs button, .tool-tabs button { min-height: 42px; padding-inline: 12px; white-space: nowrap; flex: 0 0 auto; }
  .database-filters { padding: 12px; }
  .database-grid { gap: 9px; }
  .database-card { padding: 13px; }
  .db-card-top { align-items: flex-start; margin-bottom: 12px; }
  .db-card-top strong { font-size: 13px; overflow-wrap: anywhere; }
  .db-card-top span { font-size: 10px; line-height: 1.6; }
  .db-specs, .detail-grid, .cost-totals, .compat-detail { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .spec { min-width: 0; }
  .spec strong { font-size: 11px; }
  .cost-summary { align-items: flex-start; gap: 10px; padding: 14px; }
  .cost-summary h2 { font-size: 16px; }
  .cost-badge { padding: 8px; font-size: 10px; }
  .table-card { padding: 12px; }
  .table-wrap { margin-inline: -12px; padding-inline: 12px; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 620px; }
  .table-input { min-width: 92px; min-height: 40px; }
  th, td { padding: 10px 8px; }
  .section-manager { padding: 10px; }
  .section-manager-row { min-height: 36px; }
  .custom-size-row { align-items: stretch; flex-wrap: wrap; }
  .custom-size-row input { min-width: 0; }
  .custom-size-row .button { min-height: 42px; }
  .admin-table { padding: 10px; }
  .choice-list, .array-plan-rows { -webkit-overflow-scrolling: touch; }
  .chassis-kpis, .indicator-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chassis-controls, .chassis-output, .bom-card, .chassis-diagram { min-width: 0; }
  .array-diagram, .array-plan-rows { overflow-x: auto; }
  .tool-card, .legacy-tools-block { padding: 13px; }
  .tool-card-head { align-items: flex-start; gap: 8px; }
  .tool-card-head h2 { font-size: 16px; line-height: 1.45; }
  .tool-card-head p { font-size: 11px; line-height: 1.7; }
  .toggle-row { align-items: flex-start; padding-block: 9px; }
  .toggle-row input { width: 44px; height: 26px; min-height: 26px; flex: 0 0 auto; }
}
@media (max-width: 380px) {
  .db-specs, .detail-grid, .cost-totals, .compat-detail, .chassis-kpis, .indicator-grid { grid-template-columns: 1fr; }
  .action-row { grid-template-columns: 1fr; }
  .action-row .button:first-child { grid-column: auto; }
}
@media (hover: none) and (pointer: coarse) {
  button, .nav-item, .header-nav-item, .tabs button, .tool-tabs button, .chip { touch-action: manipulation; }
  input, select, textarea { touch-action: manipulation; }
}

/* Optional live phone preview, available on larger screens only. */
.phone-preview-launch {
  position: fixed; right: 18px; bottom: 18px; z-index: 60; min-height: 44px;
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid #111;
  border-radius: 999px; padding: 10px 14px; background: #111; color: #fff;
  box-shadow: 0 10px 24px rgba(0,0,0,.18); font: 700 12px 'Cairo', sans-serif;
}
.phone-preview-launch:hover { background: #333; transform: translateY(-1px); }
.phone-preview-launch span { font-size: 16px; line-height: 1; }
.phone-preview-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  padding: 18px; background: rgba(17,17,17,.58); backdrop-filter: blur(3px);
}
.phone-preview-dialog {
  width: min(100%, 430px); overflow: hidden; border: 1px solid #555;
  border-radius: 24px; background: #111; box-shadow: 0 24px 60px rgba(0,0,0,.4);
}
.phone-preview-bar {
  min-height: 48px; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px 8px 14px; color: #fff; font: 700 12px 'Cairo', sans-serif;
}
.phone-preview-close {
  width: 34px; height: 34px; min-height: 34px; border: 1px solid #777;
  border-radius: 50%; background: transparent; color: #fff; font-size: 22px; line-height: 1;
}
.phone-preview-frame {
  display: block; width: 100%; height: min(78vh, 820px); border: 0; background: #f7f7f7;
}
@media (max-width: 640px) {
  .phone-preview-launch { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .phone-preview-launch { transition: none; }
}
