/* AI Council - Design System */
:root {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-elevated: #242835;
  --border: #2e3345;
  --text: #e4e7ef;
  --text-dim: #8b90a0;
  --claude: #c084fc;
  --claude-bg: rgba(192,132,252,0.1);
  --gemini: #60a5fa;
  --gemini-bg: rgba(96,165,250,0.1);
  --codex: #34d399;
  --codex-bg: rgba(52,211,153,0.1);
  --user: #f59e0b;
  --user-bg: rgba(245,158,11,0.1);
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 8px;
  --radius-lg: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', -apple-system, sans-serif; background: var(--bg); color: var(--text); height: 100vh; height: 100dvh; overflow: hidden; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* Header */
#header { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; background: var(--bg-surface); border-bottom: 1px solid var(--border); }
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 20px; font-weight: 700; }
.subtitle { color: var(--text-dim); font-size: 13px; }
.header-right { display: flex; gap: 8px; }

/* Buttons */
.btn { padding: 6px 14px; border-radius: var(--radius); border: none; cursor: pointer; font-size: 13px; font-weight: 500; transition: all 0.15s; }
.btn-primary { background: var(--claude); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-outline:hover { border-color: var(--text-dim); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.hidden { display: none !important; }

/* Main Layout */
#main { display: flex; flex: 1; overflow: hidden; }

/* Sidebar */
#sidebar { width: 280px; background: var(--bg-surface); border-right: 1px solid var(--border); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }
.sidebar-section h3 { font-size: 13px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; }

/* Mode Tabs */
.mode-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: var(--radius); padding: 3px; }
.mode-tab { flex: 1; padding: 6px; border: none; background: transparent; color: var(--text-dim); border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; }
.mode-tab.active { background: var(--bg-elevated); color: var(--text); }

/* AI Toggles */
.ai-toggles { display: flex; flex-direction: column; gap: 8px; }
.ai-toggle { display: flex; align-items: center; gap: 8px; padding: 8px; background: var(--bg); border-radius: var(--radius); flex-wrap: wrap; }
.ai-toggle input[type="checkbox"] { accent-color: var(--claude); }
.ai-badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 4px; }
.ai-badge.claude { background: var(--claude-bg); color: var(--claude); }
.ai-badge.gemini { background: var(--gemini-bg); color: var(--gemini); }
.ai-badge.codex { background: var(--codex-bg); color: var(--codex); }
.persona-select { width: 100%; margin-top: 4px; padding: 4px 6px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 4px; color: var(--text); font-size: 11px; }

/* Settings */
.setting-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.setting-row label { font-size: 12px; color: var(--text-dim); }
.setting-row input { padding: 6px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 13px; }
.count-badge { background: var(--bg-elevated); padding: 1px 6px; border-radius: 10px; font-size: 11px; }

/* Persona List */
.persona-list { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.persona-item { padding: 4px 8px; font-size: 11px; color: var(--text-dim); background: var(--bg); border-radius: 4px; cursor: default; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Chat Area */
#chatArea { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }

/* Message Bubbles */
.message { display: flex; gap: 10px; max-width: 85%; animation: fadeIn 0.2s; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.claude { align-self: flex-start; }
.message.gemini { align-self: flex-start; }
.message.codex { align-self: flex-start; }
.message.system { align-self: center; max-width: 100%; }

.msg-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; flex-shrink: 0; }
.msg-avatar.claude { background: var(--claude-bg); color: var(--claude); }
.msg-avatar.gemini { background: var(--gemini-bg); color: var(--gemini); }
.msg-avatar.codex { background: var(--codex-bg); color: var(--codex); }
.msg-avatar.user { background: var(--user-bg); color: var(--user); }
.msg-avatar.system { background: var(--bg-elevated); color: var(--text-dim); }

.msg-body { display: flex; flex-direction: column; gap: 4px; }
.msg-header { display: flex; align-items: center; gap: 6px; }
.msg-name { font-size: 12px; font-weight: 600; }
.msg-name.claude { color: var(--claude); }
.msg-name.gemini { color: var(--gemini); }
.msg-name.codex { color: var(--codex); }
.msg-name.user { color: var(--user); }
.msg-name.system { color: var(--text-dim); }
.msg-persona { font-size: 10px; color: var(--text-dim); }
.msg-time { font-size: 10px; color: var(--text-dim); }

.msg-content { padding: 10px 14px; border-radius: var(--radius-lg); font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.message.claude .msg-content { background: var(--claude-bg); border: 1px solid rgba(192,132,252,0.2); }
.message.gemini .msg-content { background: var(--gemini-bg); border: 1px solid rgba(96,165,250,0.2); }
.message.codex .msg-content { background: var(--codex-bg); border: 1px solid rgba(52,211,153,0.2); }
.message.user .msg-content { background: var(--user-bg); border: 1px solid rgba(245,158,11,0.2); }
.message.system .msg-content { background: var(--bg-elevated); border: 1px solid var(--border); font-size: 12px; color: var(--text-dim); text-align: center; }

/* Streaming indicator */
.streaming .msg-content::after { content: ' '; display: inline-block; width: 6px; height: 14px; background: currentColor; animation: blink 0.8s infinite; margin-left: 2px; vertical-align: text-bottom; }

/* Input Bar */
#inputBar { padding: 16px 20px; background: var(--bg-surface); border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-end; }
#userInput { flex: 1; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--text); font-size: 14px; resize: none; font-family: inherit; line-height: 1.5; }
#userInput:focus { outline: none; border-color: var(--claude); }
.input-actions { display: flex; gap: 6px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; min-width: 400px; max-width: 600px; }
.modal-content h2 { margin-bottom: 16px; }

/* Health Check */
.health-item { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--bg); border-radius: var(--radius); margin-bottom: 8px; }
.health-dot { width: 10px; height: 10px; border-radius: 50%; }
.health-dot.ok { background: var(--success); }
.health-dot.fail { background: var(--danger); }
.health-dot.checking { background: var(--user); animation: pulse 1s infinite; }
.health-name { font-weight: 600; font-size: 14px; }
.health-detail { font-size: 12px; color: var(--text-dim); }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* History List */
.history-list { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.history-item { padding: 8px 10px; background: var(--bg); border-radius: var(--radius); cursor: pointer; transition: background 0.15s; }
.history-item:hover { background: var(--bg-elevated); }
.history-item .history-topic { font-size: 12px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .history-meta { font-size: 10px; color: var(--text-dim); margin-top: 2px; }

/* Markdown Content Styles */
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 8px 0 4px; }
.msg-content h1 { font-size: 18px; }
.msg-content h2 { font-size: 16px; }
.msg-content h3 { font-size: 14px; }
.msg-content p { margin: 4px 0; }
.msg-content ul, .msg-content ol { margin: 4px 0; padding-left: 20px; }
.msg-content pre { background: #1e1e2e; border-radius: 6px; padding: 12px; overflow-x: auto; margin: 8px 0; }
.msg-content code { font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: 13px; }
.msg-content :not(pre) > code { background: var(--bg-elevated); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.msg-content table { border-collapse: collapse; margin: 8px 0; width: 100%; }
.msg-content th, .msg-content td { border: 1px solid var(--border); padding: 6px 10px; font-size: 13px; text-align: left; }
.msg-content th { background: var(--bg-elevated); font-weight: 600; }
.msg-content blockquote { border-left: 3px solid var(--claude); padding-left: 12px; margin: 8px 0; color: var(--text-dim); }

/* Thinking/Loading indicator */
.msg-thinking { display: flex; align-items: center; gap: 6px; padding: 8px 14px; color: var(--text-dim); font-size: 13px; }
.msg-thinking .dot-pulse { display: flex; gap: 3px; }
.msg-thinking .dot-pulse span { width: 5px; height: 5px; background: var(--text-dim); border-radius: 50%; animation: dotPulse 1.2s infinite; }
.msg-thinking .dot-pulse span:nth-child(2) { animation-delay: 0.2s; }
.msg-thinking .dot-pulse span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }

/* Login Overlay */
.login-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center; z-index: 200; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.login-box { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 40px; width: 360px; text-align: center; }
.login-box h2 { font-size: 24px; margin-bottom: 8px; color: var(--claude); }
.login-box p { color: var(--text-dim); font-size: 14px; margin-bottom: 20px; }
.login-box input { width: 100%; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 15px; margin-bottom: 12px; text-align: center; }
.login-box input:focus { outline: none; border-color: var(--claude); }
.login-box .btn { width: 100%; padding: 10px; font-size: 15px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 20px; }

/* ========================================
   Mobile Sidebar Toggle (공통)
   ======================================== */
.sidebar-toggle { display: none; align-items: center; justify-content: center; width: 36px; height: 36px; background: transparent; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 18px; cursor: pointer; flex-shrink: 0; }
.sidebar-close { display: none; position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 18px; cursor: pointer; align-items: center; justify-content: center; z-index: 51; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 49; }

/* 헤더 활성 AI 표시 (모바일) */
.active-agents { display: none; gap: 6px; align-items: center; }
.agent-dot { width: 8px; height: 8px; border-radius: 50%; }
.agent-dot.claude { background: var(--claude); }
.agent-dot.gemini { background: var(--gemini); }
.agent-dot.codex { background: var(--codex); }
.active-mode-label { font-size: 11px; color: var(--text-dim); font-weight: 500; }

/* ========================================
   Mobile Responsive (max-width: 768px)
   ======================================== */
@media (max-width: 768px) {
  /* -- 안드로이드 브라우저 높이 보정 -- */
  body, #app {
    height: 100vh;
    height: 100dvh;
    height: calc(var(--vh, 1vh) * 100);
  }

  /* -- Safe area 패딩 -- */
  #header {
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    flex-shrink: 0;
  }
  .header-left { gap: 8px; }
  .header-left h1 { font-size: 16px; white-space: nowrap; }
  .subtitle { display: none; }
  .active-agents { display: flex; }
  .header-right .btn { padding: 6px 10px; font-size: 11px; min-height: 36px; }
  .sidebar-toggle { display: flex; }

  /* -- Main: 사이드바 오버레이 전환 -- */
  #main { position: relative; flex: 1; min-height: 0; }
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    max-width: 82vw;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 56px 16px 16px;
    border-right: 1px solid var(--border);
  }
  #sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; }
  .sidebar-backdrop.visible { display: block; }

  /* -- 채팅 영역 전체 너비 -- */
  #chatArea { width: 100%; min-height: 0; }
  #messages { padding: 12px; gap: 8px; flex: 1; min-height: 0; }

  /* -- 입력바: safe area 하단 -- */
  #inputBar {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    gap: 8px;
    flex-shrink: 0;
  }
  #userInput { font-size: 16px; padding: 10px 12px; min-height: 44px; border-radius: var(--radius); }
  .input-actions .btn { min-width: 52px; min-height: 44px; padding: 8px 14px; font-size: 14px; border-radius: var(--radius); }

  /* -- 메시지 -- */
  .message { max-width: 94%; gap: 8px; }
  .msg-avatar { width: 28px; height: 28px; font-size: 12px; }
  .msg-content { padding: 8px 12px; font-size: 13px; line-height: 1.5; }
  .msg-content pre { padding: 8px; font-size: 12px; }

  /* -- 사이드바 내부 -- */
  .mode-tab { padding: 10px 6px; font-size: 13px; min-height: 40px; }
  .ai-toggle { padding: 10px; }
  .ai-toggle input[type="checkbox"] { width: 20px; height: 20px; }
  .persona-select { padding: 8px 6px; font-size: 13px; min-height: 36px; }
  .persona-list { max-height: 120px; }
  .history-list { max-height: 150px; }
  .setting-row input { padding: 8px; font-size: 14px; min-height: 40px; }

  /* -- 모달 -- */
  .modal-content { min-width: unset; width: calc(100vw - 32px); max-height: 80vh; overflow-y: auto; }

  /* -- 로그인 -- */
  .login-box { width: calc(100vw - 40px); max-width: 360px; padding: 28px 20px; }
  .login-box input { font-size: 16px; }
}
