/* 自動補樣式：js/screens/report.js（_build/style.py） */
/* ==========================================================================
   回診報告：預覽、調整內容、放大檢視、快速新增問題、文字按鈕
   只補上列 class；顏色、圓角、陰影、間距一律使用 token，主題由變數自動切換
   ========================================================================== */

/* ---------- 第三層文字按鈕 c-btn--text ---------- */
.c-btn--text {
  --btn-bg: transparent;
  --btn-fg: var(--primary);
  border-color: transparent;
  background: transparent;
  color: var(--primary);
  padding: 0 var(--sp-3);
  font-size: var(--fs-callout);
  font-weight: 600;
  box-shadow: none;
}

.c-btn--text:active {
  opacity: .7;
  transform: none;
}

.c-btn--text:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

@media (pointer: coarse) {
  .c-btn--text {
    min-height: var(--tap);
  }
}

/* 以較高的特異性蓋過 .c-btn 通用 hover 的灰底 */
@media (hover: hover) and (pointer: fine) {
  .c-btn.c-btn--text:not(.u-x1):not(.u-x2):not(.u-x3):not(.u-x4):hover {
    background: var(--primary-tint);
    color: var(--primary-strong);
  }
}

/* ---------- 預覽標題列 ---------- */
.s-report-preview__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-3);
}

.s-report-preview__bar > div {
  flex: 1 1 200px;
  min-width: 0;
}

.s-report-preview__title {
  margin: 0;
  font-size: var(--fs-title3);
  line-height: var(--lh-title3);
  font-weight: var(--fw-title3);
  letter-spacing: var(--ls-title);
  color: var(--text);
}

.s-report-preview__sub {
  margin: 2px 0 0;
  font-size: var(--fs-footnote);
  line-height: var(--lh-footnote);
  color: var(--text-3);
}

.c-btn.s-report-preview__zoom {
  flex: none;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  white-space: nowrap;
}

.c-btn.s-report-preview__zoom svg {
  flex: none;
}

/* ---------- A4 縮放外框與內層 ----------
   外框不加 padding、不加 border：JS 以 clientWidth 計算縮放比例，
   邊線改用 box-shadow 呈現，避免高度被邊框吃掉 */
.s-report-preview__frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--border), var(--shadow-1);
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow var(--dur-2) var(--ease);
}

.s-report-preview__stage {
  display: block;
  margin-inline: auto;
  transform-origin: 0 0;
  background: var(--paper-bg);
  color: var(--paper-text);
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  will-change: transform;
}

/* 超過預覽高度：底部漸隱，提示還有內容 */
.s-report-preview__frame.is-clipped::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 72px;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--surface-2) 0%, transparent),
    var(--surface-2)
  );
}

@media (hover: hover) and (pointer: fine) {
  .s-report-preview__frame:hover {
    box-shadow: 0 0 0 1px var(--text-3), var(--shadow-2);
  }
}

/* ---------- 放大檢視 sheet 內容 ----------
   紙張維持 A4 實際寬度；較窄的視窗可左右捲動、雙指縮放 */
.s-report-zoom {
  max-width: 100%;
  padding: var(--sp-2);
  overflow-x: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--border) inset;
}

.s-report-zoom > * {
  width: 794px;
  max-width: none;
  margin-inline: auto;
  box-shadow: var(--shadow-1);
}

/* ---------- 調整內容（details） ---------- */
.s-report-adjust {
  container-type: inline-size;
  container-name: adjust;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

.s-report-adjust__summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: var(--sp-3);
  align-items: center;
  min-height: 56px;
  padding: var(--sp-3) var(--sp-4);
  list-style: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: background var(--dur-1) var(--ease);
}

.s-report-adjust__summary::-webkit-details-marker {
  display: none;
}

.s-report-adjust__summary::marker {
  content: '';
}

.s-report-adjust__summary > span:first-child {
  grid-column: 1;
  font-size: var(--fs-title3);
  line-height: var(--lh-title3);
  font-weight: var(--fw-title3);
  letter-spacing: var(--ls-title);
}

.s-report-adjust__sub {
  grid-column: 1;
  min-width: 0;
  margin-top: 2px;
  font-size: var(--fs-footnote);
  line-height: var(--lh-footnote);
  font-weight: 400;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* 展開指示：純 CSS 箭頭 */
.s-report-adjust__summary::after {
  content: '';
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  width: 10px;
  height: 10px;
  margin: 0 var(--sp-2) 4px;
  border-right: 2px solid var(--text-3);
  border-bottom: 2px solid var(--text-3);
  transform: rotate(45deg);
  transition: transform var(--dur-2) var(--ease);
}

.s-report-adjust[open] > .s-report-adjust__summary::after {
  margin-bottom: -4px;
  transform: rotate(-135deg);
}

.s-report-adjust[open] > .s-report-adjust__summary {
  border-bottom: 1px solid var(--divider);
}

.s-report-adjust__summary:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
  border-radius: var(--r-card);
}

@media (hover: hover) and (pointer: fine) {
  .s-report-adjust__summary:hover {
    background: var(--surface-2);
  }
}

.s-report-adjust__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
  padding: var(--sp-4);
}

.s-report-adjust__body > * {
  min-width: 0;
}

/* 內嵌的設定卡不再各自浮起，避免卡中卡 */
.s-report-adjust__body > .c-card {
  box-shadow: none;
}

/* 較寬的容器（平板、桌面）：設定卡兩欄排列 */
@container adjust (min-width: 600px) {
  .s-report-adjust__body {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: var(--sp-4);
    padding: var(--sp-5);
  }
}

/* ---------- 新增看診問題輸入列 ---------- */
.s-report-quick {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-2);
  margin: var(--sp-3) 0;
}

.s-report-quick .s-report-quick__input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 0 var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--r-input);
  background: var(--surface-2);
  color: var(--text);
  font-size: max(16px, 1rem);
  line-height: 1.4;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}

.s-report-quick .s-report-quick__input::placeholder {
  color: var(--text-3);
}

.s-report-quick .s-report-quick__input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.s-report-quick .s-report-quick__input:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.s-report-quick > .c-btn {
  flex: none;
  min-height: 48px;
  padding: 0 var(--sp-4);
  white-space: nowrap;
}

@media (pointer: fine) {
  .s-report-quick .s-report-quick__input,
  .s-report-quick > .c-btn {
    min-height: 44px;
  }
}

@media (hover: hover) and (pointer: fine) {
  .s-report-quick .s-report-quick__input:not(:focus):hover {
    border-color: var(--text-3);
  }
}

/* ---------- 手機橫式矮螢幕 ---------- */
@media (orientation: landscape) and (max-height: 500px) {
  .s-report-preview__bar {
    margin-bottom: var(--sp-2);
  }

  .s-report-adjust__summary {
    min-height: 48px;
    padding-block: var(--sp-2);
  }

  .s-report-adjust__body {
    padding: var(--sp-3);
  }
}

/* ---------- 減少動態 ---------- */
@media (prefers-reduced-motion: reduce) {
  .s-report-preview__frame,
  .s-report-adjust__summary,
  .s-report-adjust__summary::after,
  .s-report-quick .s-report-quick__input {
    transition-duration: 0.01ms !important;
  }
}
