/* =========================================================
   品目詳細（drug.html）専用のスタイル

   このページだけ、スクロールなしで全体像が入るタイルの置き方をする。
   共通の style.css には入れない。.log .tile .rows .chart のような
   ありふれた名前を全ページに配ると、他のページの部品と当たるため
   ========================================================= */
/* サイトのヘッダーの下をタイルで埋める。ページ自体はスクロールしない */
html.dt-page, html.dt-page body { height: 100%; }
html.dt-page body { margin: 0; display: flex; flex-direction: column; overflow: hidden; }
html.dt-page .site-header { flex: 0 0 auto; }
html.dt-page .site-footer { flex: 0 0 auto; padding: 6px 0; }
html.dt-page .site-footer .f-note, html.dt-page .site-footer .f-back { display: none; }
html.dt-page .site-footer .f-brand { margin: 0; font-size: 11px; }

/* =========================================================
   品目詳細をタイルで1画面に収める案（案3のブラッシュアップ）

   ねらい
     ・スクロールなしで、品目の全体像が一目で入る
     ・要点だけをタイルに置き、細かいところはタイルを押して別枠で見る
     ・情報は削らない。置き場所を変えるだけ
   ========================================================= */


.dt-main { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px 20px 14px; }

/* ---- 品目の帯 ---- */
.dt-head { flex: 0 0 auto; display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap;
  padding-bottom: 10px; border-bottom: 2px solid var(--line); }
.dt-name { font-size: 21px; font-weight: 800; line-height: 1.25; }
.dt-sub { font-size: 12.5px; color: var(--ink-soft); line-height: 1.7; }
.dt-tags { display: flex; gap: 5px; flex-wrap: wrap; }
/* 品目コードのとなりに置く、同一成分規格への入口 */
/* サイトの .btn と同じ形にして、押せることが分かるようにする。
   丸くて細い枠だけだと、区分の札（.tag）と見分けがつかず、
   押せるものに見えない。枠を色付きにして、影と矢印を添える */
.same-btn { appearance: none; font: inherit; font-size: 12px; font-weight: 700;
  margin-left: 8px; text-decoration: none; display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 12px; cursor: pointer; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--bg-elev); color: var(--accent);
  box-shadow: 0 1px 2px rgba(0,0,0,.10);
  transition: background .15s, border-color .15s, transform .15s, box-shadow .15s; }
.same-btn::after { content: '›'; font-size: 14px; line-height: 1; opacity: .75; }
.same-btn:hover { border-color: var(--accent); color: var(--accent-deep);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-elev));
  transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,.16); }
.same-btn:active { transform: none; box-shadow: none; }
.same-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* 3つの数字は、見出しの行数も単位の長さもばらばら（「薬価が動いた回数」は
   2行に折れ、「円（2026/04/01〜）」も折れる）。ブロックを下端でそろえると、
   そのぶんが数字の位置に出て、上端が16px/45px/45pxとずれていた。
   見出し・数字・単位をそれぞれ同じ段に置いて、数字の高さをそろえる */
.dt-kpi {
  margin-left: auto;
  display: grid; grid-auto-flow: column; grid-template-rows: auto auto auto;
  gap: 0 26px; justify-items: end; align-content: end;
}
/* 枠を消して、中の3つをそのまま段に載せる */
.dt-kpi > div { display: contents; }
.dt-kpi .k { font-size: 11px; color: var(--ink-soft); letter-spacing: .04em; text-align: right; }
/* 数字と単位はひとつながりで読ませる。折り返させない */
.dt-kpi .v { font-size: 25px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; white-space: nowrap; }
/* 単位（円・回）。数字と同じ段に置くので、大きさと太さだけ落とす */
.dt-kpi .vu { font-size: 11.5px; font-weight: 500; color: var(--ink-soft); margin-left: 1px; }
.dt-kpi .v.down { color: var(--danger); }
/* 添え書き（適用日）。1行に収める */
.dt-kpi .u { font-size: 11.5px; color: var(--ink-soft); font-weight: 500; text-align: right; white-space: nowrap; }

/* ---- タイル ----
   左上に図、右に年表を通しで、左下に収載時と後発品を横並びにする。
   図は縦に伸ばすと金額の落差が見え、年表は縦に伸ばすと全期が入る */
/* 年表は「引き上げ・維持」と「引き下げ」の2列を抱えていて、
   制度の名前（長期収載品（GE置換80％超過品）など）が長い。
   図より年表を広く取る */
.dt-grid { flex: 1; min-height: 0; display: grid; gap: 10px;
  grid-template-columns: 1fr 1fr 1.9fr; grid-template-rows: 1fr auto; }
#tile-chart   { grid-area: 1 / 1 / 1 / span 2; }
#tile-log     { grid-area: 1 / 3 / span 2 / 3; }
#tile-listing { grid-area: 2 / 1; }
#tile-generic { grid-area: 2 / 2; }
.tile { border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  padding: 10px 12px 8px; display: flex; flex-direction: column; min-height: 0; position: relative; }
.tile > h2 { margin: 0 0 7px; font-size: 12px; font-weight: 700; letter-spacing: .04em;
  color: var(--ink-mid); display: flex; align-items: center; gap: 6px; }
.tile > h2 .cnt { font-weight: 500; color: var(--ink-soft); }
.tile .more { margin-left: auto; font-size: 11px; color: var(--accent); background: none; border: 0;
  padding: 2px 6px; border-radius: 5px; cursor: pointer; font-family: inherit; }
.tile .more:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.tile .body { flex: 1; min-height: 0; overflow: hidden; }
.tile.span2 { grid-column: span 2; }
.tile.span3 { grid-column: span 3; }
.tile.dim { opacity: .62; }

/* 年表の1行。年度／引き上げ・維持／引き下げ／変化率／根拠のリンク。
   制度には薬価を維持・引き上げるもの（新薬創出加算・改定時加算・不採算品再算定・
   基礎的医薬品・最低薬価）と、引き下げるもの（実勢価改定・再算定・長期収載品G1）が
   あり、同じ年度に両方が効くことがある。混ぜて並べると読み解けないので分ける */
.log { display: grid; gap: 2px; font-size: 12px; line-height: 1.55; }
/* 根拠のリンクの列を auto にすると、リンクが無い行だけ他の列が広がって
   行ごとに文字の左端がずれる。すべて固定にして縦をそろえる */
.log > div { display: grid;
  grid-template-columns: 82px var(--up, 1.08fr) var(--dn, 1.12fr) 70px 56px var(--src, 62px); gap: 7px;
  padding: 2px 6px; border-radius: 5px; align-items: baseline; }
/* 後発品だけ、薬価のとなりに価格帯の列を足す。
   先発品には無い話なので、そのときは列ごと置かない */
.log.ge > div { grid-template-columns: 82px var(--up, 1.05fr) var(--dn, 1fr) 70px 44px 56px var(--src, 62px); }
.log .bd { font-size: 11px; text-align: center; border-radius: 4px; padding: 0 3px;
  color: var(--ink-soft); background: var(--bg-sunken); }
.log > div:nth-child(even) .bd { background: var(--bg); }
.log .lh .bd { background: none; padding: 0; }
.log .bd.hi { color: var(--danger); }
.log .bd.mid { color: var(--warn); }
.log .bd.lo { color: var(--accent-2); }
.log > div:nth-child(even) { background: var(--bg-sunken); }
.log .lh { background: none !important; color: var(--ink-soft); font-size: 10.5px;
  letter-spacing: .04em; padding-bottom: 3px; border-bottom: 1px solid var(--line); }
.log .y { color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
/* 制度の名前は長いものがある（長期収載品（GE置換80％超過品）、
   引上げ　PMP（薬価維持）・改定時加算（迅 A=5） など）。
   1行に押し込めて切るより、折り返して読めるようにする。
   行が伸びたぶんは、はみ出した末尾の期を畳んで帳尻を合わせる */
/* 制度の名前の途中で折り返さない。「不採算品再算定・基礎的医薬品」が
   「基礎的医薬／品」で切れると、読み手はいったん止まってしまう。
   keep-all で名前の中では折らず、「・」や「、」の区切りで折る。
   1つの名前が列に入りきらないときだけ anywhere で折る
   （長期収載品（GE置換80％超過品）など） */
.log .t { word-break: keep-all; overflow-wrap: anywhere; }
.log .t.up { color: var(--accent-2); }
.log .t.dn { color: var(--danger); }
/* 制度の名前。並びごと1行に収めたいので、本文より少し小さくする */
.log .t .rgs { white-space: nowrap; font-size: 11px; }
.log .t .rgs.one { white-space: normal; }
/* 必要な幅を測るあいだだけ、折り返しを止めて中身なりの幅にする。
   -webkit-box のままだと列の幅に押し込まれてしまい、
   scrollWidth を読んでも「いま割り当てられている幅」しか返ってこない */
.log.measuring .t, .log.measuring .t .rgs.one { white-space: nowrap; }
.log.measuring .t { display: inline-block; width: max-content; max-width: none; overflow: visible; }
.log.measuring .s { width: max-content; overflow: visible; flex-wrap: nowrap; }
.log .t .rg { opacity: .72; }
/* その年度に効かなかった制度（PMPの薬価非維持など） */
.log .t .rg.off { color: var(--ink-soft); opacity: .95; }
.log .t .no { color: var(--ink-soft); opacity: .5; }
/* 収載区分の移動。上げでも下げでもないので色を持たせない */
.log .t .nt { color: var(--ink-soft); }
.log .v { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; overflow: hidden; }
.log .v.down { color: var(--danger); }
.log .v.up { color: var(--accent-2); }
.log .v.p { color: var(--ink-mid); }
/* 統一名収載にまとめられていた年度。薬価はその統一名収載品のもの */
.log .v.p.via { color: var(--ink-soft); font-style: italic; }
.log .v .yen { font-size: 10px; color: var(--ink-soft); margin-left: 1px; }
/* 税抜き／税込みの切り替え */
.tax-pick { display: inline-flex; gap: 2px; }
.tax-pick button { appearance: none; font: inherit; font-size: 10.5px; padding: 1px 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink-soft); border-radius: 5px; }
.tax-pick button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 700; }
/* 資料が多い行は折り返す。列を伸ばすと本文がそのぶん痩せるので、
   幅は3つぶんまでにして、あふれたら次の行に落とす */
.log .s { display: flex; gap: 4px 4px; white-space: nowrap; flex-wrap: wrap; align-content: flex-start; }
/* PDFと中医協の対。折り返すときは対のまま次の行へ */
.log .s .pair { display: flex; gap: 4px; }
.log .s a { font-size: 10.5px; padding: 0 4px; border: 1px solid var(--line); border-radius: 4px;
  color: var(--ink-soft); text-decoration: none; }
.log .s a:hover { border-color: var(--accent); color: var(--accent); }

/* ---- 密な行（1行22px）。本番の履歴は1件72〜100pxあり1画面に入らない ---- */
.rows { display: grid; gap: 2px; font-size: 12px; line-height: 1.55; }
.rows > div { display: grid; grid-template-columns: 68px 1fr auto; gap: 8px; padding: 2px 6px; border-radius: 5px; }
.rows > div:nth-child(odd) { background: var(--bg-sunken); }
.rows .y { color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .v { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.rows .v.down { color: var(--danger); }
.rows .v.up { color: var(--accent-2); }

.pairs { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12px; line-height: 1.7; margin: 0; }
.pairs dt { color: var(--ink-soft); white-space: nowrap; }
.pairs dd { margin: 0; font-weight: 600; }
/* 後発品の価格帯。自分がどの帯にいるのかを目立たせる */
.band-me { color: var(--accent); font-variant-numeric: tabular-nums; }
.band-rank { font-weight: 700; }
.ge-rule { color: var(--ink-soft); font-weight: 500; }
.pairs dd b.acc { color: var(--accent); }
.band-rank.hi { color: var(--danger); }
.band-rank.mid { color: var(--warn); }
.band-rank.lo { color: var(--accent-2); }
.band-p { font-variant-numeric: tabular-nums; font-weight: 500; padding: 0 3px; border-radius: 3px; }
.band-p.hi { color: var(--danger); }
.band-p.mid { color: var(--warn); }
.band-p.lo { color: var(--accent-2); }
.band-p.me { background: color-mix(in srgb, var(--accent) 18%, transparent); font-weight: 800; }
.band-other { color: var(--ink-soft); font-weight: 500; font-variant-numeric: tabular-nums; }
.none { font-size: 12px; color: var(--ink-soft); line-height: 1.8; }

/* ---- グラフ ---- */
.chart { flex: 1; min-height: 0; position: relative; }
/* カーソルを当てた段の薬価 */
.chart .tip { position: absolute; display: none; pointer-events: none; z-index: 2;
  background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 5px 9px;
  font-size: 11.5px; line-height: 1.55; white-space: nowrap; box-shadow: 0 3px 10px rgba(0,0,0,.22); }
.chart .tip .d { color: var(--ink-soft); font-size: 10.5px; }
.chart .tip b { font-size: 14px; font-variant-numeric: tabular-nums; }
.chart .tip .w { color: var(--ink-mid); white-space: normal; max-width: 230px; }
.chart .hv { stroke: var(--ink-soft); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .hd { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart .gl { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--ink-soft); font-size: 10px; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .ar { fill: color-mix(in srgb, var(--accent) 10%, transparent); }
.chart .dt2 { fill: var(--accent); }
.chart .bl { fill: var(--bg-sunken); }
.chart .bd { fill: color-mix(in srgb, var(--accent) 50%, transparent); }
.chart .bd.rc { fill: color-mix(in srgb, var(--danger) 50%, transparent); }
.chart .bd.g1 { fill: color-mix(in srgb, var(--warn) 55%, transparent); }
.chart .bn { fill: var(--ink-soft); font-size: 9.5px; }
/* 段ごとに書き添える薬価 */
.chart .pv { fill: var(--ink-mid); font-size: 9.5px; font-variant-numeric: tabular-nums; }
.chart .mk { stroke: var(--danger); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .mt { fill: var(--danger); font-size: 10px; font-weight: 700; }

/* ---- 押したときに開く別枠 ---- */
dialog.sheet { width: min(880px, 92vw); max-height: 84vh; border: 1px solid var(--line);
  border-radius: 14px; padding: 0; background: var(--bg); color: var(--ink); }
dialog.sheet::backdrop { background: rgba(0,0,0,.42); }
dialog.sheet .sh-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); }
dialog.sheet .sh-head h2 { margin: 0; font-size: 16px; }
dialog.sheet .sh-head button { margin-left: auto; }
dialog.sheet .sh-body { padding: 16px 18px 22px; overflow: auto; max-height: calc(84vh - 60px); }

/* 狭い画面では横に並べられないので、1列に積んでスクロールに戻す */
/* 横に3列並べられない画面では、1列に積んでスクロールに戻す。
   ここで overflow を戻さないと、積んだぶんが画面の外に出て読めなくなる */
@media (max-width: 1080px) {
  .dt-grid { grid-template-columns: 1fr; grid-template-rows: 340px auto auto auto; }
  .dt-grid > .tile { grid-area: auto !important; }
  html.dt-page, html.dt-page body { height: auto; }
  html.dt-page body { display: block; overflow: visible; }
  .dt-main { display: block; }
  .dt-grid { display: grid; }
  .tile .body { overflow: visible; }
  html.dt-page .site-footer { padding: 26px 0; }
  html.dt-page .site-footer .f-note, html.dt-page .site-footer .f-back { display: block; }
  html.dt-page .site-footer .f-brand { font-size: 15px; margin-bottom: 6px; }
}

/* 狭い画面の年表。
   列の固定幅（82+70+44+56+62＝314px）と gap 7px×6 が積み上がり、
   中身が52px以下でも行の最小幅が418pxになっていた。
   その結果、390pxの画面でビューポートが438pxへ押し広げられていた。
   中身ではなく列定義が原因なので、固定列だけを詰める。
   横スクロールにしないのは、タイルの中がさらに横に動くと
   縦スクロールと競合して扱いにくくなるため */
@media (max-width: 480px) {
  .log { font-size: 11.5px; }
  .log > div {
    grid-template-columns: 58px var(--up, 1.08fr) var(--dn, 1.12fr) 52px 46px var(--src, 44px);
    gap: 4px; padding: 2px 4px;
  }
  .log.ge > div {
    grid-template-columns: 58px var(--up, 1.05fr) var(--dn, 1fr) 52px 34px 46px var(--src, 44px);
  }
  /* 列が縮むぶん、中身が列を押し広げないようにする */
  .log > div > * { min-width: 0; }
  .log .bd { padding: 0 2px; font-size: 10.5px; }
}

/* 銘柄として開いたとき、その銘柄が売られる前の期間。
   図は収載の単位（統一名）の薬価の動きなので線は続いているが、
   この銘柄の話ではない部分だと分かるように覆いをかける */
.chart .pre-sale { fill: var(--bg); opacity: .55; }
.chart .sale-line { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; opacity: .8; }
.chart .sale-tx { fill: var(--accent); font-size: 9.5px; font-weight: 700;
  paint-order: stroke; stroke: var(--bg); stroke-width: 3; stroke-linejoin: round; }
