/* ===========================================================================
   AILEX v2 デザインシステム
   モックアップ(仕様書 §10)の値をそのまま持ち込んでいる。
   現行の配色(ネイビー/ブルー)を継承しつつ、最小文字サイズを 12px に引き上げ、
   絵文字アイコンは SVG に置き換えた。
   =========================================================================== */

:root {
  --ink:            #1e293b;
  --ink-strong:     #0f172a;
  --ink-soft:       #64748b;
  --ink-faint:      #94a3b8;

  --surface:        #ffffff;
  --bg:             #f4f6f9;
  --line:           #e2e8f0;
  --line-strong:    #cbd5e1;

  --navy:           #0f172a;
  --navy-mid:       #1e293b;
  --navy-active:    #1e3a5f;

  --blue:           #2563eb;
  --blue-hover:     #1d4ed8;
  --blue-bg:        #dbeafe;
  --blue-text:      #1e40af;
  --blue-tint:      #eff6ff;

  --red:            #dc2626;
  --red-bg:         #fee2e2;
  --red-text:       #991b1b;
  --red-tint:       #fef2f2;

  --green:          #16a34a;
  --green-bg:       #dcfce7;
  --green-text:     #166534;

  --amber-bg:       #fef9c3;
  --amber-text:     #854d0e;

  --radius:         10px;
  --radius-sm:      8px;
  --shadow:         0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md:      0 4px 6px -1px rgba(0, 0, 0, 0.08);

  --sidebar-w:      224px;
}

* { box-sizing: border-box; }

/*
  hidden 属性は必ず効かせる。
  ブラウザ既定の [hidden]{display:none} は詳細度が低く、
  .palette-backdrop{display:flex} のようなクラス指定に負けてしまう。
  JS 側は hidden の付け外しで開閉を制御しているので、ここで優先させる。
*/
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink);
  background: var(--bg);
}

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

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* --- レイアウト ---------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  /* 設定の細目まで開くと 900px を超える。画面に貼り付いているので、はみ出た分はページを
     スクロールしても出てこなかった（9/26）。サイドバーの中だけでスクロールさせる */
  overflow-y: auto;
  overscroll-behavior: contain;
}

.logo { display: flex; align-items: center; padding: 0 14px 18px; }
/* ロゴは画像（9/29）。高さだけ決め、幅は比率で決まる。ロゴの紺はサイドバーの紺に沈むので白い台に載せる */
.logo-img { display: block; height: 32px; width: auto; box-sizing: content-box; padding: 6px 10px; background: #fff; border-radius: 6px; }

.search-trigger {
  display: flex; align-items: center; gap: 8px;
  margin: 0 6px 16px; padding: 9px 12px;
  background: var(--navy-mid); border: 1px solid #334155;
  border-radius: var(--radius-sm);
  color: var(--ink-faint); font-size: 13px;
  font-family: inherit; width: calc(100% - 12px); cursor: pointer; text-align: left;
}
.search-trigger:hover { border-color: #475569; color: #cbd5e1; }
.search-trigger .kbd {
  margin-left: auto; font-size: 11px; border: 1px solid #334155;
  border-radius: 4px; padding: 1px 5px; color: var(--ink-soft);
}

.sidebar-menu { display: flex; flex-direction: column; }
.nav-toggle { display: none; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  color: var(--ink-faint); font-size: 14px; font-weight: 500;
}
.nav-item:hover { background: var(--navy-mid); color: #e2e8f0; }
.nav-item.is-active { background: var(--navy-active); color: #fff; }
.nav-item svg { flex-shrink: 0; }

.sidebar-user {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-top: 1px solid var(--navy-mid);
}
.avatar {
  width: 32px; height: 32px; border-radius: 999px; background: var(--blue);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.sidebar-user-name { font-size: 13px; font-weight: 500; color: #e2e8f0; }
.sidebar-user-firm { font-size: 12px; color: var(--ink-soft); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.page-head {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 18px 32px 0;
}
.page-title { margin: 0; font-size: 22px; font-weight: 700; color: var(--ink-strong); }
.page-sub   { margin: 2px 0 0; font-size: 13px; color: var(--ink-soft); }
.page-body  { padding: 20px 32px 40px; }

/* --- 部品 ---------------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px 10px;
}
.card-title {
  margin: 0; font-size: 13px; font-weight: 700;
  color: var(--ink-soft); letter-spacing: 0.04em;
}

.grid { display: grid; gap: 20px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.row-flex { display: flex; align-items: center; gap: 12px; }
.push { margin-left: auto; }

.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 18px; border-top: 1px solid #f1f5f9;
}
.list-row:first-of-type { border-top: none; }
.list-row-strong { font-size: 14px; font-weight: 500; color: var(--ink-strong); }
.list-row-sub    { font-size: 12px; color: var(--ink-soft); }

.time {
  font-variant-numeric: tabular-nums; font-weight: 700;
  font-size: 14px; color: var(--ink-strong); width: 48px; flex-shrink: 0;
}

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700; padding: 2px 10px;
  border-radius: 999px; white-space: nowrap;
}
.chip-red   { background: var(--red-bg);   color: var(--red-text); }
.chip-blue  { background: var(--blue-bg);  color: var(--blue-text); }
.chip-green { background: var(--green-bg); color: var(--green-text); }
.chip-amber { background: var(--amber-bg); color: var(--amber-text); }
.chip-gray  { background: #f1f5f9;         color: #475569; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 700; font-family: inherit;
  cursor: pointer; border: 1px solid transparent;
  min-height: 40px;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: #475569; font-weight: 500; }
.btn-secondary:hover { background: #f8fafc; color: var(--ink); }
.btn-block { width: 100%; justify-content: center; }

.urgent {
  background: var(--red-tint);
  border-left: 3px solid var(--red);
  border-radius: var(--radius-sm);
  border-top: none;
  margin: 0 10px;
}

.meta { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 7px; }

.empty {
  padding: 28px 18px; text-align: center;
  font-size: 13px; color: var(--ink-faint);
}

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-soft);
  padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td { padding: 12px 16px; border-top: 1px solid #f1f5f9; }
table.data tr:hover td { background: #fafbfc; }
.num { font-variant-numeric: tabular-nums; }

/* --- 事件ワークスペース --------------------------------------------------- */

.matter-head {
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 16px 32px 0;
}
.tabs { display: flex; gap: 26px; margin-top: 12px; }
.tab {
  padding: 10px 4px; font-size: 14px; font-weight: 500;
  color: var(--ink-soft); border-bottom: 2px solid transparent;
  display: flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 700; }
.tab-count {
  font-size: 12px; font-weight: 700; background: #f1f5f9;
  color: var(--ink-soft); border-radius: 999px; padding: 0 7px;
}

.workspace { display: flex; gap: 20px; padding: 20px 32px 40px; align-items: flex-start; }
.workspace-main { flex: 1; min-width: 0; }

.ai-panel {
  width: 360px; flex-shrink: 0;
  background: #eef3fb; border: 1px solid #dbe3ef;
  border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column;
  position: sticky; top: 20px;
}
.ai-panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px; border-bottom: 1px solid #dbe3ef;
  font-size: 13px; font-weight: 700; color: var(--navy-active);
}
.ai-actions { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; }
.ai-action {
  display: flex; align-items: center; gap: 9px; width: 100%;
  text-align: left; padding: 10px 12px;
  background: var(--surface); border: 1px solid #dbe3ef;
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  color: var(--navy-active); cursor: pointer; font-family: inherit;
  min-height: 44px;
}
.ai-action:hover { border-color: var(--blue); color: var(--blue); }

.ai-thread { flex: 1; padding: 4px 16px; display: flex; flex-direction: column; gap: 10px; min-height: 80px; }
.ai-msg { max-width: 92%; font-size: 13px; line-height: 1.7; padding: 10px 13px; }
.ai-msg-user {
  align-self: flex-end; background: var(--blue); color: #fff;
  border-radius: 12px 12px 3px 12px; max-width: 85%;
}
.ai-msg-bot {
  align-self: flex-start; background: var(--surface);
  border: 1px solid #dbe3ef; border-radius: 12px 12px 12px 3px;
}
.ai-composer { padding: 12px 16px; border-top: 1px solid #dbe3ef; }
.ai-input {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 9px; padding: 4px 10px;
}
.ai-input input {
  flex: 1; border: none; outline: none; background: none;
  font-family: inherit; font-size: 13px; padding: 7px 2px; color: var(--ink);
}
.ai-note { font-size: 12px; color: var(--ink-faint); margin-top: 6px; }

/* --- 書面 ---------------------------------------------------------------- */

.paper {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  padding: 44px 56px; max-width: 760px; margin: 0 auto;
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", serif;
  font-size: 14px; line-height: 2.05;
  white-space: pre-wrap; word-break: break-word;
}
/* 手で書くときも、仕上がりと同じ見え方で書けるようにする */
textarea.paper {
  display: block; width: 100%; resize: vertical; min-height: 60vh;
  color: inherit; outline: none;
}
textarea.paper:focus { border-color: var(--blue, #2563eb); }

.version-chips { display: flex; align-items: center; gap: 8px; }
.vchip {
  font-size: 12px; font-weight: 700; padding: 4px 12px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-soft);
}
.vchip.is-active { background: var(--blue-bg); border-color: #93c5fd; color: var(--blue-text); }

/* --- フォーム ------------------------------------------------------------ */

.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 13px; font-weight: 700; color: #475569; }
.input, .textarea, .select {
  width: 100%; padding: 10px 12px; font-family: inherit; font-size: 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); min-height: 44px;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.7; }
.error-text { font-size: 12px; color: var(--red-text); }

/* パスワード欄の「表示」ボタン（ui.js が付ける） */
.pw-wrap { position: relative; display: block; min-width: 0; }
.pw-wrap > .input { padding-right: 64px; }
.pw-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  min-height: 32px; padding: 4px 10px; border: 0; border-radius: 6px;
  background: transparent; color: var(--ink-soft); font: inherit; font-size: 13px; cursor: pointer;
}
.pw-toggle:hover { background: var(--line); color: var(--ink); }
.pw-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

.alert {
  padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px;
  border: 1px solid transparent;
}
.alert-error { background: var(--red-tint); border-color: #fecaca; color: var(--red-text); }
.alert-info  { background: var(--blue-tint); border-color: #bfdbfe; color: var(--blue-text); }

.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; }

/* --- ログイン ------------------------------------------------------------ */

.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--navy);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border-radius: 14px; padding: 36px 32px; box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}
.auth-logo { text-align: center; margin-bottom: 24px; }
.auth-logo-img { display: inline-block; height: 64px; width: auto; max-width: 100%; }
/* 文中のリンクを色だけで見分けさせない（WCAG 1.4.1）。押せる高さは 24px 以上（2.5.8）。第 6 回検査 F-2・F-4 */
.auth-card a:not(.btn) { text-decoration: underline; text-underline-offset: 2px; display: inline-block; min-height: 24px; line-height: 24px; }
.auth-card input[type="checkbox"] { width: 20px; height: 20px; margin: 2px; flex-shrink: 0; }
.auth-card label:has(> input[type="checkbox"]) { min-height: 24px; cursor: pointer; }

/* --- レスポンシブ(§10: 外出先での参照を成立させる) --------------------- */

@media (max-width: 900px) {
  .shell { flex-direction: column; }

  /*
   * スマホでは 1 本のバー（ロゴ・検索・お知らせ・メニュー）にして、メニューは押したら縦に開く。
   * 横スクロールの帯だと検索ボタンの文字が縦に 5 行に折れてバーが画面の 1/6 を占め、
   * 「今日」「案件」より先の項目は存在に気づけなかった（9/26）
   */
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 40;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 8px 10px; gap: 4px; overflow: visible;
  }
  .logo { padding: 0 6px; margin-right: auto; }
  .logo-img { height: 24px; padding: 4px 8px; }
  .search-trigger .kbd, .search-label, .nav-notify .nav-label { display: none; }
  .search-trigger, .nav-toggle, .nav-notify {
    width: 44px; height: 44px; margin: 0; padding: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
  }
  .search-trigger { background: transparent; border: none; color: #cbd5e1; }
  .nav-notify { color: #cbd5e1; }
  .nav-toggle { background: none; border: none; color: #fff; cursor: pointer; }
  .nav-toggle[aria-expanded="true"] { background: var(--navy-active); }

  /* 開いたときだけバーの下に全幅で出す。中が長ければその中でスクロールする */
  .sidebar-menu, .sidebar-user { display: none; order: 10; width: 100%; }
  .sidebar.is-open .sidebar-menu {
    display: flex; max-height: calc(100vh - 140px); overflow-y: auto;
    overscroll-behavior: contain; padding: 8px 0 4px; border-top: 1px solid var(--navy-mid); margin-top: 6px;
  }
  .sidebar.is-open .sidebar-user { display: flex; order: 11; margin-top: 0; }

  .page-head, .matter-head { padding: 16px 16px 0; }
  .page-body { padding: 16px 16px 32px; }
  /* 1fr だと最小幅が中身に引っ張られ、長い 1 行があるとカードごと画面外へ広がった（今日で 617px） */
  .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .span-2, .span-3 { grid-column: auto; }

  .workspace { flex-direction: column; padding: 16px; }
  .ai-panel { width: 100%; position: static; }
  /* タブは縮めずに横スクロールさせる。縮むと「概要」が 1 文字ずつ縦に折れた */
  .tabs { overflow-x: auto; gap: 18px; scrollbar-width: none; }
  .tab { flex-shrink: 0; white-space: nowrap; }
  .paper { padding: 24px 20px; }
}

/* --- ⌘K 横断検索パレット ------------------------------------------------- */

.palette-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 20px 20px;
}
.palette {
  width: 100%; max-width: 620px;
  background: var(--surface); border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.3);
  overflow: hidden; display: flex; flex-direction: column;
  max-height: 70vh;
}
.palette-input-row {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.palette-input-row input {
  flex: 1; border: none; outline: none; background: none;
  font-family: inherit; font-size: 16px; color: var(--ink);
}
.palette-results { overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; color: inherit;
}
.palette-item.is-active { background: var(--blue-tint); }
.palette-item-body { min-width: 0; display: flex; flex-direction: column; }
.palette-item-title {
  font-size: 14px; font-weight: 500; color: var(--ink-strong);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.palette-item-sub {
  font-size: 12px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- コンフリクトチェック ------------------------------------------------ */

.conflict-hit {
  border-left: 3px solid var(--red);
  background: var(--red-tint);
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
}

/* --- パイプライン -------------------------------------------------------- */

.pipeline {
  display: flex; gap: 14px;
  overflow-x: auto; padding-bottom: 12px;
  align-items: flex-start;
}
.pipeline-column {
  flex: 0 0 260px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.pipeline-column-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--ink-soft);
  padding-bottom: 10px; margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.pipeline-column-head span:first-child { flex: 1; min-width: 0; }
.pipeline-card {
  display: block; color: inherit;
  background: #fbfcfe; border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 11px 12px;
}
.pipeline-card:hover { border-color: var(--blue); color: inherit; }
.pipeline-card-title {
  font-size: 13px; font-weight: 500; color: var(--ink-strong);
  line-height: 1.6;
}

/* 系統の名前は細目を開閉するだけ。開いているかを右端の矢印で見せる */
.nav-group > summary { list-style: none; cursor: pointer; user-select: none; }
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::after {
  content: ""; margin-left: auto; width: 7px; height: 7px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s; opacity: .7;
}
.nav-group[open] > summary::after { transform: rotate(45deg); }
.nav-group > summary:focus-visible { outline: 2px solid #93c5fd; outline-offset: -2px; }

/* 開いている系統の細目。常時出すとナビが長くなるので、そのときだけ見せる */
.nav-children {
  display: flex; flex-direction: column;
  margin: 2px 0 6px 26px; padding-left: 12px;
  border-left: 1px solid #334155;
}
.nav-child {
  font-size: 13px; color: var(--ink-soft);
  padding: 7px 10px; border-radius: 6px;
}
.nav-child:hover { color: #e2e8f0; background: var(--navy-mid); }
.nav-child.is-active { color: #fff; font-weight: 500; }
/* 運営者だけに見える細目の印 */
.nav-child-lock { margin-left: 6px; vertical-align: -1px; opacity: .75; }


/* --- ヘルプ（右下常駐） ------------------------------------------------- */

.help-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 90;
  width: 48px; height: 48px; border-radius: 999px;
  background: var(--navy); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.28);
}
.help-fab:hover { background: var(--navy-active); }

.help-panel {
  position: fixed; right: 20px; bottom: 78px; z-index: 90;
  width: 340px; max-height: 60vh;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 16px 32px rgba(0, 0, 0, 0.18);
  display: flex; flex-direction: column; overflow: hidden;
}
.help-panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  color: var(--navy-active);
}
.help-thread {
  flex: 1; overflow-y: auto; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.help-composer { padding: 10px 14px 14px; border-top: 1px solid var(--line); }

@media (max-width: 640px) {
  .help-panel { right: 12px; left: 12px; width: auto; }
}

/* ===== 表・数値・補助表示 ============================================== */

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-weight: 600; color: var(--ink-soft);
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table-compact td, .table-compact th { padding: 6px 8px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 表は横に伸びる。画面ごと横スクロールさせず、表の中だけで収める。 */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.text-muted { color: var(--ink-soft); }
.prose { font-size: 14px; line-height: 1.8; color: var(--ink); }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* 兆候の色。既存の chip-* に別名を与え、意味で呼べるようにする。 */
.chip-muted { background: #f1f5f9;         color: #475569; }
.chip-warn  { background: var(--amber-bg); color: var(--amber-text); }
.chip-bad   { background: var(--red-bg);   color: var(--red-text); }
.chip-good  { background: var(--green-bg); color: var(--green-text); }

.empty-state { padding: 32px 20px; text-align: center; color: var(--ink-soft); }

.stat-row { display: flex; flex-wrap: wrap; gap: 12px; }
.stat {
  flex: 1; min-width: 130px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; gap: 2px;
}
.stat-value { font-size: 22px; font-weight: 700; color: var(--ink-strong); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--ink-soft); }

/* ===== 入力の並び ====================================================== */

.field-label { font-size: 13px; font-weight: 600; color: #475569; display: flex; align-items: center; gap: 6px; }
.field-help  { font-size: 12px; color: var(--ink-soft); line-height: 1.6; }
.field-row   { display: flex; gap: 12px; align-items: flex-start; }
.field-row > .field { flex: 1; min-width: 0; }

/* ===== スマートフォン ================================================== */

/*
 * iOS Safari は 16px 未満の入力欄に焦点が当たると、勝手に拡大する。
 * 一度拡大されると元の倍率に戻らず、以降の操作が続けて破綻する。
 * viewport で拡大を禁じる手もあるが、それは弱視の利用者から
 * 拡大手段を奪うので採らない。文字を大きくして防ぐ。
 */
@media (max-width: 640px) {
  .input, .textarea, .select { font-size: 16px; padding: 11px 12px; }

  /* 指で押す対象は 44px 角を下回らせない */
  .btn { min-height: 44px; padding: 10px 16px; }
  .nav-item, .nav-child { min-height: 40px; display: flex; align-items: center; }
  .list-row { padding-top: 12px; padding-bottom: 12px; }

  .field-row { flex-direction: column; gap: 10px; }
  .field-row > .field { max-width: none !important; width: 100%; }

  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-head .push { margin-left: 0; }
  .page-title { font-size: 19px; }

  /* 見出し横のボタン群は、横に溢れずに折り返す */
  .page-head > div[style*="display:flex"] { flex-wrap: wrap; }

  .stat { min-width: calc(50% - 6px); padding: 12px; }
  .stat-value { font-size: 18px; }

  /* 表は画面幅で潰れるより、表の中で横スクロールさせる */
  .card > .table, .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  .row-flex { flex-wrap: wrap; }
  .trend { height: 90px; }

  /* iPhone の下端（ホームバー）に隠れないようにする */
  .page-body { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  .help-fab  { bottom: calc(16px + env(safe-area-inset-bottom)); right: 16px; }
  .help-panel { bottom: calc(74px + env(safe-area-inset-bottom)); }
}

/* 長い文字列（メールアドレス・URL・事件番号）で横スクロールを起こさせない */
.list-row-strong, .list-row-sub, .prose, .stat-label { overflow-wrap: anywhere; }

/* ===== 書類の並べ替え・取り込み ======================================== */

.doc-grip { color: var(--ink-faint); cursor: grab; font-size: 15px; flex-shrink: 0; user-select: none; }
.doc-row.is-dragging { opacity: .4; }
.doc-row { transition: background .12s; }
.doc-row .doc-main { min-width: 0; flex: 1; }
.doc-row[draggable="true"]:hover .doc-grip { color: var(--ink-soft); }

.reorder-bar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; background: var(--amber-bg);
  border-top: 1px solid var(--line); font-size: 13px;
}

.drop-zone {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, .55); color: #fff;
  font-size: 17px; font-weight: 600; pointer-events: none;
}

/* ui.js の data-confirm。ブラウザのダイアログの代わりに、押した所の隣に出す */
.inline-confirm {
  display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 6px 0 6px 8px; padding: 8px 10px;
  background: var(--amber-bg); color: var(--amber-text);
  border-radius: var(--radius-sm); font-size: 13px; line-height: 1.5;
  max-width: 100%;
}
.inline-confirm .btn { min-height: 30px; padding: 4px 12px; font-size: 13px; }

.btn-ghost {
  background: none; border: 1px solid var(--line);
  color: var(--ink-soft); font-size: 12px;
  padding: 4px 10px; min-height: 30px; border-radius: var(--radius-sm);
}
.btn-ghost:hover { background: var(--surface-alt); color: var(--ink); }

/*
 * 掴む操作は指では難しい。狭い画面では掴む所を隠し、
 * 上下ボタンに切り替える。並べ替え自体は残す。
 */
.doc-move { display: none; gap: 4px; flex-shrink: 0; }
.doc-move .btn { padding: 4px 8px; }

@media (max-width: 640px) {
  .doc-grip { display: none; }
  .doc-move { display: flex; }
  .doc-row { flex-wrap: wrap; }
  /* 名前は 1 行まるごと使う。flex:1 のままだと折り返す前に幅 0 まで縮み、1 文字ずつ縦に並ぶ（9/26） */
  .doc-row .doc-main { flex: 1 1 100%; }
  .reorder-bar { flex-wrap: wrap; }
}

/* 掴む操作ができない環境では、常に上下ボタンを出す */
@media (hover: none) and (pointer: coarse) {
  .doc-grip { display: none; }
  .doc-move { display: flex; }
}

/* ===== 当事者の連絡先 ================================================== */

.party-row-group + .party-row-group { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }

.party-detail { margin: 6px 0 0 4px; }
.party-detail > summary {
  cursor: pointer; font-size: 12px; color: var(--ink-soft);
  display: flex; align-items: center; gap: 6px; padding: 4px 0;
  list-style: none;
}
.party-detail > summary::before { content: '▸'; font-size: 10px; }
.party-detail[open] > summary::before { content: '▾'; }
.party-detail > summary::-webkit-details-marker { display: none; }

.party-detail-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px; padding: 10px 0 4px;
}

@media (max-width: 900px) { .party-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .party-detail-grid { grid-template-columns: 1fr; }
  /* 当事者の行は狭い画面では縦に積む */
  .party-row { grid-template-columns: 1fr !important; }
}

/* mints に出すときのファイル名。触れば選択できるように全選択にする。 */
.mints-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--blue-tint);
  color: var(--blue-text);
  padding: 2px 6px;
  border-radius: 4px;
  user-select: all;
  word-break: break-all;
}

/* ===== お知らせ ======================================================== */

/*
 * 縦位置は 50% で取る。固定の px で置くと、行の高さが変わるたびに
 * 微妙にずれる（サイドバーが横並びになる幅で実際にずれていた）。
 */
.unread-badge {
  position: absolute; top: 50%; right: 8px; transform: translateY(-50%);
  min-width: 18px; height: 18px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
  background: var(--red, #dc2626); color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 999px;
}

.unread-dot {
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--blue, #2563eb); flex-shrink: 0;
}

.list-row.is-unread { background: var(--blue-bg, #eff6ff); }

/* 狭い画面ではお知らせがアイコンだけのボタンになる。バッジを右上に寄せる */
@media (max-width: 900px) {
  .nav-notify .unread-badge { top: 4px; right: 0; transform: none; }
}

/* 期限が来ているものは、色で分かるようにする */
.card.is-due { border-color: var(--amber-text, #b45309); background: var(--amber-bg, #fffbeb); }

/*
 * 画面ごとに置いた固定列のグリッド（"140px 1fr" など）は、
 * 狭い画面では2列目が潰れる。インラインで指定されているので
 * !important で上書きし、縦に積む。
 */
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr !important; }
  .grid-3, .grid-2 { grid-template-columns: 1fr !important; }
}

/* ===== 請求書の項目選択 ================================================ */

.entry-group + .entry-group { border-top: 1px solid var(--line); }
/* 請求先で絞ると先頭が入れ替わる。見えている先頭に区切り線は要らない。 */
.entry-group.is-first-visible { border-top: 0; }
.entry-group-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; background: var(--surface-alt, #f8fafc);
  font-size: 13px;
}
.entry-group-sums {
  display: flex; flex-wrap: wrap; gap: 14px;
  padding: 8px 18px 12px 32px;
  font-size: 12px; color: var(--ink-soft);
}

/* ===== 行の編集 ======================================================== */

.fee-edit-form { padding: 12px 18px; background: var(--surface-alt, #f8fafc); border-bottom: 1px solid var(--line); }

/* ===== AI相談 ========================================================== */

.ai-turn.is-mine { background: var(--blue-bg, #eff6ff); }

/* ===== 事務所のアカウントでのログイン ================================== */

.sso-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 18px 0 4px; color: var(--ink-faint); font-size: 12px;
}
.sso-divider::before, .sso-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}

.alert-warn { background: var(--amber-bg); color: var(--amber-text); border: 1px solid var(--amber-text); padding: 14px 16px; border-radius: var(--radius-sm); }

/* ===== ご契約の状態 ==================================================== */

.plan-notice {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin: 16px 24px 0; padding: 14px 18px;
  border-radius: var(--radius-sm); border: 1px solid;
}
.plan-notice-warn { background: var(--amber-bg); border-color: var(--amber-text); }
.plan-notice-info { background: var(--blue-bg);  border-color: var(--blue); }

.plan-notice-title { font-size: 14px; font-weight: 700; color: var(--ink-strong); }
.plan-notice-body  { font-size: 13px; color: var(--ink); margin-top: 2px; line-height: 1.7; }

@media (max-width: 640px) {
  .plan-notice { margin: 12px 16px 0; }
  .plan-notice .btn { flex: 1; }
}

/* --- スマホの一覧表 ----------------------------------------------------- */

/*
 * 5〜6 列の表を 390px に押し込むと、事件名が 1 文字ずつ折れて読めなかった（9/26）。
 * 狭い画面では 1 行を 1 枚のカードにし、見出しを各値の前に出す（見出しは ui.js が data-label に写す）。
 */
@media (max-width: 640px) {
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data thead { display: none; }
  table.data tr { padding: 12px 16px; border-top: 1px solid var(--line); }
  table.data tr:first-child { border-top: none; }
  table.data tr:hover td { background: none; }
  table.data td {
    display: flex; gap: 12px; padding: 3px 0; border-top: none;
    text-align: left !important; overflow-wrap: anywhere;
  }
  table.data td[data-label]::before {
    content: attr(data-label); flex: 0 0 6.5em;
    font-size: 12px; color: var(--ink-soft);
  }
  /* 先頭の列（事件名・氏名など）はカードの見出しにする */
  table.data td:first-child { font-size: 15px; font-weight: 700; padding-bottom: 6px; }
  table.data td:first-child::before { display: none; }
  table.data td[colspan] { display: block; }
  .card:has(> table.data) { overflow-x: visible; }
}

/* 設定の利用者の行。狭い画面では権限・単価・最終利用を名前の下に回す */
@media (max-width: 640px) {
  .member-row { flex-wrap: wrap; }
  .member-row > div:nth-child(2) { flex: 1 1 calc(100% - 50px) !important; }
  .member-row > form.row-flex { margin-left: 44px; }
  .member-row > .member-last-use { width: auto !important; text-align: left !important; }
}

/* 案内の帯（plan-notice）は、狭い画面では文章とボタンを縦に積む。横並びだと本文が 1 行 12 文字ほどに詰まった */
@media (max-width: 640px) {
  .plan-notice { flex-direction: column; align-items: stretch; }
  .plan-notice .btn { width: 100%; justify-content: center; }
}

/* カード見出しの横の「足す」などを開いたら、フォームは見出しの下に全幅で出す */
.card-head { flex-wrap: wrap; }
.card-head > details[open] { flex-basis: 100%; }
.card-head > details[open] > summary { text-align: right; }

/*
 * 書面の検査（9/26）。重さの順に 1 件 1 行。理由と根拠は開いたときだけ出す。
 * 「本文へ」で本文の該当箇所に飛び、【要確認】の欄は本文でも色を付ける。
 */
.rv { padding: 14px 16px; margin-bottom: 16px; font-size: 13px; line-height: 1.7; }
.rv p { margin: 0; }
.rv .btn-sm { min-height: 30px; padding: 4px 10px; font-size: 12px; }
.rv-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rv-counts { display: flex; flex-wrap: wrap; gap: 6px; }
.rv-counts .chip { text-decoration: none; }
.rv-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.rv-status { margin-top: 8px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 4px; }
.rv-summary { color: var(--ink-strong); }
.rv-group { margin-top: 12px; }
.rv-group-title { font-weight: 600; font-size: 12px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.rv-group-title .text-muted { font-weight: 400; margin-left: 6px; }
.rv-group-fold > summary { cursor: pointer; }
.rv-next { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; gap: 8px; }
.rv-next ol { margin: 0; padding-left: 1.4em; }
.rv-record { display: flex; flex-direction: column; gap: 6px; }
.rv-record .btn, .rv-finalize .btn { align-self: flex-start; }
.rv-finalize { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rv-item { border-bottom: 1px solid var(--line); }
.rv-item > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 7px 2px;
}
.rv-item > summary::-webkit-details-marker { display: none; }
.rv-item > summary:hover { background: var(--bg-soft, #f8fafc); }
.rv-item .chip { flex-shrink: 0; }
.rv-where { flex-shrink: 0; font-size: 12px; color: var(--ink-soft); min-width: 3.5em; }
.rv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-strong); }
.rv-item[open] .rv-title { white-space: normal; }
.rv-jump {
  flex-shrink: 0; border: 1px solid var(--line); background: none; border-radius: 6px;
  font-size: 11px; padding: 2px 8px; color: var(--blue-text); cursor: pointer;
}
.rv-body { padding: 2px 4px 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.rv-fold { margin-top: 10px; }
.rv-fold > summary { cursor: pointer; color: var(--ink-soft); font-size: 12px; padding: 4px 0; }
.rv-empty { margin-top: 10px !important; color: var(--green-text); }
.rv-note { margin-top: 10px !important; }
.paper mark.rv-todo { background: var(--amber-bg); color: var(--amber-text); border-radius: 3px; padding: 0 2px; }
.paper ::selection { background: #fde68a; }

@media (max-width: 640px) {
  .rv-actions { margin-left: 0; width: 100%; }
  .rv-where { min-width: 0; }
}

/* 書面の画面。左に生成の操作、右に検査と本文。狭い画面では縦に積み、本文を先に出す（9/26） */
.draft-layout { display: flex; gap: 20px; align-items: flex-start; }
.draft-aside { width: 300px; flex-shrink: 0; }
@media (max-width: 900px) {
  .draft-layout { flex-direction: column; align-items: stretch; }
  .draft-aside { width: auto; order: 2; }
}

/* 相談の準備（カルテ）の項目。チェックして詳細シートで聞ける（9/27） */
.brief-items { list-style: none; margin: 0; padding: 0; font-size: 13px; line-height: 1.8; }
.brief-items li { padding: 2px 0; }
.brief-items label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.brief-items input { margin-top: 5px; flex-shrink: 0; }

/* 書面の本文を Markdown として描画したもの（第7回検証 R-3）。改行は <br> で残る */
.paper.paper-rendered { white-space: normal; }
.paper-rendered p { margin: 0 0 1em; }
.paper-rendered h1, .paper-rendered h2, .paper-rendered h3, .paper-rendered h4 { font-size: 1em; font-weight: 700; margin: 1.2em 0 .4em; }
.paper-rendered h1 { font-size: 1.15em; text-align: center; }
.paper-rendered table { border-collapse: collapse; width: 100%; margin: .6em 0 1em; font-size: .95em; }
.paper-rendered th, .paper-rendered td { border: 1px solid var(--line-strong, #94a3b8); padding: 2px 8px; vertical-align: top; font-weight: 400; }
.paper-rendered blockquote { margin: 0 0 1em 1em; padding: 0; }
.paper-rendered hr { display: none; }
.paper-rendered ul, .paper-rendered ol { margin: 0 0 1em; padding-left: 1.5em; }

/* 小さいボタン。以前は検査欄の中でしか効いていなかった */
.btn.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 12px; }

/* AI の待ち時間の表示（ui.js の aiWait。9/29）。動いている印・いま何をしているか・経過時間 */
.ai-wait { margin-bottom: 16px; }
.ai-wait-overlay {
  position: fixed; inset: 0; z-index: 1000; margin: 0;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(15, 23, 42, 0.35);
}
.ai-wait-card {
  display: flex; gap: 16px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--blue-bg); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-md);
}
.ai-wait-overlay .ai-wait-card { width: 100%; max-width: 440px; box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18); }
.ai-wait-dots { display: flex; gap: 5px; padding-top: 7px; flex-shrink: 0; }
.ai-wait-dots span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--blue);
  animation: ai-wait-pulse 1.2s ease-in-out infinite;
}
.ai-wait-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-wait-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-wait-pulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}
.ai-wait-body { min-width: 0; flex: 1; }
.ai-wait-title { font-weight: 700; color: var(--ink-strong); font-size: 15px; }
.ai-wait-step { margin-top: 4px; font-size: 13px; color: var(--blue-text); min-height: 1.4em; }
.ai-wait-meta { margin-top: 8px; font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.ai-wait-note { margin-top: 4px; font-size: 12px; color: var(--ink-soft); }
.ai-wait-note:empty { display: none; }
