/* ==========================================================================
   grip — 統合タスク台帳 デザイントークン + 共通コンポーネント
   参考: linear.app（実サイトの static CSS から実際の配色トークンを抽出し
        `--color-bg-primary` 等の命名思想ごと踏襲。ハードコードでなく
        「トークンで一元管理する」設計そのものを模写している）
   このファイルは個別画面のスタイルではなく、土台（トークン＋部品）のみ。
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Zen+Kaku+Gothic+New:wght@400;500;700&display=swap');

/* --------------------------------------------------------------------------
   トークン: ライト（既定）
   -------------------------------------------------------------------------- */
:root {
  /* 色 — 背景（階層。数字が大きいほど手前に浮く） */
  --bg:            #ffffff;   /* ページ全体 */
  --bg-secondary:  #f9f8f9;   /* トップバー・テーブルヘッダー・sidebar */
  --bg-tertiary:   #f4f2f4;   /* 行hover・軽い塗り */
  --bg-quaternary: #eeedef;   /* 選択状態・押下中 */

  /* 色 — ボーダー（すべて1px・髪の毛のように細く） */
  --border:        #e9e8ea;
  --border-strong: #e4e2e4;

  /* 色 — 文字 */
  --text-primary:   #282a30;
  --text-secondary: #3c4149;
  --text-tertiary:  #6f6e77;
  --text-on-accent: #ffffff;

  /* 色 — アクセント（linear.app実サイトの --color-brand-bg / --color-accent-tint を継承） */
  --accent:       #5e6ad2;
  --accent-hover: #4c58c0;
  --accent-tint:  #f1f1ff;   /* 抽出値そのまま */

  /* 色 — セマンティック（アクセントとは別枠。状態専用） */
  --success:      #1a7f37;
  --success-bg:   #e6f6ea;
  --warning:      #9a6700;
  --warning-bg:   #fff6e0;
  --danger:       #cf222e;
  --danger-bg:    #ffe8e8;
  --info:         #0552b5;
  --info-bg:      #e8f0fe;

  /* タイポグラフィ */
  --font-sans: 'Inter', 'Zen Kaku Gothic New', -apple-system, BlinkMacSystemFont,
               'Hiragino Kaku Gothic ProN', 'Segoe UI', Meiryo, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;

  --text-xs:  12px;
  --text-sm:  13px;
  --text-base:14px;
  --text-md:  15px;
  --text-lg:  18px;
  --text-xl:  22px;
  --text-2xl: 28px;

  --leading-tight:   1.3;
  --leading-normal:  1.55;
  --leading-relaxed: 1.75;

  --tracking-tight: -0.012em; /* 見出し用。linear.appのh1(-.015em)に準拠 */

  /* 余白スケール（4px基準） */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 48px;

  /* 角丸 */
  --radius-sm:   6px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-pill: 999px;

  /* 影（既定はborderで階層を作る。影は浮遊要素のみに限定使用） */
  --shadow-sm: 0 1px 2px rgba(15, 15, 20, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 15, 20, 0.12);

  /* モーション（linear.appの --ease-out-quint を踏襲） */
  --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
  --duration-fast: 120ms;
  --duration-base: 180ms;

  /* テーブル・行 */
  --row-h:       40px;
  --row-h-dense: 30px;

  /* z-index スケール */
  --z-sticky:   10;
  --z-dropdown: 20;
  --z-modal:    30;
  --z-toast:    40;
}

/* --------------------------------------------------------------------------
   トークン: ダーク — OS設定に追従（[data-theme="light"] 明示時は除外）
   linear.appの実サイトCSSから抽出した実値（--color-bg-primary:#08090a 等）
   -------------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #08090a;
    --bg-secondary:  #1c1c1f;
    --bg-tertiary:   #232326;
    --bg-quaternary: #28282c;

    --border:        #23252a;
    --border-strong: #34343a;

    --text-primary:   #f7f8f8;
    --text-secondary: #d0d6e0;
    --text-tertiary:  #8a8f98;
    --text-on-accent: #ffffff;

    --accent:       #7c89f5;
    --accent-hover: #8989f0;
    --accent-tint:  #18182f;   /* 抽出値そのまま */

    --success:      #4ade80;
    --success-bg:   #10261a;
    --warning:      #f0bf00;   /* linear.appの実抽出値 */
    --warning-bg:   #2b2210;
    --danger:       #ff6b6b;
    --danger-bg:    #2d1214;
    --info:         #5eb0ff;   /* linear.appの実抽出値 */
    --info-bg:      #0f1f2e;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.55);
  }
}

/* 明示切替（テーマ切替UIがある場合、こちらが必ず勝つ） */
:root[data-theme="dark"] {
  --bg:            #08090a;
  --bg-secondary:  #1c1c1f;
  --bg-tertiary:   #232326;
  --bg-quaternary: #28282c;

  --border:        #23252a;
  --border-strong: #34343a;

  --text-primary:   #f7f8f8;
  --text-secondary: #d0d6e0;
  --text-tertiary:  #8a8f98;
  --text-on-accent: #ffffff;

  --accent:       #7c89f5;
  --accent-hover: #8989f0;
  --accent-tint:  #18182f;

  --success:      #4ade80;
  --success-bg:   #10261a;
  --warning:      #f0bf00;
  --warning-bg:   #2b2210;
  --danger:       #ff6b6b;
  --danger-bg:    #2d1214;
  --info:         #5eb0ff;
  --info-bg:      #0f1f2e;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.55);
}

/* --------------------------------------------------------------------------
   基礎リセット
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--duration-base) var(--ease-out-quint);
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
}
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }

p { margin: 0; }

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

button, input, select, textarea { font-family: inherit; color: inherit; }

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

.tabular-nums { font-variant-numeric: tabular-nums; }

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

/* --------------------------------------------------------------------------
   レイアウト骨格
   トップバーはlinear.app同様「濃い帯」を作らず、bodyと同じ地色に
   hairlineボーダーだけで境界を作る（階層は塗りでなく罫線で示す）。
   -------------------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 52px;
  padding: 0 var(--space-5);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}
.topbar .brand {
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
}
.topbar .spacer { flex: 1; }
.topbar .who { font-size: var(--text-sm); color: var(--text-tertiary); }

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-9);
}
.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}
.page-header .desc { font-size: var(--text-sm); color: var(--text-tertiary); }

.section {
  margin-bottom: var(--space-7);
}
.section-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}

.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

/* 子項目を持つ場合の入れ子表示（詳細ページ内に「小さいA」を再帰表示） */
.panel--nested {
  background: var(--bg-secondary);
  padding: var(--space-4);
  margin-top: var(--space-3);
}

/* --------------------------------------------------------------------------
   全体マイルストーン帯（一覧ページ上部・期限のある項目だけの横1本タイムライン）
   -------------------------------------------------------------------------- */
.milestone-band {
  position: relative;
  overflow-x: auto;
  overflow-y: visible;
  padding: var(--space-6) var(--space-5) var(--space-4);
}
.milestone-track {
  position: relative;
  height: 2px;
  background: var(--border-strong);
  border-radius: 1px;
  min-width: 640px;
}
.milestone-track .milestone-today {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 2px;
  background: var(--accent);
}
.milestone-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  cursor: pointer;
}
.milestone-marker--done   { border-color: var(--success); background: var(--success); }
.milestone-marker--overdue{ border-color: var(--danger); background: var(--danger); }
.milestone-marker--upcoming{ border-color: var(--accent); }
.milestone-label {
  position: absolute;
  top: calc(50% + 12px);
  transform: translateX(-50%);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.milestone-label--above {
  top: auto;
  bottom: calc(50% + 12px);
}

/* --------------------------------------------------------------------------
   テーブル（項目一覧）
   縦罫は引かない=linear.app準拠（密度は行の罫線と余白だけで作る）。
   横スクロールは.table-wrap自身に閉じ込め、本体(body)は動かさない。
   -------------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  min-width: 640px;
}
table.grid thead th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--bg-secondary);
  color: var(--text-tertiary);
  font-weight: 500;
  font-size: var(--text-xs);
  text-align: left;
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.grid thead th.th-num { text-align: right; }
table.grid thead th[aria-sort] { cursor: pointer; user-select: none; }
table.grid thead th[aria-sort]::after { margin-left: var(--space-1); color: var(--text-tertiary); }
table.grid thead th[aria-sort="ascending"]::after  { content: "▲"; }
table.grid thead th[aria-sort="descending"]::after { content: "▼"; }

table.grid tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background-color var(--duration-fast) var(--ease-out-quint);
}
table.grid tbody tr:last-child { border-bottom: none; }
table.grid tbody tr:hover { background: var(--bg-tertiary); cursor: pointer; }
table.grid tbody td {
  padding: var(--space-3);
  height: var(--row-h);
  color: var(--text-primary);
  vertical-align: middle;
}
table.grid tbody td.cell-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}
table.grid tbody td.cell-muted { color: var(--text-tertiary); }
table.grid tbody td.cell-title { font-weight: 500; max-width: 360px; }

/* 密度を落とした版（子項目=入れ子の「小さいA」用） */
table.grid.grid--dense thead th { padding: var(--space-2) var(--space-2); }
table.grid.grid--dense tbody td { padding: var(--space-2); height: var(--row-h-dense); font-size: var(--text-xs); }

.table-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: var(--space-2) 0 var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* 絞り込み中であることを明示するチップ列 */
.filter-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: var(--accent-tint);
  color: var(--accent);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 500;
}
.filter-chip button {
  background: none; border: none; cursor: pointer; color: inherit;
  font-size: var(--text-xs); line-height: 1; padding: 0 0 0 var(--space-1);
}

/* --------------------------------------------------------------------------
   バッジ / タグ — 色だけで意味を伝えない。形も併用する。
   種別(type)=角丸square、状態(status)=pill+アイコン形状 で視覚的に区別。
   -------------------------------------------------------------------------- */
.type-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.type-tag::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 2px; /* square = 種別 */
  background: currentColor;
  opacity: .55;
}
.type-tag--ai_thread    { color: var(--accent); }
.type-tag--personal_task{ color: var(--success); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-3) 2px var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; flex: none; }

/* 未着手・待ち = 中抜きの丸 */
.badge--neutral {
  background: var(--bg-tertiary); color: var(--text-secondary);
}
.badge--neutral::before {
  border-radius: 50%; border: 1.5px solid var(--text-tertiary); background: transparent;
}

/* 進行中 = 塗りの丸 */
.badge--progress {
  background: var(--info-bg); color: var(--info);
}
.badge--progress::before { border-radius: 50%; background: var(--info); }

/* 完了 = チェック（三角ではなくチェックマークで形を差別化） */
.badge--done {
  background: var(--success-bg); color: var(--success);
}
.badge--done::before {
  width: 8px; height: 8px; border-radius: 50%; background: transparent;
  border: none;
  background-image: linear-gradient(45deg, transparent 40%, currentColor 40%, currentColor 55%, transparent 55%),
                     linear-gradient(-45deg, transparent 55%, currentColor 55%, currentColor 70%, transparent 70%);
}

/* 停滞・要対応 = 菱形（警告） */
.badge--blocked {
  background: var(--danger-bg); color: var(--danger);
}
.badge--blocked::before { transform: rotate(45deg); background: var(--danger); border-radius: 1px; }

/* 相手待ち・確認待ち = 半円（帯） */
.badge--waiting {
  background: var(--warning-bg); color: var(--warning);
}
.badge--waiting::before { border-radius: 50% 50% 0 0; background: var(--warning); }

/* --------------------------------------------------------------------------
   記録ログ / 決定事項ログ（追記専用タイムライン）
   status_log = 丸ドット、decision_log = ひし形ドット、で種別を形で区別
   -------------------------------------------------------------------------- */
.log-list {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0 0 0 var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.log-list::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--border);
}
.log-item { position: relative; }
.log-item::before {
  content: "";
  position: absolute;
  left: -21px;
  top: 4px;
  width: 9px; height: 9px;
  background: var(--bg-tertiary);
  border: 2px solid var(--text-tertiary);
  border-radius: 50%;
}
.log-item--decision::before {
  border-color: var(--accent);
  background: var(--accent);
  border-radius: 2px;
  transform: rotate(45deg);
}
.log-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-bottom: var(--space-1);
}
.log-time { font-variant-numeric: tabular-nums; }

/* 発言者チップ: 人=丸アイコン / AI=四角アイコン と形で区別（色だけに頼らない） */
.author-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px var(--space-2) 1px 2px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 500;
}
.author-chip::before { content: ""; width: 6px; height: 6px; background: currentColor; }
.author-chip--human { background: var(--success-bg); color: var(--success); }
.author-chip--human::before { border-radius: 50%; }
.author-chip--ai { background: var(--accent-tint); color: var(--accent); }
.author-chip--ai::before { border-radius: 1px; }

.log-body {
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
  white-space: pre-wrap; /* ユーザー入力の改行を必ず尊重する */
}
.log-attachment {
  display: block;
  margin-top: var(--space-2);
  max-width: 280px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

/* --------------------------------------------------------------------------
   時間軸（オプション項目。値が無いブロックはJS側で非表示にする前提）
   -------------------------------------------------------------------------- */
.timeline-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}
.timeline-row:last-child { border-bottom: none; }
.timeline-row .timeline-date {
  min-width: 96px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   フォーム部品
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
.field label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
}
.field .required { color: var(--danger); margin-left: 2px; }
.field .optional { color: var(--text-tertiary); font-weight: 400; margin-left: var(--space-1); }
.field .help { font-size: var(--text-xs); color: var(--text-tertiary); }
.field .error { font-size: var(--text-xs); color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  font-size: 16px; /* iOS自動ズーム防止(16px未満は不可) */
  padding: var(--space-2) var(--space-3);
  background: var(--bg);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out-quint);
}
textarea { min-height: 96px; resize: vertical; line-height: var(--leading-normal); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--text-tertiary); }

/* --------------------------------------------------------------------------
   ボタン
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out-quint),
              border-color var(--duration-fast) var(--ease-out-quint);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: var(--text-on-accent); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn--secondary { background: var(--bg); color: var(--text-primary); border-color: var(--border-strong); }
.btn--secondary:hover:not(:disabled) { background: var(--bg-tertiary); }

.btn--ghost { background: transparent; color: var(--text-secondary); }
.btn--ghost:hover:not(:disabled) { background: var(--bg-tertiary); }

.btn--danger { background: var(--danger-bg); color: var(--danger); }
.btn--danger:hover:not(:disabled) { background: var(--danger); color: var(--text-on-accent); }

/* --------------------------------------------------------------------------
   状態表示: 読み込み中 / 0件 / エラー（3つを必ず見た目で区別する）
   -------------------------------------------------------------------------- */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}
.state-title { font-size: var(--text-base); font-weight: 600; color: var(--text-secondary); }

.state--loading .spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: grip-spin .7s linear infinite;
}
@keyframes grip-spin { to { transform: rotate(360deg); } }

.state--error {
  border-style: solid;
  border-color: var(--danger-bg);
  background: var(--danger-bg);
  color: var(--danger);
}
.state--error .state-title { color: var(--danger); }

/* --------------------------------------------------------------------------
   レスポンシブ（320px幅でも二方向スクロールを作らない）
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .page { padding: var(--space-4) var(--space-3) var(--space-8); }
  .topbar { padding: 0 var(--space-3); }
  .page-header { flex-direction: column; align-items: flex-start; gap: var(--space-2); }
}
