/* ===== AI Builder - Global Styles ===== */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+JP:wght@700;900&family=JetBrains+Mono:wght@400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; }

:root {
  /* ベース(白基調)*/
  --bg:        #f7faff;
  --bg-2:      #ffffff;
  --bg-3:      #fbfcfe;
  --paper:     #ffffff;
  --border:    rgba(11, 33, 71, 0.10);
  --border-2:  rgba(11, 33, 71, 0.15);
  --text:      #0b1929;
  --muted:     #56657c;
  --muted-2:   #8e9bb0;

  /* ブルー(プライマリ)*/
  --navy:      #0b2147;
  --navy-2:    #122d5e;
  --accent:    #1e4fb0;
  --accent-2:  #2563eb;
  --primary-pale: #dbeafe;

  /* ゴールド(プレミアムアクセント)*/
  --gold:      #c69214;
  --gold-2:    #d4a017;
  --gold-3:    #e0b94a;
  --gold-pale: #fdf3d1;
  --gold-line: rgba(198, 146, 20, 0.35);

  /* セマンティックカラー */
  --success:   #16a34a;
  --warning:   #d97706;
  --danger:    #dc2626;
  --claude:    #9333ea;       /* 紫 */
  --gpt:       #16a34a;       /* 緑 */
  --user:      #1e4fb0;       /* ブルー */

  --shadow-sm: 0 1px 2px rgba(11,33,71,0.04), 0 1px 3px rgba(11,33,71,0.06);
  --shadow-md: 0 4px 12px rgba(11,33,71,0.06), 0 12px 28px rgba(11,33,71,0.08);
}

body {
  margin: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(59,130,246,0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 14px/1.65 -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  min-height: 100vh;
}

/* ===== Top bar(白×ネイビー+ゴールドハイライト線)===== */
.topbar {
  background: #ffffff;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  box-shadow: inset 0 2px 0 var(--gold-2), 0 1px 3px rgba(11,33,71,0.04);
}
.topbar h1 {
  font-size: 18px;
  margin: 0;
  color: var(--navy);
  font-family: 'Noto Serif JP', serif;
  font-weight: 700;
  letter-spacing: -0.005em;
}
.topbar .sub { color: var(--muted); font-size: 12px; }
.topbar .back { color: var(--accent); text-decoration: none; font-weight: 600; }
.topbar .back:hover { color: var(--gold); }

/* ===== Cards ===== */
.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  margin: 0 0 12px;
  font-size: 17px;
  color: var(--navy);
  font-family: 'Noto Serif JP', serif;
  font-weight: 700;
}
.card h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
}

textarea, input[type=text], input[type=email], input[type=password], input[type=tel], select {
  width: 100%; padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: 8px;
  font: inherit;
  transition: all 0.2s ease;
}
textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(30, 79, 176, 0.12);
}
textarea { resize: vertical; min-height: 80px; }
.row { display: flex; gap: 8px; margin-top: 8px; }
.row input { flex: 1; }

/* ===== Buttons(ニュートラル白+ホバーで青のヒント)===== */
button, .btn {
  padding: 9px 16px;
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  display: inline-block;
  font-weight: 500;
  transition: all 0.2s ease;
}
button:hover, .btn:hover {
  background: var(--bg-3);
  border-color: var(--accent);
  color: var(--accent);
}
/* メインCTA:ロイヤルブルーグラデーション */
button.primary, .primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--navy-2) 100%);
  border: 1px solid var(--navy);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(30,79,176,0.25), inset 0 1px 0 rgba(255,255,255,0.18);
}
button.primary:hover, .primary:hover {
  background: linear-gradient(180deg, var(--accent-2) 0%, var(--accent) 100%);
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(30,79,176,0.35), inset 0 1px 0 rgba(255,255,255,0.25);
  color: #ffffff;
}
/* プレミアム版CTA:ゴールド */
button.gold, .gold {
  background: linear-gradient(180deg, var(--gold-3) 0%, var(--gold-2) 100%);
  border: 1px solid var(--gold);
  color: var(--navy);
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(198,146,20,0.25), inset 0 1px 0 rgba(255,255,255,0.4);
}
button.gold:hover, .gold:hover {
  background: linear-gradient(180deg, var(--gold-2) 0%, var(--gold) 100%);
  color: var(--navy);
  transform: translateY(-1px);
}
button.success, .success {
  background: var(--success); border-color: var(--success); color: #fff; font-weight: 600;
}
button.success:hover, .success:hover { background: #15803d; border-color: #15803d; color: #fff; }
button.full { width: 100%; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Table ===== */
.projects { width: 100%; border-collapse: collapse; font-size: 13px; }
.projects th, .projects td {
  padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left;
}
.projects th {
  color: var(--muted-2); font-weight: 700;
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  background: var(--bg-3);
}
.projects tr:hover td { background: var(--bg-3); }
.empty { text-align: center; color: var(--muted); padding: 30px; }

/* バッジ:すべて薄背景+濃い文字でレジビリティ確保 */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 100px;
  font-size: 11px; background: var(--bg-3); color: var(--muted);
  font-weight: 600; letter-spacing: 0.04em;
}
.status-planning   { background: #e5e7eb; color: #374151; }
.status-generating { background: #dbeafe; color: #1e3a8a; }
.status-prototype  { background: #ede9fe; color: #5b21b6; }
.status-production { background: #d1fae5; color: #065f46; }
.status-archived   { background: #f3f4f6; color: #4b5563; }

/* ===== Layout for project page ===== */
.layout {
  display: grid; grid-template-columns: 1fr 380px;
  gap: 16px; max-width: 1400px; margin: 16px auto; padding: 0 16px;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

/* ===== Chat / Avatars ===== */
.chat-pane { display: flex; flex-direction: column; min-height: 80vh; }
.avatars-row {
  display: flex; gap: 12px; margin-bottom: 12px;
}
.avatar-card {
  flex: 1;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex; align-items: center; gap: 10px;
  transition: all .3s;
  box-shadow: var(--shadow-sm);
}
.avatar-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30, 79, 176, 0.15), var(--shadow-md);
}
#avatar-claude.active { border-color: var(--claude); box-shadow: 0 0 0 3px rgba(147, 51, 234, 0.15), var(--shadow-md); }
#avatar-gpt.active    { border-color: var(--gpt);    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15), var(--shadow-md); }
.avatar-icon { font-size: 28px; }
.avatar-name { font-weight: 700; color: var(--navy); }
.avatar-status { color: var(--muted); font-size: 12px; }
.avatar-card.active .avatar-status::before {
  content: ""; display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; margin-right: 4px;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { opacity: .3; } 50% { opacity: 1; }
}

.chat-stream {
  flex: 1; overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.bubble {
  display: flex; gap: 10px; margin: 10px 0;
  animation: appear .25s ease-out;
}
@keyframes appear {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.bubble .icon {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  background: var(--bg-3);
  border: 1px solid var(--border);
}
.bubble .body {
  background: var(--bg-3);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  max-width: 88%;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.bubble .meta {
  font-size: 11px; color: var(--muted); margin-bottom: 4px;
}
.bubble.user            { flex-direction: row-reverse; }
.bubble.user .body      {
  background: linear-gradient(180deg, var(--accent) 0%, var(--navy-2) 100%);
  color: #ffffff;
  border-color: var(--navy);
}
.bubble.claude .icon    { background: #f3e8ff; border-color: #d8b4fe; }
.bubble.claude .body    { border-left: 3px solid var(--claude); }
.bubble.gpt .icon       { background: #dcfce7; border-color: #86efac; }
.bubble.gpt .body       { border-left: 3px solid var(--gpt); }
.bubble.system .body    { background: var(--gold-pale); color: #78350f; border-color: var(--gold-line); font-size: 13px; }
.bubble.status .body    { background: var(--bg-3); color: var(--muted); font-style: italic; font-size: 13px; }

/* ===== Side pane ===== */
.cost-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.cost-grid > div {
  background: var(--bg-3); padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border);
}
.cost-grid span { display: block; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; }
.cost-grid b { font-size: 16px; color: var(--navy); }

.phases { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.phase-btn { text-align: left; }
.phase-btn.done { background: var(--success); border-color: var(--success); color: #fff; }
.phase-btn.running {
  background: linear-gradient(180deg, var(--accent) 0%, var(--navy-2) 100%);
  border-color: var(--navy); color: #fff;
  animation: pulse 1.5s ease-in-out infinite;
}

.file-list { list-style: none; padding: 0; margin: 0 0 8px; max-height: 200px; overflow-y: auto; }
.file-list li {
  padding: 6px 10px; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
}
.file-list li:hover { background: var(--bg-3); }
.file-list .fpath { flex: 1; cursor: pointer; color: var(--text); }
.file-list .type { color: var(--muted); font-size: 10px; }
.file-list .refine-target-check { cursor: pointer; flex-shrink: 0; }
.file-list li:has(.refine-target-check:checked) {
  background: var(--gold-pale);
  border-left: 3px solid var(--gold-2);
  padding-left: 7px;
}

.production-card { border-color: var(--success); box-shadow: 0 0 0 1px var(--success) inset; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(11, 33, 71, 0.35);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--paper);
  border-radius: 12px;
  border: 1px solid var(--border-2);
  width: 90%; max-width: 900px; max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 30px 80px rgba(11, 33, 71, 0.30);
}
.modal-header {
  display: flex; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  color: var(--navy);
  font-weight: 600;
}
.modal-content pre {
  margin: 0; padding: 18px; overflow: auto;
  font-family: "SF Mono", "JetBrains Mono", Menlo, monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-word;
  color: var(--text);
  background: var(--bg-3);
}

/* ===== Auth pages(register など共有 style.css 使用)===== */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at top right, rgba(212,160,23,0.10), transparent 50%),
    radial-gradient(ellipse at bottom left, rgba(30,79,176,0.12), transparent 50%),
    linear-gradient(135deg, #f7faff 0%, #eef3fb 100%);
  color: var(--text);
}
.auth-box {
  background: var(--paper);
  border: 1px solid var(--border-2);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%; max-width: 440px;
  box-shadow: 0 30px 60px rgba(11, 33, 71, 0.12), 0 8px 24px rgba(11, 33, 71, 0.08);
  position: relative;
  overflow: hidden;
}
.auth-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent 0%, var(--gold-2) 30%, var(--gold-3) 50%, var(--gold-2) 70%, transparent 100%);
}
.auth-box h1 {
  text-align: center; margin: 0 0 8px; font-size: 22px;
  font-family: 'Noto Serif JP', serif;
  color: var(--navy); font-weight: 900;
}
.auth-box h2 {
  text-align: center; color: var(--muted); margin: 0 0 24px;
  font-size: 13px; font-weight: 500; letter-spacing: 0.02em;
}
.auth-box form label {
  display: block; margin-bottom: 14px; font-size: 12.5px;
  color: var(--text); font-weight: 600;
}
.auth-box form input { margin-top: 6px; }
.auth-box .hint { text-align: center; margin-top: 18px; font-size: 13px; color: var(--muted); }
.auth-box .hint a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-box .hint a:hover { color: var(--gold); text-decoration: underline; }

/* ===== Alerts ===== */
.alert {
  padding: 12px 16px; border-radius: 10px; margin: 12px 0;
  border: 1px solid; font-size: 13px;
}
.alert.error { background: #fff3f3; border-color: rgba(220,38,38,0.25); color: #991b1b; }
.alert.info  { background: var(--gold-pale); border-color: var(--gold-line); color: var(--gold); }
.alert .btn  { margin-left: 8px; }

/* ===== Topbar additions ===== */
.topbar-right {
  margin-left: auto; display: flex; gap: 10px; align-items: center;
}
/* バランスピル:ゴールドのプレミアム感 */
.balance-pill {
  background: linear-gradient(180deg, var(--gold-3) 0%, var(--gold-2) 100%);
  border: 1px solid var(--gold);
  padding: 5px 14px; border-radius: 100px;
  font-weight: 700; color: var(--navy);
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(198,146,20,0.20), inset 0 1px 0 rgba(255,255,255,0.4);
  letter-spacing: 0.02em;
}

/* ===== Account page ===== */
.balance-display {
  font-size: 40px; font-weight: 900;
  color: var(--gold);
  text-align: center; padding: 20px 0;
  font-family: 'Noto Serif JP', serif;
  letter-spacing: -0.02em;
}
.kv { width: 100%; border-collapse: collapse; }
.kv th {
  text-align: left; color: var(--muted); font-weight: 600;
  padding: 8px 10px; width: 30%; border-bottom: 1px solid var(--border);
  font-size: 12px; letter-spacing: 0.04em;
}
.kv td { padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--text); }

.pos { color: var(--success); font-weight: 600; }
.neg { color: var(--danger); font-weight: 600; }

/* Plan badges */
.plan-trial    { background: var(--gold-pale); color: var(--gold); border: 1px solid var(--gold-line); }
.plan-paid     { background: #d1fae5; color: #065f46; }
.plan-suspended{ background: #fee2e2; color: #991b1b; }

/* Transaction type badges */
.type-grant_free  { background: #dbeafe; color: #1e3a8a; }
.type-grant_admin { background: #ede9fe; color: #5b21b6; }
.type-purchase    { background: #d1fae5; color: #065f46; }
.type-use         { background: #fee2e2; color: #991b1b; }
.type-expire      { background: #f3f4f6; color: #4b5563; }

/* Admin */
.container.wide { max-width: 1400px; }
.settings-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin-bottom: 12px;
}
.settings-grid label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.settings-grid input, .settings-grid select { margin-top: 6px; }
@media (max-width: 800px) {
  .settings-grid { grid-template-columns: 1fr; }
}

.btn.xs { padding: 3px 10px; font-size: 11px; }

/* =====================================================================
   スマートフォン最適化(本体管理画面)  v40
   ===================================================================== */

/* タブレット以下 */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 12px; padding: 0 12px; margin: 12px auto; }
  .avatars-row { flex-wrap: wrap; }
  .avatar-card { min-width: 140px; }
}

/* スマートフォン */
@media (max-width: 640px) {
  /* タップ時の文字自動拡大を抑制 */
  html { -webkit-text-size-adjust: 100%; }

  /* ヘッダー: 折り返して収める */
  .topbar { padding: 10px 14px; gap: 8px 10px; flex-wrap: wrap; }
  .topbar h1 { font-size: 16px; line-height: 1.3; }
  .topbar .sub { font-size: 11px; }
  .topbar-right { margin-left: auto; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
  .balance-pill { font-size: 12px; padding: 4px 10px; }

  /* コンテナ・カード */
  .container, .container.wide { margin: 12px auto; padding: 0 12px; }
  .card { padding: 14px; border-radius: 12px; }
  .card h2 { font-size: 17px; }
  .card h3 { font-size: 15px; }

  /* レイアウト(プロジェクト画面) */
  .layout { padding: 0 10px; gap: 12px; }
  .chat-pane { min-height: 60vh; }

  /* 大きい表は横スクロールで崩さない */
  .projects, table.projects, .card table, table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .projects th, .projects td, table th, table td { font-size: 12px; padding: 8px 10px; }

  /* 入力欄: iOSの自動ズーム防止のため16px、幅いっぱい */
  textarea, input[type=text], input[type=email], input[type=password],
  input[type=tel], input[type=number], input[type=search], select {
    font-size: 16px;
    width: 100%;
    box-sizing: border-box;
  }

  /* ボタン: 押しやすいサイズ。全幅ボタンは縦並び */
  button, .btn { padding: 11px 16px; font-size: 14px; min-height: 44px; }
  .btn.xs { min-height: 0; padding: 4px 10px; font-size: 11px; }
  .btn.full, .primary.full { width: 100%; }
  .row { flex-wrap: wrap; gap: 8px; }
  .row .btn, .row button { flex: 1 1 auto; }

  /* コスト表示などのグリッドは2列→1列で見やすく */
  .cost-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .cost-grid b { font-size: 15px; }

  /* チャットツール(検索など)は折り返す */
  .chat-tools { gap: 6px; }
  .chat-tools #chatSearch { min-width: 0; flex: 1 1 100%; }

  /* 認証・アカウントのカード */
  .auth-box { width: 100%; max-width: 100%; padding: 18px; }

  /* 設定グリッドは1列 */
  .settings-grid { grid-template-columns: 1fr; }

  /* アバター行は縦積み */
  .avatars-row { flex-direction: column; }
  .avatar-card { width: 100%; }

  /* 横はみ出しの保険 */
  body { overflow-x: hidden; }
  img { max-width: 100%; height: auto; }
}

/* 極小端末 */
@media (max-width: 380px) {
  .topbar h1 { font-size: 15px; }
  .cost-grid { grid-template-columns: 1fr; }
}
