:root {
  --bg: #e7f2ea;
  --panel: #f9fef9;
  --panel-border: #bcd8c1;
  --text: #173125;
  --muted: #3f6652;
  --accent: #1d8f4f;
  --accent-hover: #15683a;
  --user-msg: #dff5e6;
  --bot-msg: #ecf5ef;
  --error: #b53d3d;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 18%, #b7e5bf 0%, rgba(183, 229, 191, 0) 40%),
    radial-gradient(circle at 88% 12%, #8cd2a0 0%, rgba(140, 210, 160, 0) 42%),
    linear-gradient(165deg, #e6f4e9 0%, #d6eedc 34%, #c6e7cf 68%, #bae2c4 100%),
    var(--bg);
}

.app-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 1.2rem;
  display: grid;
  gap: 1rem;
}

.topbar,
.settings-panel,
.chat-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 14px 30px rgba(32, 51, 32, 0.1);
}

.topbar {
  padding: 1rem 1.2rem 1.1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  position: relative;
  overflow: hidden;
}

.topbar::after {
  content: "";
  position: absolute;
  inset: auto -50px -60px auto;
  width: 220px;
  height: 160px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(40, 170, 95, 0.35) 0, rgba(40, 170, 95, 0) 70%);
  pointer-events: none;
}

.topbar h1 {
  margin: 0;
  font-size: 1.3rem;
}

.topbar p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.brand-stack {
  display: grid;
  gap: 0.7rem;
}

.brand-row {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.brand-logo {
  height: 2rem;
  max-width: 210px;
  display: block;
  object-fit: contain;
  border-radius: 8px;
  padding: 0.2rem 0.35rem;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.66);
}

.agrovisio-logo {
  border-color: #8ecb99;
}

.trakbot-logo {
  border-color: #95c9a2;
  max-width: 150px;
}

.settings-panel {
  padding: 1rem 1.2rem;
}

.settings-panel h2 {
  margin-top: 0;
  font-size: 1rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.58rem 0.7rem;
  color: var(--text);
  background: #ffffff;
}

textarea {
  width: 100%;
  resize: none;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 0.6rem 0.95rem;
  font-weight: 600;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
  transition: background 120ms ease;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ghost-btn {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(2px);
}

.chat-panel {
  min-height: 60vh;
  display: grid;
  grid-template-rows: 1fr auto;
  border-top: 4px solid #f0b35f;
}

.chat-log {
  overflow-y: auto;
  padding: 1rem;
  display: grid;
  gap: 0.7rem;
}

.thinking-indicator {
  margin: 0 1rem 0.6rem;
  width: fit-content;
  max-width: calc(100% - 2rem);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.46rem 0.65rem;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: #edf5ef;
}

.thinking-logo {
  width: 1.25rem;
  height: 1.25rem;
  object-fit: contain;
  border-radius: 4px;
}

.thinking-text {
  font-size: 0.84rem;
  color: var(--muted);
}

.thinking-dots {
  display: inline-flex;
  gap: 0.18rem;
}

.thinking-dots span {
  width: 0.28rem;
  height: 0.28rem;
  border-radius: 999px;
  background: var(--accent);
  animation: thinking-bounce 1s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes thinking-bounce {
  0%, 80%, 100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.message {
  max-width: 78%;
  border-radius: 14px;
  padding: 0.6rem 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
  display: grid;
  gap: 0.45rem;
}

.message.user {
  justify-self: end;
  background: var(--user-msg);
}

.message.bot {
  justify-self: start;
  background: var(--bot-msg);
}

.message.error {
  justify-self: start;
  background: #f8e4e4;
  color: var(--error);
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.message-image-btn {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  border-radius: 10px;
  overflow: hidden;
}

.message-image-thumb {
  width: 92px;
  height: 92px;
  object-fit: cover;
  display: block;
  border: 1px solid var(--panel-border);
  background: #ece6dc;
}

.message-file-pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  border: 1px solid var(--panel-border);
  background: #f7f4ee;
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
}

.chat-form {
  border-top: 1px solid var(--panel-border);
  padding: 0.8rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
}

.chat-form.drop-active {
  background: rgba(31, 111, 95, 0.08);
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
}

.composer-toolbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  align-items: center;
}

.icon-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 999px;
  font-size: 1.15rem;
  line-height: 1;
}

.attachments-list {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: 0;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  padding: 0.32rem 0.5rem;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: #f7f4ee;
  font-size: 0.82rem;
}

.attachment-thumb {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 0.35rem;
  object-fit: cover;
  border: 1px solid var(--panel-border);
  background: #ece6dc;
  flex: 0 0 auto;
}

.attachment-chip-name {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-remove-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  font-size: 0.95rem;
}

.compose-hint {
  margin: 0;
  align-self: center;
  font-size: 0.82rem;
  color: var(--muted);
}

.status-text {
  margin: 0.6rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.chat-form .status-text {
  grid-column: 1 / -1;
}

.hidden {
  display: none;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(16, 16, 16, 0.74);
  display: grid;
  place-items: center;
  padding: 1.2rem;
}

.image-modal.hidden {
  display: none;
}

.image-modal-image {
  max-width: min(92vw, 1200px);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 12px;
  background: #111111;
}

.image-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 999px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

@media (max-width: 760px) {
  .chat-panel {
    min-height: 68vh;
  }

  .topbar {
    align-items: stretch;
  }

  .brand-row {
    gap: 0.4rem;
  }

  .composer-toolbar {
    grid-template-columns: 1fr;
  }

  .attachment-chip-name {
    max-width: 180px;
  }

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