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

:root {
  /* ── Panel colours ── */
  --bg:          #e9eaed;
  --surface:     #f2f3f5;
  --surface-alt: #ffffff;
  --border:      #d4d5d9;
  --text:        #1a1a1a;
  --text-muted:  #6b6c72;

  /* ── Agent accents ── */
  --accent-designer: #3383bc;
  --accent-farmer:   #537d00;
  --accent-cfo:      #cb3c33;
  --accent-user:     #6b3fa0;

  /* ── UI action colour (send button, focus ring) ── */
  --accent-action:   #4a7fb5;

  --radius: 12px;
  --font: 'Inter', system-ui, sans-serif;

  /* ── Panel dimensions ── */
  --panel-width: 640px;
}

body {
  background-color: #2a2a2e;
  background-image: url('/assets/designer_bg.png');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  font-family: var(--font);
  font-size: 14px;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

/* ─── App Panel (centered card) ─────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--panel-width);
  height: calc(100dvh - 130px);
  margin-top: 64px;
  margin-bottom: 66px;
  background: var(--bg);
  position: relative;
  border-radius: 12px;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.35), 0 2px 12px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

/* ─── Header ────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

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

.header-brand {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
  padding-left: 4px;
}

.agent-badges {
  display: flex;
  gap: 6px;
}

.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  border: 1.5px solid currentColor;
  opacity: 0.75;
  cursor: default;
  transition: opacity 0.2s, box-shadow 0.2s;
  letter-spacing: 0.02em;
}

.badge--designer { color: var(--accent-designer); }
.badge--farmer   { color: var(--accent-farmer); }
.badge--cfo      { color: var(--accent-cfo); }

.badge.active {
  opacity: 1;
  box-shadow: 0 0 6px currentColor;
}

.clear-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  text-decoration: none;
}

.clear-btn:hover { color: var(--text); border-color: var(--text-muted); }

.settings-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}

.settings-btn:hover { color: var(--text); border-color: var(--text-muted); }

/* ─── Chat Area ─────────────────────────────────────────── */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  background: var(--bg);
}

/* ─── Suggested Questions ───────────────────────────────── */
.suggested {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 6px;
}

.suggested-btn {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  font-family: var(--font);
}

.suggested-btn:hover { color: var(--text); }

.suggested-btn--designer { border-color: var(--accent-designer); background: #f3f8fb; }
.suggested-btn--designer:hover { border-color: var(--accent-designer); background: #e8f2f9; }

.suggested-btn--farmer { border-color: var(--accent-farmer); background: #f4f7ee; }
.suggested-btn--farmer:hover { border-color: var(--accent-farmer); background: #ecf2e2; }

.suggested-btn--cfo { border-color: var(--accent-cfo); background: #fcf3f3; }
.suggested-btn--cfo:hover { border-color: var(--accent-cfo); background: #f9e8e8; }

/* ─── Follow-up questions ───────────────────────────────── */
.follow-up {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-left: 2px;
}

/* ─── Message Bubbles ───────────────────────────────────── */
.message {
  max-width: 82%;
  line-height: 1.6;
}

.message--user {
  align-self: flex-end;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  padding: 9px 14px;
  color: var(--text);
}

.message--agent {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.message__label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.7;
}

.message__label--designer { color: var(--accent-designer); }
.message__label--farmer   { color: var(--accent-farmer); }
.message__label--cfo      { color: var(--accent-cfo); }

.message__body {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  padding: 10px 14px;
  white-space: normal;
  word-break: break-word;
  color: var(--text);
  overflow: hidden;
}

.message__body--designer { border-left-color: var(--accent-designer); background: #f3f8fb; }
.message__body--farmer   { border-left-color: var(--accent-farmer);   background: #f4f7ee; }
.message__body--cfo      { border-left-color: var(--accent-cfo);      background: #fcf3f3; }

/* Markdown headings */
.message__body h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 12px 0 6px;
  color: var(--text);
}

.message__body h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 10px 0 6px;
  color: var(--text);
}

.message__body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

/* Markdown table */
.table-wrap {
  overflow-x: auto;
  margin: 8px 0;
  border-radius: 4px;
  -webkit-overflow-scrolling: touch;
}

.message__body table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  margin: 0;
  font-size: 12px;
}

.message__body th, .message__body td {
  border: 1px solid var(--border);
  padding: 5px 10px;
  text-align: left;
  white-space: nowrap;
}

.message__body th {
  background: var(--surface);
  font-weight: 600;
}

/* ─── Typing indicator ──────────────────────────────────── */
.typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 10px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* ─── @mention autocomplete ─────────────────────────────── */
.mention-menu {
  position: absolute;
  bottom: 72px;
  left: 16px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 100;
  min-width: 240px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.mention-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 13px;
  cursor: pointer;
  transition: background 0.1s;
}

.mention-item:hover,
.mention-item.selected {
  background: var(--surface);
}

.mention-name {
  font-size: 13px;
  font-weight: 600;
}

.mention-item:nth-child(1) .mention-name { color: var(--accent-designer); }
.mention-item:nth-child(2) .mention-name { color: var(--accent-farmer); }
.mention-item:nth-child(3) .mention-name { color: var(--accent-cfo); }

.mention-desc {
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Image preview bar ─────────────────────────────────── */
.image-preview-bar[hidden] { display: none !important; }

.image-preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.preview-thumb {
  height: 44px;
  width: auto;
  max-width: 72px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: cover;
}

.preview-label {
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
}

.preview-remove {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}

.preview-remove:hover { color: var(--text); border-color: var(--text-muted); }

/* ─── Input Bar ─────────────────────────────────────────── */
.input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

#input {
  flex: 1;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 9px 13px;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.15s;
}

#input::placeholder { color: var(--text-muted); }
#input:focus { border-color: var(--accent-action); }

#send-btn {
  background: var(--accent-action);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  align-self: flex-end;
  font-family: var(--font);
}

#send-btn:hover { opacity: 0.85; }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Attach button ─────────────────────────────────────── */
.attach-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}

.attach-btn:hover { color: var(--text); border-color: var(--text-muted); }
.attach-btn input[type="file"] { display: none; }

/* ─── Image in user message bubble ─────────────────────── */
.message--user img.msg-image {
  display: block;
  max-width: 200px;
  max-height: 150px;
  border-radius: 8px;
  margin-bottom: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
}

/* ─── Footer ─────────────────────────────────────────────── */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.45);
  padding: 10px 16px 12px;
  line-height: 1.8;
  pointer-events: none;
}

.app-footer__inner {
  width: 100%;
  max-width: var(--panel-width);
  text-align: left;
}

.app-footer a {
  color: rgba(255, 255, 255, 0.55);
  text-decoration: none;
  pointer-events: auto;
}

.app-footer a:hover {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: underline;
}

/* ─── Mobile ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  body {
    background-attachment: scroll; /* background-attachment: fixed breaks on iOS Safari */
    align-items: center;
  }

  .app {
    width: calc(100% - 24px);
    max-width: 100%;
    margin: 0;
    height: calc(100dvh - 80px);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  }

  /* Header: hide brand, spread badges left / buttons right */
  .header-brand { display: none; }

  .header-right {
    width: 100%;
  }

  .header-right .clear-btn {
    margin-left: auto;
  }

  .badge {
    font-size: 9px;
    padding: 2px 7px;
  }

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