:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --owner-bg: #1e3a5f;
  --dots-bg: #12352c;
  --muse-bg: #3b1d5e;
  --agy-bg: #1e293b;
  --system-bg: #172033;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Yu Gothic UI", sans-serif;
  line-height: 1.5;
}

[hidden] {
  display: none !important;
}

code {
  background: rgba(148, 163, 184, 0.18);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

.muted {
  color: var(--muted);
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
}

.error-text {
  color: #fca5a5;
  font-size: 0.88rem;
  margin: 0.3rem 0;
}

.hint-text {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 1rem;
}

/* ログイン */
.login-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.brand-icon {
  width: 44px;
  height: 44px;
}

.brand-row h1 {
  margin: 0;
  font-size: 1.35rem;
}

.login-form label,
.modal-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.7rem 0 0.25rem;
}

input, select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-warning { background: #78350f; border-color: var(--warning); }
.btn-danger { background: #7f1d1d; border-color: var(--danger); }
.btn-success { background: #064e3b; border-color: var(--success); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.82rem; }
.btn-full { width: 100%; margin-top: 1rem; }

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 1rem;
}

/* アプリ本体 */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.room-heading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge-group {
  display: inline-flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  font-size: 0.74rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge-scope { color: #93c5fd; border-color: #1d4ed8; }
.badge-paused { color: #fcd34d; border-color: #b45309; background: #451a03; }

.status-pill {
  font-size: 0.76rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.status-online { color: #6ee7b7; border-color: #059669; background: #064e3b; }
.status-offline { color: #fca5a5; border-color: #dc2626; background: #450a0a; }

.workspace-grid {
  display: grid;
  grid-template-columns: 260px 1fr 330px;
  flex: 1;
  min-height: 0;
}

.sidebar-left, .sidebar-right {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.sidebar-left { border-right: 1px solid var(--border); }
.sidebar-right { border-left: 1px solid var(--border); padding: 0.75rem; gap: 0.85rem; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  font-weight: 700;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.rooms-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.room-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
}

.room-item:hover { background: var(--surface-2); }
.room-item.active { background: #1e3a8a; border-color: var(--primary); }

.room-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.92rem;
}

.room-title-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding-left: 2px;
}

.unread-dot {
  position: absolute;
  top: -3px;
  left: -7px;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #ef4444;
  box-shadow: 0 0 0 2px var(--surface);
}

.room-item.active .unread-dot {
  box-shadow: 0 0 0 2px #1e3a8a;
}

.room-item-sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 0.7rem 0.85rem;
  font-size: 0.78rem;
}

.mini-title {
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.status-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

/* チャット中央 */
.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.topic-bar {
  padding: 0.45rem 1rem;
  background: rgba(30, 41, 59, 0.55);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
}

.messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.msg-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
}

.msg-actor-owner { background: var(--owner-bg); border-color: #2563eb; }
.msg-actor-dots { background: var(--dots-bg); border-color: #059669; }
.msg-actor-muse, .msg-actor-muse-local { background: var(--muse-bg); border-color: #9333ea; }
.msg-actor-gemini { background: #1d2b53; border-color: #6366f1; }
.msg-actor-antigravity { background: var(--agy-bg); border-color: #38bdf8; }
.msg-actor-system { background: var(--system-bg); border-style: dashed; }

.msg-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.msg-author {
  font-weight: 700;
  color: var(--text);
}

.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.94rem;
}

/* 入力欄 */
.composer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 0.6rem 0.85rem;
  padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
}

.composer-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.45rem;
}

.mention-chips, .worker-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.chip-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.worker-actions select {
  width: auto;
  padding: 0.28rem 0.5rem;
  font-size: 0.82rem;
}

.composer-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.composer-row textarea {
  resize: vertical;
  min-height: 48px;
  max-height: 180px;
}

/* 右パネル */
.panel-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.summary-textarea {
  border: none;
  border-radius: 0;
  resize: vertical;
  font-size: 0.88rem;
}

.actions-list {
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.action-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem;
  font-size: 0.85rem;
}

.action-title {
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.action-desc {
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 0.5rem;
}

.action-buttons {
  display: flex;
  gap: 0.45rem;
}

/* モーダル */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.modal-card-wide {
  max-width: 640px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
}

.profiles-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.profiles-editor-list {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  overflow-y: auto;
  padding-right: 0.25rem;
  max-height: 55dvh;
}

.profile-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.profile-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.profile-preview {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.profile-controls {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem;
  align-items: center;
}

.profile-controls input[type="text"] {
  padding: 0.38rem 0.55rem;
  font-size: 0.86rem;
}

.color-field {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.color-field input[type="color"] {
  width: 34px;
  height: 30px;
  padding: 2px;
  border-radius: 6px;
  cursor: pointer;
}

.modal-actions-split {
  justify-content: space-between;
  align-items: center;
}

.modal-form {
  padding: 0.85rem 1rem 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.mobile-only { display: none; }

.room-settings-body {
  padding: 0.65rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.room-settings-body label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.room-settings-body input[type="text"] {
  padding: 0.38rem 0.55rem;
  font-size: 0.85rem;
}

.inline-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.inline-row input[type="number"] {
  width: 76px;
  padding: 0.35rem 0.5rem;
}

.inline-row .btn {
  white-space: nowrap;
}

/* OAuth 2.1 同意画面 */
.consent-meta {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.9rem;
  font-size: 0.84rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  word-break: break-all;
}

.consent-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.1rem;
}

@media (max-width: 960px) {
  .mobile-only { display: inline-flex; }

  .workspace-grid {
    grid-template-columns: 1fr;
    position: relative;
  }

  .sidebar-left, .sidebar-right {
    position: fixed;
    top: 52px;
    bottom: 0;
    width: min(86vw, 340px);
    z-index: 40;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  }

  .sidebar-left {
    left: 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .sidebar-left.open { transform: translateX(0); }

  .sidebar-right {
    right: 0;
    transform: translateX(105%);
    transition: transform 0.2s ease;
  }
  .sidebar-right.open { transform: translateX(0); }
}
