:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #fbfcfd;
  --border: #e3e7ec;
  --text: #16202c;
  --muted: #66778a;
  --accent: #2f6bff;
  --accent-soft: #eaf0ff;
  --ok: #12915f;
  --ok-soft: #e6f6ef;
  --warn: #b7791f;
  --warn-soft: #fdf3e2;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --panel: #161b22;
    --panel-2: #1b212a;
    --border: #29313d;
    --text: #e6edf3;
    --muted: #8b98a9;
    --accent: #5b8cff;
    --accent-soft: #1b2740;
    --ok: #3fb984;
    --ok-soft: #12291f;
    --warn: #e0a63f;
    --warn-soft: #2b2416;
    --danger: #f0776a;
    --danger-soft: #2e1a18;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.7;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }

/* ---------- レイアウト ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 16px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px;
}
.brand-name { font-weight: 700; letter-spacing: .02em; }
.brand-sub { font-size: 11px; color: var(--muted); line-height: 1.3; }

.nav-btn {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 9px;
  background: none; border: none; cursor: pointer; text-align: left; width: 100%;
  color: var(--muted); font-weight: 600;
}
.nav-btn:hover { background: var(--panel-2); color: var(--text); }
.nav-btn.active { background: var(--accent-soft); color: var(--accent); }
.nav-btn .badge {
  margin-left: auto; background: var(--accent); color: #fff;
  border-radius: 99px; padding: 0 7px; font-size: 11px; font-weight: 700;
}
.nav-sep { height: 1px; background: var(--border); margin: 10px 6px; }
.sidebar-foot { margin-top: auto; font-size: 11px; color: var(--muted); padding: 8px; }

.main { padding: 22px 26px 60px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 21px; letter-spacing: .01em; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.page-head .spacer { flex: 1; }

/* ---------- 部品 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 14px; }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.cols2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.kpi-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.01em; margin-top: 2px; }
.kpi-foot { font-size: 12px; color: var(--muted); margin-top: 4px; }

.btn {
  border: 1px solid var(--border); background: var(--panel-2);
  padding: 7px 13px; border-radius: 9px; cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.btn.danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 700;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.pill.running { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.pill.review { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.pill.approved { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.pill.published { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.pill.rejected { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], textarea, select {
  width: 100%; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel-2);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; line-height: 1.7; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Consolas", monospace; font-size: 12px; }
.empty { color: var(--muted); text-align: center; padding: 34px 10px; border: 1px dashed var(--border); border-radius: var(--radius); }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.scroll-x { overflow-x: auto; }

/* ---------- チャネル ---------- */
.ch-card { display: flex; flex-direction: column; gap: 9px; }
.ch-top { display: flex; align-items: center; gap: 9px; }
.ch-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); font-size: 16px; }
.ch-name { font-weight: 700; }
.bar { height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #8b5cf6); }

/* ---------- カンバン ---------- */
.kanban { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: 12px; }
.kanban-col { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 140px; }
.kanban-col h3 { margin: 0 0 9px; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.kanban-col h3 b { margin-left: auto; }
.task-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 8px; cursor: pointer; }
.task-card:hover { border-color: var(--accent); }
.task-card .t { font-weight: 700; font-size: 13px; line-height: 1.5; }
.task-card .m { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- 承認 ---------- */
.review-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: var(--panel); }
.review-body {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 12px; white-space: pre-wrap; max-height: 320px; overflow-y: auto; font-size: 13px;
}

/* ---------- チャット ---------- */
.chat-log { display: flex; flex-direction: column; gap: 10px; max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.msg { display: flex; gap: 9px; }
.msg .av { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); font-size: 14px; flex: none; }
.msg .bubble { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; white-space: pre-wrap; }
.msg.user .bubble { background: var(--accent-soft); border-color: var(--accent); }
.msg .who { font-size: 11px; color: var(--muted); font-weight: 700; margin-bottom: 2px; }

/* ---------- エージェント ---------- */
.agent-card { display: flex; flex-direction: column; gap: 8px; }
.agent-top { display: flex; gap: 10px; align-items: center; }
.agent-av { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); display: grid; place-items: center; font-size: 18px; }

/* ---------- カレンダー ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .dow { font-size: 11px; color: var(--muted); text-align: center; font-weight: 700; padding: 4px 0; }
.cal .day { border: 1px solid var(--border); border-radius: 8px; min-height: 78px; padding: 5px; background: var(--panel-2); }
.cal .day.other { opacity: .38; }
.cal .day.today { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.cal .day .n { font-size: 11px; color: var(--muted); font-weight: 700; }
.cal .ev { font-size: 10px; background: var(--accent-soft); color: var(--accent); border-radius: 5px; padding: 1px 4px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- テーブル ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: top; }
th { color: var(--muted); font-size: 12px; }

/* ---------- トースト ---------- */
#toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 9px; padding: 10px 14px; box-shadow: var(--shadow); font-weight: 600; max-width: 340px;
}
.toast.err { border-left-color: var(--danger); }

/* ---------- モーダル ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10,14,20,.5); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px; width: min(700px, 100%); max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .brand { width: 100%; }
  .nav-btn { width: auto; }
  .main { padding: 16px; }
  .kanban { grid-template-columns: repeat(2, minmax(170px, 1fr)); }
}
