:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef3f6;
  --ink: #15202b;
  --muted: #627080;
  --line: #d9e0e7;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e6f2f1;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --customer-bg: #e8f0fe;
  --ai-bg: #f0fdf4;
  --shadow: 0 18px 50px rgba(20,32,43,0.08);
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0; min-width: 320px;
  background: var(--bg); color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(1400px, 100%); margin: 0 auto; padding: 20px 24px; }

/* ── Topbar ── */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 44px; height: 44px; border-radius: var(--radius); box-shadow: var(--shadow); }
.eyebrow { margin: 0 0 2px; color: var(--accent); font-size: 12px; font-weight: 700; }
h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.3px; }
.status-pill { display: flex; align-items: center; gap: 8px; padding: 6px 16px; border-radius: 100px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot.ready { background: #16a34a; }
.status-dot.loading { background: #f59e0b; animation: pulse 1s infinite; }
.status-dot.error { background: var(--danger); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── Layout ── */
.layout { display: grid; grid-template-columns: 240px 1fr; gap: 0; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: var(--surface); height: calc(100vh - 130px); }

/* ── Sidebar ── */
.sidebar { background: var(--surface-soft); border-right: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.sidebar-head h2 { margin: 0; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.sidebar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); font-size: 16px; display: flex; align-items: center; justify-content: center;
  color: var(--ink); transition: background 0.15s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

.project-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.project-item {
  padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500;
  display: flex; align-items: center; justify-content: space-between; transition: background 0.15s;
}
.project-item:hover { background: var(--accent-soft); }
.project-item.active { background: var(--accent); color: white; }
.project-time { font-size: 11px; opacity: 0.6; }

/* ── Conv List ── */
.conv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 250px; overflow-y: auto; }
.conv-item {
  padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 12px;
  transition: background 0.15s;
}
.conv-item:hover { background: var(--accent-soft); }
.conv-item.active { background: var(--accent); color: white; }
.conv-item .conv-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-meta { font-size: 10px; opacity: 0.6; display: flex; justify-content: space-between; margin-top: 2px; }
.conv-item .conv-delete {
  float: right; font-size: 14px; opacity: 0; padding: 0 4px; cursor: pointer; transition: opacity 0.15s;
}
.conv-item:hover .conv-delete { opacity: 0.7; }
.conv-item .conv-delete:hover { opacity: 1; color: var(--danger); }
.conv-empty-list { font-size: 12px; color: var(--muted); padding: 8px 10px; }

.sidebar-section { border-top: 1px solid var(--line); padding-top: 12px; }
.sidebar-section h2 { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.upload-zone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 12px; border: 2px dashed var(--line); border-radius: 10px;
  cursor: pointer; transition: all 0.2s; text-align: center; font-size: 12px; color: var(--muted);
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.upload-icon { font-size: 24px; }
.upload-status { font-size: 11px; color: var(--muted); margin: 4px 0 0; min-height: 16px; }
.upload-status.success { color: #16a34a; }
.upload-status.error { color: var(--danger); }

/* ── Conversation Header ── */
.conv-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.conv-header-left { display: flex; align-items: center; gap: 10px; }
.conv-header-left h3 { margin: 0; font-size: 16px; font-weight: 700; }
.conv-badge { font-size: 11px; padding: 2px 10px; border-radius: 100px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.conv-header-right { display: flex; align-items: center; gap: 12px; }

.platform-tags { display: flex; gap: 3px; }
.tag {
  font-size: 11px; padding: 3px 9px; border-radius: 100px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-weight: 500; transition: all 0.15s;
}
.tag:hover { border-color: var(--accent); color: var(--accent); }
.tag.active { background: var(--accent); color: white; border-color: var(--accent); }

.text-btn { background: none; border: none; color: var(--accent); font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 6px; transition: background 0.15s; }
.text-btn:hover { background: var(--accent-soft); }

/* ── Conversation Area ── */
.conv-area { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.conv-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.conv-empty p { margin: 0 0 6px; font-size: 15px; }
.conv-empty .sub { font-size: 13px; opacity: 0.7; }

/* ── Message Bubbles ── */
.msg-group { display: flex; flex-direction: column; gap: 6px; }
.msg-bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.msg-bubble.customer {
  align-self: flex-end; background: var(--customer-bg); border-bottom-right-radius: 4px;
}
.msg-bubble.agent {
  align-self: flex-start; background: var(--ai-bg); border-bottom-left-radius: 4px;
}
.msg-label { font-size: 11px; color: var(--muted); padding: 0 4px; }
.msg-label.customer { text-align: right; }
.msg-label.agent { text-align: left; }
.msg-meta { display: flex; align-items: center; gap: 8px; padding: 0 4px; font-size: 12px; }
.msg-meta.customer { justify-content: flex-end; }

.ai-reply-card {
  align-self: flex-start; max-width: 85%;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 14px;
  padding: 12px 16px; font-size: 13px;
}
.ai-reply-card .reply-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.ai-reply-card .reply-header strong { font-size: 13px; color: var(--accent); }
.ai-reply-card .reply-preview { color: var(--muted); font-size: 13px; line-height: 1.5; max-height: 60px; overflow: hidden; }
.ai-reply-card .reply-actions { display: flex; gap: 6px; margin-top: 8px; }
.small-btn {
  font-size: 12px; padding: 4px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 500; transition: all 0.15s;
}
.small-btn:hover { border-color: var(--accent); color: var(--accent); }
.small-btn.primary { background: var(--accent); color: white; border-color: var(--accent); }
.small-btn.primary:hover { background: var(--accent-strong); }

/* ── Input Area ── */
.input-area { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-end; flex-shrink: 0; }
.input-area textarea { flex: 1; padding: 10px 14px; border: 2px solid var(--line); border-radius: 10px; resize: none; font-size: 14px; line-height: 1.5; outline: none; transition: border-color 0.15s; background: var(--surface); }
.input-area textarea:focus { border-color: var(--accent); }
.primary-btn {
  padding: 10px 22px; border: none; border-radius: 10px; background: var(--accent); color: white;
  font-size: 14px; font-weight: 700; white-space: nowrap; transition: background 0.15s, transform 0.1s;
}
.primary-btn:hover { background: var(--accent-strong); }
.primary-btn:active { transform: scale(0.97); }
.primary-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ── Reply Dialog ── */
.reply-dialog-content { white-space: pre-wrap; line-height: 1.7; font-size: 14px; }
.reply-dialog-content .diagnosis {
  background: var(--accent-soft); padding: 10px 14px; border-radius: 8px; margin-bottom: 14px;
  font-size: 13px; color: var(--accent); font-weight: 500;
}
.reply-dialog-content .version-block {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 18px; margin-bottom: 12px; position: relative;
}
.reply-dialog-content .version-block h4 { margin: 0 0 8px; font-size: 14px; color: var(--accent); }
.reply-dialog-content .copy-btn {
  position: absolute; top: 12px; right: 14px;
  font-size: 12px; padding: 2px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--muted); cursor: pointer; transition: all 0.15s;
}
.reply-dialog-content .copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.reply-dialog-content .copy-btn.copied { background: #16a34a; color: white; border-color: #16a34a; }
.reply-dialog-content .reminders {
  background: var(--warn-soft); padding: 12px 16px; border-radius: 8px; font-size: 13px;
  border-left: 3px solid var(--warn);
}

/* ── Modal ── */
.modal { border: none; border-radius: var(--radius); padding: 0; box-shadow: 0 24px 80px rgba(0,0,0,.18); width: min(720px, 95vw); max-height: 85vh; overflow: hidden; }
.modal::backdrop { background: rgba(0,0,0,.3); }
.modal-card { padding: 24px; display: flex; flex-direction: column; gap: 14px; max-height: 80vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 18px; }
.close-btn { font-size: 22px; }
.modal-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.modal-card input, .modal-card textarea {
  padding: 10px 14px; border: 2px solid var(--line); border-radius: 8px; font-size: 14px; outline: none; transition: border-color 0.15s;
}
.modal-card input:focus, .modal-card textarea:focus { border-color: var(--accent); }
.modal-card textarea { resize: vertical; font-family: monospace; font-size: 13px; line-height: 1.5; }
.dialog-upload-hint { font-size: 11px; color: var(--muted); font-weight: 400; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.spacer { flex: 1; }
.danger-btn {
  padding: 8px 18px; border: 1px solid var(--danger); border-radius: 8px; background: white;
  color: var(--danger); font-size: 14px; font-weight: 600; transition: all 0.15s;
}
.danger-btn:hover { background: var(--danger-soft); }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%);
  padding: 10px 24px; border-radius: 100px; background: var(--ink); color: white;
  font-size: 14px; font-weight: 500; z-index: 100;
  box-shadow: 0 8px 30px rgba(0,0,0,.2); transition: opacity 0.3s, transform 0.3s;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(20px); pointer-events: none; }

.hidden { display: none !important; }

.loading-spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { max-height: 200px; }
}
