/* Command Center: plain CSS, phone first. Light and dark follow the device setting. */
:root {
  --bg: #f4f5f8; --panel: #ffffff; --card: #ffffff; --ink: #1b1d23; --muted: #5d6475; --line: #dfe2ea;
  --accent: #3b5bdb; --accent-ink: #ffffff; --warn: #b54708; --warn-bg: #fff4e5; --bad: #c92a2a; --ok: #2b8a3e;
  --shadow: 0 1px 2px rgba(20, 24, 40, .08), 0 4px 14px rgba(20, 24, 40, .08);
  --radius: 12px; --tap: 44px; --top: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c; --panel: #1c1f27; --card: #232733; --ink: #e9ebf1; --muted: #a2a9ba; --line: #333948;
    --accent: #7b93ff; --accent-ink: #0d1020; --warn: #ffb35c; --warn-bg: #3a2a14; --bad: #ff8787; --ok: #69db7c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; font-size: 16px; color: inherit; }
button {
  min-height: var(--tap); min-width: var(--tap); padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; touch-action: manipulation;
}
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, .card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.icon { padding: 0; width: var(--tap); }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input:not([type]), select, textarea {
  min-height: var(--tap); width: 100%; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); max-width: 100%;
}
input[type=color] { width: var(--tap); height: var(--tap); padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
textarea { resize: vertical; line-height: 1.4; }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
code { font-size: 14px; word-break: break-all; }

/* ---------- top bar ---------- */
.top {
  flex: none; height: var(--top); display: flex; align-items: center; gap: 8px; padding: 0 8px;
  padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right));
  background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0;
}
.brand { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 17px; white-space: nowrap; min-width: 0; }
.logo { width: 24px; height: 24px; border-radius: 7px; flex: none; background: linear-gradient(135deg, #3b5bdb 0 50%, #f59f00 50% 100%); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.seg button { border: 0; border-radius: 0; background: transparent; padding: 0 12px; }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: none; }
.live { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); opacity: .5; }
.live.on { background: var(--ok); opacity: 1; }
@media (max-width: 520px) { .brand-text { display: none; } .seg button, .top-actions button { padding: 0 10px; } }
.waiting-btn .ws { display: none; }
.filter-seg .fs { display: none; }
@media (max-width: 900px) { .filter-seg .fl { display: none; } .filter-seg .fs { display: inline; } }
@media (max-width: 520px) { .waiting-btn .wl { display: none; } .waiting-btn .ws { display: inline; } .top { height: auto; min-height: var(--top); flex-wrap: wrap; gap: 6px; padding-top: 4px; padding-bottom: 4px; } .top-actions { gap: 4px; } }
@media (max-width: 380px) { .seg button, .top-actions button { padding: 0 8px; } }

main { flex: 1; min-height: 0; position: relative; }

/* ---------- board ---------- */
.board { position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.board.panning { cursor: grabbing; }
.canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.col-label { position: absolute; top: 18px; width: 250px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.card {
  position: absolute; width: 250px; padding: 12px; border-radius: var(--radius); background: var(--card);
  border: 1px solid var(--line); box-shadow: var(--shadow); cursor: pointer; -webkit-touch-callout: none;
  transition: box-shadow .15s, transform .15s;
}
.card.holding { transform: scale(.98); }
.card.dragging { box-shadow: 0 10px 30px rgba(0, 0, 0, .3); transform: scale(1.03); z-index: 5; cursor: grabbing; }
.title { display: block; margin: 0 0 6px; font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); border: 1px solid var(--line); color: var(--ink); white-space: nowrap; }
.pill.s-active { border-color: #4c6ef5; } .pill.s-blocked { border-color: var(--bad); color: var(--bad); }
.pill.s-waiting { border-color: #e8590c; color: #e8590c; font-weight: 700; } .owner { font-weight: 600; }
.waiting-btn.alert { border-color: #e8590c; color: #e8590c; font-weight: 700; }
.pill.s-review { border-color: #ae3ec9; } .pill.s-done { border-color: var(--ok); color: var(--ok); }
.leader { font-weight: 600; color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 2px 8px 2px 4px; border-radius: 999px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.chip .dot, .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.warns { margin-top: 6px; display: grid; gap: 4px; }
.warn { font-size: 13px; padding: 4px 8px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); overflow-wrap: anywhere; }
.sample-tag { font-size: 12px; font-weight: 700; color: var(--warn); }

.board-tools { position: absolute; right: 10px; bottom: calc(10px + var(--safe-b)); display: flex; gap: 6px; background: var(--panel); padding: 6px; border-radius: 14px; box-shadow: var(--shadow); }
.hint { position: absolute; left: 10px; bottom: calc(10px + var(--safe-b)); margin: 0; font-size: 13px; color: var(--muted); max-width: calc(100% - 260px); }
@media (max-width: 520px) { .hint { display: none; } }

/* ---------- list ---------- */
.list { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; padding: 8px 10px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.group h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 16px 4px 8px; }
.row { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.row-open { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 0; min-height: var(--tap); }
.row-status { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.row-status label { margin: 0; flex: none; }
.row-status select { flex: 1; }
.empty { color: var(--muted); padding: 4px 6px 8px; font-size: 14px; }

/* ---------- sheet: bottom sheet on phones, side panel on desktop ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20; }
.sheet {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; top: auto;
  height: var(--vvh, 100dvh); max-height: var(--vvh, 100dvh);
  display: flex; flex-direction: column; background: var(--panel);
  border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
  transform: translateY(var(--vvo, 0px)); overflow: hidden;
}
@media (min-width: 761px) {
  .sheet { left: auto; top: 0; bottom: 0; width: 460px; height: auto; max-height: none; border-radius: 0; border-left: 1px solid var(--line); transform: none; }
  .scrim { background: rgba(0, 0, 0, .12); }
}
.sheet-head { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--line); position: relative; }
.grab { position: absolute; top: 4px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--line); }
@media (min-width: 761px) { .grab { display: none; } }
.sheet-head h2 { flex: 1; margin: 8px 0 4px; font-size: 18px; overflow-wrap: anywhere; min-width: 0; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 4px 14px 16px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-foot { flex: none; border-top: 1px solid var(--line); padding: 8px 10px calc(8px + var(--safe-b)); background: var(--panel); }
.sheet-foot:empty { display: none; }
.postbox { display: flex; gap: 8px; align-items: flex-end; }
.postbox textarea { min-height: var(--tap); max-height: 30vh; resize: none; }
.sec { border-top: 1px solid var(--line); padding: 10px 0; }
.sec:first-child { border-top: 0; }
.sec > h3 { margin: 4px 0 8px; font-size: 15px; }
.line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.line > select, .line > input { flex: 1 1 140px; width: auto; min-width: 0; }
.stack { display: grid; gap: 8px; }
.muted { color: var(--muted); font-size: 14px; }
.plan { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.member { display: flex; align-items: center; gap: 8px; padding: 4px 0; flex-wrap: wrap; }
.member .name { flex: 1 1 120px; min-width: 0; overflow-wrap: anywhere; }
.member .lvl { font-size: 12px; color: var(--muted); }
.part { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-bottom: 8px; }
.part p { margin: 0 0 6px; overflow-wrap: anywhere; white-space: pre-wrap; }
.part .line select { flex: 1 1 120px; }
.posts { display: grid; gap: 8px; }
.post { border-radius: 10px; padding: 8px 10px; background: var(--bg); border-left: 4px solid var(--line); }
.post .who { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; font-size: 13px; color: var(--muted); }
.post .who b { color: var(--ink); }
.post .txt { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.post.k-plan { border-left-color: var(--accent); } .post.k-result { border-left-color: var(--ok); }
.post.k-question { border-left-color: var(--warn); } .post.k-ai_request, .post.k-ai_answer { border-left-color: #ae3ec9; }
textarea.paste { min-height: 180px; }
.token { display: grid; gap: 8px; padding: 10px; border-radius: 10px; background: var(--warn-bg); margin: 8px 0; }
.token code { font-size: 14px; background: var(--panel); padding: 8px; border-radius: 8px; user-select: all; }
.token code { overflow-wrap: anywhere; word-break: break-all; }
.connector .howto { margin: 0; line-height: 1.45; }
.steps { margin: 6px 0; padding-left: 20px; font-size: 14px; }
.steps li { margin: 4px 0; overflow-wrap: anywhere; }
.appitem { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; }
.appitem .head { display: flex; gap: 8px; align-items: center; }
.appitem .head b { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.signin { max-width: 520px; margin: 40px auto; padding: 0 16px; }

.toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  max-width: calc(100vw - 24px); padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--bg);
  box-shadow: var(--shadow); font-size: 15px; text-align: center;
}
@media (prefers-reduced-motion: reduce) { .card, .card.dragging { transition: none; } }
summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; list-style-position: inside; }
summary::before { content: "▸"; margin-right: 6px; }
details[open] > summary::before { content: "▾"; }
summary::-webkit-details-marker { display: none; }
.member input[type=checkbox] { flex: none; }
label.member { min-height: var(--tap); margin: 0; color: var(--ink); font-size: 16px; cursor: pointer; }

.done-btn { margin-top: 8px; min-height: 44px; padding: 6px 14px; border-radius: 8px; border: 1px solid var(--ok); background: var(--bg); color: var(--ok); font-weight: 700; font-size: 14px; cursor: pointer; }
.row-status .done-btn { margin-top: 0; margin-left: auto; }
