/* ============================================
   AgentTalk — Ink & Paper Chat Interface
   ============================================ */

:root {
  /* Ink palette */
  --ink-900: #0a0a0c;
  --ink-800: #141418;
  --ink-700: #1e1e24;
  --ink-600: #2a2a32;
  --ink-500: #3a3a44;
  --ink-400: #5a5a66;
  --ink-300: #8a8a96;
  --ink-200: #b8b8c2;
  --ink-100: #e0e0e6;
  --ink-50: #f2f2f5;

  /* Paper palette */
  --paper: #fafaf8;
  --paper-warm: #f5f3ef;
  --paper-hover: #eeecea;

  /* Accent — vermillion seal red */
  --accent: #c73e1d;
  --accent-soft: rgba(199, 62, 29, 0.1);
  --accent-glow: rgba(199, 62, 29, 0.25);

  /* Agent bubble — warm stone */
  --agent-bg: #f0ede8;
  --agent-border: #e0dbd4;

  /* User bubble */
  --user-bg: #1a1a20;
  --user-text: #f0f0f2;

  /* Spacing */
  --sidebar-width: 300px;
  --header-height: 56px;
  --input-max-height: 200px;

  /* Typography */
  --font-serif: 'Noto Serif SC', 'Songti SC', serif;
  --font-mono: 'JetBrains Mono', 'Menlo', monospace;
  --font-system: -apple-system, 'PingFang SC', 'Helvetica Neue', sans-serif;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-system);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-800);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

/* ── App layout ── */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--ink-800);
  color: var(--ink-200);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--ink-600);
  flex-shrink: 0;
  z-index: 100;
}

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

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

.brand-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 16px;
}

.brand-text {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 17px;
  color: var(--ink-100);
  letter-spacing: 0.5px;
}

.btn-new-chat {
  width: 34px;
  height: 34px;
  border: 1px solid var(--ink-500);
  background: transparent;
  color: var(--ink-300);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--ease-out);
}

.btn-new-chat:hover {
  background: var(--ink-600);
  color: var(--ink-100);
  border-color: var(--ink-400);
}

.sidebar-search {
  padding: 12px 16px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  border-radius: 8px;
  color: var(--ink-100);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.sidebar-search input::placeholder { color: var(--ink-400); }
.sidebar-search input:focus { border-color: var(--ink-400); }

/* Conversation list */
.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.conversation-list::-webkit-scrollbar { width: 4px; }
.conversation-list::-webkit-scrollbar-thumb { background: var(--ink-600); border-radius: 4px; }

.conv-item {
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.15s;
  position: relative;
}

.conv-item:hover { background: var(--ink-700); }
.conv-item.active { background: var(--ink-600); }

.conv-item .conv-title {
  font-size: 14px;
  color: var(--ink-100);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.conv-item .conv-preview {
  font-size: 12px;
  color: var(--ink-400);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item .conv-time {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 11px;
  color: var(--ink-500);
}

.conv-item .conv-delete {
  display: none;
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--ink-400);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
}

.conv-item:hover .conv-delete { display: block; }
.conv-item .conv-delete:hover { color: var(--accent); background: var(--accent-soft); }

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--ink-600);
}

.agent-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.agent-dot {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.agent-name {
  font-family: var(--font-serif);
  color: var(--ink-300);
}

/* ============================================
   Chat Main
   ============================================ */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--paper);
}

/* Chat header */
.chat-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--ink-100);
  background: rgba(250, 250, 248, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  gap: 12px;
  flex-shrink: 0;
}

.btn-menu {
  display: none;
  background: none;
  border: none;
  color: var(--ink-500);
  cursor: pointer;
  padding: 4px;
}

.chat-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-text {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 16px;
  color: var(--ink-800);
}

.title-status {
  font-size: 12px;
  color: var(--ink-300);
  font-style: italic;
}

.btn-settings {
  background: none;
  border: none;
  color: var(--ink-400);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.15s;
}

.btn-settings:hover { color: var(--ink-700); background: var(--ink-50); }

/* ============================================
   Messages
   ============================================ */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar { width: 6px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--ink-200); border-radius: 6px; }
.messages-container::-webkit-scrollbar-thumb:hover { background: var(--ink-300); }

.messages-scroll {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px 40px;
  text-align: center;
  animation: fadeUp 0.6s var(--ease-out);
}

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

.welcome-icon {
  width: 72px;
  height: 72px;
  background: var(--ink-800);
  color: var(--paper);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 32px;
  margin-bottom: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.welcome-title {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 700;
  color: var(--ink-800);
  margin-bottom: 8px;
}

.welcome-desc {
  color: var(--ink-400);
  font-size: 15px;
  max-width: 400px;
  margin-bottom: 32px;
}

.welcome-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.prompt-chip {
  padding: 10px 18px;
  background: var(--paper-warm);
  border: 1px solid var(--ink-100);
  border-radius: 20px;
  font-size: 14px;
  color: var(--ink-600);
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  font-family: var(--font-system);
}

.prompt-chip:hover {
  background: var(--ink-800);
  color: var(--paper);
  border-color: var(--ink-800);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Message bubbles */
.message {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  animation: msgAppear 0.35s var(--ease-out);
}

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

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

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

.message.assistant .message-avatar {
  background: var(--ink-800);
  color: var(--paper);
  font-family: var(--font-serif);
}

.message.user .message-avatar {
  background: var(--accent);
  color: white;
}

.message-content {
  max-width: 85%;
  min-width: 40px;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.65;
  font-size: 15px;
  position: relative;
}

.message.assistant .message-bubble {
  background: var(--agent-bg);
  border: 1px solid var(--agent-border);
  border-top-left-radius: 4px;
  color: var(--ink-800);
}

.message.user .message-bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-top-right-radius: 4px;
}

.message-time {
  font-size: 11px;
  color: var(--ink-300);
  margin-top: 4px;
  padding: 0 4px;
}

.message.user .message-time {
  text-align: right;
}

/* Markdown in messages */
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  font-family: var(--font-serif);
  margin: 16px 0 8px;
}

.message-bubble h1 { font-size: 1.3em; }
.message-bubble h2 { font-size: 1.15em; }
.message-bubble h3 { font-size: 1.05em; }

.message-bubble p { margin: 8px 0; }
.message-bubble p:first-child { margin-top: 0; }
.message-bubble p:last-child { margin-bottom: 0; }

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

.message.user .message-bubble code {
  background: rgba(255, 255, 255, 0.12);
}

.message-bubble pre {
  background: var(--ink-800);
  color: var(--ink-100);
  padding: 14px 16px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.5;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

.message-bubble ul, .message-bubble ol {
  padding-left: 20px;
  margin: 8px 0;
}

.message-bubble li { margin: 4px 0; }

.message-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 12px 0;
  color: var(--ink-500);
  font-style: italic;
}

.message-bubble strong {
  font-weight: 600;
}

.message-bubble table {
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
  width: 100%;
}

.message-bubble th, .message-bubble td {
  border: 1px solid var(--ink-200);
  padding: 8px 12px;
  text-align: left;
}

.message-bubble th {
  background: var(--paper-warm);
  font-weight: 600;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--ink-400);
  border-radius: 50%;
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Cursor blink for streaming */
.streaming-cursor::after {
  content: '▍';
  color: var(--accent);
  animation: cursorBlink 0.8s ease-in-out infinite;
  margin-left: 1px;
}

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

/* ============================================
   Input area
   ============================================ */
.input-area {
  padding: 0 20px 16px;
  flex-shrink: 0;
}

.input-wrapper {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: white;
  border: 1.5px solid var(--ink-200);
  border-radius: 16px;
  padding: 10px 12px 10px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--ink-500);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}

.input-wrapper textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 15px;
  font-family: var(--font-system);
  line-height: 1.5;
  color: var(--ink-800);
  background: transparent;
  max-height: var(--input-max-height);
  scrollbar-width: none;
}

.input-wrapper textarea::-webkit-scrollbar { display: none; }
.input-wrapper textarea::placeholder { color: var(--ink-300); }

.btn-send {
  width: 36px;
  height: 36px;
  background: var(--ink-800);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s var(--ease-out);
}

.btn-send:disabled {
  background: var(--ink-100);
  color: var(--ink-300);
  cursor: not-allowed;
}

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

.input-footer {
  max-width: 780px;
  margin: 6px auto 0;
  display: flex;
  justify-content: space-between;
  padding: 0 4px;
}

.char-count, .input-hint {
  font-size: 11px;
  color: var(--ink-300);
}

/* ============================================
   Settings Modal
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: white;
  border-radius: 16px;
  width: 90%;
  max-width: 480px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.2);
  animation: modalSlide 0.3s var(--ease-out);
}

@keyframes modalSlide {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h2 {
  font-family: var(--font-serif);
  font-size: 18px;
  color: var(--ink-800);
}

.btn-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--ink-400);
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 20px 24px 24px;
}

.setting-group {
  margin-bottom: 16px;
}

.setting-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-600);
  margin-bottom: 6px;
}

.setting-group input,
.setting-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--ink-200);
  border-radius: 10px;
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--ink-800);
  outline: none;
  transition: border-color 0.2s;
}

.setting-group input:focus,
.setting-group textarea:focus {
  border-color: var(--ink-500);
}

.btn-save {
  width: 100%;
  padding: 12px;
  background: var(--ink-800);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 8px;
}

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

/* ============================================
   Mobile responsive
   ============================================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease-out);
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.3);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
    display: none;
  }

  .sidebar-overlay.open {
    display: block;
    animation: fadeIn 0.2s ease;
  }

  .btn-menu { display: block; }

  .messages-scroll {
    padding: 16px 14px 80px;
  }

  .message-content { max-width: 90%; }

  .welcome { padding: 40px 16px 24px; }
  .welcome-icon { width: 56px; height: 56px; font-size: 24px; }
  .welcome-title { font-size: 20px; }

  .input-area { padding: 0 12px 12px; }
}

/* ============================================
   Utility
   ============================================ */
.hidden { display: none !important; }
