/* ==== カラートークン ====
   デフォルト（:root）はこれまで通りのダークモード（グレートーン）。
   ライトモード（ベージュトーン）は [data-theme="light"] 側で上書きする。切替は右上のボタンから。 */
:root {
  color-scheme: dark; /* ダークモード時、日付入力欄のカレンダーアイコンなどブラウザ標準部品をダーク背景でも見える色にする */
  --bg: #14161a;
  --card-bg: #1c1f24;
  --border: #2c313a;
  --text: #e6e8eb;
  --text-muted: #9aa3af;
  --text-faint: #6d7580;
  --header-bg: #22262c;
  --row-hover: #20242a;

  --new-bg: #3a1a1a;
  --new-border: #ef434c;
  --new-text: #ef434c;

  --assigned-bg: #3a2a12;
  --assigned-text: #e3a869;
  --zacd-bg: #3a1a1a;
  --zacd-text: #ef434c;
  --won-bg: #3a1a1a;
  --won-text: #ef434c;
  --lost-text: #7c8ba1;
  --done-bg: #2a2e35;
  --done-text: #8b93a1;

  --accent: #e6e8eb;
  --accent-contrast: #14161a;
  --link: #4a9eff;

  --unassigned-bg: #2a2412;
  --unassigned-border: #a9791f;
  --unassigned-text: #e8b84b;

  --stale-border: #6d7580;
  --stale-text: #9aa3af;

  --lost-row-bg: rgba(74,158,255,.28);
  --zebra-bg: #22262c;
}

/* ライトモード（グレートーン）。以前のベージュトーンから変更 */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f4f6;
  --card-bg: #ffffff;
  --border: #e1e4e8;
  --text: #23262b;
  --text-muted: #5f6672;
  --text-faint: #939aa5;
  --header-bg: #eceef1;
  --row-hover: #eef1f4;

  --new-bg: #fbe4df;
  --new-border: #ef434c;
  --new-text: #ef434c;

  --assigned-bg: #fdecd3;
  --assigned-text: #ad7027;
  --zacd-bg: #fbe4df;
  --zacd-text: #ef434c;
  --won-bg: #fbe4df;
  --won-text: #ef434c;
  --lost-text: #9096a2;
  --done-bg: #e5e7eb;
  --done-text: #6b7280;

  --accent: #23262b;
  --accent-contrast: #f3f4f6;
  --link: #4a9eff;

  --unassigned-bg: #eceef1;
  --unassigned-border: #c7cdd6;
  --unassigned-text: #23262b;

  --stale-border: #939aa5;
  --stale-text: #7a828d;

  --lost-row-bg: rgba(74,158,255,.14);
  --zebra-bg: #f9fafb;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Hiragino Sans", "Helvetica Neue", Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--link); }

/* ==== 上部ナビ（Dタブ／制作タブ／ガントチャート＋ダークモード切替） ==== */
.topnav { display: flex; align-items: center; justify-content: space-between; padding: 10px 24px; background: var(--card-bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topnav .tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.topnav .tabs a { padding: 8px 16px; font-size: 13px; font-weight: 700; color: var(--text-muted); text-decoration: none; border-right: 1px solid var(--border); }
.topnav .tabs a:last-child { border-right: none; }
.topnav .tabs a.active { background: var(--accent); color: var(--accent-contrast); }
.topnav .right { display: flex; align-items: center; gap: 10px; }
.search-box input, .btn { font-family: inherit; }
.search-box input { border: 1px solid var(--border); background: var(--card-bg); color: var(--text); border-radius: 6px; padding: 6px 10px; font-size: 12px; width: 220px; }
.btn.small { font-size: 11px; padding: 5px 10px; }

/* ダーク／ライト切替：太陽・月アイコン付きのトグルスイッチ */
.theme-switch { display: inline-flex; align-items: center; cursor: pointer; user-select: none; }
.theme-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.theme-switch-track { position: relative; width: 50px; height: 26px; background: var(--header-bg); border: 1px solid var(--border); border-radius: 999px; display: flex; align-items: center; justify-content: space-between; padding: 0 5px; box-sizing: border-box; }
.theme-switch-icon { font-size: 12px; line-height: 1; z-index: 1; opacity: .8; }
.theme-switch-thumb { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--card-bg); border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .18s ease; }
.theme-switch input:checked ~ .theme-switch-track .theme-switch-thumb { transform: translateX(24px); }

.page { padding: 20px 28px 60px; max-width: none; margin: 0 auto; }
.sort-note { font-size: 11px; color: var(--text-faint); margin: 0 0 14px 2px; }

.staff-block { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 36px; overflow: hidden; scroll-margin-top: 70px; } /* 上部の固定ナビ(.topnav)に隠れないよう、アンカー時の余白を確保 */
.staff-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--header-bg); border-bottom: 1px solid var(--border); }
.staff-name { font-size: 16px; font-weight: 700; }
.add-case-btn { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin-left: 20px; border-radius: 6px; border: none; background: #4a9eff; color: #fff; text-decoration: none; font-size: 16px; font-weight: 800; line-height: 1; vertical-align: -2px; }
.add-case-btn:hover { background: #2f86e6; color: #fff; }
.total-badge { display: inline-flex; align-items: baseline; gap: 3px; color: var(--text); padding: 0; }
.total-badge .num { font-size: 20px; font-weight: 800; line-height: 1; }
.total-badge .unit { font-size: 10px; font-weight: 600; color: var(--text-faint); }

.case-row { display: grid; grid-template-columns: 22px 90px 2.16fr 90px 70px 64px 64px 3fr 40px; align-items: center; gap: 0; padding: 6px 12px; border-top: 1px solid var(--border); font-size: 12px; position: relative; }
.case-row:first-child { border-top: none; }
.case-row:hover { background: var(--row-hover); }
.case-row > div { padding: 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.case-row.row-alt { background: var(--zebra-bg); }
.case-row.is-lost { background: var(--lost-row-bg); }
.case-row.is-done { background: var(--header-bg); }
.case-row.is-done > *:not(.row-menu) { opacity: .6; }
.case-row.is-new { background: var(--new-bg); border-left: 3px solid var(--new-border); }
.case-row.is-won { background: var(--new-bg); border-left: 3px solid var(--new-border); }
.case-row.is-lost:hover, .case-row.is-done:hover, .case-row.row-alt:hover { background: var(--row-hover); }
.case-row.zac-stale > *:not(.row-menu) { opacity: .7; }
.stale-tag { font-size: 9px; font-weight: 700; color: var(--stale-text); border: 1px solid var(--stale-border); border-radius: 4px; padding: 0 4px; margin-left: 5px; white-space: nowrap; }
.source-link-tag { display: inline-block; font-size: 12px; font-weight: 700; color: var(--link); background: #fff; border-radius: 5px; padding: 3px 9px; margin-left: 6px; white-space: nowrap; text-decoration: none; line-height: 1.4; vertical-align: middle; }
.source-link-tag:hover { text-decoration: underline; }

.case-name { font-size: 13.5px; font-weight: 400; color: var(--text); white-space: normal !important; }
.case-name a { color: var(--text); text-decoration: none; }
.case-name a:hover { text-decoration: underline; }
.case-row.is-new .case-name { color: var(--new-text); }
.case-row.is-new .case-name a { color: var(--new-text); }
.case-row.is-hikitsugi .type-tag, .case-row.is-hikitsugi .case-name, .case-row.is-hikitsugi .case-name a { color: var(--assigned-text); }
.effort { font-size: 15px; font-weight: 800; color: var(--text); text-align: center; }
.type-tag { font-size: 11px; color: var(--text-muted); }
.type-tag.zac { color: var(--text); font-weight: 600; }
.new-tag { font-size: 9.5px; font-weight: 800; color: var(--new-text); background: var(--new-bg); border: 1px solid var(--new-border); border-radius: 4px; padding: 1px 5px; margin-right: 6px; vertical-align: 1px; }

.pill { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill.assigned { background: var(--assigned-bg); color: var(--assigned-text); }
.pill.assigned.is-new { background: var(--new-bg); color: var(--new-text); }
.pill.zacd { background: var(--zacd-bg); color: var(--zacd-text); }
.pill.won { background: #ef434c; color: #fff; }
.pill.won-settled { background: var(--header-bg); color: var(--text-muted); }
.pill.lost { background: rgba(74,158,255,.18); color: #4a9eff; font-weight: 500; }
.pill.done { background: var(--done-bg); color: var(--done-text); font-weight: 500; }

.pf-text { font-weight: 700; }
.pf-text.pf-need { color: #f59e0b; }
.pf-text.pf-done { color: #4a9eff; }
.pf-text.pf-draft { color: #ef434c; }
.pf-text.pf-na, .pf-text.pf-none { color: var(--text-faint); font-weight: 400; }

.remark { color: var(--text); opacity: .8; white-space: normal !important; font-size: 12px; }

.approval-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; }
.approval-row:first-child { border-top: none; }
.text-right { text-align: right; }

/* 工数・開始日・納品日・PF・ステータスのセルは中央揃え */
.case-row [data-cell="status"],
.case-row [data-cell="start_date"],
.case-row [data-cell="due_date"],
.case-row [data-cell="pf_status"] { text-align: center; }

/* 一覧画面上での直接編集（工数・日付・概要） */
.editable-cell { cursor: text; border-radius: 4px; min-height: 18px; line-height: 18px; }
.editable-cell:hover { background: var(--row-hover); outline: 1px dashed var(--border); }
.inline-edit-input { width: 100%; font: inherit; color: inherit; background: var(--card-bg); border: 1px solid var(--accent); border-radius: 4px; padding: 1px 4px; box-sizing: border-box; }

/* ドラッグ＆ドロップでの並び替え（JOBNo.欄の左側のハンドル） */
.drag-handle { cursor: grab; color: var(--text-faint); font-size: 13px; padding: 2px 0; text-align: center; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.case-row.dragging { opacity: .4; }

/* ⋯ メニュー */
.case-row > .row-menu { position: relative; text-align: right; overflow: visible; }
.row-menu > button { border: none; background: none; color: var(--text-faint); font-size: 16px; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.row-menu > button:hover { background: var(--row-hover); }
.row-menu .dropdown { display: none; position: absolute; right: 0; top: 26px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.12); min-width: 160px; z-index: 20; }
.row-menu.open .dropdown { display: block; }
.row-menu .dropdown button, .row-menu .dropdown a { display: block; width: 100%; text-align: left; background: none; border: none; padding: 9px 12px; font-size: 12px; color: var(--text); cursor: pointer; text-decoration: none; }
.row-menu .dropdown button:hover, .row-menu .dropdown a:hover { background: var(--row-hover); }
.row-menu .dropdown button.danger { color: #ef434c; }

/* 「Dをアサイン」モーダル（引合案件ブロック：D候補選択＋任意メッセージ） */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal-box { width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,.35); }
.modal-box textarea { resize: vertical; }

/* 「引合案件」ブロック：他の担当者ブロックと同じ見た目に統一（特別に目立たせない） */
.unassigned-block { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 36px; overflow: hidden; }
.unassigned-block .staff-header { background: var(--header-bg); border-bottom: 1px solid var(--border); }
.unassigned-block .staff-name { color: var(--text); }

.block-foot { display: flex; justify-content: space-between; align-items: center; padding: 7px 16px; font-size: 11px; color: var(--text-faint); border-top: 1px dashed var(--border); background: var(--row-hover); }

.btn { border: 1px solid var(--border); background: var(--card-bg); border-radius: 5px; padding: 6px 12px; font-size: 12px; font-weight: 600; color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { background: var(--row-hover); }
.btn.primary { background: var(--link); border-color: var(--link); color: #fff; }

.search-results { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 20px; }
.search-results .case-row { grid-template-columns: 90px 2.16fr 90px 1fr 100px; }

/* フォーム（列見出しの代わりに、ここにラベルを持たせる） */
.form-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; max-width: 960px; }
.form-section { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.form-section:last-child { border-bottom: none; }
.field-label { font-size: 11px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; display: block; }
.form-section input, .form-section select, .form-section textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font-size: 13px;
  background: var(--card-bg); color: var(--text); font-family: inherit;
}
.form-row { display: flex; gap: 10px; border-bottom: 1px solid var(--border); }
.form-row:last-child { border-bottom: none; }
.form-row > div { flex: 1; }
.form-row > .form-section { border-bottom: none; }

/* 打診方法（直接／個別）などのボタン風トグル */
.method-toggle { display: flex; gap: 8px; }
.method-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 700; color: var(--text-muted); background: var(--card-bg); white-space: nowrap; }
.method-btn input { width: auto; padding: 0; border: none; border-radius: 0; background: none; accent-color: #4a9eff; margin: 0; }
.method-btn:has(input:checked) { border-color: #4a9eff; background: rgba(74,158,255,.15); color: var(--text); }
.method-btn:has(input:disabled) { opacity: .5; cursor: not-allowed; }

/* 所属chが1つに固定されているスタッフ選択時、送信先ch欄を操作不可に見せる */
.field-locked { pointer-events: none; opacity: .55; }

@media (max-width: 720px) {
  .case-row { grid-template-columns: 70px 1fr 60px 30px; }
  .case-row > .drag-handle { display: none; }
  .case-row > div:nth-child(5), .case-row > div:nth-child(6), .case-row > div:nth-child(7) { display: none; }
}
