/* PT評価バッテリー参照ツール — スマホ縦向き・片手操作優先 */
:root {
  --primary: #1a6b5e;
  --primary-light: #e4f2ef;
  --accent: #e8912d;
  --bg: #f7f8f8;
  --card: #ffffff;
  --text: #22302d;
  --text-sub: #6b7a76;
  --border: #dde4e2;
  --tap-min: 44px; /* 最小タップ領域 */
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
}

.loading { padding: 2rem; text-align: center; color: var(--text-sub); }

/* ===== ヘッダー ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: #fff;
  padding: calc(0.6rem + env(safe-area-inset-top)) 1rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.header h1 {
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.back-btn {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  border: none;
  background: transparent;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
}
.back-btn:active { background: rgba(255, 255, 255, 0.2); }

/* ===== 検索 ===== */
.search-wrap {
  padding: 0.75rem 1rem;
  position: sticky;
  top: calc(3.1rem + env(safe-area-inset-top));
  background: var(--bg);
  z-index: 9;
}
.search-input {
  width: 100%;
  min-height: var(--tap-min);
  padding: 0.6rem 1rem;
  font-size: 16px; /* iOSの自動ズーム防止のため16px以上 */
  border: 1.5px solid var(--border);
  border-radius: 24px;
  background: var(--card);
  outline: none;
}
.search-input:focus { border-color: var(--primary); }

/* ===== ホーム ===== */
.section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-sub);
  padding: 0.75rem 1rem 0.25rem;
}
.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
}
.tile {
  min-height: 64px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-family: inherit;
  text-align: left;
}
.tile:active { background: var(--primary-light); }
.tile .tile-name { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.tile .tile-count { font-size: 0.75rem; color: var(--text-sub); }

/* ===== 評価リスト ===== */
.assess-list { list-style: none; padding: 0.25rem 1rem 1rem; }
.assess-row {
  width: 100%;
  min-height: 64px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  display: block;
}
.assess-row:active { background: var(--primary-light); }
.row-top { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.row-abbr { font-size: 1rem; font-weight: 700; color: var(--primary); }
.row-name { font-size: 0.85rem; color: var(--text); }
.row-meta { display: flex; gap: 0.4rem; margin-top: 0.2rem; flex-wrap: wrap; }
.tag {
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  white-space: nowrap;
}
.tag.time { background: #fdf1e3; color: #b06a10; }
.empty-msg { padding: 1.5rem 1rem; color: var(--text-sub); text-align: center; }
.version { text-align: center; color: var(--text-sub); font-size: 0.72rem; padding: 1.5rem 1rem 0.5rem; }
.version-actions { text-align: center; padding: 0 1rem 2rem; }
.refresh-btn {
  min-height: var(--tap-min);
  padding: 0 1.2rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text-sub);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
}
.refresh-btn:active { background: var(--primary-light); color: var(--primary); }

/* ===== 詳細画面 ===== */
.detail { padding: 0.75rem 1rem 6.5rem; }
.detail-head {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 0.6rem;
}
.detail-abbr { font-size: 1.3rem; font-weight: 800; color: var(--primary); }
.detail-name { font-size: 0.9rem; color: var(--text-sub); margin-bottom: 0.4rem; }
.detail-summary { font-size: 0.9rem; }
.detail-tags { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }

details.section {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  overflow: hidden;
}
details.section summary {
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  padding: 0.6rem 1rem;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}
details.section summary::-webkit-details-marker { display: none; }
details.section summary::after {
  content: "＋";
  margin-left: auto;
  color: var(--text-sub);
  font-size: 1.1rem;
}
details.section[open] summary::after { content: "−"; }
.section-body { padding: 0 1rem 0.9rem; font-size: 0.9rem; }
.section-body ol, .section-body ul { padding-left: 1.3rem; }
.section-body li { margin-bottom: 0.35rem; }
.section-body table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.section-body th, .section-body td {
  border-bottom: 1px solid var(--border);
  padding: 0.35rem 0.4rem;
  text-align: left;
  vertical-align: top;
}
.section-body th { color: var(--text-sub); font-weight: 600; white-space: nowrap; }
.note-box {
  background: #fdf6ec;
  border-left: 3px solid var(--accent);
  padding: 0.5rem 0.75rem;
  border-radius: 0 8px 8px 0;
  margin-top: 0.5rem;
  font-size: 0.82rem;
}
.license-box {
  background: #fbeaea;
  border-left: 3px solid #c0392b;
  padding: 0.5rem 0.75rem;
  border-radius: 0 8px 8px 0;
  margin-top: 0.5rem;
  font-size: 0.82rem;
}
.ref-text { font-size: 0.78rem; color: var(--text-sub); word-break: break-all; }

/* ===== 下部固定ボタン ===== */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
  display: flex;
  gap: 0.6rem;
}
.primary-btn {
  flex: 1;
  min-height: 52px;
  border: none;
  border-radius: 26px;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(26, 107, 94, 0.35);
}
.primary-btn:active { background: #145248; }
.primary-btn:disabled { background: #9db5b0; box-shadow: none; }

/* ===== エラー・スタブ表示 ===== */
.stub { padding: 2rem 1.5rem; text-align: center; color: var(--text-sub); }
.stub .stub-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }

/* ===== 入力モード ===== */
.score-summary {
  position: sticky;
  top: calc(3.1rem + env(safe-area-inset-top));
  z-index: 8;
  background: var(--primary);
  color: #fff;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.sum-main { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.sum-score { font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.sum-score small { font-size: 0.85rem; font-weight: 600; opacity: 0.85; }
.sum-judge {
  font-size: 0.82rem;
  background: rgba(255, 255, 255, 0.22);
  padding: 0.15rem 0.55rem;
  border-radius: 10px;
}
.sum-sub { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.sum-warn {
  font-size: 0.72rem;
  background: var(--accent);
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  white-space: nowrap;
}
.fmt-toggle { display: inline-flex; border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 8px; overflow: hidden; }
.fmt-toggle .fmt {
  min-height: 30px;
  padding: 0 0.5rem;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
}
.fmt-toggle .fmt.sel { background: #fff; color: var(--primary); font-weight: 700; }

.input-form { padding: 0.75rem 1rem 7rem; }
.input-notice {
  font-size: 0.78rem;
  color: var(--text-sub);
  background: var(--primary-light);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.75rem;
}

.q-item {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
  margin-bottom: 0.5rem;
}
.q-label { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.5rem; }
.q-note {
  font-size: 0.78rem;
  color: var(--text-sub);
  line-height: 1.45;
  margin: -0.25rem 0 0.5rem;
  padding: 0.35rem 0.5rem;
  background: var(--bg);
  border-radius: 6px;
}
.na-hint { font-size: 0.72rem; color: var(--text-sub); font-weight: 400; }
.hint { font-size: 0.75rem; color: var(--text-sub); margin-top: 0.4rem; }

.q-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.q-buttons.vertical { flex-direction: column; }
.opt {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  padding: 0.4rem 0.7rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  flex: 0 0 auto;
}
.q-buttons.vertical .opt { width: 100%; text-align: left; font-size: 0.88rem; font-weight: 500; }
.opt:active { background: var(--primary-light); }
.opt.sel { background: var(--primary); color: #fff; border-color: var(--primary); }
.opt.na.sel { background: var(--text-sub); border-color: var(--text-sub); }
.opt.pf.sel { background: var(--accent); border-color: var(--accent); }

/* 選択中の判定基準（ボタン下に表示） */
.selected-crit {
  font-size: 0.82rem;
  color: var(--primary);
  font-weight: 600;
  margin-top: 0.45rem;
  padding-left: 0.3rem;
  border-left: 3px solid var(--primary);
  min-height: 0;
}
.selected-crit:empty { display: none; }

/* 採点基準の折りたたみ */
.criteria { margin-top: 0.4rem; }
.criteria summary {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  font-size: 0.78rem;
  color: var(--text-sub);
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}
.criteria summary::-webkit-details-marker { display: none; }
.criteria summary::before { content: "▸ "; margin-right: 0.2rem; }
.criteria[open] summary::before { content: "▾ "; }
.crit-list {
  list-style: none;
  padding: 0.3rem 0 0;
  margin: 0;
}
.crit-list li {
  display: flex;
  gap: 0.5rem;
  padding: 0.35rem 0.3rem;
  font-size: 0.83rem;
  line-height: 1.45;
  border-top: 1px solid var(--border);
}
.crit-list li b {
  flex-shrink: 0;
  width: 1.4rem;
  text-align: center;
  color: var(--primary);
  font-weight: 800;
}

.side-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.4rem; }
.side-tag {
  flex-shrink: 0;
  width: 1.8rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-sub);
  text-align: center;
}

.num-wrap { display: flex; align-items: center; gap: 0.5rem; }
.num-input {
  flex: 1;
  min-height: 52px;
  padding: 0.4rem 0.8rem;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: right;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  outline: none;
}
.num-input:focus { border-color: var(--primary); }
.num-unit { font-size: 1rem; font-weight: 600; color: var(--text-sub); flex-shrink: 0; }
.single-input-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.subscale-group { margin-bottom: 0.75rem; }
.subscale-head {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  padding: 0.4rem 0.2rem 0.3rem;
  border-bottom: 2px solid var(--primary-light);
  margin-bottom: 0.5rem;
}

.target-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.6rem;
}
.target-title { font-size: 0.9rem; font-weight: 700; color: var(--primary); margin-bottom: 0.5rem; }
.target-card .q-item { border: none; padding: 0.3rem 0; margin-bottom: 0.3rem; }
.computed-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fdf6ec;
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  margin-top: 0.3rem;
  font-size: 0.82rem;
}
.computed-val { font-size: 1.05rem; color: var(--accent); }

.preview { margin-top: 1rem; }
.preview summary {
  font-size: 0.82rem;
  color: var(--text-sub);
  cursor: pointer;
  padding: 0.4rem 0;
}
.preview pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #2b3835;
  color: #e8efed;
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.5;
}

.bottom-bar.input-bar { gap: 0.5rem; }
.ghost-btn {
  min-height: 52px;
  padding: 0 1.1rem;
  border: 1.5px solid var(--border);
  border-radius: 26px;
  background: var(--card);
  color: var(--text-sub);
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
}
.ghost-btn:active { background: #eee; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 5.5rem;
  transform: translateX(-50%) translateY(1rem);
  background: rgba(20, 30, 28, 0.95);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 22px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
