/* =============================================================
   CORVUS Dashboard - style.css
   Dark purple/navy theme, no build tools, CDN only
   ============================================================= */

/* ── 1. CSS 변수 ── */
:root {
  --bg-primary:    #0f1117;
  --bg-secondary:  #1a1d2e;
  --bg-tertiary:   #252840;
  --accent:        #7c6af7;
  --accent-hover:  #9b8ffa;
  --text-primary:  #e8e9f3;
  --text-secondary:#8b8fa8;
  --text-muted:    #565a73;
  --border:        #2d3055;
  --success:       #4caf78;
  --warning:       #f5a623;
  --error:         #e05c5c;
  --running:       #5cc8f5;

  --sidebar-width: 240px;
  --radius-sm:     6px;
  --radius-md:     10px;
  --radius-lg:     16px;
  --transition:    0.2s ease;
}

/* ── 2. 리셋 & 기본 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

button {
  cursor: pointer;
  border: none;
  font-family: inherit;
  font-size: inherit;
}

/* ── 3. 레이아웃 ── */
#app-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── 4. 사이드바 ── */
#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo .logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent) 0%, #5b4de0 100%);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-logo .logo-text {
  display: flex;
  flex-direction: column;
}

.sidebar-logo .logo-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-primary);
}

.sidebar-logo .logo-sub {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 8px 4px;
  margin-top: 8px;
}

.nav-label:first-child { margin-top: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  user-select: none;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(124, 106, 247, 0.15);
  color: var(--accent);
}

.nav-item .nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-item .nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
  padding: 1px 6px;
  line-height: 1.6;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-footer .version {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-footer .sys-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot.online  { background: var(--success); box-shadow: 0 0 5px var(--success); }
.status-dot.offline { background: var(--error); }
.status-dot.connecting { background: var(--warning); animation: pulse 1s infinite; }

/* ── 5. 메인 컨텐츠 ── */
#main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* 탭 섹션 공통 */
.tab-section {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 28px 32px;
  animation: fadeIn 0.25s ease;
}

.tab-section.active {
  display: flex;
}

/* ── 6. 대시보드 ── */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.page-header .page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

/* 통계 카드 그리드 */
#stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition);
}

.stat-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}

.stat-card:hover::before { opacity: 1; }

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.stat-icon.purple { background: rgba(124, 106, 247, 0.15); }
.stat-icon.green  { background: rgba(76, 175, 120, 0.15); }
.stat-icon.blue   { background: rgba(92, 200, 245, 0.15); }
.stat-icon.orange { background: rgba(245, 166, 35, 0.15); }

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.stat-change {
  font-size: 11px;
  color: var(--text-muted);
}

.stat-change.up   { color: var(--success); }
.stat-change.down { color: var(--error); }

/* 에이전트 그리드 */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.section-header .refresh-btn {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  transition: color var(--transition), border-color var(--transition);
}

.section-header .refresh-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

#agents-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.agent-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color var(--transition), transform var(--transition);
}

.agent-card:hover {
  border-color: var(--border);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.agent-card-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--border) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.agent-info { flex: 1; min-width: 0; }

.agent-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-type {
  font-size: 11px;
  color: var(--text-muted);
}

.agent-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.agent-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.agent-last-active {
  font-size: 11px;
  color: var(--text-muted);
}

.agent-actions {
  display: flex;
  gap: 6px;
}

.btn-sm {
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* 태스크 테이블 */
.table-wrapper {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 32px;
}

#tasks-table {
  width: 100%;
  border-collapse: collapse;
}

#tasks-table thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

#tasks-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

#tasks-table tbody tr:last-child { border-bottom: none; }

#tasks-table tbody tr:hover { background: var(--bg-tertiary); }

#tasks-table tbody td {
  padding: 12px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.task-id {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 11px;
  color: var(--text-muted);
}

.task-title {
  color: var(--text-primary);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── 7. 상태 배지 ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.badge-active   { background: rgba(76,175,120,0.15); color: var(--success); }
.badge-active::before   { background: var(--success); }

.badge-inactive { background: rgba(86,90,115,0.2);  color: var(--text-muted); }
.badge-inactive::before { background: var(--text-muted); }

.badge-running  { background: rgba(92,200,245,0.15); color: var(--running); }
.badge-running::before  { background: var(--running); animation: pulse 1s infinite; }

.badge-error    { background: rgba(224,92,92,0.15);  color: var(--error); }
.badge-error::before    { background: var(--error); }

.badge-pending  { background: rgba(245,166,35,0.15); color: var(--warning); }
.badge-pending::before  { background: var(--warning); }

.badge-completed { background: rgba(76,175,120,0.15); color: var(--success); }
.badge-completed::before { background: var(--success); }

/* ── 8. 채팅 ── */
#tab-chat {
  padding: 0;
  flex: 1;
  overflow: hidden;
}

#chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.corvus-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #5b4de0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.chat-header-info .chat-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-header-info .chat-desc {
  font-size: 11px;
  color: var(--text-secondary);
}

#connection-status {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

#connection-status .status-dot { flex-shrink: 0; }

#messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* 메시지 버블 */
.message-row {
  display: flex;
  gap: 10px;
  animation: msgIn 0.22s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.message-row.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  align-self: flex-end;
}

.msg-avatar.corvus {
  background: linear-gradient(135deg, var(--accent), #5b4de0);
}

.msg-avatar.user-av {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
}

.msg-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 65%;
}

.message-row.user .msg-content { align-items: flex-end; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-row.corvus .msg-bubble {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message-row.user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-meta {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* 코드 블록 in message */
.msg-bubble code {
  background: rgba(0,0,0,0.25);
  border-radius: 4px;
  padding: 2px 5px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12px;
}

.msg-bubble pre {
  background: rgba(0,0,0,0.3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 8px;
  overflow-x: auto;
}

.msg-bubble pre code {
  background: transparent;
  padding: 0;
}

/* 타이핑 인디케이터 */
#typing-indicator {
  display: none;
  padding: 0 24px 12px;
  animation: fadeIn 0.2s ease;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-secondary);
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingDot 1.2s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* 채팅 입력창 */
#chat-input-area {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#message-input::placeholder { color: var(--text-muted); }

#message-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 106, 247, 0.12);
}

#send-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
}

#send-btn:hover { background: var(--accent-hover); }
#send-btn:active { transform: scale(0.96); }
#send-btn:disabled { background: var(--bg-tertiary); color: var(--text-muted); cursor: not-allowed; }

/* 빈 상태 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.empty-state .empty-icon { font-size: 36px; opacity: 0.4; }

/* ── 9. 토스트 ── */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.25,0.8,0.25,1);
  max-width: 320px;
}

.toast.info    { border-left: 3px solid var(--accent); }
.toast.success { border-left: 3px solid var(--success); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.error   { border-left: 3px solid var(--error); }

.toast-icon { font-size: 15px; flex-shrink: 0; }
.toast-msg  { flex: 1; }
.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  padding: 0 2px;
  cursor: pointer;
  flex-shrink: 0;
}
.toast-close:hover { color: var(--text-primary); }

.toast.removing {
  animation: toastOut 0.25s ease forwards;
}

/* ── 10. 로딩 스피너 ── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* 스켈레톤 로딩 */
.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-tertiary) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}

/* ── 11. 스크롤바 ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* ── 12. 애니메이션 ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(30px); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

@keyframes typingDot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%           { transform: scale(1);   opacity: 1; }
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ── 13. 반응형 (1200px 이하) ── */
@media (max-width: 1200px) {
  #stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  :root { --sidebar-width: 56px; }

  .sidebar-logo .logo-text,
  .nav-item span:not(.nav-icon),
  .sidebar-footer .version,
  .nav-label,
  .nav-item .nav-badge { display: none; }

  .nav-item { justify-content: center; padding: 10px; }
  .sidebar-logo { padding: 16px 10px; justify-content: center; }

  .tab-section { padding: 20px 16px; }
  #agents-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  #stats-grid { grid-template-columns: repeat(2, 1fr); }
  .tab-section { padding: 14px 10px; }
  .msg-content { max-width: 80%; }
}
