:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-soft: #f7fafc;
  --text: #172033;
  --muted: #667085;
  --border: #d9e2ec;
  --primary: #d92d20;
  --primary-strong: #b42318;
  --medical: #1d72d2;
  --agriculture: #22965b;
  --detect: #d97706;
  --user: #1d72d2;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
  --font-size: 16px;
}

.dark {
  --bg: #111827;
  --surface: #1f2937;
  --surface-soft: #172033;
  --text: #f4f7fb;
  --muted: #a5b4c6;
  --border: #344054;
  --primary: #ff6258;
  --primary-strong: #ff8a83;
  --medical: #60a5fa;
  --agriculture: #4ade80;
  --detect: #fbbf24;
  --user: #2563eb;
  --shadow: 0 10px 32px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: flex;
  width: 100%;
  height: 100%;
  min-width: 320px;
}

.sidebar {
  width: 292px;
  min-width: 292px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
}

.brand {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 64px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-soft);
  overflow: hidden;
  flex-shrink: 0;
}

.brand-mark img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 16px;
  line-height: 1.25;
}

.brand span {
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
}

.nav-list,
.quick-panel,
.domain-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item,
.quick-chip,
.theme-button,
.icon-button,
.send-button,
.welcome-chip {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  font-weight: 600;
  text-align: left;
}

.nav-item.active {
  color: var(--primary);
  background: rgba(217, 45, 32, 0.08);
  border-color: rgba(217, 45, 32, 0.2);
}

.nav-icon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--primary);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
}

.panel-label {
  margin: 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.domain-status {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 600;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--muted);
}

.domain-status.medical {
  color: var(--medical);
  border-color: rgba(29, 114, 210, 0.35);
}

.domain-status.medical .status-dot {
  background: var(--medical);
}

.domain-status.agriculture {
  color: var(--agriculture);
  border-color: rgba(34, 150, 91, 0.35);
}

.domain-status.agriculture .status-dot {
  background: var(--agriculture);
}

.domain-status.detect {
  color: var(--detect);
  border-color: rgba(217, 119, 6, 0.35);
}

.domain-status.detect .status-dot {
  background: var(--detect);
}

.quick-chip,
.welcome-chip {
  padding: 11px 12px;
  text-align: left;
  color: var(--text);
  background: var(--surface);
}

.quick-chip:hover,
.welcome-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--border);
}

.dark .topbar {
  background: rgba(31, 41, 55, 0.9);
}

.menu-button {
  display: none;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  z-index: 999;
}

.topbar h1,
.topbar p {
  margin: 0;
}

.topbar h1 {
  font-size: 19px;
  line-height: 1.25;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.theme-button,
.icon-button {
  min-height: 38px;
  background: var(--surface);
  color: var(--text);
}

.theme-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-weight: 600;
}

.icon-button {
  width: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.theme-button:hover,
.icon-button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.welcome {
  height: 100%;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}

.welcome-logo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 22px;
}

.welcome-logo-row img {
  width: 92px;
  height: 58px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  object-fit: contain;
  padding: 5px;
  box-shadow: var(--shadow);
}

.welcome h2 {
  margin: 0;
  color: var(--primary);
  font-size: 28px;
  line-height: 1.25;
}

.welcome p {
  margin: 12px 0 28px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  max-width: 560px;
}

.welcome-chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
  width: min(640px, 100%);
}

.welcome-chip {
  text-align: center;
  min-height: 48px;
}

.message-row {
  display: flex;
  gap: 12px;
  max-width: 860px;
}

.message-row.from-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.from-user .avatar {
  background: var(--user);
  border-color: var(--user);
  color: #ffffff;
}

.message-stack {
  max-width: min(720px, calc(100vw - 420px));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.from-user .message-stack {
  align-items: flex-end;
}

.message-bubble {
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.58;
  font-size: 15px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.05);
  white-space: normal;
}

.from-user .message-bubble {
  background: var(--user);
  border-color: var(--user);
  color: #ffffff;
}

.message-bubble strong {
  color: var(--primary);
}

.from-user .message-bubble strong {
  color: #ffffff;
}

.message-bubble.error {
  background: #fff4f3;
  border-color: #f4b5af;
  color: #9f1f17;
}

.dark .message-bubble.error {
  background: rgba(217, 45, 32, 0.12);
  border-color: rgba(255, 98, 88, 0.45);
  color: #ffb4ad;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.bot-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  background: var(--surface);
  border: 1px solid var(--border);
}

.bot-pill.medical {
  color: var(--medical);
  border-color: rgba(29, 114, 210, 0.35);
}

.bot-pill.agriculture {
  color: var(--agriculture);
  border-color: rgba(34, 150, 91, 0.35);
}

.bot-pill.detect {
  color: var(--detect);
  border-color: rgba(217, 119, 6, 0.35);
}

.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 48px;
  min-height: 22px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
  animation: typing 1.2s infinite ease-in-out;
}

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

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

@keyframes typing {

  0%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }

  50% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.composer {
  padding: 16px 22px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-soft);
}

.composer-inner:focus-within {
  border-color: var(--primary);
}

textarea {
  flex: 1;
  min-height: 28px;
  max-height: 132px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  line-height: 1.5;
  padding: 3px 0;
}

textarea::placeholder {
  color: var(--muted);
}

textarea:disabled {
  opacity: 0.7;
}

.send-button {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  font-size: 18px;
}

.send-button:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

.send-button:disabled {
  background: #98a2b3;
  border-color: #98a2b3;
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .menu-button {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    flex-direction: column;
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.active {
    display: block;
  }

  .quick-panel,
  .nav-list {
    display: block;
  }

  .topbar {
    align-items: center;
  }

  .topbar h1 {
    font-size: 17px;
  }

  .theme-button {
    width: 38px;
    justify-content: center;
    padding: 0;
  }

  #themeText {
    display: none;
  }

  .welcome {
    min-height: 360px;
    padding: 18px 8px;
  }

  .welcome h2 {
    font-size: 23px;
  }

  .welcome-chips {
    grid-template-columns: 1fr;
  }

  .welcome-logo-row img {
    width: 78px;
    height: 50px;
  }

  .avatar {
    display: none;
  }

  .message-row,
  .message-stack {
    max-width: 100%;
  }

  .composer {
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  }
}