/* —— 手機導覽與全域適配 —— */
@media (max-width: 720px) {
  /* 併排選項方塊高度對齊原本 .btn 列，不再拉成大方格 */
  body { --opt-tile-h: 2.15rem; }
  /* 防止表單／網格 min-width 把整頁撐出橫向捲動 */
  html, body {
    overflow-x: clip;
  }
  .wrap,
  .panel,
  .filters,
  .toolbar,
  .case-find,
  .case-find-form,
  .case-find-shell,
  .stats-filters,
  .home-toolbar,
  .lam-media-board,
  .lam-media-section,
  .lam-media-grid {
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  .filters .lam-combo,
  .vocab-row .lam-combo,
  .inline-add .lam-combo {
    min-width: 0 !important;
    max-width: 100%;
  }
  .bulk-export-cols-body {
    min-width: 0;
    width: 100%;
  }
  .consistency-banner .inline-form input {
    min-width: 0;
    flex: 1 1 100%;
  }
  .stats-field {
    min-width: 0;
    flex: 1 1 calc(50% - 0.35rem);
    max-width: 100%;
  }
  .stats-year {
    min-width: 0;
    max-width: none;
    flex: 1 1 calc(50% - 0.35rem);
  }
  .wrap {
    width: min(100%, calc(100% - 1rem));
    margin: 0.75rem auto calc(2rem + var(--safe-bottom));
  }
  h1 { font-size: 1.35rem; }
  .case-head h1 { font-size: 1.25rem; }

  .nav-toggle { display: inline-flex; }
  .top {
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.35rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  .top-brand-row {
    flex: 1;
    justify-content: space-between;
    width: 100%;
  }
  .top nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
    padding: 0.35rem 0 0.55rem;
    border-top: 1px solid var(--line);
    margin-top: 0.15rem;
  }
  .top.is-nav-open nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.3rem;
  }
  .top-nav-case-actions {
    display: contents;
  }
  .top-nav-primary {
    display: contents;
  }
  .top-nav-case-actions .btn {
    min-height: var(--opt-tile-h);
    height: auto;
    padding: 0.25rem 0.4rem;
    font-size: var(--fs-sm);
  }
  .top-nav-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.3rem;
    grid-column: 1 / -1;
    margin: 0.15rem 0 0;
    padding: 0.45rem 0 0;
    border: none;
    border-top: 1px dashed var(--line);
  }
  .top-nav-meta .who {
    grid-column: 1 / -1;
  }
  .top-nav-meta .chrome-toggles-nav {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
    width: 100%;
    margin: 0;
    padding: 0;
    min-height: 0;
  }
  .top nav > a,
  .top-nav-primary > a {
    padding: 0.25rem 0.4rem;
    min-height: var(--opt-tile-h);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    font-size: var(--fs-sm);
  }
  .top nav > a:hover {
    border-bottom-color: var(--line);
    background: var(--head);
  }
  .who {
    padding: 0.45rem 0.35rem 0.2rem;
    font-size: var(--fs-sm);
  }
  .top-nav-meta > a.btn,
  .top .inline,
  .top .inline button {
    width: 100%;
    min-height: var(--opt-tile-h);
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-sizing: border-box;
    padding: 0.25rem 0.4rem !important;
    font-size: var(--fs-sm) !important;
    font-weight: 500;
    border-color: var(--line);
    background: var(--head);
    color: var(--ink);
    border-radius: var(--radius);
  }
  .top-nav-meta > a.btn {
    background: var(--surface);
  }
  .chrome-toggles-fixed {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    top: max(0.55rem, var(--safe-top));
    right: calc(0.75rem + var(--touch-min) + 0.35rem);
  }
  .chrome-toggles-fixed .chrome-toggle-label,
  .chrome-toggles-fixed .theme-toggle-label {
    display: none;
  }
  .chrome-toggles-fixed .chrome-toggle {
    min-width: var(--touch-min);
    min-height: var(--touch-min);
  }
  .chrome-toggles-fixed .chrome-toggle > svg {
    width: 1.1rem;
    height: 1.1rem;
  }
  .chrome-toggles-nav {
    display: none !important;
  }
  body:not(:has(#lam-nav)) .theme-toggle-fixed,
  body:not(:has(#lam-nav)) .chrome-toggles-fixed {
    display: grid;
    grid-template-columns: repeat(2, minmax(4.5rem, 1fr));
    gap: 0.4rem;
    width: auto;
    height: auto;
    padding: 0;
    right: max(0.9rem, env(safe-area-inset-right, 0px));
  }
  body:not(:has(#lam-nav)) .chrome-toggles-fixed .locale-switch,
  body:not(:has(#lam-nav)) .chrome-toggles-fixed .theme-toggle,
  body:not(:has(#lam-nav)) .chrome-toggles-fixed .size-switch {
    width: 100%;
  }
  body:not(:has(#lam-nav)) .chrome-toggles-fixed .chrome-toggle {
    width: 100%;
    min-width: 0;
    min-height: 3.15rem;
    height: 100%;
    padding: 0.45rem 0.35rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.2rem;
    box-sizing: border-box;
  }
  body:not(:has(#lam-nav)) .chrome-toggles-fixed .size-switch {
    grid-column: 1 / -1;
  }
  body:not(:has(#lam-nav)) .chrome-toggles-fixed .chrome-toggle-label {
    display: block;
    text-align: center;
    line-height: 1.2;
    font-size: var(--fs-sm);
    font-weight: 500;
  }
  .chrome-toggles-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-self: stretch;
    align-items: stretch;
    width: 100%;
    height: auto;
    min-height: 0;
    justify-content: stretch;
    margin: 0;
    padding: 0;
    gap: 0.4rem;
  }
  .theme-toggle-nav {
    display: flex;
  }
  .chrome-toggles-nav .locale-switch,
  .chrome-toggles-nav .look-switch,
  .chrome-toggles-nav .size-switch,
  .chrome-toggles-nav .theme-toggle-nav {
    width: 100%;
    margin: 0;
    min-height: 3.15rem;
    align-self: stretch;
  }
  button.theme-toggle-nav,
  .locale-switch-nav > summary.chrome-toggle {
    width: 100%;
    height: 100%;
    min-height: 3.15rem;
    padding: 0.45rem 0.35rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.2rem;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-sizing: border-box;
  }
  summary.theme-toggle-nav {
    width: 100%;
    height: 100%;
    min-height: 3.15rem;
    padding: 0.45rem 0.35rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.2rem;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-sizing: border-box;
  }
  .theme-toggle-nav .theme-toggle-label,
  .chrome-toggles-nav .chrome-toggle-label,
  .chrome-toggles-nav .theme-toggle-label {
    display: block;
    text-align: center;
    line-height: 1.2;
    font-size: var(--fs-sm);
    font-weight: 500;
  }
  .chrome-toggles-nav .chrome-toggle > svg,
  .chrome-toggles-nav .theme-toggle > svg,
  body:not(:has(#lam-nav)) .chrome-toggles-fixed .chrome-toggle > svg {
    width: 1.1rem;
    height: 1.1rem;
  }
  .locale-switch-nav .locale-menu {
    right: auto;
    left: 0;
    min-width: 100%;
  }

  .toolbar {
    align-items: flex-start;
    gap: 0.65rem;
  }
  .toolbar .actions,
  .toolbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(5.2rem, 1fr));
    gap: 0.3rem;
    justify-content: stretch;
  }
  .toolbar .actions .btn,
  .toolbar-actions .btn,
  .home-toolbar-actions .btn {
    flex: unset;
    width: 100%;
    min-height: var(--opt-tile-h);
    height: var(--opt-tile-h);
    padding: 0.25rem 0.45rem;
    text-align: center;
    white-space: normal;
    line-height: 1.25;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .case-ops-primary {
    --ops-control-h: var(--opt-tile-h);
  }
  .case-ops-primary .btn {
    height: var(--ops-control-h);
    min-height: var(--ops-control-h);
  }

  .filters {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.45rem;
  }
  .filters input[type="search"],
  .filters select,
  .filters .lam-combo {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }
  .filters button,
  .filters .btn,
  .filters button[type="submit"] {
    width: auto;
    min-width: 0;
    flex: 1 1 calc(50% - 0.25rem);
    min-height: var(--filters-control-h, var(--opt-tile-h));
    height: var(--filters-control-h, var(--opt-tile-h));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }
  .filter-chips {
    gap: 0.4rem;
  }
  .filter-chip {
    min-height: var(--touch-min);
    padding: 0.35rem 0.7rem;
    font-size: var(--fs-sm);
  }

  .status-rail {
    width: 100%;
  }
  .status-rail li {
    flex: 1 1 auto;
    text-align: center;
    min-height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .grid-2 { grid-template-columns: 1fr; }
  .kv {
    grid-template-columns: 1fr;
    gap: 0.1rem 0;
  }
  .kv dt { margin-top: 0.35rem; }
  .kv dt:first-child { margin-top: 0; }

  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 8.5rem), 1fr));
  }
  .media-grid.lam-media-grid,
  .lam-media-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .narrow {
    max-width: none;
    margin: 1.25rem auto;
    padding: 1rem 0.9rem;
  }
  .brand-hero { font-size: 2rem; }
  .narrow button[type="submit"] {
    width: 100%;
    min-height: var(--touch-min);
  }

  .form-actions-bar {
    position: sticky;
    bottom: 0;
    z-index: 40;
    /* 不要用負邊距拉出表單：會比上面的欄位更寬，手機上可橫向滑出右側 */
    margin-left: 0;
    margin-right: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin-bottom: calc(-0.85rem);
    padding: 0.75rem 0 calc(0.75rem + var(--safe-bottom));
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
  .form-actions-bar .btn,
  .form-actions-bar button[type="submit"] {
    flex: 1 1 auto;
    justify-content: center;
    text-align: center;
  }
  .form-actions-bar .btn.ghost {
    flex: 0 0 auto;
  }
  /* 有底部導覽列時，置底操作列要墊高於導覽列——否則被蓋住只露 11px、按鈕按不到 */
  body.has-bottom-nav .form-actions-bar {
    bottom: calc(var(--shell-bottom-h, 3.65rem) + var(--safe-bottom));
  }

  .lam-prompt {
    margin: 0;
    margin-top: auto;
    margin-bottom: 0;
    max-width: 100%;
    width: 100%;
  }
  .lam-prompt-card {
    width: 100%;
    max-width: none;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 1rem 1rem calc(1rem + var(--safe-bottom));
    transform: translateY(8px) scale(1);
  }
  .lam-prompt[open]:not(.is-closing) .lam-prompt-card,
  .lam-prompt.is-open .lam-prompt-card {
    transform: translateY(0) scale(1);
  }
  .lam-prompt.is-closing .lam-prompt-card {
    transform: translateY(12px) scale(1);
  }

  .lam-picker .lam-combo-list {
    max-height: min(16rem, 55vh);
  }
  button.lam-combo-option,
  button.lam-combo-trigger {
    min-height: var(--touch-min);
  }
  button.lam-combo-trigger {
    padding-top: 0;
    padding-bottom: 0;
    line-height: calc(var(--touch-min) - 2px);
  }
  select {
    min-height: var(--touch-min);
  }

  .panel, .filters {
    padding-left: 0.8rem;
    padding-right: 0.8rem;
  }

  .foot {
    padding-bottom: calc(1rem + var(--safe-bottom));
  }
}

@media (max-width: 420px) {
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .media-grid.lam-media-grid,
  .lam-media-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (hover: hover) and (pointer: fine) {
  .filter-chip:hover { background: transparent; color: var(--accent-hover); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  button:active,
  .btn:active,
  .is-pressed,
  .wl-chip:active,
  .assay-stage-row-main:active,
  .bottom-nav a:active,
  .bottom-nav button:active,
  a.pill:active,
  .status-mark:active,
  .case-tabs a:active {
    transform: none !important;
  }
  .lam-prompt-card,
  .lam-quick-modal-card,
  .lam-picker-card,
  .lam-lightbox,
  .locale-menu,
  .look-menu,
  .size-menu {
    transform: none !important;
  }
}

.media-section {
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
  margin-top: 0.35rem;
}
.media-section > summary,
.form-fold > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0.45rem;
}
.media-section > summary::-webkit-details-marker,
.form-fold > summary::-webkit-details-marker { display: none; }
.media-section > summary h2,
.form-fold > summary h2 {
  display: inline;
  margin: 0;
  font-size: var(--fs-sm);
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}
.media-section > summary::before,
.form-fold > summary::before {
  content: "▸ ";
  font-family: var(--font-mono);
  color: var(--muted);
}
.media-section[open] > summary::before,
.form-fold[open] > summary::before { content: "▾ "; }
.media-section > summary:hover h2,
.form-fold > summary:hover h2 { color: var(--ink); }
/* 摺疊展開：與搜尋進階面板同一進場 */
.media-section[open] > :not(summary),
.form-fold[open] > :not(summary) {
  animation: lam-panel-in var(--motion-in) var(--ease-out);
}

/* 收摺疊的次要欄位群；summary 標示已填筆數，避免收起後看不見既有資料 */
.form-fold {
  display: grid;
  gap: 0.65rem;
}
/* details 會被 .form-section:first-of-type 誤判為區段開頭，這裡把分隔線補回 */
.form-fold.form-section {
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
  margin-top: 0.35rem;
}
.form-fold.nested-fold {
  border-top: 1px dashed var(--line);
  padding-top: 0.6rem;
  margin-top: 0.15rem;
}
.fold-count {
  margin-left: 0.4rem;
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  color: var(--accent);
}
.fold-count.muted { color: var(--muted); }

.danger-zone {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
}
.danger-zone > h2 { color: var(--danger); }
.delete-batch-form {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--line);
}

@media (max-width: 720px) {
  .case-ops-primary .btn,
  .case-ops-primary button,
  .ops-more-body .btn,
  .ops-more-body button,
  .case-ops-actions .btn,
  .case-ops-actions button {
    width: 100%;
    min-height: var(--opt-tile-h);
    padding: 0.25rem 0.45rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    white-space: normal;
    line-height: 1.25;
  }
}

