/*
 * Agronavti AI Chatbot Styles
 * Version: 2.9 (Modern Dark / Glassmorphism Refresh)
 */

/* ============ DESIGN TOKENS ============ */
:root {
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);

  --bg-canvas: #05070a;
  --bg-deep: #0d1117;
  --bg-surface: #161b22;
  --bg-surface-2: #1c232c;
  --bg-glass: rgba(22, 27, 34, 0.72);
  --border-color: #30363d;
  --border-soft: rgba(201, 209, 217, 0.1);

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary: #6e7681;

  --accent-primary: #22c55e;
  --accent-hover: #34d76f;
  --accent-soft: rgba(34, 197, 94, 0.14);
  --accent-glow: rgba(34, 197, 94, 0.35);

  --info: #58a6ff;
  --warning: #fbbf24;
  --danger: #f87171;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 12px 34px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.5);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 0.15s;
  --dur-base: 0.25s;
  --dur-slow: 0.4s;
}

/* ============ GLOBAL RESETS ============ */
*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; height: -webkit-fill-available; }

body, html {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  font-family: 'BPG Nino Mtavruli', 'Segoe UI', system-ui, Arial, sans-serif;
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============ MAIN WIDGET CONTAINER ============ */
#agronavti-ai-root {
  position: relative;
  max-width: 500px;
  margin: 34px auto 32px auto;
  background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg-deep) 100%);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 0;
  overflow: hidden;
  height: min(760px, calc(100dvh - 68px));
  height: min(760px, calc(100vh - 68px));
  display: flex;
  isolation: isolate;
}

#agronavti-ai-root::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 15% -10%, var(--accent-soft), transparent 55%),
    radial-gradient(circle at 100% 110%, rgba(88, 166, 255, 0.08), transparent 50%);
  pointer-events: none;
  z-index: 0;
}

#agronavti-chat-widget {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: relative;
  z-index: 1;
}

/* --- Language Picker --- */
#agronavti-language-picker {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 40px;
  align-items: center;
  flex-grow: 1;
}
.lang-btn {
  font-size: 1.05rem;
  padding: 14px 34px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--accent-primary);
  background: rgba(34, 197, 94, 0.06);
  color: var(--accent-primary);
  font-weight: 700;
  cursor: pointer;
  transition: background var(--dur-base) var(--ease), color var(--dur-base) var(--ease),
    box-shadow var(--dur-base) var(--ease), transform var(--dur-fast) var(--ease);
}
.lang-btn:hover {
  background: var(--accent-primary);
  color: #06170c;
  box-shadow: 0 0 24px var(--accent-glow);
  transform: translateY(-2px);
}
.lang-btn:active { transform: translateY(0) scale(0.97); }
.lang-btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
}

/* --- Sector Picker (Crops vs. Cattle) --- */
#agronavti-sector-picker {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  padding: 44px 26px 28px;
  flex-grow: 1;
}
.sector-back-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 1.8rem;
}
.sector-picker-title {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}
#sector-options {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sector-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dur-base) var(--ease), transform var(--dur-fast) var(--ease),
    box-shadow var(--dur-base) var(--ease), background var(--dur-base) var(--ease);
}
.sector-btn:hover {
  border-color: var(--accent-primary);
  background: var(--accent-soft);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}
.sector-btn:active { transform: translateY(0) scale(0.98); }
.sector-btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}
.sector-icon { font-size: 1.8rem; flex-shrink: 0; line-height: 1; }
.sector-copy { display: flex; flex-direction: column; gap: 4px; }
.sector-title { font-weight: 700; font-size: 1rem; }
.sector-desc { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.4; }

/* ============ CHAT INTERFACE ============ */
#agronavti-chat-area {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background-color: var(--bg-deep);
}

/* --- Header --- */
#chat-top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px;
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  padding-top: calc(12px + var(--safe-area-inset-top));
  padding-left: calc(10px + var(--safe-area-inset-left));
  padding-right: calc(10px + var(--safe-area-inset-right));
}
#chat-header-title { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.01em; }
.header-btn {
  background: none;
  border: none;
  color: var(--accent-primary);
  font-size: 2rem;
  cursor: pointer;
  padding: 0 12px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.header-btn:hover { background: var(--accent-soft); }
.header-btn:active { transform: scale(0.92); }
.header-btn-placeholder { width: 48px; }

/* --- Progress Bar --- */
#progress-container {
  width: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
  height: 4px;
  overflow: hidden;
}
#progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-hover));
  transition: width var(--dur-slow) var(--ease);
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 10px var(--accent-glow);
}

/* --- Chat Log --- */
#chat-log {
  flex-grow: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: #3a4149 transparent;
}
#chat-log::-webkit-scrollbar { width: 6px; }
#chat-log::-webkit-scrollbar-track { background: transparent; }
#chat-log::-webkit-scrollbar-thumb { background-color: #3a4149; border-radius: 6px; }
#chat-log::-webkit-scrollbar-thumb:hover { background-color: #4b5563; }

/* --- Message Bubbles & Animations --- */
.message {
  max-width: 88%;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  line-height: 1.6;
  margin-bottom: 12px;
  word-break: break-word;
  animation: message-fade-in var(--dur-slow) var(--ease);
  box-shadow: var(--shadow-sm);
}
@keyframes message-fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.user-message {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-hover));
  color: #06170c;
  font-weight: 600;
  border-radius: var(--radius-md) var(--radius-md) 6px var(--radius-md);
  box-shadow: 0 6px 20px rgba(34, 197, 94, 0.25);
}
.bot-message {
  align-self: flex-start;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 6px;
}
.bot-message.disclaimer-message {
  margin-top: 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: var(--bg-surface-2);
  border-style: dashed;
}
.bot-message.disclaimer-message a { color: var(--accent-primary); }
.bot-message.disclaimer-message.cattle-disclaimer {
  border-color: rgba(88, 166, 255, 0.35);
}
.bot-message.disclaimer-message.cattle-disclaimer a { color: var(--info); }
.bot-message.business-plan-prompt {
  margin-top: 16px;
  background: transparent;
  border-style: dashed;
  box-shadow: none;
}

/* --- Typing indicator --- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 2px;
}
.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* --- Input Area (floating / docked bar) --- */
#chat-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  flex-shrink: 0;
  position: relative;
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border-soft);
  padding-bottom: calc(12px + var(--safe-area-inset-bottom));
  padding-left: calc(10px + var(--safe-area-inset-left));
  padding-right: calc(10px + var(--safe-area-inset-right));
}
#chat-input {
  width: 100%;
  padding: 14px 18px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  background: var(--bg-deep);
  font-size: 1.02rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--dur-base) var(--ease), box-shadow var(--dur-base) var(--ease);
}
#chat-input::placeholder { color: var(--text-tertiary); }
#chat-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#chat-send {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  font-size: 1.4rem;
  color: #06170c;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-hover));
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(34, 197, 94, 0.35);
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-base) var(--ease);
}
#chat-send:hover { box-shadow: 0 8px 22px var(--accent-glow); transform: translateY(-1px); }
#chat-send:active { transform: scale(0.92); }

/* --- File Upload Trigger --- */
.file-upload-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-pill);
  border: 1px dashed var(--accent-primary);
  background: var(--accent-soft);
  color: var(--accent-primary);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background var(--dur-base) var(--ease), transform var(--dur-fast) var(--ease);
}
.file-upload-label::before { content: "📎"; font-size: 1rem; }
.file-upload-label:hover { background: rgba(34, 197, 94, 0.22); transform: translateY(-1px); }
.file-upload-label:active { transform: translateY(0) scale(0.98); }

/* --- Download / Option Buttons --- */
#download-pdf, .opt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 10px 16px 16px;
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: border-color var(--dur-base) var(--ease), background var(--dur-base) var(--ease),
    transform var(--dur-fast) var(--ease);
}
#download-pdf:hover, .opt-btn:hover {
  border-color: var(--accent-primary);
  background: var(--accent-soft);
  color: var(--accent-primary);
}
#download-pdf:active, .opt-btn:active { transform: scale(0.97); }
.opt-btn { margin: 10px 0 0; }

/* --- Location Suggestions --- */
#location-suggestions-container {
  position: relative;
  width: 0;
  height: 0;
}
#location-suggestions {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  width: min(340px, calc(100vw - 40px));
  max-height: 220px;
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 40;
  animation: message-fade-in var(--dur-fast) var(--ease);
}
#location-suggestions li {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
  white-space: normal;
  line-height: 1.4;
}
#location-suggestions li:hover,
#location-suggestions li:focus-visible {
  background: var(--accent-soft);
  color: var(--accent-primary);
}
#location-suggestions li:active { background: var(--accent-soft); }
#location-suggestions li + li { margin-top: 2px; }

/* --- Map Container --- */
.map-container-in-chat {
  width: 100%;
  height: 200px;
  margin-top: 12px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  background: var(--bg-surface-2);
  animation: map-fade-in var(--dur-slow) var(--ease);
  position: relative;
  z-index: 0;
}
@keyframes map-fade-in {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}
.map-container-in-chat .leaflet-container { border-radius: var(--radius-md); background: var(--bg-surface-2); }

/* --- Recommendation Cards --- */
.recommendation-card {
  background: linear-gradient(160deg, var(--bg-surface) 0%, var(--bg-surface-2) 100%);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-primary);
  padding: 1.2rem;
  border-radius: var(--radius-md);
  margin-bottom: 15px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-base) var(--ease), box-shadow var(--dur-base) var(--ease);
}
.recommendation-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.recommendation-card h3 {
  margin: 0 0 12px 0;
  color: var(--text-primary);
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.recommendation-card h3::before { content: "🌱"; font-size: 1.05rem; }

.rec-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 0.92rem;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 8px;
}
.rec-field:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.rec-field .label {
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.rec-field .value {
  color: var(--text-primary);
  font-weight: 600;
  text-align: right;
}

/* Data badges for recognized field types */
.rec-field--yield .value,
.rec-field--profit .value,
.rec-field--difficulty .value,
.rec-field--rating .value,
.rec-field--demand .value {
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
}
.rec-field--yield .value { background: rgba(88, 166, 255, 0.14); color: var(--info); }
.rec-field--profit .value { background: var(--accent-soft); color: var(--accent-hover); }
.rec-field--difficulty .value { background: rgba(251, 191, 36, 0.14); color: var(--warning); }
.rec-field--rating .value { background: rgba(251, 191, 36, 0.14); color: var(--warning); letter-spacing: 1px; }
.rec-field--demand .value { background: rgba(139, 148, 158, 0.16); color: var(--text-primary); }

/* ============ TABLET / DESKTOP ============ */
@media (min-width: 600px) {
  #agronavti-ai-root {
    max-width: 540px;
    margin: 48px auto;
    height: min(780px, calc(100dvh - 96px));
    height: min(780px, calc(100vh - 96px));
  }
}
@media (min-width: 900px) {
  #agronavti-ai-root { max-width: 580px; }
}

/* ============ MOBILE / PWA FULLSCREEN LAYOUT ============ */
@media (max-width: 599px) {
  body, html { overflow: hidden; }
  #agronavti-ai-root {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    height: -webkit-fill-available;
    max-width: 100%;
    margin: 0;
    border-radius: 0;
    border: none;
  }
  .message { max-width: 92%; }
  #location-suggestions { width: calc(100vw - 40px); }
}
