/*
 * デザインの土台は SmartHR Design System (smarthr-ui のテーマ) の作法に合わせる。
 *   - 色は役割の名前 (TEXT_BLACK / TEXT_GREY / MAIN / BORDER / HEAD ...) で持ち、灰色は色味のある段階で作る
 *   - 文字は比率 6 の段階 (XS 0.75 / S 0.857 / M 1 / L 1.2 / XL 1.5rem)
 *   - 余白は 8px 刻み、角丸は 4 / 6 / 8px、影は薄い LAYER1、フォーカスは白い縁 + 2px の outline
 * 色相だけこのツール用に置き換える (SmartHR の暖色の灰色 → 藍色寄りの灰色、MAIN は藍色)。
 * 文字のコントラストは light / dark とも 4.5:1 以上、入力欄の枠は 3:1 以上。
 */

:root {
  /* ---- 灰色の段階 (SmartHR の GREY_5〜100 と同じ明るさ、色相 222°) ---- */
  --grey-5: #f6f7f9;
  --grey-7: #f0f2f5;
  --grey-9: #eaedf2;
  --grey-20: #d2d7e0;
  --grey-30: #bcc2cd;
  --grey-50: #878fa0;
  --grey-65: #5f6878;
  --grey-100: #1e2330;

  /* ---- 役割の色 ---- */
  --color-text-black: var(--grey-100);
  --color-text-grey: var(--grey-65);
  --color-text-white: #fff;
  --color-text-link: #3149b8;
  --color-white: #fff;
  --color-background: var(--grey-5);
  --color-over-background: var(--grey-7);
  --color-head: var(--grey-9);
  --color-border: var(--grey-20);
  --color-border-input: var(--grey-50);
  --color-main: #3651c9;
  --color-main-darken: #2c44ad;
  --color-main-tint: #e9ecfb;
  --color-brand: #2b2f6b;
  --color-danger: #c8304a;
  --color-success: #1d7a4f;
  --color-success-tint: #e2f3ea;
  --color-warning: #8a5a00;
  --color-warning-tint: #fdf1d6;
  --color-outline: #3651c9;

  /* ---- 文字 ---- */
  --font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  --font-size-xs: .75rem;
  --font-size-s: .857rem;
  --font-size-m: 1rem;
  --font-size-l: 1.2rem;
  --font-size-xl: 1.5rem;
  --font-size-xxl: 2rem;
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-loose: 1.75;

  /* ---- 余白 (8px 刻み) ---- */
  --space-x3s: 4px;
  --space-xxs: 8px;
  --space-xs: 16px;
  --space-s: 24px;
  --space-m: 32px;
  --space-l: 40px;
  --space-xl: 48px;

  /* ---- 角丸・影・動き ---- */
  --radius-s: 4px;
  --radius-m: 6px;
  --radius-l: 8px;
  --radius-full: 10000px;
  --shadow-layer1: 0 1px 2px 0 rgba(10, 14, 30, .2);
  --shadow-dialog: 0 4px 10px 0 rgba(10, 14, 30, .3);
  --hover-animation: .3s ease-out;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --grey-5: #14161c;
    --grey-7: #1d2029;
    --grey-9: #262a35;
    --grey-20: #394050;
    --grey-30: #4a5266;
    --grey-50: #7a8396;
    --grey-65: #a3aab8;
    --grey-100: #e8eaf0;
    --color-white: #1d2029;
    --color-over-background: #232733;
    --color-text-link: #a5b4ff;
    --color-main: #8ea2ff;
    --color-main-darken: #a5b4ff;
    --color-main-tint: #252c4d;
    --color-text-white: #10162e;
    --color-brand: #1a1d3f;
    --color-danger: #ff8a9b;
    --color-success: #7fd6a8;
    --color-success-tint: #193326;
    --color-warning: #f2c46b;
    --color-warning-tint: #382c12;
    --color-outline: #8ea2ff;
    --shadow-layer1: 0 1px 2px 0 rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

/* ================= 土台 ================= */

* { box-sizing: border-box; }
/* display を指定した部品 (button など) でも hidden 属性で必ず隠れるようにする */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--color-background);
  color: var(--color-text-black);
  font-family: var(--font-family);
  font-size: var(--font-size-m);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: var(--leading-tight); margin: 0 0 var(--space-xs); font-weight: bold; }
h1 { font-size: var(--font-size-xl); }
h2 { font-size: var(--font-size-l); }
h3 { font-size: var(--font-size-m); margin-bottom: var(--space-xxs); }
p { margin: 0 0 var(--space-xs); }
a { color: var(--color-text-link); }
:focus-visible {
  outline: 2px solid var(--color-outline);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--color-white);
}
.muted { color: var(--color-text-grey); font-size: var(--font-size-s); }
.hint { color: var(--color-text-grey); font-size: var(--font-size-s); margin: var(--space-x3s) 0 var(--space-xxs); }
.error { color: var(--color-danger); font-size: var(--font-size-s); }
.error:empty { display: none; }

/* ================= ヘッダ (SmartHR の AppHeader に倣う) ================= */

.app-header {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  height: 48px;
  padding: 0 var(--space-s);
  background: var(--color-brand);
  color: #fff;
}
.app-header .product { font-weight: bold; letter-spacing: .02em; display: flex; align-items: center; gap: var(--space-xxs); }
.app-header .product::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: radial-gradient(circle at 35% 35%, #c7d0ff, #6f80f5 60%, #3651c9);
  box-shadow: 0 0 0 3px rgba(165, 180, 255, .25);
}
.app-header .me { margin-left: auto; display: flex; align-items: center; gap: var(--space-xs); font-size: var(--font-size-s); }
.app-header button.link { color: #fff; text-decoration: underline; }
.app-header button.link:hover:not(:disabled) { color: #fff; }

/* ================= 部品 ================= */

/* Base (白い面) */
.card {
  background: var(--color-white);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-layer1);
  padding: var(--space-s);
  margin-bottom: var(--space-xs);
}

/* Button */
button, a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-x3s);
  min-height: 40px;
  padding: 0 var(--space-xs);
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-m);
  background: var(--color-white);
  color: var(--color-text-black);
  font: inherit;
  font-weight: bold;
  line-height: var(--leading-tight);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--hover-animation), border-color var(--hover-animation);
}
button:hover:not(:disabled), a.button:hover { background: var(--color-over-background); }
button.primary, a.button.primary { background: var(--color-main); border-color: var(--color-main); color: var(--color-text-white); }
button.primary:hover:not(:disabled), a.button.primary:hover { background: var(--color-main-darken); border-color: var(--color-main-darken); }
button.danger { color: var(--color-danger); border-color: var(--color-danger); }
button.danger:hover:not(:disabled) { background: var(--color-danger); color: var(--color-white); }
button.link {
  min-height: 0;
  padding: var(--space-x3s);
  border: 0;
  background: none;
  color: var(--color-text-link);
  font-weight: normal;
}
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }
button.link.danger { color: var(--color-danger); }
button.link.danger:hover:not(:disabled) { background: none; color: var(--color-danger); }
button:disabled { color: var(--grey-50); border-color: var(--color-border); background: var(--color-over-background); cursor: not-allowed; }
button.primary:disabled { background: var(--grey-30); border-color: var(--grey-30); color: var(--color-white); }
button.link:disabled { background: none; color: var(--grey-30); }
button.big { min-height: 48px; padding: 0 var(--space-m); font-size: var(--font-size-l); border-radius: var(--radius-l); }
.wide { width: 100%; }

/* Input / Textarea / Select */
input, textarea, select {
  width: 100%;
  min-height: 40px;
  padding: var(--space-xxs) 12px;
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-m);
  background: var(--color-white);
  color: var(--color-text-black);
  font: inherit;
}
input::placeholder, textarea::placeholder { color: var(--grey-50); }
textarea { resize: vertical; line-height: var(--leading-normal); }
input:focus-visible, textarea:focus-visible, select:focus-visible { border-color: var(--color-main); }
.narrow { width: 6em; }
input[type="checkbox"] {
  width: 18px; height: 18px; min-height: 0; margin: 0 var(--space-xxs) 0 0; padding: 0;
  accent-color: var(--color-main); flex: none;
}

/* FormControl の見出し */
label { display: block; font-weight: bold; margin: var(--space-xs) 0 var(--space-xxs); }
label.check { display: flex; align-items: center; font-weight: normal; cursor: pointer; }

/* StatusLabel */
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 var(--space-xxs);
  border: 1px solid var(--color-text-grey);
  border-radius: var(--radius-s);
  background: var(--color-white);
  color: var(--color-text-grey);
  font-size: var(--font-size-xs);
  font-weight: bold;
  white-space: nowrap;
  vertical-align: middle;
}
.badge.ok { border-color: var(--color-success); color: var(--color-success); background: var(--color-success-tint); }
.badge.warn { border-color: var(--color-warning); color: var(--color-warning); background: var(--color-warning-tint); }

/* Table */
.table-wrap { overflow-x: auto; margin: 0 calc(-1 * var(--space-s)); padding: 0 var(--space-s); }
table { width: 100%; border-collapse: collapse; font-size: var(--font-size-s); }
th {
  background: var(--color-head);
  color: var(--color-text-black);
  font-weight: bold;
  text-align: left;
  padding: var(--space-xxs) 12px;
  white-space: nowrap;
}
td { padding: 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
td.actions { white-space: nowrap; text-align: right; }
td.actions a { margin-left: var(--space-xxs); }

/* 定義リスト */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-x3s) var(--space-xs); margin: 0 0 var(--space-xs); font-size: var(--font-size-s); }
.facts dt { color: var(--color-text-grey); font-weight: bold; }
.facts dd { margin: 0; }

/* Notification / Toast */
.toast {
  position: fixed; left: 50%; bottom: var(--space-s); transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--grey-100); color: var(--grey-5);
  padding: 12px var(--space-xs); border-radius: var(--radius-m);
  box-shadow: var(--shadow-dialog);
  font-size: var(--font-size-s);
  overflow-wrap: anywhere;
}

/* 並べる */
.row { display: flex; gap: var(--space-xxs); align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { justify-content: center; }
.right { text-align: right; }
.mt { margin-top: var(--space-xs); }
.mt-s { margin-top: var(--space-xxs); }
.mb { margin-bottom: var(--space-xs); }
.mb0 { margin-bottom: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 var(--space-s); }
.stat { font-size: var(--font-size-xxl); font-weight: bold; line-height: var(--leading-tight); margin: var(--space-xxs) 0; }
.stat .muted { font-size: var(--font-size-m); font-weight: normal; }

/* ================= ログイン ================= */

.login { max-width: 420px; margin: 12vh auto 0; padding: 0 var(--space-xs); }
.login h1 { font-size: var(--font-size-l); }
.login button { margin-top: var(--space-s); }

/* ================= 管理画面 ================= */

/* 管理画面は文字を一回り大きくする (デザインの値は rem なので、基準を上げると全体がそろって大きくなる) */
.admin-root { font-size: 18px; }

.admin { display: grid; grid-template-columns: 270px 1fr; min-height: calc(100vh - 48px); }
.admin aside {
  background: var(--color-white);
  border-right: 1px solid var(--color-border);
  padding: var(--space-xs);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}
.admin main { padding: var(--space-s) var(--space-m); max-width: 1040px; width: 100%; min-width: 0; }
.guide-list { list-style: none; padding: 0; margin: 0; }
.guide-list a {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-m);
  text-decoration: none;
  color: var(--color-text-black);
  font-size: var(--font-size-s);
  font-weight: bold;
}
.guide-list a .muted { font-weight: normal; font-size: var(--font-size-xs); }
.guide-list a:hover { background: var(--color-over-background); }
.guide-list a.active { background: var(--color-main-tint); }

.page-title { display: flex; align-items: flex-start; gap: var(--space-xs); margin-bottom: var(--space-s); }
.page-title h1 { font-size: var(--font-size-xl); margin-bottom: var(--space-x3s); display: flex; align-items: center; gap: var(--space-xxs); }
.back { margin: 0 0 var(--space-xxs); font-size: var(--font-size-s); }
.back a { text-decoration: none; }
.empty { margin: var(--space-xs) 0 0; }
.small { font-size: var(--font-size-xs); }
.lead { line-height: var(--leading-loose); }

.form > label:first-child { margin-top: 0; }
.label-note { font-weight: normal; color: var(--color-text-grey); font-size: var(--font-size-s); margin-left: var(--space-xxs); }
.form-foot { margin-top: var(--space-s); gap: var(--space-xs); }
.narrow-select { width: 12em; }
input.tiny { width: 5em; }
.item-edit { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.item-edit .num {
  flex: none; width: 22px; height: 22px; margin-top: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full); background: var(--color-head);
  font-size: var(--font-size-xs); font-weight: bold; color: var(--color-text-grey);
}
.item-fields { display: flex; flex-direction: column; gap: var(--space-x3s); }
.item-fields .memo { min-height: 32px; padding: 4px 12px; font-size: var(--font-size-s); border-color: var(--color-border); }
.item-actions { display: flex; margin-top: 6px; }
details.more { margin-top: var(--space-s); border-top: 1px solid var(--color-border); padding-top: var(--space-xs); }
details summary { cursor: pointer; font-weight: bold; color: var(--color-text-black); }
details summary .muted { font-weight: normal; }
.more-card summary { list-style-position: inside; }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--color-over-background); }
td a { text-decoration: none; font-weight: bold; color: var(--color-text-black); }

/* 結果 (まとめ) の画面: 読みやすさ優先で、行間と余白を広めに取り、1 行を長くしすぎない */
.result-card { padding: var(--space-m); }
.result-card h2 { font-size: var(--font-size-l); margin-bottom: var(--space-xs); }
.result-head { margin-bottom: var(--space-s); }
.lead { margin: 0; max-width: 42em; line-height: 1.9; }
.result-item { max-width: 42em; padding: 0 0 0 var(--space-s); margin-bottom: var(--space-m); border-left: 3px solid var(--color-border); }
.result-item:last-child { margin-bottom: 0; }
.result-item.covered { border-color: var(--color-success); }
.result-item.partial { border-color: var(--color-warning); }
.result-item-head { display: flex; align-items: center; gap: 12px; margin-bottom: var(--space-xxs); }
.result-item-head h3 { margin: 0; font-size: var(--font-size-m); }
.result-text { margin: 0; line-height: 1.9; }
.quotes { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-xxs); }
.quotes li {
  padding: var(--space-xxs) 12px;
  border-radius: var(--radius-m);
  background: var(--color-over-background);
  color: var(--color-text-grey);
  font-size: var(--font-size-s);
  line-height: var(--leading-loose);
}
.quotes li::before { content: "「"; }
.quotes li::after { content: "」"; }
.follow-ups { margin: 0; padding-left: 1.4em; max-width: 42em; line-height: 1.8; }
.follow-ups li + li { margin-top: var(--space-xxs); }
.follow-ups li::marker { color: var(--color-text-grey); }
.transcript p { margin: 0 0 var(--space-xs); display: grid; grid-template-columns: 4em 1fr; gap: var(--space-xxs); line-height: var(--leading-loose); max-width: 46em; }
.transcript .who { font-weight: bold; color: var(--color-text-grey); font-size: var(--font-size-s); padding-top: 2px; }
.steps-list { margin: 0; padding-left: 1.4em; line-height: 2; }

@media (max-width: 760px) {
  .app-header { padding: 0 var(--space-xs); }
  .admin { grid-template-columns: 1fr; }
  .admin aside { border-right: 0; border-bottom: 1px solid var(--color-border); }
  .admin main { padding: var(--space-xs); }
  .result-card { padding: var(--space-s) var(--space-xs); }
  .result-item { padding-left: var(--space-xs); }
  .page-title { flex-wrap: wrap; }
  .card { padding: var(--space-xs); }
  .table-wrap { margin: 0 calc(-1 * var(--space-xs)); padding: 0 var(--space-xs); }
  .transcript p { grid-template-columns: 1fr; gap: 0; }
}

/* ================= インタビュー画面 ================= */

.interview { max-width: 560px; margin: 0 auto; padding: var(--space-m) var(--space-xs) var(--space-xl); }
.page-head { margin-bottom: var(--space-s); }
.page-head h1 { margin-bottom: var(--space-x3s); }
.page-head .muted { margin: 0; }
.center-text { text-align: center; }

/* 始める前: カード 1 枚に手順を上から並べる */
.setup { padding: var(--space-s); }
.step-block { padding-bottom: var(--space-s); margin-bottom: var(--space-s); border-bottom: 1px solid var(--color-border); }
.step-block label:first-child { margin-top: 0; }
.step-block h2 { font-size: var(--font-size-m); margin-bottom: 12px; display: flex; align-items: center; }
.step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; margin-right: var(--space-xxs);
  border-radius: var(--radius-full);
  background: var(--color-main); color: var(--color-text-white);
  font-size: var(--font-size-xs);
}
.consent-text {
  white-space: pre-wrap;
  margin-bottom: 12px;
  color: var(--color-text-grey);
  font-size: var(--font-size-s);
  line-height: var(--leading-loose);
}
.meter { height: 6px; margin-top: 12px; border-radius: var(--radius-full); background: var(--color-head); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--color-success); transition: width .08s linear; }
.mic-help {
  margin-top: 12px; padding: 12px var(--space-xs);
  border-radius: var(--radius-m);
  background: var(--color-warning-tint); color: var(--color-text-black);
  font-size: var(--font-size-s);
}
.mic-help p + p { margin-top: var(--space-x3s); }
.topics { margin: 0; padding-left: 1.4em; color: var(--color-text-grey); }
.topics li { padding: 2px 0; }
.setup #start-hint { margin: 12px 0 0; }
.setup .error { margin: var(--space-xs) 0 0; text-align: center; }
.done { text-align: center; padding: var(--space-l) var(--space-s); }

/* インタビュアーの状態の絵。絵の中の動きは SVG 自身が持つ */
.avatar { flex: none; display: block; width: 150px; height: 150px; }

/* 始めた後: 左 = まとめ / 右 = 会話 */
.in-call .interview { max-width: 1200px; }
.call { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: var(--space-s); align-items: start; }
.call-side { display: flex; flex-direction: column; gap: var(--space-xs); }
.call-side .card { margin-bottom: 0; }

/* 左上: 状態の絵・状態・経過時間・終える */
.status-card { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--space-xs) var(--space-s) var(--space-s); }
.status-text { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.status-card .state { font-weight: bold; font-size: var(--font-size-l); }
.status-actions { margin-top: 12px; justify-content: center; }
.status-actions:not(:has(button:not([hidden]))) { display: none; }
.call-error { margin: 12px 0 0; }
.call-error:empty { display: none; }
.notes-card h2 { font-size: var(--font-size-m); }
.notes { list-style: none; padding: 0; margin: var(--space-xs) 0 0; }
.note { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--color-border); }
.note .mark {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; margin-top: 1px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border-input);
  color: var(--color-text-grey);
  font-size: var(--font-size-xs);
  font-weight: bold;
}
.note.covered .mark { background: var(--color-success); border-color: var(--color-success); color: var(--color-white); }
.note.partial .mark { border-color: var(--color-warning); color: var(--color-warning); }
.note.not_covered .note-title { color: var(--color-text-grey); }
.note-body { min-width: 0; }
.note-title { font-weight: bold; font-size: var(--font-size-s); }
.note-summary { margin: var(--space-x3s) 0 0; font-size: var(--font-size-s); line-height: var(--leading-loose); }
.note-empty { color: var(--color-text-grey); font-size: var(--font-size-s); padding-top: var(--space-xxs); }

.chat-card {
  display: flex; flex-direction: column;
  padding: 0;
  position: sticky; top: var(--space-xs);
  height: calc(100vh - 48px - 160px); min-height: 440px;
  margin-bottom: 0;
}
.chat-head { padding: var(--space-xs) var(--space-s); border-bottom: 1px solid var(--color-border); }
.chat-head h2 { font-size: var(--font-size-m); }
.chat { flex: 1; overflow-y: auto; padding: var(--space-s); display: flex; flex-direction: column; gap: 10px; }
.chat-empty { margin: auto; color: var(--color-text-grey); font-size: var(--font-size-s); }
.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: var(--leading-loose);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble.ai { align-self: flex-start; background: var(--color-main-tint); border-bottom-left-radius: var(--radius-s); }
.bubble.me { align-self: flex-end; background: var(--color-over-background); border-bottom-right-radius: var(--radius-s); }
.bubble.partial::after { content: "▍"; margin-left: 2px; color: var(--color-text-grey); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .bubble.partial::after { animation: none; } }
.call-foot { margin: 0; padding: 10px var(--space-s); border-top: 1px solid var(--color-border); color: var(--color-text-grey); font-size: var(--font-size-xs); }

@media (max-width: 860px) {
  .call { grid-template-columns: 1fr; gap: var(--space-xs); }
  .call-side { display: contents; }
  /* スマホ幅: 絵と状態を横に並べた段を一番上に、その下に会話、まとめ */
  .status-card { order: 1; flex-direction: row; flex-wrap: wrap; text-align: left; gap: var(--space-xs); padding: 12px var(--space-xs); }
  .status-text { align-items: flex-start; flex: 1; min-width: 0; }
  .status-card .state { font-size: var(--font-size-m); }
  .status-actions { justify-content: flex-start; margin-top: var(--space-xxs); }
  .call-error { flex-basis: 100%; }
  .chat-card { order: 2; position: static; height: 60vh; min-height: 340px; }
  .notes-card { order: 3; }
  .avatar { width: 110px; height: 110px; }
}

.row + .facts { margin-top: var(--space-xs); }
