:root {
  --green-900: #1b3a2b;
  --green-700: #2f5d42;
  --green-600: #3a7351;
  --green-500: #4f9268;
  --green-100: #e6f0e8;
  --cream: #faf7f0;
  --ink: #202521;
  --ink-soft: #5c645d;
  --border: #dfe6e0;
  --danger: #b3462c;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --green-900: #eaf3ec;
    --green-700: #bfe0cc;
    --green-600: #8fcea8;
    --green-500: #7fd3a0;
    --green-100: #1e2e24;
    --cream: #141815;
    --ink: #eef1ee;
    --ink-soft: #a3aaa4;
    --border: #2b332d;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--cream);
  color: var(--ink);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 4px 14px;
  border-bottom: 1px solid var(--border);
}

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

.brand-mark {
  font-size: 28px;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  color: var(--green-900);
}

.brand p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}

.ghost-btn:hover {
  border-color: var(--green-500);
  color: var(--green-700);
}

.ghost-btn.danger {
  color: var(--danger);
}

.ghost-btn.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view.hidden {
  display: none;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  padding: 0 20px 14px;
}

.empty-state.hidden {
  display: none;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 6px;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble {
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg.user .bubble {
  background: var(--green-600);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.assistant .bubble {
  background: var(--green-100);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}

.msg.assistant .bubble.error {
  background: #fbe9e4;
  color: var(--danger);
}

.bubble p {
  margin: 0 0 10px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble ul {
  margin: 0 0 10px;
  padding-left: 20px;
}

.bubble ul:last-child {
  margin-bottom: 0;
}

.bubble li {
  margin-bottom: 4px;
}

.msg-images {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.msg-images img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 2px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green-500);
  animation: bounce 1.2s infinite ease-in-out;
}

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

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

.composer {
  border-top: 1px solid var(--border);
  padding: 10px 4px 16px;
}

.preview-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.preview-strip:empty {
  display: none;
}

.preview-thumb {
  position: relative;
  width: 60px;
  height: 60px;
}

.preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.preview-thumb button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--green-100);
  border-radius: 20px;
  padding: 8px 8px 8px 12px;
}

.attach-btn {
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
}

#text-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 14.5px;
  font-family: inherit;
  color: var(--ink);
  max-height: 120px;
  padding: 6px 0;
}

#text-input:focus {
  outline: none;
}

.send-btn {
  background: var(--green-600);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-btn:hover:not(:disabled) {
  background: var(--green-700);
}

/* Save banner */

.save-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--green-100);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 0 4px 10px;
  font-size: 13.5px;
  color: var(--ink);
}

.save-banner.hidden {
  display: none;
}

.save-btn {
  background: var(--green-600);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.save-btn:hover:not(:disabled) {
  background: var(--green-700);
}

.save-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* My Plants view */

#plants-content {
  flex: 1;
  overflow-y: auto;
  padding: 18px 4px;
}

.plants-status {
  color: var(--ink-soft);
  font-size: 14px;
  text-align: center;
  padding: 40px 20px;
}

.plants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.plant-card {
  background: var(--green-100);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.plant-card:hover {
  border-color: var(--green-500);
}

.plant-card-photo {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}

.plant-card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.plant-card-info h3 {
  margin: 0 0 2px;
  font-size: 14px;
}

.plant-card-sci {
  margin: 0 0 6px;
  font-size: 12px;
  font-style: italic;
  color: var(--ink-soft);
}

.plant-tag {
  display: inline-block;
  font-size: 11px;
  background: var(--green-600);
  color: #fff;
  border-radius: 999px;
  padding: 2px 9px;
}

.back-btn {
  margin-bottom: 14px;
}

.plant-detail {
  max-width: 480px;
}

.plant-detail-photo {
  width: 100%;
  max-width: 260px;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--green-100);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  margin-bottom: 12px;
}

.plant-detail-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.plant-detail h2 {
  margin: 0 0 2px;
}

.plant-care-summary {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 10px 0 16px;
}

.care-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.care-grid > div {
  background: var(--green-100);
  border-radius: 10px;
  padding: 8px 10px;
}

.care-grid span {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 2px;
}

.care-grid p {
  margin: 0;
  font-size: 13.5px;
}

.plant-detail h3 {
  font-size: 14px;
  margin-bottom: 8px;
}

.plant-history {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.plant-history li {
  border-left: 2px solid var(--green-500);
  padding-left: 10px;
}

.plant-history-date {
  font-size: 11px;
  color: var(--ink-soft);
}

.plant-history p {
  margin: 2px 0 0;
  font-size: 13.5px;
}

.plant-detail-actions {
  display: flex;
  gap: 8px;
}
