/* ==========================================================================
   rt-app.css  —  Runtera アプリ風コンポーネント集（rt-ui.css の拡張）
   - 読み込み順: rt-ui.css の後に読み込むこと（bar.php が両方を link する）
   - 変数は rt-ui.css の --rt-* をそのまま使う（ライト/ダーク両対応）
   - rt-ui.css で既に定義済みのクラス（.rt-card / .rt-btn / .rt-chip /
     .rt-seg / .rt-field / .rt-item / .rt-empty / .rt-skel / .rt-overlay /
     .rt-modal / .rt-tabs 等）は再定義しない。ここは「追加分」だけ
   ========================================================================== */

/* ---------- アプリ共通の下地 ---------- */
/* iOS の入力ズーム防止: タッチ端末では入力欄を 16px に固定する */
@media (max-width: 1000px), (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select, textarea { font-size: 16px !important; }
}
/* タップ時の反応を速く・気持ちよく */
a, button, .rt-cell, .rt-chipbtn, .rt-switch { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.rt-press { transition: transform .12s ease, background .15s ease, border-color .15s ease; }
.rt-press:active { transform: scale(.97); }

/* 下部タブバー分の余白（セーフエリア込み）を確保したいページのメイン領域に */
.rt-pagepad { padding-bottom: 40px; }
@media (max-width: 1000px) {
  .rt-pagepad { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
}
.rt-safe-b { padding-bottom: env(safe-area-inset-bottom); }

/* ---------- セクション見出し ---------- */
.rt-sec { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 10px; }
.rt-sec:first-child { margin-top: 0; }
.rt-sec-t { font-size: 1.02rem; font-weight: 800; color: var(--rt-ink); letter-spacing: -.01em; display: inline-flex; align-items: center; gap: 7px; }
.rt-sec-t .material-icons { font-size: 1.25rem; color: var(--rt-brand); }
.rt-sec .rt-spacer { flex: 1; }
.rt-sec-a { font-size: .8rem; font-weight: 700; color: var(--rt-brand); text-decoration: none; display: inline-flex; align-items: center; gap: 2px; }
.rt-sec-a .material-icons { font-size: 1rem; }
.rt-hr { border: 0; border-top: 1px solid var(--rt-line-2); margin: 16px 0; }

/* ---------- バナー（お知らせ・アラート） ---------- */
.rt-banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px;
  background: var(--rt-brand-soft); color: var(--rt-ink); font-size: .88rem; font-weight: 600; line-height: 1.55; margin-bottom: 14px; }
.rt-banner .material-icons { font-size: 1.25rem; color: var(--rt-brand); flex: none; margin-top: 1px; }
.rt-banner p { margin: 0; flex: 1; min-width: 0; }
.rt-banner small { display: block; font-weight: 600; opacity: .75; margin-top: 2px; }
.rt-banner.ok { background: var(--rt-ok-soft); } .rt-banner.ok .material-icons { color: var(--rt-ok); }
.rt-banner.warn { background: var(--rt-warn-soft); } .rt-banner.warn .material-icons { color: var(--rt-warn); }
.rt-banner.bad { background: var(--rt-bad-soft); } .rt-banner.bad .material-icons { color: var(--rt-bad); }
.rt-banner.track { background: var(--rt-track-soft); } .rt-banner.track .material-icons { color: var(--rt-track); }

/* ---------- 設定風リスト（一覧行） ---------- */
.rt-list { background: var(--rt-surface); border: 1px solid var(--rt-line); border-radius: var(--rt-radius);
  box-shadow: var(--rt-shadow); overflow: hidden; box-sizing: border-box; }
.rt-list + .rt-list { margin-top: 14px; }
.rt-cell { display: flex; align-items: center; gap: 12px; width: 100%; box-sizing: border-box;
  padding: 12px 16px; min-height: 58px; background: transparent; border: 0; border-bottom: 1px solid var(--rt-line-2);
  color: var(--rt-ink); text-decoration: none; font: inherit; text-align: left; cursor: pointer;
  transition: background .15s ease, transform .12s ease; }
.rt-cell:last-child { border-bottom: 0; }
a.rt-cell:active, button.rt-cell:active { background: var(--rt-surface-2); transform: scale(.995); }
.rt-cell-ic { width: 38px; height: 38px; flex: none; border-radius: 11px; display: grid; place-items: center;
  background: var(--rt-brand-soft); color: var(--rt-brand); }
.rt-cell-ic .material-icons { font-size: 1.25rem; }
.rt-cell-ic.track { background: var(--rt-track-soft); color: var(--rt-track); }
.rt-cell-ic.ok { background: var(--rt-ok-soft); color: var(--rt-ok); }
.rt-cell-ic.warn { background: var(--rt-warn-soft); color: var(--rt-warn); }
.rt-cell-ic.bad { background: var(--rt-bad-soft); color: var(--rt-bad); }
.rt-cell-ic.plain { background: var(--rt-surface-2); color: var(--rt-ink-3); }
.rt-cell-b { flex: 1; min-width: 0; }
.rt-cell-t1 { display: block; font-size: .93rem; font-weight: 700; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rt-cell-t2 { display: block; font-size: .76rem; font-weight: 600; color: var(--rt-ink-3); margin-top: 1px; line-height: 1.45;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rt-cell-t { flex: none; display: inline-flex; align-items: center; gap: 4px; font-size: .84rem; font-weight: 700; color: var(--rt-ink-3); }
.rt-cell-t .material-icons { font-size: 1.15rem; }
.rt-cell-t .val { font-family: var(--rt-num); font-variant-numeric: tabular-nums; color: var(--rt-ink-2); }
.rt-cell.danger .rt-cell-t1 { color: var(--rt-bad); }
.rt-cell.danger .rt-cell-ic { background: var(--rt-bad-soft); color: var(--rt-bad); }
.rt-cell.off { opacity: .45; pointer-events: none; }

/* ---------- 選択チップ（トグル式） ---------- */
.rt-chiprow { display: flex; flex-wrap: wrap; gap: 8px; }
.rt-chipbtn { display: inline-flex; align-items: center; gap: 5px; padding: 8px 14px; min-height: 38px; border-radius: 999px;
  border: 1px solid var(--rt-line); background: var(--rt-surface); color: var(--rt-ink-2);
  font: 700 .82rem/1 var(--rt-font); cursor: pointer; transition: .15s; }
.rt-chipbtn .material-icons { font-size: 1rem; }
.rt-chipbtn:active { transform: scale(.96); }
.rt-chipbtn.on { background: var(--rt-brand); border-color: var(--rt-brand); color: #fff; }
.rt-chipbtn.on.track { background: var(--rt-track); border-color: var(--rt-track); }

/* ---------- セグメント（rt-ui.css の .rt-seg への全幅修飾） ---------- */
.rt-seg.full { display: flex; width: 100%; box-sizing: border-box; }
.rt-seg.full button { flex: 1; min-height: 38px; }

/* ---------- スイッチ ---------- */
.rt-switch { position: relative; display: inline-block; width: 50px; height: 30px; flex: none; cursor: pointer; }
.rt-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.rt-switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--rt-line); transition: background .18s; pointer-events: none; }
.rt-switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(11,27,51,.3); transition: transform .18s cubic-bezier(.2,.8,.2,1); }
.rt-switch input:checked + i { background: var(--rt-brand); }
.rt-switch input:checked + i::after { transform: translateX(20px); }
.rt-switch input:focus-visible + i { outline: 2px solid var(--rt-brand); outline-offset: 2px; }
.rt-switch.track input:checked + i { background: var(--rt-track); }
.rt-switch.sm { width: 42px; height: 26px; }
.rt-switch.sm i::after { width: 20px; height: 20px; }
.rt-switch.sm input:checked + i::after { transform: translateX(16px); }

/* ---------- FAB ---------- */
.rt-fab { position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 990;
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--rt-track); color: #fff; box-shadow: 0 12px 26px -8px rgba(226,85,45,.65), var(--rt-shadow);
  transition: transform .15s ease, filter .15s ease; }
.rt-fab .material-icons { font-size: 1.6rem; }
.rt-fab:hover { filter: brightness(1.06); }
.rt-fab:active { transform: scale(.93); }
.rt-fab.brand { background: var(--rt-brand); box-shadow: 0 12px 26px -8px rgba(31,86,224,.6), var(--rt-shadow); }
.rt-fab.ext { width: auto; height: 52px; border-radius: 999px; padding: 0 20px 0 16px; font: 800 .9rem/1 var(--rt-font); }
.rt-fab.ext .material-icons { font-size: 1.35rem; }
@media (min-width: 1001px) { .rt-fab { bottom: 28px; right: 28px; } }

/* ---------- 画面下固定のアクションバー ---------- */
.rt-actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1500;
  display: flex; gap: 10px; align-items: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--rt-surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--rt-line); box-sizing: border-box; }
.rt-actionbar .rt-btn { flex: 1; min-height: 48px; }
.rt-actionbar .rt-btn.fix { flex: none; }
@media (min-width: 1001px) { .rt-actionbar { left: 260px; padding-bottom: 12px; } }

/* ---------- ボトムシート（汎用） ---------- */
.rt-sheetwrap { position: fixed; inset: 0; z-index: 25000; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(8,16,32,.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s; }
.rt-sheetwrap.on { opacity: 1; visibility: visible; }
.rt-sheet { width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--rt-surface); color: var(--rt-ink); border-radius: 20px 20px 0 0; box-shadow: var(--rt-shadow-lg);
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom)); box-sizing: border-box;
  transform: translateY(28px); transition: transform .26s cubic-bezier(.2,.85,.3,1); }
.rt-sheetwrap.on .rt-sheet { transform: none; }
.rt-sheet-handle { width: 42px; height: 5px; border-radius: 99px; background: var(--rt-line); margin: 6px auto 12px; }
.rt-sheet-h { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 1.05rem; font-weight: 800; }
.rt-sheet-h .material-icons { color: var(--rt-brand); font-size: 1.3rem; }
.rt-sheet-h .rt-spacer { flex: 1; }
.rt-sheet-x { border: 0; background: var(--rt-surface-2); color: var(--rt-ink-2); width: 34px; height: 34px; border-radius: 50%;
  display: inline-grid; place-items: center; cursor: pointer; flex: none; }
.rt-sheet-x .material-icons { color: inherit; font-size: 1.15rem; }
.rt-sheet-x:active { transform: scale(.92); }
@media (min-width: 621px) {
  .rt-sheetwrap { align-items: center; padding: 18px; }
  .rt-sheet { border-radius: 18px; padding-bottom: 22px; transform: translateY(14px) scale(.98); }
}

/* ---------- スケルトン（rt-ui.css の .rt-skel と組み合わせて使う） ---------- */
.rt-skel-line { height: 14px; margin: 9px 0; }
.rt-skel-line.lg { height: 22px; } .rt-skel-line.sm { height: 10px; }
.rt-skel.w40 { width: 40%; } .rt-skel.w60 { width: 60%; } .rt-skel.w80 { width: 80%; }
.rt-skel-circle { border-radius: 50%; width: 40px; height: 40px; min-height: 40px; flex: none; }
.rt-skel-cell { display: flex; gap: 12px; align-items: center; padding: 12px 0; }
.rt-skel-cell .grow { flex: 1; min-width: 0; }

/* ---------- 空状態の補助 ---------- */
.rt-empty .rt-btn { margin-top: 14px; }
.rt-empty.sm { padding: 20px 12px; }
.rt-empty.sm .material-icons { font-size: 30px; }

/* ---------- ステッパー（数値の増減） ---------- */
.rt-stepper { display: inline-flex; align-items: center; gap: 2px; background: var(--rt-surface-2);
  border: 1px solid var(--rt-line); border-radius: 999px; padding: 3px; }
.rt-stepper button { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--rt-surface);
  color: var(--rt-brand); display: grid; place-items: center; cursor: pointer; box-shadow: 0 1px 2px rgba(11,27,51,.12); }
.rt-stepper button:active { transform: scale(.92); }
.rt-stepper .val { min-width: 56px; text-align: center; font: 800 1rem var(--rt-num); font-variant-numeric: tabular-nums; color: var(--rt-ink); }
.rt-stepper .val small { font-size: .7rem; color: var(--rt-ink-3); font-weight: 700; margin-left: 2px; }

/* ---------- アコーディオン ---------- */
.rt-acc { border: 1px solid var(--rt-line); border-radius: var(--rt-radius); background: var(--rt-surface);
  box-shadow: var(--rt-shadow); overflow: hidden; }
.rt-acc + .rt-acc { margin-top: 12px; }
.rt-acc > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 15px 16px; font-weight: 800; font-size: .94rem; color: var(--rt-ink); }
.rt-acc > summary::-webkit-details-marker { display: none; }
.rt-acc > summary .material-icons:first-child { color: var(--rt-brand); font-size: 1.25rem; }
.rt-acc > summary .chev { margin-left: auto; color: var(--rt-ink-3); transition: transform .2s; }
.rt-acc[open ] > summary .chev { transform: rotate(180deg); }
.rt-acc > summary:active { background: var(--rt-surface-2); }
.rt-acc-body { padding: 0 16px 16px; font-size: .9rem; line-height: 1.7; color: var(--rt-ink-2); }

/* ダーク時: ダッシュボードの自動分析バナーは JS が薄色背景をインライン指定するため、読みやすさ優先で上書きする（読込中のスケルトン表示は除く） */
html[data-theme="dark"] #dynamic_insight:not(.skeleton) {
  background: var(--rt-surface-2) !important;
  color: var(--rt-ink) !important;
}
