/* base.css — 全画面共通のスタイルと、画面固有のスタイルをまとめたファイル。
   よく使う色は :root の CSS 変数に定義し、var(--color-text) のように参照する */

/* ══════════════════════════════════════════════════════════
   全画面共通 */

:root {
  color-scheme: light;
  --color-bg: #f6f7f4;
  --color-surface: #ffffff;
  --color-text: #1f2a24;
  --color-muted: #66736c;
  --color-border: #d7ddd8;
  --color-primary: #2f6f4e;
  --color-primary-dark: #24553d;
  --color-danger: #9f2d3f;
  --color-warning: #8a5f12;
  --shadow-soft: 0 1px 2px rgb(31 42 36 / 0.08);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* フォーム部品のフォントをページ本文と同じにする。
   これにより入力欄が 16px になり、iPhone の自動ズームを防げる */
button,
input,
textarea,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-soft);
}

.site-header__inner,
.page-main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 0;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
}

.brand__title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
}

.brand__subtitle {
  font-size: 0.78rem;
  color: var(--color-muted);
}

.nav-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-list a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--color-text);
  font-size: 0.92rem;
}

.nav-list a[aria-current="page"] {
  background: #e3eee7;
  color: var(--color-primary-dark);
  font-weight: 700;
}

.page-main {
  padding: 28px 0 48px;
}

.page-heading {
  display: grid;
  gap: 8px;
  margin-bottom: 24px;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(1.45rem, 4vw, 2rem);
  letter-spacing: 0;
  line-height: 1.25;
}

.page-heading p {
  margin: 0;
  max-width: 760px;
  color: var(--color-muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.panel,
.metric-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.panel {
  padding: 18px;
}

.panel h2,
.metric-card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  letter-spacing: 0;
}

.metric-card {
  padding: 16px;
}

.metric-card__value {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.metric-card__note,
.placeholder-text,
.form-help {
  color: var(--color-muted);
  font-size: 0.92rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--color-primary);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.button:hover {
  background: var(--color-primary-dark);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button--secondary {
  background: #ffffff;
  border-color: var(--color-border);
  color: var(--color-text);
}

.button--secondary:hover {
  background: #eef2ef;
}

.button--danger {
  background: var(--color-danger);
}

.button--danger:hover {
  background: #7d2030;
}

.status-line {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef2ef;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.status-line[data-state="recording"] {
  background: #f8e5e9;
  color: var(--color-danger);
}

.status-line[data-state="recorded"],
.status-line[data-state="completed"] {
  background: #e3eee7;
  color: var(--color-primary-dark);
}

.status-line[data-state="uploading"] {
  background: #fff3d2;
  color: var(--color-warning);
}

.status-line[data-state="error"] {
  background: #f8e5e9;
  color: var(--color-danger);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 0.9rem;
  font-weight: 700;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--color-text);
}

.field textarea {
  min-height: 120px;
  resize: vertical;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.result-item {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.result-item dt {
  color: var(--color-muted);
  font-size: 0.82rem;
}

.result-item dd {
  margin: 4px 0 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.pre-box {
  min-height: 120px;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
  white-space: pre-wrap;
  word-break: break-word;
}

.stack {
  display: grid;
  gap: 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  .site-header__inner {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .nav-list {
    justify-content: flex-start;
  }

  .nav-list a {
    min-height: 34px;
    padding-inline: 8px;
  }
}

/* ══════════════════════════════════════════════════════════
   画面固有のスタイル */

/* ── メッセージ・補足文 ─────────────────────────────────── */
.error {
  color: var(--color-danger);
}

.muted {
  color: var(--color-muted);
}

/* 打ち間違い警告。表示するだけで確定処理は拒否しない */
.warning {
  color: var(--color-warning);
}

/* ── QR カメラ映像（input.html） ─────────────────────────── */
video {
  width: 100%;
  max-width: 480px; /* PC で巨大にならないよう上限を設定 */
  margin-top: 1rem;
  background: #000;
  border-radius: 4px;
}

/* ── draft 一覧・確定値一覧のカード ──────────────────────── */
#draft-list,
#measurement-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

#draft-list li,
#measurement-list li {
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.8rem;
  margin-top: 1rem;
  background: var(--color-surface);
}

#draft-list p,
#measurement-list p {
  margin: 0 0 0.3rem;
}

/* 行内ボタンは小さめにして、画面下部の主ボタンと区別する。
   ボタン同士の間隔は .toolbar の gap が担当する */
#draft-list button {
  padding: 0.4rem 1.2rem;
}

/* ── ログイン画面の幅 ─────────────────────────────────────
   login.html はヘッダーがなく、通常の 1120px 幅では広すぎる。
   .page-main に追加して幅だけ狭める */
.page-main--narrow {
  width: min(420px, calc(100% - 32px));
}

/* ── <a class="button"> の下線打ち消し ────────────────────
   <a> にボタンの見た目を付けた場合、hover 時に下線が表示されてしまう。
   ボタンでは下線を出さない */
a.button:hover {
  text-decoration: none;
}

/* ── hidden 属性の強制 ────────────────────────────────────
   HTML の hidden 属性は「この要素を非表示にする」という意味だが、
   CSS でクラスに display を指定すると hidden が無視されてしまう。
   !important を付けて hidden を必ず優先させる */
[hidden] {
  display: none !important;
}

/* ── .field select の補完 ─────────────────────────────────
   共通部分の .field は input と textarea だけ定義している。
   select（プルダウン）にも同じ見た目を適用する */
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--color-text);
}

/* ── 音声入力マイクボタン（input.html） ──────────────────────
   丸型のトグルボタン。
   待機中は緑のマイクアイコン、録音中は赤の停止アイコンに切り替わる。
   JS は .is-recording クラスを付与・除去するだけで、
   見た目の切り替えはすべてこの CSS で行う */
.voice-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.button--voice {
  width: 56px;
  min-height: 56px;
  padding: 0;
  border-radius: 50%;
  flex: none;
}

.button--voice .voice-icon--stop {
  display: none;
}

.button--voice.is-recording {
  background: var(--color-danger);
}

.button--voice.is-recording:hover {
  background: #7d2030;
}

.button--voice.is-recording .voice-icon--mic {
  display: none;
}

.button--voice.is-recording .voice-icon--stop {
  display: block;
}

/* ── 備考専用マイク（input.html） ─────────────────────────
   備考入力欄の横にマイクボタンを並べる。
   Route A（左）と Route B（右）の2つがあり、
   それぞれの下に識別ラベル（.note-voice-caption）を表示する */
.note-voice-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.note-voice-row input {
  flex: 1;
  min-width: 0; /* これがないと長いテキストが親の幅を超えてはみ出す */
}

.note-voice-mic {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: none;
}

.note-voice-caption {
  font-size: 0.78rem;
  color: var(--color-muted);
}

/* 備考マイクは計測マイク（56px）より小さくする。
   44px はスマートフォンでタッチしやすい最小サイズの目安 */
.note-voice-mic .button--voice {
  width: 44px;
  min-height: 44px;
}

.note-voice-mic .voice-icon {
  width: 22px;
  height: 22px;
}

/* ── アカウントメニュー（header.js が生成） ──────────────────
   ドロップダウン式。
   開閉は JS が hidden 属性と aria-expanded を切り替える。
   専用の状態クラスは持たない */
.account-menu {
  position: relative;
  flex: none;
}

.account-menu__toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
}

.account-menu__toggle:hover {
  background: #eef2ef;
}

.account-menu__toggle[aria-expanded="true"] {
  background: #e3eee7;
  border-color: var(--color-border);
}

.account-icon {
  width: 30px;
  height: 30px;
}

.account-caret {
  width: 14px;
  height: 14px;
  color: var(--color-muted);
}

.account-menu__panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  display: grid;
  min-width: 220px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
  box-shadow: 0 8px 24px rgb(31 42 36 / 0.16);
  overflow: hidden; /* 角丸の外に中身がはみ出さないようにする */
}

/* リンクとボタンの見た目を同じ「行」に統一する */
.account-menu__panel a,
.account-menu__panel button {
  padding: 12px 16px;
  min-height: 44px; /* スマートフォンでタッチしやすい最小サイズ */
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-text);
  font-size: 1rem;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
}

/* 項目間に区切り線を自動で表示する */
.account-menu__panel > * + * {
  border-top: 1px solid var(--color-border);
}

.account-menu__panel a:hover,
.account-menu__panel button:hover {
  background: #eef2ef;
  text-decoration: none;
}

.account-menu__panel [aria-current="page"] {
  background: #e3eee7;
  color: var(--color-primary-dark);
  font-weight: 700;
}

/* ── 狭い画面でのヘッダー再配置 ──────────────────────────
   共通部分の 720px メディアクエリはナビを縦積みにするだけだが、
   アカウントメニューが加わると配置が崩れる。
   ここで横並び＋折り返しに変更し、
   1行目＝ブランド＋アカウントアイコン、2行目＝ナビにする */
@media (max-width: 720px) {
  .site-header__inner {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .brand {
    order: 0;
    flex: 1 1 auto;
    min-width: 0; /* ブランド名が長くてもアイコンを押し出さない */
  }

  .account-menu {
    order: 1;
  }

  .site-header__inner > nav {
    order: 2;
    flex: 1 0 100%; /* ナビだけで2行目を全幅使う */
  }
}

/* --- センサデータ画面の折れ線グラフ --------------------- */
/* 幅は親要素に合わせて伸縮し、高さは viewBox の比率で決まる */
.chart {
  display: block;
  width: 100%;
  height: auto;
}

.chart__line {
  fill: none;
  stroke: var(--color-primary);
  /* 日射量は短い間隔で大きく変動するため、太い線だと波形が潰れて読めなくなる */
  stroke-width: 1;
  stroke-linejoin: round;
}

.chart__dot {
  fill: var(--color-primary);
}

.chart__grid {
  stroke: var(--color-border);
  stroke-width: 1;
}

.chart__axis {
  font-size: 11px;
  fill: var(--color-muted);
}

/* --- 品質推定画面の表（predictions.html） ----------------- */
/* 列が7つあり狭い画面では収まらないため、表の部分のみ横スクロールさせる */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--color-muted);
  font-weight: 700;
  white-space: nowrap;
}

/* 数値の列は右揃えにし、桁を揃えて読めるようにする。
   上の .data-table th より詳細度を高くするため、.data-table を付けて指定する */
.data-table .data-table__number {
  text-align: right;
  white-space: nowrap;
}

/* エラーの内容に predict.py の出力（複数行）が含まれるため、改行をそのまま表示する */
.keep-newlines {
  white-space: pre-wrap;
}
