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

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #111111;
  --bg-surface: #1a1a1a;
  --bg-input: #1e1e1e;
  --bg-hover: #2a2a2a;
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #00d4aa;
  --accent-hover: #00b894;
  --accent-dim: rgba(0, 212, 170, 0.12);
  --border: #222222;
  --border-light: #333333;
  --danger: #ff4757;
  --warning: #ffa502;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --transition: 150ms ease;
  --transition-slow: 250ms ease;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
}

html, body {
  height: 100%;
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: #555; }

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

/* Icon button */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.icon-btn.active {
  color: var(--accent);
  background: var(--accent-dim);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* Code blocks */
.code-block {
  margin: 10px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #0d0d0d;
  border: 1px solid var(--border);
}
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: #161616;
  border-bottom: 1px solid var(--border);
}
.code-lang {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-transform: lowercase;
}
.copy-code-btn {
  font-size: 11px;
  padding: 2px 10px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-family);
}
.copy-code-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
pre {
  margin: 0;
  padding: 14px;
  overflow-x: auto;
}
code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}
p code {
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* Thinking block */
.thinking-block {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(0, 212, 170, 0.03);
}
.thinking-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition);
}
.thinking-toggle-btn:hover {
  background: rgba(0, 212, 170, 0.06);
  color: var(--text-secondary);
}
.thinking-toggle-btn .chevron {
  transition: transform var(--transition);
  font-size: 10px;
}
.thinking-block.collapsed .chevron {
  transform: rotate(-90deg);
}
.thinking-content {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  max-height: 300px;
  overflow-y: auto;
  line-height: 1.6;
}
.thinking-block.collapsed .thinking-content {
  display: none;
}

/* Attachment preview */
.attachment-preview {
  display: flex;
  gap: 8px;
  padding: 8px 14px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}
.attachment-preview.hidden { display: none; }
.attachment-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.attachment-thumb .remove-attachment {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  opacity: 0;
  transition: opacity var(--transition);
}
.attachment-thumb:hover .remove-attachment {
  opacity: 1;
}
.attachment-thumb.attachment-text {
  width: auto;
  max-width: 160px;
  height: 36px;
  display: flex;
  align-items: center;
  padding: 0 28px 0 10px;
  background: var(--bg-secondary);
}
.attachment-filename {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pdf-thumb {
  width: auto;
  max-width: 140px;
  height: auto;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  gap: 2px;
  background: var(--bg-surface);
}
.pdf-icon {
  font-size: 11px;
  font-weight: 700;
  color: var(--danger);
  background: rgba(255, 71, 87, 0.15);
  padding: 2px 8px;
  border-radius: 3px;
}
.pdf-name {
  font-size: 10px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}
.pdf-info {
  font-size: 9px;
  color: var(--text-muted);
}

/* Message bubbles */
.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeIn 200ms ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.message.user {
  align-items: flex-end;
}
.message.assistant {
  align-items: flex-start;
}
.message-role {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 4px;
}
.message-bubble {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.6;
}
.message.user .message-bubble {
  background: linear-gradient(135deg, var(--accent), #00a8cc);
  color: #000;
  border-bottom-right-radius: 4px;
}
.message.user .message-bubble p { margin: 0; }
.message.assistant .message-bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.message.assistant .message-bubble p {
  margin: 0 0 8px 0;
}
.message.assistant .message-bubble p:last-child {
  margin-bottom: 0;
}
.message.assistant .message-bubble ul,
.message.assistant .message-bubble ol {
  margin: 4px 0 8px 20px;
}
.message.assistant .message-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}
.message.assistant .message-bubble table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
}
.message.assistant .message-bubble th,
.message.assistant .message-bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.message.assistant .message-bubble th {
  background: var(--bg-hover);
}

/* Per-message copy button */
.message-bubble {
  position: relative;
}
.msg-copy-btn {
  position: absolute;
  bottom: 4px;
  right: 4px;
  padding: 3px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.message-bubble:hover .msg-copy-btn {
  opacity: 1;
}
.msg-copy-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.message.user .msg-copy-btn {
  color: rgba(0,0,0,0.4);
}
.message.user .msg-copy-btn:hover {
  background: rgba(0,0,0,0.15);
  color: rgba(0,0,0,0.7);
}

/* Message images */
.message-images {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.message-images img {
  max-width: 200px;
  max-height: 150px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  cursor: pointer;
}

/* Streaming cursor */
.streaming-cursor::after {
  content: '█';
  animation: blink 0.8s steps(2) infinite;
  color: var(--accent);
  font-weight: 100;
}
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* System message */
.system-message {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px;
}
.system-message.error {
  color: var(--danger);
}

/* Drag over state */
.drag-over {
  outline: 2px dashed var(--accent) !important;
  outline-offset: -4px;
  background: var(--accent-dim) !important;
}

/* Status dot */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.online { background: #00d4aa; box-shadow: 0 0 6px rgba(0, 212, 170, 0.5); }
.status-dot.offline { background: #ff4757; }
.status-dot.checking { background: #ffa502; animation: pulse 1s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Hidden utility */
.hidden { display: none !important; }

/* Button */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-primary {
  background: var(--accent);
  color: #000;
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background: var(--border-light);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover {
  background: rgba(255, 71, 87, 0.1);
}

/* Input */
.input {
  padding: 8px 12px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.input:focus {
  border-color: var(--accent);
}
.input::placeholder {
  color: var(--text-muted);
}

/* Label */
.form-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* iOS Safari auto-zoom prevention */
@supports (-webkit-touch-callout: none) {
  input, textarea, select {
    font-size: 16px !important;
  }
}
