:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --panel-2: #1b2740;
  --text: #e7edf7;
  --muted: #93a2bd;
  --accent: #4f8cff;
  --accent-2: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
  --border: #243150;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: linear-gradient(180deg, #0b1220 0%, #0a0f1a 100%);
  color: var(--text);
  min-height: 100vh;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(11, 18, 32, 0.9);
  backdrop-filter: blur(8px);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 40px; height: 40px; }
.brand h1 { margin: 0; font-size: 1.15rem; }
.tagline { margin: 0; font-size: 0.78rem; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.pill {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--muted);
}
.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  width: 38px; height: 38px;
  font-size: 1.1rem;
  cursor: pointer;
}
.icon-btn:hover { background: var(--panel); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 18px;
  padding: 18px;
  max-width: 1400px;
  margin: 0 auto;
}
.col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card h2 { margin: 0 0 12px; font-size: 1rem; }
.card h3 { margin: 0 0 12px; font-size: 0.92rem; color: var(--muted); }
.card-head { display: flex; align-items: center; justify-content: space-between; }

/* Composer */
.text-input, .textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 0.95rem;
  font-family: inherit;
}
.text-input { margin-bottom: 10px; }
.textarea { min-height: 150px; resize: vertical; line-height: 1.6; }
.text-input:focus, .textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.primary-btn {
  margin-top: 12px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Claude Code 連携への導線（エンジン選択直下） */
.claude-connect {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 4px 0 8px;
}
.secondary-btn {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.secondary-btn:hover { background: rgba(0, 0, 0, 0.04); }
.conn-state { font-size: 0.82rem; color: var(--muted, #777); }
.conn-state.ok { color: #1a7f37; }
.conn-state.warn { color: #b35309; }
.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--text); }
.error-text { color: var(--danger); font-size: 0.85rem; margin: 8px 0 0; }

/* Project list */
.project-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.project-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.project-item:hover { border-color: var(--accent); }
.project-item.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.project-item .pname { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Status chips */
.status-chip, .status-badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.s-queued { color: var(--muted); }
.s-running { color: var(--warn); border-color: var(--warn); }
.s-done { color: var(--accent-2); border-color: var(--accent-2); }
.s-error { color: var(--danger); border-color: var(--danger); }

/* Detail / dashboard */
.detail { display: flex; flex-direction: column; gap: 18px; }
.detail-head { display: flex; align-items: center; justify-content: space-between; }
.detail-head h2 { margin: 0 0 6px; }

.agent-track { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.agent {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--muted);
  transition: all 0.2s;
}
.agent .dot { width: 9px; height: 9px; border-radius: 50%; background: #44507a; }
.agent.active { color: var(--text); border-color: var(--accent); }
.agent.active .dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(79, 140, 255, 0.2); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

.activity-log {
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
}
.log-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel-2);
  border-radius: 8px;
  border-left: 3px solid var(--border);
}
.log-row.t-status { border-left-color: var(--accent); }
.log-row.t-error { border-left-color: var(--danger); }
.log-row.t-agent { border-left-color: var(--accent-2); }
.log-actor { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.log-msg { white-space: pre-wrap; word-break: break-word; }

/* Artifacts */
.artifact-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.artifact-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.artifact-item .meta { color: var(--muted); font-size: 0.75rem; }
.dl-btn {
  background: var(--accent-2); color: #06231a; border: none;
  border-radius: 8px; padding: 6px 12px; font-weight: 600; cursor: pointer; text-decoration: none;
  font-size: 0.82rem;
}
.muted { color: var(--muted); }

.final-output {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-size: 0.85rem;
  line-height: 1.6;
  max-height: 420px;
  overflow-y: auto;
}

.empty-state { color: var(--muted); text-align: center; padding: 48px 18px; }

/* Dialog */
.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 22px;
  width: min(440px, 92vw);
}
.dialog::backdrop { background: rgba(0,0,0,0.6); }
.dialog h2 { margin: 0 0 16px; }
.dialog label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 14px; }
.dialog label .text-input { margin-top: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Responsive */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .col-right { order: -1; }
}

/* --- Agile review UI --- */
.s-review { color: var(--accent); border-color: var(--accent); }

.review-config { display: flex; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.review-config label { flex: 1; min-width: 160px; font-size: 13px; color: var(--muted); }
.review-config .text-input { margin-top: 4px; }

.card.review { border-color: var(--accent); }
.card.review h4 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.backlog-list { list-style: none; padding: 0; margin: 0; }
.backlog-item { display: flex; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.backlog-item .bl-mark { width: 16px; text-align: center; }
.bl-done .bl-title { color: var(--muted); text-decoration: line-through; }
.bl-done .bl-mark { color: var(--accent); }
.review-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* --- Hiring / templates / AI employee identity --- */
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.template-summary { color: var(--muted); font-size: 13px; margin: 4px 0 10px; min-height: 16px; }

.project-item.emp { display: flex; align-items: center; gap: 10px; }
.emp-avatar { font-size: 22px; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; background: var(--bg); border: 1px solid var(--border); border-radius: 50%; flex: 0 0 auto; }
.emp-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.emp-info .pname { font-weight: 600; }
.emp-task { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.template-manage-list { list-style: none; padding: 0; margin: 0 0 8px; }
.tpl-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.tpl-row .tpl-emoji { font-size: 18px; }
.tpl-row .tpl-name { flex: 1; }
.tpl-form label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.textarea.sm { min-height: 60px; }
.ghost-btn.sm { padding: 5px 10px; font-size: 12px; }
.ghost-btn.full { width: 100%; margin: 6px 0; }
.ghost-btn.danger { color: #b42318; border-color: #f0c2bc; }
.ghost-btn.danger:hover { background: rgba(180, 35, 24, 0.06); }

.detail-sub { display: flex; align-items: center; gap: 8px; margin: 4px 0; flex-wrap: wrap; }
.employee-name { font-size: 0.9rem; color: var(--muted, #667); font-weight: 600; }

/* AI employee chat */
.chat-log {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 340px; overflow-y: auto; padding: 8px 2px; margin: 8px 0;
}
.chat-msg { max-width: 85%; }
.chat-msg.owner { align-self: flex-end; text-align: right; }
.chat-msg.employee { align-self: flex-start; }
.chat-who { font-size: 0.72rem; color: var(--muted, #889); margin-bottom: 2px; }
.chat-text {
  display: inline-block; white-space: pre-wrap; word-break: break-word;
  padding: 8px 12px; border-radius: 12px; font-size: 0.9rem; line-height: 1.5;
}
.chat-msg.owner .chat-text { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.employee .chat-text { background: rgba(127,127,127,0.14); border-bottom-left-radius: 4px; }
.chat-input-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-input-row .textarea { flex: 1; margin: 0; }
.chat-input-row .primary-btn { width: auto; margin: 0; white-space: nowrap; }
h3.mt { margin-top: 14px; }

/* --- Mobile-first polish (smartphone the primary device) --- */
@media (max-width: 560px) {
  .topbar { padding: 10px 14px; }
  .layout { padding: 12px; gap: 12px; }
  .card { padding: 14px; }
  .primary-btn, .submit { width: 100%; padding: 14px; font-size: 16px; }
  .review-actions { flex-direction: column; }
  .review-actions button { width: 100%; padding: 13px; }
  .review-config { flex-direction: column; gap: 8px; }
  .text-input, .textarea { font-size: 16px; } /* avoid iOS zoom-on-focus */
  .textarea { min-height: 120px; }
  .dialog { width: 94vw; max-width: 94vw; }
  .emp-avatar { width: 38px; height: 38px; font-size: 24px; }
  .activity-log { max-height: 260px; }
}

/* --- Outbound email approval --- */
.row-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.row-check input { width: auto; }
.primary-btn.sm, .ghost-btn.sm { padding: 6px 12px; font-size: 13px; }
.card.outbox { border-color: var(--warn); }
.outbox-list { list-style: none; padding: 0; margin: 0; }
.outbox-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.outbox-info .ob-to { font-weight: 600; }
.outbox-info .ob-subj { margin: 2px 0; }
.outbox-info .ob-att, .outbox-info .ob-body { font-size: 12px; margin-top: 4px; white-space: pre-wrap; }
.outbox-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
@media (max-width: 560px) {
  .outbox-actions button { flex: 1; }
}

/* --- Usage cap pill states --- */
.pill.pill-warn { border-color: var(--warn); color: var(--warn); }
.pill.pill-over { border-color: var(--danger); color: var(--danger); }

/* --- Accounts: history + login --- */
.history-list { max-height: 55vh; overflow: auto; }
.hist-row { display: grid; grid-template-columns: 150px 90px 110px 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.hist-user { color: var(--accent); font-weight: 600; }
.hist-detail { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 560px) { .hist-row { grid-template-columns: 1fr 1fr; } }
