/* ═══════════════════════════════════════════════════════
   Gravity Web — Design System & Layout
   ═══════════════════════════════════════════════════════ */

:root {
  /* Color Palette — Deep space dark theme */
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2236;
  --bg-elevated: #1e293b;
  --bg-hover: #243047;
  --bg-active: #2d3c56;

  --border-subtle: rgba(99, 102, 241, 0.12);
  --border-medium: rgba(99, 102, 241, 0.25);
  --border-strong: rgba(99, 102, 241, 0.5);

  --accent-primary: #6366f1;
  --accent-secondary: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --accent-surface: rgba(99, 102, 241, 0.08);

  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #a5b4fc;

  --success: #34d399;
  --warning: #fbbf24;
  --error: #f87171;
  --info: #60a5fa;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', monospace;

  /* Spacing */
  --sidebar-width: 280px;
  --header-height: 56px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

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

html,
body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ─── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-active);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ─── Header ─────────────────────────────────────────── */
.header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 100;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.logo-accent {
  background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-normal);
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-dot.error {
  background: var(--error);
}

/* ─── Main Layout ────────────────────────────────────── */
.main-layout {
  display: flex;
  height: calc(100vh - var(--header-height));
}

/* ─── Sidebar ────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
}

.sidebar-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

/* Session Card */
.session-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.session-card:hover {
  background: var(--bg-hover);
}

.session-card.active {
  background: var(--accent-surface);
  border-color: var(--border-medium);
}

.session-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.session-indicator.connected {
  background: var(--success);
  box-shadow: 0 0 4px rgba(52, 211, 153, 0.4);
}

.session-indicator.connecting {
  background: var(--warning);
  animation: pulse 1.5s infinite;
}

.session-indicator.disconnected {
  background: var(--text-muted);
}

.session-indicator.error {
  background: var(--error);
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

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

.session-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-detail {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.session-remove {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all var(--transition-fast);
  font-size: 14px;
}

.session-card:hover .session-remove {
  opacity: 1;
}

.session-remove:hover {
  color: var(--error);
  background: rgba(248, 113, 113, 0.1);
}

/* ─── Chat Area ──────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 13px;
  max-width: 300px;
  text-align: center;
  line-height: 1.5;
}

/* Chat Container */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
}

.chat-session-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-session-name {
  font-weight: 600;
  font-size: 14px;
}

.chat-session-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent-surface);
  color: var(--text-accent);
}

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

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg-primary);
}

.chat-welcome {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 13px;
}

/* Antigravity 에서 가져온 구조화 메시지를 렌더링하는 컴포넌트 */

/* --- 메시지 공통 --- */
.chat-messages>* {
  margin-bottom: 8px;
}

/* --- 작업 카드 (Task boundary) --- */
.msg-card {
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-secondary);
  transition: border-color var(--transition-fast);
}

.msg-card:hover {
  border-color: var(--border-medium);
}

.msg-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
}

.msg-toggle {
  font-size: 11px;
  color: var(--text-muted);
  width: 14px;
  text-align: center;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.msg-card-header:hover .msg-toggle {
  color: var(--text-primary);
}

.msg-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.msg-card-summary {
  width: 100%;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  padding-left: 22px;
}

.msg-card-body {
  border-top: 1px solid var(--border-subtle);
  padding: 8px 14px 10px;
}

.msg-card-actions {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  border-top: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.msg-step {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.msg-step-icon {
  width: 16px;
  text-align: center;
  flex-shrink: 0;
  font-size: 11px;
}

.msg-step-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

/* --- 텍스트 메시지 --- */
.msg-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
  padding: 4px 0;
  word-break: break-word;
}

.msg-text p {
  margin: 4px 0;
}

.msg-text ul,
.msg-text ol {
  padding-left: 18px;
  margin: 4px 0;
}

.msg-text li {
  margin: 2px 0;
}

.msg-text strong {
  font-weight: 600;
}

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

.msg-text a:hover {
  text-decoration: underline;
}

.msg-text code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-accent);
}

.msg-text pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
}

.msg-text img {
  max-width: 320px;
  max-height: 200px;
  border-radius: 8px;
  margin: 4px 0;
}

/* --- Thought Process --- */
.msg-thought {
  margin: 4px 0;
}

.msg-thought-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 10px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}

.msg-thought-btn:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.msg-thought-icon {
  font-size: 14px;
}

/* --- 코드 블록 --- */
.msg-code-block {
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: hidden;
  margin: 4px 0;
}

.msg-code-lang {
  padding: 4px 12px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: lowercase;
}

.msg-code-block pre {
  margin: 0;
  padding: 10px 12px;
  background: var(--bg-primary);
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
}

.msg-code-block code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
}

/* --- 이미지 --- */
.msg-image {
  margin: 4px 0;
}

.msg-image img {
  max-width: 320px;
  max-height: 200px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  object-fit: contain;
}

/* --- 액션 버튼 --- */
.msg-actions {
  display: flex;
  gap: 6px;
  padding: 4px 0;
  flex-wrap: wrap;
}

.msg-action-btn {
  padding: 4px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: default;
  transition: all var(--transition-fast);
}

.msg-action-btn[style*="cursor: pointer"]:hover {
  background: var(--bg-hover);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.msg-action-btn.msg-action-primary {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

.msg-action-btn.msg-action-primary:hover {
  background: var(--accent-secondary);
  transform: scale(1.02);
}

/* Chat Input */

/* --- 사용자 메시지 --- */
.msg-user {
  background: var(--accent-primary);
  color: white;
  padding: 8px 14px;
  border-radius: 12px 12px 4px 12px;
  margin: 4px 0;
  margin-left: auto;
  max-width: 80%;
  font-size: 13px;
  line-height: 1.5;
  width: fit-content;
}

/* --- 상태 표시 --- */
.msg-status {
  font-size: 12px;
  color: var(--text-muted, var(--text-secondary));
  opacity: 0.6;
  padding: 2px 0;
  font-style: italic;
}

/* --- 마크다운 렌더링 콘텐츠 --- */
.msg-text table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 12px;
}

.msg-text table th,
.msg-text table td {
  border: 1px solid var(--border-subtle);
  padding: 6px 10px;
  text-align: left;
}

.msg-text table th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-primary);
}

.msg-text table td {
  color: var(--text-secondary);
}

.msg-text blockquote {
  border-left: 3px solid var(--accent-primary);
  padding: 4px 12px;
  margin: 8px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.msg-text ul,
.msg-text ol {
  padding-left: 20px;
  margin: 4px 0;
}

.msg-text li {
  margin: 2px 0;
}

.msg-text h1,
.msg-text h2,
.msg-text h3,
.msg-text h4 {
  margin: 8px 0 4px;
  color: var(--text-primary);
}

.msg-text h3 {
  font-size: 14px;
}

.msg-text h4 {
  font-size: 13px;
}

.msg-text a {
  color: var(--accent-primary);
  text-decoration: underline;
}

.msg-text code {
  background: var(--bg-tertiary);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.msg-text pre {
  background: var(--bg-tertiary);
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}

.msg-text pre code {
  background: none;
  padding: 0;
}

.msg-text hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 8px 0;
}

.msg-text strong {
  color: var(--text-primary);
}

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
}

.chat-input-area textarea {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color var(--transition-fast);
}

.chat-input-area textarea::placeholder {
  color: var(--text-muted);
}

.chat-input-area textarea:focus {
  border-color: var(--accent-primary);
}

/* ─── Buttons ────────────────────────────────────────── */
.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-sm {
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition-fast);
}

.btn-sm:hover {
  background: var(--bg-hover);
  border-color: var(--border-medium);
}

.btn-send {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-primary);
  border: none;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.btn-send:hover {
  background: var(--accent-secondary);
  transform: scale(1.05);
}

.btn-send:active {
  transform: scale(0.95);
}

.btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
}

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

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

/* ─── Modal ──────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: 14px;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: none;
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 0;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 20px 18px;
}

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

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.form-group input:focus {
  border-color: var(--accent-primary);
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 4px;
}

.form-hint code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-accent);
}

/* ─── Screenshot Overlay ─────────────────────────────── */
.screenshot-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
}

.screenshot-content {
  max-width: 90%;
  max-height: 90%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-medium);
}

.screenshot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-elevated);
  font-size: 13px;
  color: var(--text-secondary);
}

.screenshot-content img {
  display: block;
  max-width: 100%;
  max-height: calc(90vh - 50px);
  object-fit: contain;
}

/* ─── Notification Toast ─────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 300;
  animation: slideInRight 0.3s ease, fadeOut 0.3s ease 2.7s;
  animation-fill-mode: forwards;
}

@keyframes slideInRight {
  from {
    transform: translateX(100px);
    opacity: 0;
  }

  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateY(10px);
  }
}

.toast.error {
  border-color: var(--error);
}

.toast.success {
  border-color: var(--success);
}

/* ─── View Tabs (Chat ↔ Mirror) ──────────────────────── */
.view-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 2px;
}

.view-tab {
  padding: 4px 12px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.view-tab:hover {
  color: var(--text-secondary);
}

.view-tab.active {
  background: var(--accent-primary);
  color: white;
  box-shadow: 0 1px 4px rgba(99, 102, 241, 0.3);
}

/* ─── Mirror Container ───────────────────────────────── */
.mirror-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
}

.mirror-container canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: default;
  outline: none;
  border-radius: 4px;
}

.mirror-container canvas:focus {
  box-shadow: 0 0 0 2px var(--accent-primary);
}

.mirror-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
  animation: pulse 1.5s infinite;
}