/* Variable Definitions & Theme */
:root {
  --bg-primary: #060a12;
  --bg-chat: #090e18;
  --card-bg: rgba(17, 24, 39, 0.5);
  --card-border: rgba(255, 255, 255, 0.05);
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  
  --color-green: #10b981;
  --color-green-glow: rgba(16, 185, 129, 0.2);
  --color-cyan: #06b6d4;
  --color-cyan-glow: rgba(6, 182, 212, 0.2);
  --color-red: #ef4444;
  --color-red-glow: rgba(239, 68, 68, 0.3);
  --color-orange: #f59e0b;
  --color-orange-glow: rgba(245, 158, 11, 0.25);
  
  --font-display: 'Outfit', 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14.5px;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.text-green { color: var(--color-green); }
.text-cyan { color: var(--color-cyan); }
.text-red { color: var(--color-red); }
.text-orange { color: var(--color-orange); }
.accent-text {
  background: linear-gradient(135deg, var(--color-green), var(--color-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hidden { display: none !important; }

/* Main layout wrapper */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* LEFT SIDEBAR: Telemetry & IoT Control Board */
.sidebar-panel {
  width: 320px;
  background-color: var(--bg-primary);
  border-right: 1px solid var(--card-border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  flex-shrink: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--card-border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.badge-ai {
  font-size: 9px;
  font-weight: 700;
  background-color: rgba(6, 182, 212, 0.1);
  color: var(--color-cyan);
  border: 1px solid rgba(6, 182, 212, 0.2);
  padding: 2px 6px;
  border-radius: 6px;
}

/* System cards inside sidebar */
.system-card {
  background-color: rgba(255, 255, 255, 0.01);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 14px;
}

.system-card h3 {
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-item {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
}

.status-label {
  color: var(--text-muted);
}

.status-value {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Blinking indicators for IoT and warning updates */
.pulse-dot {
  width: 6px;
  height: 6px;
  background-color: var(--color-green);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--color-green);
  animation: pulseLight 1.5s infinite;
}

@keyframes pulseLight {
  0% { opacity: 0.5; }
  50% { opacity: 1; box-shadow: 0 0 10px var(--color-green); }
  100% { opacity: 0.5; }
}

.telemetry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.telem-item {
  background-color: rgba(255, 255, 255, 0.02);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.telem-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.telem-val {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
}

/* Warnings Board list */
.warning-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.warning-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 6px;
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--card-border);
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s;
}

.warning-item:hover {
  transform: translateY(-1px);
  background-color: rgba(255, 255, 255, 0.04);
}

.warning-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bleep-red {
  background-color: var(--color-red);
  box-shadow: 0 0 8px var(--color-red);
  animation: bleep 1.2s infinite;
}

.bleep-orange {
  background-color: var(--color-orange);
  box-shadow: 0 0 8px var(--color-orange);
  animation: bleep 1.5s infinite;
}

@keyframes bleep {
  0% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.6; }
}

.warning-body {
  flex-grow: 1;
  line-height: 1.3;
}

.warning-body strong {
  display: block;
  font-size: 12px;
  color: var(--text-main);
}

.warning-body p {
  font-size: 10px;
  color: var(--text-muted);
}

.warning-arrow {
  font-size: 10px;
  color: var(--text-muted);
}

.warning-high { border-left: 3px solid var(--color-red); }
.warning-medium { border-left: 3px solid var(--color-orange); }

.sidebar-footer {
  margin-top: auto;
  font-size: 11px;
  color: var(--text-muted);
}

/* RIGHT PANEL: Chat Workspace */
.chat-panel {
  flex-grow: 1;
  background-color: var(--bg-chat);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  height: 70px;
  border-bottom: 1px solid var(--card-border);
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  background-color: rgba(9, 14, 24, 0.85);
  backdrop-filter: blur(10px);
}

.chat-agent-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background-color: rgba(6, 182, 212, 0.1);
  color: var(--color-cyan);
  border: 1px solid rgba(6, 182, 212, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.chat-agent-info h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
}

.chat-agent-info p {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.model-meta {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Messages history feed list */
.chat-messages-feed {
  flex-grow: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chat-message {
  display: flex;
  gap: 14px;
  max-width: 85%;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.message-agent .message-avatar {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--color-green);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.message-user .message-avatar {
  background-color: rgba(6, 182, 212, 0.1);
  color: var(--color-cyan);
  border: 1px solid rgba(6, 182, 212, 0.2);
}

.message-bubble {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 14px 18px;
  backdrop-filter: blur(8px);
  line-height: 1.6;
}

.message-bubble p {
  margin-bottom: 10px;
}

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

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

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

.message-user .message-bubble {
  background: rgba(6, 182, 212, 0.05);
  border-color: rgba(6, 182, 212, 0.18);
  border-top-right-radius: 2px;
}

.message-agent .message-bubble {
  border-top-left-radius: 2px;
}

/* Dynamic Inline Alert System Card */
.message-system-alert {
  align-self: center;
  max-width: 90%;
  width: 550px;
  margin: 10px 0;
  animation: alertPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes alertPop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.alert-card {
  border-radius: 12px;
  padding: 18px;
  display: flex;
  gap: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.alert-red {
  background-color: rgba(239, 68, 68, 0.06);
  border: 1.5px solid var(--color-red);
}

.alert-orange {
  background-color: rgba(245, 158, 11, 0.06);
  border: 1.5px solid var(--color-orange);
}

.alert-icon {
  font-size: 26px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.alert-content h4 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.2px;
}

.alert-content p {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
}

.alert-actions {
  display: flex;
  gap: 10px;
}

/* Dynamic UI Widgets inside bubbles */
.embedded-card {
  width: 500px;
  margin-top: 12px;
  background: rgba(8, 12, 21, 0.8);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.embedded-card h4 {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  padding-bottom: 6px;
  text-transform: uppercase;
}

/* Sentinel-2 Chlorophyll index mini grid */
.sat-chlorophyll-matrix {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  width: 100%;
  aspect-ratio: 16/9;
  background-color: #030508;
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--card-border);
  margin-bottom: 12px;
}

.sat-cell {
  background-color: rgba(16, 185, 129, 0.85); /* default high chlorophyll */
  border-radius: 2px;
  position: relative;
}

.sat-cell-anomaly-high {
  background-color: rgba(239, 68, 68, 0.95);
  box-shadow: inset 0 0 6px rgba(0,0,0,0.8);
  animation: alertCellBlink 1.5s infinite alternate;
}

.sat-cell-anomaly-med {
  background-color: rgba(245, 158, 11, 0.85);
}

@keyframes alertCellBlink {
  0% { opacity: 0.7; }
  100% { opacity: 1; }
}

.sat-meta-data {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  background-color: rgba(255,255,255,0.02);
  padding: 8px;
  border-radius: 6px;
}

/* NVIDIA Cosmos streaming player card */
.cosmos-video-box {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  margin-bottom: 10px;
  background-color: #020408;
}

.cosmos-video-box video {
  width: 100%;
  display: block;
}

.cosmos-overlay-alert {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: rgba(239, 68, 68, 0.85);
  color: #fff;
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  z-index: 10;
  animation: pulse 1s infinite alternate;
  display: none;
}

/* Simulated AI detection bounding box */
.cosmos-bbox {
  position: absolute;
  border: 2px solid var(--color-red);
  box-shadow: 0 0 8px var(--color-red);
  pointer-events: none;
  z-index: 5;
  display: none;
}

/* Cosmos live log terminal */
.cosmos-terminal {
  background-color: #03060c;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 10px;
  font-family: monospace;
  font-size: 11.5px;
  color: #00ffcc;
  height: 110px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.term-line {
  line-height: 1.3;
}

/* AWS & NVIDIA cloud architecture diagram widget */
.arch-diagram-card {
  width: 100%;
}

.arch-canvas {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #020407;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
}

.arch-layer {
  display: flex;
  justify-content: space-around;
  align-items: center;
  position: relative;
}

.arch-layer:not(:last-child)::after {
  content: '↓';
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.15);
  font-size: 12px;
}

.arch-node {
  background-color: rgba(255,255,255,0.02);
  border: 1px solid var(--card-border);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 11px;
  text-align: center;
  max-width: 110px;
}

.arch-node strong {
  display: block;
  font-size: 11.5px;
  margin-bottom: 2px;
}

.node-aws { border-color: rgba(245, 158, 11, 0.4); color: #f59e0b; }
.node-nvidia { border-color: rgba(16, 185, 129, 0.4); color: #10b981; }

/* Pest details dictionary card styling */
.pest-dict-card {
  width: 450px;
}

.pest-dict-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.pest-dict-img {
  width: 120px;
  height: 90px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--card-border);
  flex-shrink: 0;
}

.pest-dict-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pest-dict-info {
  flex-grow: 1;
}

.pest-dict-info h5 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
}

.pest-dict-alt {
  background-color: rgba(16, 185, 129, 0.03);
  padding: 8px;
  border-radius: 6px;
  font-size: 12px;
}

/* Quick Commands Bar chips scrollable */
.quick-commands-bar {
  height: 48px;
  padding: 4px 24px;
  display: flex;
  gap: 10px;
  align-items: center;
  overflow-x: auto;
  background-color: rgba(9, 14, 24, 0.6);
  border-top: 1px solid var(--card-border);
  flex-shrink: 0;
}

.quick-commands-bar::-webkit-scrollbar {
  display: none;
}

.command-chip {
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 6px 14px;
  color: var(--text-main);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition-fast);
}

.command-chip:hover {
  background-color: rgba(6, 182, 212, 0.08);
  border-color: rgba(6, 182, 212, 0.25);
  color: var(--color-cyan);
}

/* Chat Input form area styling */
.chat-input-area {
  height: 70px;
  padding: 12px 24px;
  background-color: rgba(9, 14, 24, 0.95);
  border-top: 1px solid var(--card-border);
  flex-shrink: 0;
}

.chat-input-form {
  display: flex;
  gap: 12px;
  height: 100%;
}

.chat-input-form input {
  flex-grow: 1;
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 0 16px;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input-form input:focus {
  border-color: var(--color-cyan);
  background-color: rgba(255, 255, 255, 0.05);
}

.btn-send {
  width: 46px;
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--color-cyan), #0891b2);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: opacity 0.2s;
}

.btn-send:hover {
  opacity: 0.95;
}

/* Voice & Leaflet Widget Custom CSS Extensions */
.btn-mic.recording {
  background-color: var(--color-red) !important;
  color: white !important;
  border-color: var(--color-red) !important;
  animation: micPulse 1.2s infinite alternate;
}

@keyframes micPulse {
  0% { box-shadow: 0 0 4px var(--color-red); }
  100% { box-shadow: 0 0 16px var(--color-red); }
}

.leaflet-popup-content-wrapper {
  background: rgba(9, 14, 24, 0.96) !important;
  color: var(--text-main) !important;
  border: 1px solid rgba(6, 182, 212, 0.3) !important;
  backdrop-filter: blur(10px) !important;
  border-radius: 8px !important;
  font-family: var(--font-body) !important;
}

.leaflet-popup-tip {
  background: rgba(9, 14, 24, 0.96) !important;
  border: 1px solid rgba(6, 182, 212, 0.3) !important;
}

.leaflet-container {
  background: #060a12 !important;
}

.map-layer-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.2s;
  font-family: var(--font-display);
}

.map-layer-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
}

.map-layer-btn.active {
  background: linear-gradient(135deg, var(--color-cyan), #0891b2);
  border-color: var(--color-cyan);
  color: #fff;
}

.term-line.success {
  color: var(--color-green) !important;
}

.term-line.warning {
  color: var(--color-orange) !important;
}

.term-line.error {
  color: var(--color-red) !important;
}

.term-line.user {
  color: #fff !important;
  font-weight: 600;
}



/* ============================================================
   MOBILE OPTIMIZATION
   ============================================================ */
@media (max-width: 820px) {
  .app-container { flex-direction: column; height: auto; min-height: 100vh; width: 100%; }
  .chat-panel { order: 1; min-height: 86vh; }
  .sidebar-panel {
    order: 2; width: 100%; box-sizing: border-box;
    border-right: none; border-top: 1px solid var(--card-border);
    overflow-x: hidden;
  }
  .chat-header { height: 56px; padding: 0 14px; }
  .chat-agent-info h2 { font-size: 14px; }
  .chat-messages-feed { padding: 14px; gap: 14px; }
  .chat-message { max-width: 94%; }
  .command-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .command-chip { flex-shrink: 0; }
  .chat-input-area { height: 62px; padding: 10px 12px; }
  /* 16px input prevents iOS auto-zoom on focus */
  .chat-input-form input { font-size: 16px; }
  .embedded-card { max-width: 100% !important; width: 100%; box-sizing: border-box; }
}

@media (max-width: 480px) {
  /* On small phones, hand the whole screen to the chat; hide the IoT board */
  .sidebar-panel { display: none; }
  .chat-panel { min-height: 100vh; }
  .chat-message { max-width: 99%; }
  .chat-messages-feed { padding: 10px; }
}
