/*
 * 条件案内チャットの見た目。
 * サイトは自分のトークンを --sc-* に割り当てる。下の値は既定値（コントラストは docs/impl-notes-widget.md）。
 * 角は 0、影なし、動きなし。インラインの style 属性は使わない前提のクラス設計。
 * 1100px の境目は widget.js の WIDE_QUERY と同じ値。パネルの方式（側面／全面）は JS がクラスで切り替える。
 */

.sc-open,
.sc-floating,
.sc-panel {
  --sc-paper: #ffffff;
  --sc-ink: #1f2328;
  --sc-accent: #0a4d9c;
  --sc-plane: #f1f4f7;
  --sc-alert: #a61b1b;
  --sc-rule: #6b7280;
  --sc-gap: 16px;
}

html.sc-has-widget {
  /* 下端の札にフォーカス中の要素が隠れないようにする */
  scroll-padding-block-end: 80px;
}

html.sc-side-open {
  /* 側面のパネルが記事を覆わないよう、記事の側に同じ幅の余白を空ける。フォーカス中の要素も隠れない */
  scroll-padding-inline-end: var(--sc-panel-w, 440px);
}

html.sc-side-open body {
  padding-inline-end: var(--sc-panel-w, 440px);
}

.sc-open[hidden],
.sc-floating[hidden],
.sc-panel [hidden] {
  display: none;
}

/* ---- 入口のボタンと右下の札 ---- */

.sc-open,
.sc-floating,
.sc-btn,
.sc-choice {
  box-sizing: border-box;
  font: inherit;
  font-size: max(1rem, 16px);
  line-height: 1.5;
  border-radius: 0;
  box-shadow: none;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

.sc-open,
.sc-floating {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: 2px solid var(--sc-accent);
  background: var(--sc-accent);
  color: var(--sc-paper);
  max-width: 100%;
  text-align: center;
}

.sc-floating {
  position: fixed;
  z-index: 900;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

/* ---- パネル ---- */

.sc-panel {
  box-sizing: border-box;
  padding: 0;
  border: 2px solid var(--sc-rule);
  border-radius: 0;
  box-shadow: none;
  background: var(--sc-paper);
  color: var(--sc-ink);
  font-size: max(1rem, 16px);
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.sc-panel *,
.sc-panel *::before,
.sc-panel *::after {
  box-sizing: border-box;
}

.sc-panel[open] {
  display: flex;
  flex-direction: column;
}

/* パネル全体はスクロールさせない（本文と選択肢の領域だけがスクロールする）。
   読み上げ用の .sc-sr（position: absolute）が dialog を包含ブロックにして、dialog の高さを伸ばさないようにする。 */
.sc-panel--side,
.sc-panel--modal {
  overflow: hidden;
}

.sc-body,
.sc-choices {
  position: relative;
}

/* 1100px 以上: 記事の表を見ながら使える右側の固定パネル（非モーダル） */
.sc-panel--side {
  position: fixed;
  z-index: 1000;
  inset: 0 0 0 auto;
  width: min(420px, 100vw);
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
}

/* 1100px 未満: 全面のモーダル。高さは dvh、ノッチ・ホームバーを避ける */
.sc-panel--modal {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  border: 0;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

.sc-panel::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

/* ---- ヘッダー（常に見える。広告表示を含む） ---- */

.sc-header {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  padding: 8px var(--sc-gap);
  background: var(--sc-plane);
  border-bottom: 2px solid var(--sc-rule);
}

/* 見出しと2つのボタンを1行に収める（320px でも）。広告表示は次の行 */
.sc-title {
  flex: 1 1 0;
  min-width: 5em;
  margin: 0;
  font-size: max(1.125rem, 18px);
  line-height: 1.5;
  font-weight: 700;
}

/* 広告表示: 本文と同じ 16px 以上・同じ濃さ・同じ太さ */
.sc-ad {
  flex: 1 1 100%;
  order: 3;
  margin: 0;
  font-size: max(1rem, 16px);
  line-height: 1.5;
  color: var(--sc-ink);
  font-weight: 400;
}

.sc-ad .sc-anchor {
  /* 文中のリンク。行の高さを押し広げない */
  display: inline;
  min-height: 0;
  padding-block: 0;
}

.sc-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 8px;
}

.sc-btn {
  padding: 8px 10px;
  border: 2px solid var(--sc-accent);
  background: var(--sc-paper);
  color: var(--sc-accent);
}

/* ---- 本文（スクロールする領域） ---- */

.sc-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding: 8px;
  padding: var(--sc-gap);
  padding-bottom: 24px;
}

.sc-screen + .sc-screen,
.sc-screen + .sc-selected,
.sc-selected + .sc-screen {
  margin-top: 24px;
}

.sc-screen + .sc-screen {
  padding-top: 24px;
  border-top: 1px solid var(--sc-rule);
}

.sc-heading {
  margin: 0 0 12px;
  font-size: max(1.125rem, 18px);
  line-height: 1.5;
  font-weight: 700;
}

.sc-body:focus-visible,
.sc-choices:focus-visible {
  outline: 3px solid var(--sc-accent);
  outline-offset: -3px;
}

.sc-heading:focus,
.sc-open:focus-visible,
.sc-floating:focus-visible,
.sc-btn:focus-visible,
.sc-choice:focus-visible,
.sc-skip:focus-visible,
.sc-anchor:focus-visible,
.sc-table-wrap:focus-visible {
  outline: 3px solid var(--sc-accent);
  outline-offset: 2px;
}

.sc-text {
  margin: 0 0 12px;
}

.sc-selected {
  margin: 16px 0 0;
  padding: 8px 12px;
  background: var(--sc-plane);
  border-left: 4px solid var(--sc-rule);
}

.sc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.sc-chip {
  padding: 4px 10px;
  border: 1px solid var(--sc-rule);
  background: var(--sc-plane);
}

.sc-chip-label {
  font-weight: 700;
}

/* ---- 結果のカード ---- */

.sc-cards {
  margin: 0 0 16px;
}

.sc-cards-heading {
  margin: 0 0 8px;
  font-size: max(1rem, 16px);
  font-weight: 700;
}

.sc-card-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* カードは軽く（v3）: 余白と行間を詰める。値ごとの出典・取得日・確認期限は出さない */
.sc-card {
  padding: 8px 12px;
  border: 1px solid var(--sc-rule);
  background: var(--sc-paper);
  line-height: 1.5;
}

.sc-cards--partial .sc-card {
  border-style: dashed;
  border-width: 2px;
}

.sc-card-name {
  margin: 0 0 4px;
  font-size: max(1rem, 16px);
  font-weight: 700;
}

.sc-values {
  margin: 0 0 4px;
}

.sc-value {
  display: grid;
  grid-template-columns: minmax(6em, 9em) 1fr;
  gap: 0 12px;
  padding: 2px 0;
  border-top: 1px solid var(--sc-plane);
}

.sc-value-label,
.sc-value-text {
  margin: 0;
}

.sc-value-label {
  font-weight: 700;
}

.sc-value--hidden {
  color: var(--sc-alert);
}

.sc-notes,
.sc-judgments {
  margin: 0 0 4px;
  padding-left: 1.25em;
}

.sc-notes {
  font-size: max(0.9375rem, 15px);
}

.sc-judgment--unknown {
  color: var(--sc-alert);
}

.sc-excluded {
  margin: 0 0 12px;
  padding: 8px 12px;
  background: var(--sc-plane);
}

/* ---- 「こんな人ならこっち」（記事の原文を出す） ---- */

.sc-recommend {
  margin: 0 0 12px;
}

.sc-recommend-line {
  margin: 0 0 8px;
  font-weight: 700;
}

.sc-recommend-why,
.sc-recommend-plans {
  margin: 0 0 8px;
}

.sc-recommend-link {
  margin: 0;
}

/* ---- 比較の表 ---- */

.sc-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 0 0 12px;
}

.sc-compare {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
}

.sc-compare th,
.sc-compare td {
  padding: 8px 10px;
  border: 1px solid var(--sc-rule);
  text-align: left;
  vertical-align: top;
}

.sc-compare-corner {
  padding: 0;
}

.sc-compare thead th,
.sc-compare tbody th {
  background: var(--sc-plane);
  font-weight: 700;
}

/* ---- リンク（ボタン風にしない。カードの中・上側に置く） ---- */

.sc-card-links,
.sc-links {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.sc-card-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
}

.sc-link {
  display: inline-block;
}

.sc-anchor {
  display: inline-block;
  min-height: 24px;
  padding-block: 4px;
  color: var(--sc-accent);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  background: none;
  border: 0;
}

.pr {
  display: inline-block;
  margin-right: 4px;
  padding: 0 6px;
  border: 1px solid var(--sc-rule);
  background: var(--sc-plane);
  color: var(--sc-ink);
  font-size: max(0.875rem, 14px);
  line-height: 1.5;
}

/* ---- 選択肢（領域の下端に固定。リンクとは線と余白で分ける） ----
   本文と一緒に縮まない（flex: 0 0 auto）。リンクとの間の 24px は、スクロールで消える内側の padding でなく、
   外側の margin-top と上線で確保する。選択肢が多い画面（6個）は、領域の半分まで広がり、それを超えたらこの領域の中でスクロールする。 */

.sc-choices {
  flex: 0 0 auto;
  max-height: 50%;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding: 8px;
  margin-top: 24px;
  padding: 8px var(--sc-gap);
  border-top: 2px solid var(--sc-rule);
  background: var(--sc-plane);
}

.sc-choices:empty {
  display: none;
}

.sc-choice-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* 選択肢が4つ以上の画面（結果・比較の行の選択）は、幅が足りれば2列にして、結果のカードに高さを残す。
   :has() に対応しないブラウザでは、1列のまま（機能は変わらない） */
.sc-choice-list:has(> .sc-choice-item:nth-child(4)):not(.sc-choice-list--long) {
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
}

/* ラベルが長い選択肢（全角で20字を超えるもの。「こんな人」の選択など）が1つでもあれば、1列にして折り返す。
   JS が .sc-choice-list--long を付ける */
.sc-choice-list--long {
  grid-template-columns: 1fr;
}

.sc-choice-item {
  margin: 0;
}

.sc-choice {
  display: block;
  width: 100%;
  padding: 8px 16px;
  border: 2px solid var(--sc-accent);
  background: var(--sc-paper);
  color: var(--sc-ink);
  text-align: left;
}

.sc-choice--selected {
  border-width: 4px;
}

.sc-current {
  margin-left: 0.5em;
  color: var(--sc-accent);
  font-weight: 700;
}

/* 結果の先頭から選択肢の領域へ移るボタン（フォーカスされたときだけ見える） */
.sc-skip:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.sc-skip {
  margin: 0 0 12px;
  padding: 8px 14px;
  border: 2px solid var(--sc-accent);
  background: var(--sc-paper);
  color: var(--sc-accent);
}

/* ---- 読み上げ専用（画面には出さない） ---- */

.sc-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 1100px) {
  .sc-header,
  .sc-body {
    padding-inline: 20px;
  }
}

/* ---- 高さが足りないとき（400% 拡大＝320×200 相当、横向きの小さな画面） ----
   本文と選択肢を別々にスクロールさせると、どちらも数十 px しか残らない。dialog 全体を1つのスクロール領域にし、
   広告表示だけを上端に貼り付ける（ヘッダーの子要素を dialog の直下に並べ直して、sticky の基準を dialog にする）。 */
@media (max-height: 520px) {
  .sc-panel.sc-panel[open] {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-content: flex-start;
    overflow: auto;
    overscroll-behavior: contain;
    scroll-padding: 40px 8px 8px;
  }

  .sc-header {
    display: contents;
  }

  .sc-title {
    padding: 8px 0 0 var(--sc-gap);
  }

  .sc-actions {
    padding: 8px var(--sc-gap) 0 0;
    margin-left: auto;
  }

  .sc-ad {
    position: sticky;
    top: 0;
    z-index: 2;
    order: 3;
    flex: 1 0 100%;
    padding: 4px var(--sc-gap);
    background: var(--sc-plane);
    border-bottom: 2px solid var(--sc-rule);
  }

  .sc-body {
    order: 4;
    flex: 1 0 100%;
    overflow: visible;
    min-height: auto;
  }

  .sc-choices {
    order: 5;
    flex: 1 0 100%;
    max-height: none;
    overflow: visible;
  }
}
