/* ============================================================
   action-manager 共通デザインシステム（Linear風）
   - バニラCSS。ビルド不要。全ページで読み込む。
   - ダーク基調（既定）＋ ライト（prefers-color-scheme / data-theme）
   ============================================================ */

:root {
  /* ダークテーマ（既定） */
  --bg: #0f0f12;
  --surface: #17171c;
  --surface-2: #1d1d24;
  --border: #26262e;
  --text: #e6e6e9;
  --text-sub: #9a9aa5;
  --text-muted: #6b6b76;
  --accent: #5e6ad2;
  --accent-weak: rgba(94, 106, 210, .15);
  --todo: #8a8a94;
  --doing: #4c8dff;
  --waiting: #e2a03f;
  --done: #3fb950;
  --urgent: #e5484d;

  --radius: 6px;
  --radius-lg: 10px;
  --gap: 8px;
  --sidebar-w: 220px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", sans-serif;
  --shadow: 0 4px 20px rgba(0, 0, 0, .35);
}

/* ライトテーマ */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --surface: #f7f7f8;
    --surface-2: #f0f0f2;
    --border: #e6e6e9;
    --text: #1a1a1e;
    --text-sub: #6b6b76;
    --text-muted: #9a9aa5;
    --accent-weak: rgba(94, 106, 210, .1);
    --shadow: 0 4px 20px rgba(0, 0, 0, .12);
  }
}
:root[data-theme="light"] {
  --bg: #ffffff; --surface: #f7f7f8; --surface-2: #f0f0f2; --border: #e6e6e9;
  --text: #1a1a1e; --text-sub: #6b6b76; --text-muted: #9a9aa5;
  --accent-weak: rgba(94, 106, 210, .1); --shadow: 0 4px 20px rgba(0, 0, 0, .12);
}
:root[data-theme="dark"] {
  --bg: #0f0f12; --surface: #17171c; --surface-2: #1d1d24; --border: #26262e;
  --text: #e6e6e9; --text-sub: #9a9aa5; --text-muted: #6b6b76;
  --accent-weak: rgba(94, 106, 210, .15); --shadow: 0 4px 20px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* ルート17pxで rem 基準を一律 +6% スケール（フォント小さい問題への全体対応） */
html { font-size: 17px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: .9rem; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.15rem; margin: 0; font-weight: 650; }
h2 { font-size: .95rem; margin: 0 0 10px; font-weight: 600; }
h3 { font-size: .82rem; margin: 0 0 8px; font-weight: 600; color: var(--text-sub); text-transform: none; }

/* ---------- レイアウト（サイドバー＋メイン） ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); padding: 14px 10px;
  display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand {
  font-weight: 700; font-size: .95rem; padding: 6px 10px 12px;
  display: flex; align-items: center; gap: 8px;
}
.sidebar .brand .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border-radius: var(--radius); color: var(--text-sub); font-weight: 500;
  cursor: pointer; font-size: .875rem; white-space: nowrap;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-weak); color: var(--text); }
.nav-item .ico { width: 18px; text-align: center; opacity: .9; }
.nav-item .nav-badge {
  margin-left: auto; background: var(--urgent); color: #fff; font-size: .68rem;
  min-width: 18px; height: 18px; border-radius: 9px; display: inline-flex;
  align-items: center; justify-content: center; padding: 0 5px; font-weight: 700;
}
.sidebar .spacer { flex: 1; }
.nav-divider { border-top: 1px solid var(--border); margin: 8px 6px; }
.sidebar .foot { padding: 8px 10px; color: var(--text-muted); font-size: .78rem; border-top: 1px solid var(--border); }

.main { flex: 1; min-width: 0; padding: 20px 24px 60px; max-width: 1000px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.topbar .sub { color: var(--text-sub); font-size: .82rem; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; }

/* モバイル用ハンバーガー（既定は非表示） */
.menu-btn {
  display: none; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); width: 34px; height: 34px; border-radius: var(--radius);
  cursor: pointer; font-size: 1.1rem;
}
.scrim { display: none; }

/* ---------- カード ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; margin-bottom: 14px;
}
.card.pad-sm { padding: 12px; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-weight: 600;
  font-size: .82rem; cursor: pointer; font-family: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: .78rem; }
/* 指で押せる最小タップ領域を確保（誤タップ・押しにくさ対策） */
.btn { min-height: 40px; }
.btn-sm { min-height: 34px; }

/* ---------- バッジ／ステータス ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: .72rem;
  padding: 2px 9px; border-radius: 99px; background: var(--surface-2);
  color: var(--text-sub); font-weight: 600; border: 1px solid var(--border);
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.s-todo    { color: var(--todo); }    .bg-todo    { background: var(--todo); }
.s-doing   { color: var(--doing); }   .bg-doing   { background: var(--doing); }
.s-waiting { color: var(--waiting); } .bg-waiting { background: var(--waiting); }
.s-done    { color: var(--done); }    .bg-done    { background: var(--done); }
.s-urgent  { color: var(--urgent); }  .bg-urgent  { background: var(--urgent); }
.s-lead{color:var(--todo)} .s-contacted{color:var(--waiting)} .s-meeting{color:var(--doing)}
.s-proposal{color:var(--accent)} .s-won{color:var(--done)} .s-lost{color:var(--urgent)}
.s-client{color:var(--done)} .s-referrer{color:var(--accent)}
.bg-lead{background:var(--todo)} .bg-contacted{background:var(--waiting)} .bg-meeting{background:var(--doing)}
.bg-proposal{background:var(--accent)} .bg-won{background:var(--done)} .bg-lost{background:var(--urgent)}
.bg-client{background:var(--done)} .bg-referrer{background:var(--accent)}

/* ---------- 密なリスト（Linear風） ---------- */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 8px; padding: 9px 8px;
  border-bottom: 1px solid var(--border); cursor: pointer; min-height: 36px;
  flex-wrap: wrap;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface-2); }
/* タイトルを最優先で確保（最低幅を持たせ、余った要素は次行に折り返す） */
.list-row .title { font-weight: 500; flex: 1 1 55%; min-width: 150px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .meta { color: var(--text-sub); font-size: .78rem; flex-shrink: 0; }
.list-row .badge, .list-row .pill { flex-shrink: 0; }
.overdue { color: var(--urgent); font-weight: 600; }

/* ---------- KPI グリッド ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.kpi { background: var(--surface-2); border-radius: var(--radius); padding: 12px; }
.kpi .label { font-size: .74rem; color: var(--text-sub); }
.kpi .val { font-size: 1.4rem; font-weight: 700; margin-top: 2px; }
.kpi .tgt { font-size: .72rem; color: var(--done); margin-top: 2px; }
.kpi .tgt.bad { color: var(--urgent); }

/* ---------- フォーム ---------- */
.field { margin-bottom: 12px; }
label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 5px; color: var(--text-sub); }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
}
/* font-size:16px は iOS のフォーカス時オートズーム（16px未満で発動）を防ぐため固定 */
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 72px; line-height: 1.6; }
.row { display: flex; gap: 10px; } .row > * { flex: 1; min-width: 0; }

/* ---------- テーブル ---------- */
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--text-sub); font-weight: 600; font-size: .76rem; }
.table-wrap { overflow-x: auto; }

/* ---------- ファネル ---------- */
.funnel-row { display: grid; grid-template-columns: 68px 1fr auto; gap: 10px; align-items: center; margin-bottom: 7px; }
.funnel-row .fl { font-size: .8rem; color: var(--text-sub); }
.funnel-bar { height: 22px; background: var(--surface-2); border-radius: var(--radius); overflow: hidden; }
.funnel-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--doing)); }
.funnel-row .fv { font-size: .78rem; color: var(--text-sub); white-space: nowrap; }

/* ---------- 進捗ゲージ ---------- */
.gauge { display: grid; grid-template-columns: 90px 1fr 84px; gap: 10px; align-items: center; margin-bottom: 8px; }
.gauge .gl { font-size: .82rem; }
.gauge .gbar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.gauge .gbar > span { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.gauge .gbar > span.warn { background: var(--waiting); }
.gauge .gbar > span.bad { background: var(--urgent); }
.gauge .gv { font-size: .78rem; color: var(--text-sub); text-align: right; }

/* ---------- 汎用 ---------- */
.muted { color: var(--text-muted); }
.sub { color: var(--text-sub); font-size: .82rem; }
kbd { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; font-size: .85em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
/* ニーズピッカー（チェック式チップ） */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; cursor: pointer; }
.chip input { display: none; }
.chip span {
  font-size: .78rem; padding: 4px 10px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-sub);
}
.chip input:checked + span { background: var(--accent-weak); border-color: var(--accent); color: var(--text); font-weight: 600; }
.callout { border-left: 3px solid var(--accent); background: var(--accent-weak); padding: 10px 12px; border-radius: 6px; }
.callout.warn { border-left-color: var(--waiting); background: rgba(226,160,63,.12); }
.pill { font-size: .72rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-sub); }
.msg { margin-top: 10px; font-weight: 600; text-align: center; }
.msg.ok { color: var(--done); } .msg.err { color: var(--urgent); }
.err-line { color: var(--urgent); font-size: .84rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
details > summary { cursor: pointer; font-weight: 600; color: var(--accent); list-style: none; }
details > summary::-webkit-details-marker { display: none; }
hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* ---------- Markdown表示（コーチの方針など） ---------- */
.md-p { margin: 6px 0; line-height: 1.75; }
.md-h { margin: 14px 0 6px; font-weight: 700; }
h2.md-h { font-size: 1rem; } h3.md-h { font-size: .92rem; } h4.md-h { font-size: .86rem; color: var(--text-sub); }
.md-h:first-child { margin-top: 0; }
.md-ul, .md-ol { margin: 6px 0; padding-left: 1.3em; line-height: 1.7; }
.md-ul li, .md-ol li { margin: 3px 0; }
.md-table { overflow-x: auto; margin: 10px 0; }
.md-table table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.md-table th, .md-table td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md-table thead th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
.md strong { font-weight: 700; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
/* コーチの方針: 既定は約3行にクランプし、下端をフェード。「全文を読む」で解除 */
.coach-clamp {
  max-height: 5.6em; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 68%, transparent);
          mask-image: linear-gradient(to bottom, #000 68%, transparent);
}

/* ---------- 今日の3件（どれも同格に目立たせ、順番は番号バッジで示すだけ） ---------- */
.hero-card { border-color: var(--accent); border-width: 1px; }
.hero-label { font-size: .78rem; font-weight: 700; color: var(--accent); letter-spacing: .02em; }
.hero-done { text-align: center; padding: 14px 0 6px; }
.hero-done .big { font-size: 1.15rem; font-weight: 700; margin-bottom: 4px; }
.focus-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.focus-head { display: flex; align-items: center; gap: 10px; }
.fnum {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-sub);
  font-size: .78rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.focus-row.first .fnum { background: var(--accent); border-color: var(--accent); color: #fff; }
.focus-title { color: var(--text); font-weight: 600; font-size: .95rem; line-height: 1.45; }
.focus-title:hover { color: var(--accent); }
.focus-sub { color: var(--text-sub); font-size: .8rem; margin: 2px 0 8px 32px; }
.focus-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-left: 32px; }
/* ✓のあとの「次の予定」ミニパネル（放置させないための1タップ導線） */
.next-step {
  border: 1px dashed var(--accent); background: var(--accent-weak);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px;
}
.triage-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 0 2px; }
.triage-chips button { font-size: .74rem; padding: 3px 10px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-sub); cursor: pointer; font-family: inherit; }
.triage-chips button:hover { border-color: var(--accent); color: var(--text); }
.mini-btn { flex-shrink: 0; font-size: .72rem; padding: 2px 8px; border-radius: var(--radius); border: 1px solid var(--border); background: transparent; color: var(--text-sub); cursor: pointer; font-family: inherit; }
.mini-btn:hover { border-color: var(--accent); color: var(--text); }

/* ---------- ファイル取り込み（📷撮影 / 🖼ファイル の2ボタン） ---------- */
.pickers { display: flex; gap: 8px; flex-wrap: wrap; }
.pick-btn {
  flex: 1; min-width: 120px; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; min-height: 48px; padding: 10px 14px; cursor: pointer;
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: .9rem;
}
.pick-btn:hover { border-color: var(--accent); border-style: solid; }
.pick-btn input { display: none; }
.pick-name { margin-top: 6px; font-size: .82rem; color: var(--text-sub); word-break: break-all; }

/* ---------- 記録FAB＋モーダル（入力フォームは1つ・呼び出し式） ---------- */
.fab {
  position: fixed; right: 20px; bottom: 24px; z-index: 46;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: .95rem;
  padding: 13px 22px; border-radius: 99px; box-shadow: var(--shadow);
}
.fab:hover { filter: brightness(1.08); }
@media (max-width: 720px) { .fab { bottom: 84px; right: 16px; } } /* タブバーの上 */
.modal-scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 55; }
.modal-scrim.show { display: block; }
.modal {
  display: none; position: fixed; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: min(440px, 94vw); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px; z-index: 56; box-shadow: var(--shadow);
}
.modal.open { display: block; }
.modal .close { float: right; cursor: pointer; color: var(--text-sub); font-size: 1.3rem; line-height: 1; }

/* ---------- 今日の行動・進捗（1行ずつ・グラフはクリックで開く） ---------- */
.meter-row { padding: 3px 0; }
.month-toggle { cursor: pointer; }
.month-toggle .pct { color: var(--accent); font-weight: 700; border-bottom: 1px dotted var(--accent); }
.chart-wrap { margin: 12px 0 6px; }
.chart-wrap svg { display: block; width: 100%; height: auto; }

/* ---------- トースト（1情報だけ・自動で消える） ---------- */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: 99px; padding: 9px 18px; font-weight: 600; font-size: .86rem;
  box-shadow: var(--shadow); z-index: 60; white-space: nowrap; max-width: 92vw;
  overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 10px;
  animation: toast-in .25s ease, toast-out .3s ease 2.7s forwards;
}
.toast.hold { animation: toast-in .25s ease, toast-out .3s ease 6s forwards; }
.toast button {
  border: none; background: none; color: var(--accent); font-weight: 700;
  cursor: pointer; font-size: .84rem; padding: 0; font-family: inherit; flex-shrink: 0;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- 右ドロワー（詳細パネル） ---------- */
.drawer-scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50; }
.drawer-scrim.show { display: block; }
.drawer {
  position: fixed; right: 0; top: 0; height: 100vh; width: min(440px, 94vw);
  background: var(--surface); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform .2s ease; z-index: 51;
  overflow-y: auto; padding: 18px 18px 40px; box-shadow: var(--shadow);
}
.drawer.open { transform: translateX(0); }
.drawer .close { float: right; cursor: pointer; color: var(--text-sub); font-size: 1.3rem; line-height: 1; }
.comment { padding: 8px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: none; }
.comment .who { font-size: .78rem; color: var(--text-sub); margin-bottom: 2px; }
.comment .who.claude { color: var(--accent); }
.comment .body { white-space: pre-wrap; font-size: .88rem; }

/* ---------- モバイル下部タブバー ---------- */
.tabbar { display: none; }
@media (max-width: 720px) {
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
  }
  .tabbar .tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
    color: var(--text-sub); font-size: .62rem; padding: 4px 0; text-decoration: none;
  }
  .tabbar .tab .tico { font-size: 1.05rem; line-height: 1.2; }
  .tabbar .tab.active { color: var(--accent); font-weight: 700; }
}

/* ---------- モバイル ---------- */
@media (max-width: 720px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .main { padding: 14px 14px 90px; }  /* 下部タブバーの分の余白 */
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; }
  .grid-2 { grid-template-columns: 1fr; }

  /* A1: 2カラムの入力行はモバイルで縦積み（横に潰れる問題の根治） */
  .row { flex-direction: column; gap: 0; }
  .row > * { flex: 1 1 auto; }
  /* ただしトリアージ等の小ボタン群・セグメントは横並びを維持 */
  .triage-chips, .seg, .hero-actions, .focus-actions { flex-direction: row; }

  /* A3: 主要な「追加」操作はFAB（右下に浮く）にして"押す場所"を明確化。
     横フル幅ボタンは画面に馴染んでボタンに見えない問題への対応。 */
  .topbar { flex-wrap: wrap; }
  .fab-action {
    position: fixed; right: 16px; bottom: 84px; z-index: 46;
    flex: none !important; width: auto;
    padding: 14px 22px; border-radius: 99px;
    font-size: 1rem; font-weight: 700;
    box-shadow: 0 6px 22px rgba(0, 0, 0, .4);
  }
  /* topbar に残る副次ボタン（フィルタ等）は自動幅で右寄せ（フル幅にしない） */
  .topbar .actions { width: auto; }

  /* A4: 検索窓と絞り込みは縦積み・セレクトの幅制限を解除 */
  #search, #status-filter, #cat-filter { max-width: none !important; }

  /* D5: ✓/📅 などの小ボタンは指で押せるサイズ・間隔に */
  .mini-btn { min-height: 34px; padding: 5px 10px; }
  .next-mini { gap: 10px; }
}
