[hidden] { display: none !important; }

/* styles.css — /spaces/ ネイティブ Space 管理 UI
 *
 * レスポンシブ (390px 基準)、セマンティック、アクセシブル。
 * 既存の public UI と同じダークテーマ変数を使用。
 */

:root {
  --bg-0: #0a0e14;
  --bg-1: #111721;
  --bg-2: #1a2230;
  --line: #1e2632;
  --line-strong: #2a3441;
  --fg-0: #f5f7fa;
  --fg-1: #c4cad4;
  --fg-2: #8a94a3;
  --fg-3: #5d6878;
  --accent: #14b8a6;
  --accent-hi: #2dd4bf;
  --accent-glow: rgba(20,184,166,0.15);
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 6px;
  --radius-lg: 10px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-0);
  color: var(--fg-0);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Noto Sans JP', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ================================================================
 * ヘッダー
 * ================================================================ */

.top {
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  background: var(--bg-0);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 960px;
  margin: 0 auto;
}

.logo {
  display: flex;
  align-items: baseline;
  gap: 0.3em;
  font-size: 15px;
  font-weight: 500;
  color: var(--fg-0);
  text-decoration: none;
  line-height: 1;
}

.logo:hover {
  color: var(--accent-hi);
}

.logo .slash {
  color: var(--accent);
}

.logo .connect {
  font-family: 'Bodoni Moda', serif;
  font-style: italic;
  font-weight: 600;
  color: var(--accent-hi);
}

.title {
  margin-left: auto;
  font-size: 13px;
  color: var(--fg-2);
}

/* Base リンク */
.base-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  min-width: 44px;
  padding: 4px 10px;
  font-size: 13px;
  color: var(--fg-2);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.base-link:hover {
  color: var(--accent-hi);
  border-color: var(--accent);
  text-decoration: none;
}

.base-link:focus-visible {
  outline: 2px solid var(--accent-hi);
  outline-offset: 2px;
}

/* ================================================================
 * メイン
 * ================================================================ */

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ================================================================
 * ステータスバー
 * ================================================================ */

.status-bar {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--fg-1);
}

.status-bar.error {
  border-color: rgba(239,68,68,0.4);
  color: #fca5a5;
  background: rgba(239,68,68,0.08);
}

/* ================================================================
 * 認証エラー
 * ================================================================ */

.auth-error {
  text-align: center;
  padding: 60px 20px;
}

.auth-error h2 {
  font-size: 20px;
  margin: 0 0 10px;
  color: var(--fg-0);
}

.auth-error p {
  color: var(--fg-2);
  margin: 0 0 20px;
}

/* ================================================================
 * セクション
 * ================================================================ */

.space-section {
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 18px;
  margin: 0;
  font-weight: 500;
}

.section-header h3 {
  font-size: 16px;
  margin: 0;
  font-weight: 500;
}

/* ================================================================
 * ボタン
 * ================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #04211e;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
}

.btn:hover {
  background: var(--accent-hi);
  text-decoration: none;
  color: #04211e;
}

.btn:focus-visible {
  outline: 2px solid var(--accent-hi);
  outline-offset: 2px;
}

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

.btn-ghost {
  background: transparent;
  color: var(--fg-1);
  border: 1px solid var(--line-strong);
}

.btn-ghost:hover {
  background: var(--bg-2);
  color: var(--fg-0);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

/* ================================================================
 * Space 一覧
 * ================================================================ */

.space-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.space-item {
  margin-bottom: 8px;
}

.space-item-btn {
  width: 100%;
  text-align: left;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  color: var(--fg-0);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.15s;
}

.space-item-btn:hover {
  border-color: var(--accent);
  background: var(--bg-2);
}

.space-item-btn:focus-visible {
  outline: 2px solid var(--accent-hi);
  outline-offset: 2px;
}

.space-name {
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.space-meta {
  font-size: 12px;
  color: var(--fg-3);
  flex-shrink: 0;
}

/* ================================================================
 * フォーム
 * ================================================================ */

.space-form {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.field {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg-2);
  margin-bottom: 6px;
}

.field-help {
  display: block;
  font-size: 12px;
  color: var(--fg-3);
  margin-top: 4px;
}

input[type="text"] {
  width: 100%;
  background: var(--bg-0);
  color: var(--fg-0);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input[type="text"]:invalid:not(:placeholder-shown) {
  border-color: var(--bad);
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.draft-label {
  font-size: 12px;
  color: var(--warn);
  margin-left: 8px;
}

/* ================================================================
 * データソーステーブル
 * ================================================================ */

.sources-section {
  margin-top: 24px;
}

.sources-section h3 {
  font-size: 16px;
  margin: 0 0 12px;
  font-weight: 500;
  color: var(--fg-1);
}

.sources-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: fixed;
  overflow-wrap: anywhere;
}

.sources-table thead th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-strong);
  color: var(--fg-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
}

.sources-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--fg-1);
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.status-badge.active,
.status-badge.confirmed,
.status-badge.ok {
  background: rgba(16,185,129,0.15);
  color: var(--good);
}

.status-badge.pending,
.status-badge.draft {
  background: rgba(245,158,11,0.15);
  color: var(--warn);
}

.status-badge.error,
.status-badge.failed {
  background: rgba(239,68,68,0.15);
  color: var(--bad);
}

.status-badge.unknown {
  background: var(--bg-2);
  color: var(--fg-3);
}

/* ================================================================
 * 空状態
 * ================================================================ */

.empty-state p {
  color: var(--fg-3);
  font-size: 14px;
  padding: 20px 0;
  text-align: center;
}

/* ================================================================
 * レスポンシブ (390px 基準)
 * ================================================================ */

@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

  .top {
    padding: 10px 12px;
  }

  main {
    padding: 16px 12px;
  }

  .section-header h2 {
    font-size: 16px;
  }

  .space-form {
    padding: 16px;
  }

  .btn {
    padding: 8px 14px;
    font-size: 13px;
  }

  .sources-table {
    font-size: 13px;
  }

  .sources-table thead th,
  .sources-table tbody td {
    padding: 8px;
    overflow-wrap: anywhere;
  }

  .base-link {
    font-size: 12px;
    padding: 2px 6px;
    min-width: 36px;
  }

  .top-nav {
    flex-wrap: wrap;
  }
}

/* ================================================================
 * アクセシビリティ
 * ================================================================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* スクリーンリーダー用 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ================================================================
 * Members AI Permission Panel
 * ================================================================ */

.members-panel {
  margin-top: 20px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  animation: fadeIn 0.15s ease;
}

.members-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.members-panel-header h3 {
  font-size: 16px;
  margin: 0;
  font-weight: 500;
  color: var(--fg-1);
}

.members-loading {
  text-align: center;
  padding: 20px 0;
  color: var(--fg-3);
  font-size: 14px;
}

.members-error {
  padding: 12px 16px;
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.4);
  border-radius: var(--radius);
  color: #fca5a5;
  font-size: 14px;
}

.members-groups-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: fixed;
}

.members-groups-table thead th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-strong);
  color: var(--fg-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
}

.members-groups-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--fg-1);
  vertical-align: middle;
}

.perm-row {
  transition: background 0.15s;
}

.perm-row:hover {
  background: var(--bg-2);
}

.perm-group-name {
  font-weight: 500;
  color: var(--fg-0);
}

.perm-group-slug {
  font-size: 12px;
  color: var(--fg-3);
  margin-left: 6px;
}

.perm-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.perm-allowed {
  background: rgba(16,185,129,0.15);
  color: var(--good);
}

.perm-denied {
  background: rgba(245,158,11,0.15);
  color: var(--warn);
}

.perm-none {
  background: var(--bg-2);
  color: var(--fg-3);
}

.perm-stale {
  opacity: 0.7;
  text-decoration: line-through;
}

.perm-version {
  font-size: 11px;
  color: var(--fg-3);
  margin-left: 6px;
}

.perm-readonly {
  font-size: 12px;
  color: var(--fg-3);
  font-style: italic;
}

.perm-busy {
  font-size: 12px;
  color: var(--fg-3);
}

.perm-toggle-btn {
  min-width: 80px;
}

.perm-revoke-btn {
  background: var(--bad);
  color: #fff;
}

.perm-revoke-btn:hover {
  background: #dc2626;
  color: #fff;
}

/* Confirm area within Members panel */
.perm-confirm-area {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.perm-confirm-info {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--fg-1);
  line-height: 1.5;
}

.perm-confirm-checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 14px;
  color: var(--fg-0);
  cursor: pointer;
  margin-bottom: 12px;
}

.perm-confirm-checkbox-label input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.perm-confirm-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Members button in sources table */
.members-btn {
  white-space: nowrap;
}

/* ================================================================
 * Responsive adjustments for Members panel
 * ================================================================ */

@media (max-width: 480px) {
  .members-panel {
    padding: 16px;
  }

  .members-panel-header h3 {
    font-size: 14px;
  }

  .members-groups-table {
    font-size: 13px;
  }

  .members-groups-table thead th,
  .members-groups-table tbody td {
    padding: 8px;
  }

  .perm-confirm-area {
    padding: 12px;
  }

  .perm-confirm-checkbox-label {
    font-size: 13px;
  }
}
