/* ============================================================
   PaperSmith — Premium Dark Theme
   ============================================================ */

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

:root {
  --bg-root: #0a0a0f;
  --bg-card: #12121a;
  --bg-card-hover: #16161f;
  --bg-elevated: #1a1a26;
  --border: #1e1e2e;
  --border-subtle: #16162a;
  --text-primary: #e4e4ed;
  --text-secondary: #8888a4;
  --text-muted: #55556a;
  --accent: #10b981;
  --accent-dim: #0d9668;
  --accent-glow: rgba(16, 185, 129, 0.25);
  --accent2: #8b5cf6;
  --accent2-dim: #7c3aed;
  --accent2-glow: rgba(139, 92, 246, 0.2);
  --danger: #ef4444;
  --sidebar-width: 300px;
  --topbar-height: 56px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg-root);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Custom 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-muted);
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: rgba(18, 18, 26, 0.7);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-right: 1px solid var(--border);
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

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

.brand-icon {
  font-size: 28px;
  line-height: 1;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-tagline {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: var(--transition);
}
.sidebar-close:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Sidebar Sections ---------- */
.sidebar-section {
  padding: 12px 20px;
}

.section-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

/* Select */
.select-wrapper {
  position: relative;
}

.select-wrapper select {
  width: 100%;
  appearance: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 10px 36px 10px 14px;
  cursor: pointer;
  transition: var(--transition);
  outline: none;
}
.select-wrapper select:hover {
  border-color: var(--accent-dim);
}
.select-wrapper select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* File Tree */
.files-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.file-tree {
  flex: 1;
  overflow-y: auto;
  min-height: 60px;
  max-height: 300px;
}

.file-tree-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 24px 0;
  font-style: italic;
}

.file-tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: default;
  transition: var(--transition);
  word-break: break-all;
}
.file-tree-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.file-tree-item .file-icon {
  flex-shrink: 0;
  font-size: 14px;
}
.file-tree-item .file-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Download Button */
.download-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #059669);
  color: #fff;
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.download-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow), 0 0 40px rgba(16, 185, 129, 0.15);
}
.download-btn:active {
  transform: translateY(0);
}

/* Token Stats */
.token-section {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.token-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.token-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
}
.token-label {
  color: var(--text-muted);
}
.token-value {
  color: var(--text-secondary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.token-row.total {
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
  margin-top: 2px;
}
.token-row.total .token-label {
  color: var(--text-secondary);
}
.token-row.total .token-value {
  color: var(--accent);
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

/* Topbar */
.topbar {
  display: none;
  align-items: center;
  padding: 0 16px;
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-radius: 6px;
  transition: var(--transition);
}
.hamburger:hover {
  background: var(--bg-elevated);
}
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: var(--transition);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 12px;
}
.topbar-icon {
  font-size: 20px;
}
.topbar-title {
  font-weight: 700;
  font-size: 1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.topbar-spacer {
  flex: 1;
}

/* ---------- Chat Container ---------- */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 8px;
  scroll-behavior: smooth;
}

/* Welcome Hero */
.welcome-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 24px 40px;
  animation: fadeInUp 0.6s ease;
}

.welcome-icon {
  font-size: 56px;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 20px var(--accent-glow));
  animation: float 3s ease-in-out infinite;
}

.welcome-title {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.welcome-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 440px;
  line-height: 1.6;
}

.welcome-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 32px;
  justify-content: center;
}

.hint-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 8px 16px;
  cursor: pointer;
  transition: var(--transition);
}
.hint-chip:hover {
  border-color: var(--accent-dim);
  color: var(--text-primary);
  background: var(--bg-card-hover);
  box-shadow: 0 0 20px var(--accent-glow);
  transform: translateY(-1px);
}

/* ---------- Messages ---------- */
.message {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  max-width: 780px;
  animation: fadeInUp 0.35s ease;
}

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

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.assistant .message-avatar {
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.message.user .message-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.message-bubble {
  border-radius: var(--radius);
  padding: 14px 18px;
  line-height: 1.65;
  font-size: 0.92rem;
  word-break: break-word;
  position: relative;
}

.message.assistant .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.message.user .message-bubble {
  background: linear-gradient(135deg, var(--accent-dim), #047857);
  color: #fff;
  border: none;
}

/* ---------- Code Blocks ---------- */
.message-bubble pre {
  background: #0d0d14;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 10px 0;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.6;
}

.message-bubble pre code {
  font-family: var(--font-mono);
  color: #c9d1d9;
  background: none;
  padding: 0;
  border-radius: 0;
}

.message-bubble code {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.84em;
  color: var(--accent);
}

/* Syntax highlighting (minimal) */
.code-keyword { color: #c678dd; }
.code-string { color: #98c379; }
.code-comment { color: #5c6370; font-style: italic; }
.code-number { color: #d19a66; }
.code-annotation { color: #e5c07b; }
.code-type { color: #61afef; }

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border-subtle);
  margin: -14px -16px 12px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.code-lang {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.code-copy-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.7rem;
  padding: 3px 10px;
  cursor: pointer;
  transition: var(--transition);
}
.code-copy-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent-dim);
  background: var(--bg-elevated);
}
.code-copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent-dim);
}

/* ---------- Typing Indicator ---------- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  animation: fadeInUp 0.3s ease;
}

.typing-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.typing-dots {
  display: flex;
  gap: 4px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

/* ---------- Input Bar ---------- */
.input-bar {
  padding: 0 24px 20px;
  background: linear-gradient(to top, var(--bg-root) 60%, transparent);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 20px;
  transition: var(--transition);
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), 0 8px 32px rgba(0,0,0,0.3);
}

.input-wrapper textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.92rem;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  padding: 6px 0;
}
.input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
  opacity: 0.5;
}
.send-btn:not(:disabled) {
  opacity: 1;
}
.send-btn:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px var(--accent-glow);
}
.send-btn:not(:disabled):active {
  transform: scale(0.97);
}
.send-btn:disabled {
  cursor: not-allowed;
}

.input-footer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ---------- Sidebar Overlay (mobile) ---------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.sidebar-overlay.active {
  opacity: 1;
}

/* ---------- Animations ---------- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes bounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-6px);
  }
}

@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 20px 4px var(--accent-glow); }
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-close {
    display: block;
  }
  .sidebar-overlay {
    display: block;
    pointer-events: none;
  }
  .sidebar-overlay.active {
    pointer-events: auto;
  }
  .topbar {
    display: flex;
  }
  .chat-container {
    padding: 16px 16px 8px;
  }
  .input-bar {
    padding: 0 12px 12px;
  }
  .welcome-hero {
    padding: 40px 20px 32px;
  }
  .welcome-title {
    font-size: 1.6rem;
  }
  .welcome-subtitle {
    font-size: 0.9rem;
  }
  .message {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .welcome-hints {
    flex-direction: column;
  }
  .hint-chip {
    width: 100%;
    text-align: center;
  }
}
