:root {
  --bg:        #f5f4f1;
  --surface:   #ffffff;
  --surface-2: #f0ede8;
  --border:    #e2dbd2;
  --border-2:  #cec5b8;
  --text:      #1c1917;
  --text-2:    #6b6259;
  --text-3:    #b0a89e;
  --accent:    #c95c2a;
  --accent-bg: rgba(201,92,42,0.07);
  --accent-bd: rgba(201,92,42,0.2);
  --slate:     #1e293b;
  --green:     #166534;
  --green-bg:  rgba(22,101,52,0.08);
  --green-bd:  rgba(22,101,52,0.22);
  --red:       #b91c1c;
  --font:      'DM Sans', system-ui, sans-serif;
  --serif:     'Lora', Georgia, serif;
  --mono:      'Menlo', 'Consolas', 'Monaco', monospace;
  --r:         10px;
}

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

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

body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ─── Header ─────────────────────────────────────────────────────────── */
header {
  flex-shrink: 0;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border);
  z-index: 20;
}

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

.logo-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: #fff;
  box-shadow: 0 1px 4px rgba(201,92,42,0.3);
}

.logo-name {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 400;
  color: var(--text);
}
.logo-name em { font-style: italic; color: var(--accent); }
.logo-by { font-size: 12px; font-style: normal; color: var(--text-3); font-family: var(--font); margin-left: 4px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 4px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.user-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.user-avatar-fallback {
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.user-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logout-btn {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  text-decoration: none;
  padding: 3px 10px 3px 6px;
  border-left: 1px solid var(--border);
  margin-left: 2px;
  transition: color 0.14s;
}
.logout-btn:hover { color: var(--accent); }

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

#status-badge {
  display: none;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--green);
  background: var(--green-bg);
  border: 1px solid var(--green-bd);
  padding: 3px 10px;
  border-radius: 20px;
  transition: opacity 0.3s;
}
#status-badge.visible { display: flex; }
#status-badge::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--green);
  animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

.model-pill {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 20px;
}

/* ─── Feed ───────────────────────────────────────────────────────────── */
.feed-wrapper { flex: 1; overflow: hidden; }

#messages {
  height: 100%;
  overflow-y: auto;
  padding: 32px 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }

/* ─── Empty state ─────────────────────────────────────────────────── */
#empty {
  flex: 1;
  min-height: 52vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  user-select: none;
  animation: up 0.4s ease;
}
@keyframes up { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }

.empty-headline {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 400;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
}
.empty-headline em { font-style: italic; color: var(--accent); }

.empty-sub {
  font-size: 14px;
  color: var(--text-2);
  text-align: center;
  max-width: 360px;
  line-height: 1.6;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 540px;
  margin-top: 6px;
}

.sug {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s, transform 0.12s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.sug:hover {
  border-color: var(--accent-bd);
  background: var(--accent-bg);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ─── Messages ───────────────────────────────────────────────────────── */
.msg {
  display: flex;
  flex-direction: column;
  opacity: 0;
  animation: up 0.18s cubic-bezier(0.16,1,0.3,1) forwards;
}

/* User */
.msg.user { align-items: flex-end; }
.msg.user .bubble {
  max-width: 66%;
  background: var(--slate);
  color: #dde4f0;
  border-radius: var(--r) var(--r) 2px var(--r);
  padding: 11px 15px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 2px 10px rgba(30,41,59,0.2);
}

/* Assistant */
.msg.assistant { align-items: flex-start; gap: 0; }

.asst-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.avatar {
  width: 24px; height: 24px;
  border-radius: 6px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 12px;
  color: #fff;
  flex-shrink: 0;
}

.asst-label {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--accent);
}

/* Tool steps */
.steps {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
}

.step {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-bg);
  border: 1px solid var(--accent-bd);
  border-radius: 6px;
  padding: 4px 10px;
  width: fit-content;
  opacity: 0;
  animation: up 0.12s ease forwards;
}
.step-done { color: var(--green); margin-left: 3px; }

/* ─── Thinking animation ─────────────────────────────────────────────── */
.thinking {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 0 8px;
}
.thinking span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  display: block;
  animation: bounce 1.3s ease-in-out infinite;
}
.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.30s; }
@keyframes bounce {
  0%,60%,100% { transform: translateY(0);   opacity: 0.3; }
  30%          { transform: translateY(-7px); opacity: 1;   }
}

/* Text body */
.body {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text);
  word-break: break-word;
}

/* ─── Code ───────────────────────────────────────────────────────────── */
.body code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}
.body pre {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 13px 16px;
  border-radius: 0 8px 8px 0;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 12.5px;
  line-height: 1.6;
}
.body pre code { background:none; border:none; padding:0; color:#7c3d18; }
.body strong { color: var(--text); font-weight: 600; }
.body em { font-style: italic; color: var(--text-2); }

/* ─── Headings ───────────────────────────────────────────────────────── */
.body h1, .body h2, .body h3 {
  font-family: var(--serif);
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  margin: 18px 0 6px;
}
.body h1 { font-size: 20px; }
.body h2 { font-size: 17px; }
.body h3 { font-size: 15px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.body h1:first-child, .body h2:first-child, .body h3:first-child { margin-top: 2px; }

/* ─── Lists ──────────────────────────────────────────────────────────── */
.body ul, .body ol {
  margin: 6px 0 10px;
  padding-left: 22px;
}
.body li { margin: 3px 0; line-height: 1.7; }
.body ul li { list-style-type: disc; }
.body ol li { list-style-type: decimal; }

/* ─── HR ─────────────────────────────────────────────────────────────── */
.body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ─── Tables ─────────────────────────────────────────────────────────── */
.body .tbl-wrap {
  overflow-x: auto;
  margin: 12px 0;
  border-radius: var(--r);
  border: 1px solid var(--border);
  box-shadow: 0 1px 8px rgba(0,0,0,0.06);
}
.body table {
  border-collapse: collapse;
  font-size: 13px;
  background: #fff;
  width: max-content;
  min-width: 100%;
}
.body table thead { background: var(--surface-2); }
.body table th {
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-align: left;
  padding: 10px 14px;
  color: var(--accent);
  border-bottom: 1px solid var(--border-2);
  white-space: nowrap;
}
.body table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
  white-space: nowrap;
}
.body table tbody tr:nth-child(even) { background: #fafaf8; }
.body table tbody tr:hover { background: var(--accent-bg); }
.body table tbody tr:last-child td { border-bottom: none; }

/* ─── Ad Card ───────────────────────────────────────────────────────────── */
.ad-card {
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  background: #fff;
  max-width: 420px;
  margin: 10px 0;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  animation: up 0.2s ease forwards;
}
.ac-img-wrap { width: 100%; background: var(--surface-2); max-height: 260px; overflow: hidden; }
.ac-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ac-content { padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 5px; }
.ac-name {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}
.ac-title {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}
.ac-body {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ac-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 8px;
  flex-wrap: wrap;
}
.ac-actions { display: flex; align-items: center; gap: 10px; }
.ac-cta {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.14s, transform 0.12s;
}
.ac-cta:hover { background: #b84d1f; transform: translateY(-1px); }
.ac-ig {
  font-size: 12px;
  color: var(--text-3);
  text-decoration: none;
  transition: color 0.14s;
}
.ac-ig:hover { color: var(--accent); }
.ac-status {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.ac-status--active   { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-bd); }
.ac-status--paused   { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.ac-status--deleted  { background: #fee2e2; color: var(--red); border: 1px solid #fca5a5; }
.ac-status--archived { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }

/* ─── Input ──────────────────────────────────────────────────────────── */
footer {
  flex-shrink: 0;
  padding: 14px 28px 20px;
  background: #fff;
  border-top: 1px solid var(--border);
  z-index: 20;
}

.input-outer { max-width: 1200px; margin: 0 auto; }

.input-card {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1.5px solid var(--border-2);
  border-radius: 14px;
  padding: 11px 12px 11px 16px;
  transition: border-color 0.18s, box-shadow 0.18s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.input-card:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

#prompt {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  resize: none;
  min-height: 22px;
  max-height: 150px;
  overflow-y: auto;
  line-height: 1.55;
}
#prompt::placeholder { color: var(--text-3); }
#prompt:disabled { opacity: 0.5; cursor: not-allowed; }

#send {
  flex-shrink: 0;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.14s, transform 0.14s, box-shadow 0.14s;
  box-shadow: 0 2px 6px rgba(201,92,42,0.28);
  color: #fff;
}
#send:hover:not(:disabled) { background: #b84d1f; transform: translateY(-1px); }
#send:active:not(:disabled) { transform: scale(0.94); }
#send:disabled { opacity: 0.28; cursor: default; box-shadow: none; }

.input-hint {
  margin-top: 7px;
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
}
