/* design.ai-portal.jp — メインスタイル
   DESIGN.md 準拠: Notion 日本語版ベース（kzhrknt/awesome-design-md-jp）
   Phase 0 実測: 生成 25〜85秒 → プログレスバー必須・長め待機メッセージ */

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

:root {
  /* ─── ニュートラル ─────────────────────────────────────────────────── */
  --c-bg:        #f7f7f8;
  --c-surface:   #ffffff;
  --c-border:    #e0e0e0;
  --c-text:      #1a1a1a;
  --c-muted:     #6b7280;

  /* ─── プライマリ（アクション） ────────────────────────────────────── */
  --c-primary:      #2563eb;
  --c-primary-h:    #1d4ed8;
  --c-primary-light:#eff6ff;

  /* ─── セマンティック ──────────────────────────────────────────────── */
  --c-danger:        #dc2626;
  --c-warning:       #f59e0b;
  --c-warning-bg:    #fffbeb;
  --c-warning-border:#fde68a;
  --c-success:       #059669;

  /* ─── ロール別バッジ色（DESIGN.md: material=青/style=ピンク/img2img=緑） */
  --c-role-material: #3b82f6;
  --c-role-style:    #ec4899;
  --c-role-img2img:  #10b981;

  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

body {
  /* DESIGN.md 3.1: Hiragino Sans → Yu Gothic UI → Inter のシステムフォントスタック */
  font-family: -apple-system, BlinkMacSystemFont,
    "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Yu Gothic UI", "Meiryo",
    Inter, "Segoe UI", sans-serif;
  /* DESIGN.md 3.2: 本文 14px / line-height 1.6 */
  font-size: 14px;
  line-height: 1.6;
  color: var(--c-text);
  background: var(--c-bg);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  /* DESIGN.md 3.4: 禁則処理 */
  word-break: break-word;
  overflow-wrap: break-word;
}

/* ─── ヘッダー（DESIGN.md 4-1: 高さ 52px）────────────────────────────── */
header {
  height: 52px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
/* DESIGN.md 3.2: App Title 15px / 600 */
header h1 { font-size: 15px; font-weight: 600; }
/* DESIGN.md 4-1: コストバッジ — pill 型・緑バッジ */
header .cost-badge {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-success);
  background: #d1fae5;
  padding: 3px 8px;
  border-radius: 12px;
}
.btn-back {
  background: none; border: none; cursor: pointer;
  color: var(--c-primary); font-size: 20px; line-height: 1;
}

/* ─── チャット一覧画面 ─────────────────────────────────────────────────── */
#screen-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}
.list-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.list-header h2 { font-size: 16px; font-weight: 600; }

/* DESIGN.md 4-2: チャット一覧カード */
.chat-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: box-shadow .15s;
}
.chat-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.10); }
.chat-card .title { font-weight: 600; margin-bottom: 4px; }
/* DESIGN.md: メタ 12px / muted / flex */
.chat-card .meta  { font-size: 12px; color: var(--c-muted); display: flex; gap: 12px; }

/* ─── 3ペインレイアウト（DESIGN.md 4-3 準拠）──────────────────────────── */
#screen-chat {
  flex: 1;
  display: none;
  overflow: hidden;
}
#screen-chat.active { display: flex; }

/* DESIGN.md 4-3: 左パネル 200px */
.pane-left {
  width: 200px;
  flex-shrink: 0;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  padding: 16px 12px;
  overflow-y: auto;
}
/* DESIGN.md 4-4: セクションラベル uppercase / 0.05em */
.pane-left h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
/* DESIGN.md 4-4: 商品アイテム */
.product-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--c-text);
  transition: background .12s, color .12s;
}
.product-item.active,
.product-item:hover {
  background: var(--c-primary-light);
  color: var(--c-primary);
}

/* DESIGN.md 4-3: 中央パネル — bg は --c-bg（画像が映えるよう surface より暗め） */
.pane-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--c-bg);
}

/* DESIGN.md 4-5: チャットメッセージエリア */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* DESIGN.md 4-6: 生成画像カード */
.msg-image {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  overflow: hidden;
  max-width: 600px;
  box-shadow: var(--shadow);
}
.msg-image img { width: 100%; display: block; }
.msg-image .img-meta {
  padding: 10px 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  border-top: 1px solid var(--c-border);
}
/* DESIGN.md 4-6: バッジ */
.img-meta .badge {
  font-size: 11px; padding: 2px 7px; border-radius: 10px;
  background: #f3f4f6; color: var(--c-muted);
}
.img-meta .badge.cost { background: #d1fae5; color: var(--c-success); }
.img-meta .badge.time { background: #ede9fe; color: #7c3aed; }
.img-meta .img-actions { margin-left: auto; display: flex; gap: 6px; }

/* DESIGN.md 4-5: ユーザーメッセージ */
.msg-text {
  background: var(--c-primary-light);
  border-radius: var(--radius);
  padding: 10px 14px;
  max-width: 480px;
  align-self: flex-end;
  font-size: 14px;
  line-height: 1.6;
}

/* DESIGN.md 4-5: システムメッセージ（エラー） */
.msg-system {
  color: var(--c-danger);
  font-size: 13px;
  background: #fef2f2;
  border-radius: var(--radius);
  padding: 8px 12px;
}

/* ─── 入力エリア（DESIGN.md 4-7）──────────────────────────────────────── */
.chat-input-area {
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* DESIGN.md 4-7: ★ テキストラジオ — 赤ラベルで必須強調 */
.text-mode-row {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
}
.text-mode-row .label {
  font-weight: 600;
  color: var(--c-danger);
  font-size: 12px;
}
.text-mode-row label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
#text-content-wrap { display: none; }
#text-content {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  transition: border-color .15s;
}
#text-content:focus { outline: none; border-color: var(--c-primary); }

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#prompt-input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  min-height: 38px;
  max-height: 120px;
  transition: border-color .15s;
}
#prompt-input:focus { outline: none; border-color: var(--c-primary); }

/* DESIGN.md 4-7: サイズ select */
.size-select {
  padding: 8px 6px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: inherit;
  background: var(--c-surface);
  cursor: pointer;
}

/* DESIGN.md 4-7: モデルトグル */
.model-toggle {
  display: flex;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 12px;
}
.model-toggle button {
  padding: 8px 10px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--c-muted);
  font-family: inherit;
  transition: background .12s, color .12s;
}
.model-toggle button.active {
  background: var(--c-primary);
  color: #fff;
}

/* ─── プログレスバー（DESIGN.md 4-9 / Phase 0 必須: 平均40秒・最大85秒）── */
.progress-wrap {
  display: none;
  padding: 12px 16px;
  background: var(--c-warning-bg);
  border-top: 1px solid var(--c-warning-border);
  flex-direction: column;
  gap: 6px;
}
.progress-wrap.visible { display: flex; }
.progress-bar-track {
  height: 6px;
  background: var(--c-warning-border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #f97316);
  border-radius: 3px;
  width: 0%;
  transition: width .5s linear;
  animation: progress-pulse 2s ease-in-out infinite;
}
@keyframes progress-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .7; }
}
.progress-msg {
  font-size: 12px;
  color: #92400e;
  display: flex;
  align-items: center;
  gap: 6px;
}
.progress-msg .spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--c-warning-border);
  border-top-color: var(--c-warning);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* DESIGN.md 4-8: 生成ボタン */
#btn-generate {
  padding: 8px 18px;
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
#btn-generate:hover:not(:disabled) { background: var(--c-primary-h); }
#btn-generate:disabled { opacity: .5; cursor: not-allowed; }

/* ─── 右パネル（DESIGN.md 4-10）──────────────────────────────────────── */
.pane-right {
  width: 280px;
  flex-shrink: 0;
  background: var(--c-surface);
  border-left: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pane-right-tabs {
  display: flex;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}
.pane-right-tabs button {
  flex: 1; padding: 10px 0; border: none; background: none;
  font-size: 13px; font-family: inherit; cursor: pointer;
  color: var(--c-muted);
  border-bottom: 2px solid transparent;
  transition: color .12s, border-color .12s;
}
.pane-right-tabs button.active {
  color: var(--c-primary);
  border-bottom-color: var(--c-primary);
}
.asset-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.asset-section { margin-bottom: 16px; }
/* DESIGN.md 4-10: セクションラベル uppercase / 11px */
.asset-section h4 {
  font-size: 11px;
  font-weight: 600;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

/* DESIGN.md 4-10: アセットグリッド — 2列固定（DESIGN.md 仕様: 280px幅で3列は小さすぎる） */
.asset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.asset-thumb {
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  background: var(--c-bg);
  transition: border-color .12s;
}
.asset-thumb img { width: 100%; height: 100%; object-fit: cover; }
.asset-thumb.selected { border-color: var(--c-primary); }
/* DESIGN.md 4-10: 役割ドット */
.asset-thumb .role-dot {
  position: absolute; top: 3px; right: 3px;
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1.5px solid #fff;
}
.role-dot.material  { background: var(--c-role-material); }
.role-dot.style     { background: var(--c-role-style); }
.role-dot.img2img   { background: var(--c-role-img2img); }

/* DESIGN.md 4-10: 役割選択ポップオーバー */
.role-picker {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(0,0,0,.8);
  border-radius: 0 0 4px 4px;
}
.role-picker button {
  flex: 1; border: none; background: none;
  color: #fff; font-size: 9px; padding: 4px 0;
  font-family: inherit;
  cursor: pointer; transition: background .1s;
}
.role-picker button:hover { background: rgba(255,255,255,.15); }

/* ─── 共通ボタン（DESIGN.md 4-11）────────────────────────────────────── */
.btn {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--c-bg); }
.btn-primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn-primary:hover { background: var(--c-primary-h); }

/* ─── 新規チャットボタン ─────────────────────────────────────────────── */
.btn-new-chat {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: var(--c-primary); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 13px; font-family: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.btn-new-chat:hover { background: var(--c-primary-h); }

/* ─── ユーティリティ ─────────────────────────────────────────────────── */
.hidden { display: none !important; }
