/* =========================
   Global Theme & Resets
   ========================= */
:root {
  --bg: #0f172a;
  --panel: #111827;
  --muted: #94a3b8;
  --text: #e5e7eb;
  --accent: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --card: #0b1220;
  --border: #1f2937;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

:root[data-theme="light"] {
  --bg: #f8fafc;
  --panel: #ffffff;
  --muted: #64748b;
  --text: #1e293b;
  --accent: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --card: #ffffff;
  --border: #e2e8f0;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* =========================
   Header / Nav
   ========================= */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(160%) blur(8px);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}
.logo img {
  width: 28px;
  height: 28px;
}
nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
}
nav a:hover { color: var(--text); background: rgba(255,255,255,0.08); }

/* =========================
   Cards / Grid
   ========================= */
.grid {
  display: grid;
  gap: 16px;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.col-3 { grid-column: span 3 / span 3; }
.col-4 { grid-column: span 4 / span 4; }
.col-6 { grid-column: span 6 / span 6; }
.col-8 { grid-column: span 8 / span 8; }
.col-12 { grid-column: 1 / -1; }

/* Mobile Responsive - Stack everything on small screens */
@media (max-width: 768px) {
  .grid {
    padding: 12px;
    gap: 12px;
  }
  .col-3, .col-4, .col-6, .col-8 { 
    grid-column: 1 / -1; 
  }
}

/* Tablet Responsive - Optimize for medium screens */
@media (max-width: 1024px) and (min-width: 769px) {
  .col-3 { grid-column: span 6 / span 6; }
  .col-4 { grid-column: span 6 / span 6; }
  .col-6 { grid-column: span 6 / span 6; }
  .col-8 { grid-column: span 12 / span 12; }
}

/* Desktop layout improvement for charts */
@media (min-width: 1025px) {
  /* Ensure charts stay in left column and have consistent sizing */
  .chart-card.col-4 {
    grid-column: span 4 / span 4;
  }
  
  /* Fleet list takes up remaining space */
  .fleet-list-container.col-8 {
    grid-column: span 8 / span 8;
  }
}

/* =========================
   KPI Cards
   ========================= */
.kpi h3 {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}
.kpi .value {
  font-size: 28px;
  font-weight: 700;
}
.kpi .note {
  font-size: 12px;
  color: var(--muted);
}

/* =========================
   Fleet List
   ========================= */
.fleet-list { display: grid; gap: 8px; }
.turbine {
  display: grid;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.02);
}

/* Mobile layout */
@media (max-width: 768px) {
  .turbine {
    grid-template-columns: 32px 1fr auto;
  }
}

/* Desktop layout - very specific selector */
@media (min-width: 769px) {
  .fleet-list .turbine,
  #fleetList .turbine {
    grid-template-columns: 50px 160px 90px 80px 160px 120px 90px 100px 130px !important;
    /*                     Icon  Name   Wind  Oil   Vibes  Faults Effic Bear  Status */
    padding: 0 !important;
    gap: 0 !important;
    border-radius: 8px !important;
    align-items: stretch !important;
    display: grid !important;
  }
  
  .fleet-list .turbine .t-icon,
  #fleetList .turbine .t-icon {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 16px !important;
  }
  
  .fleet-list .turbine .t-metric-item,
  #fleetList .turbine .t-metric-item {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
    padding: 16px 8px !important;
    text-align: center !important;
    border-right: 1px solid rgba(255,255,255,0.05) !important;
  }
}
.turbine:hover { background: rgba(255,255,255,0.05); }
.t-icon img { width: 28px; height: 28px; }
.t-meta .name { font-weight: 600; }
.t-meta .metrics { font-size: 13px; color: var(--muted); }
.t-right { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.ok { background: var(--accent); }
.warn { background: var(--warn); }
.bad { background: var(--bad); }
.link { font-size: 13px; color: #3b82f6; }
.link:hover { text-decoration: underline; }

/* =========================
   Chart Responsive Fixes
   ========================= */
canvas {
  max-width: 100%;
  height: auto !important;
  min-height: 200px;
}

/* Ensure chart containers have proper sizing */
.card canvas {
  width: 100% !important;
  height: 200px !important;
}

/* Chart cards specific sizing for better layout */
.chart-card {
  display: flex;
  flex-direction: column;
}

.chart-card canvas {
  flex: 1;
  min-height: 180px;
  max-height: 200px;
}

@media (max-width: 768px) {
  .card canvas {
    height: 200px !important;
  }
  
  /* Additional mobile optimizations */
  .card {
    padding: 12px;
    border-radius: 12px;
  }
  
  /* Ensure all metric grids stack properly on mobile */
  .card [style*="grid-template-columns"] {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }
  
  /* Mobile-friendly font sizes */
  h2 { font-size: 1.2rem; }
  h3 { font-size: 1.1rem; }
  
  /* Improve touch targets */
  button, .ai-link {
    min-height: 44px;
    padding: 12px;
  }
}

/* =========================
   Alert Styles
   ========================= */
.alerts-container { 
  display: grid; 
  gap: 8px; 
}

.fleet-alert {
  display: grid; 
  grid-template-columns: 1fr auto auto; 
  gap: 12px; 
  align-items: center;
  padding: 12px; 
  border-radius: 8px; 
  border: 1px solid var(--border);
  transition: all 0.2s ease;
  /* Dashboard alerts use darker backgrounds for light text */
  background: rgba(15, 23, 42, 0.6);
}

.fleet-alert:hover { 
  background: rgba(15, 23, 42, 0.8); 
}

.fleet-alert.warning { 
  border-left: 4px solid var(--warn); 
  background: rgba(245, 158, 11, 0.15);
}

.fleet-alert.warning:hover {
  background: rgba(245, 158, 11, 0.25);
}

.fleet-alert.critical { 
  border-left: 4px solid var(--bad); 
  background: rgba(239, 68, 68, 0.15);
}

.fleet-alert.critical:hover {
  background: rgba(239, 68, 68, 0.25);
}

.alert-content { 
  display: grid; 
  gap: 4px; 
}

.alert-title { 
  font-weight: 600; 
  color: var(--text);
}

.alert-desc { 
  font-size: 13px; 
  color: var(--muted); 
}

/* Turbine page specific alert styling - use stronger selectors */
.card .fleet-alert {
  /* Turbine page alerts use lighter backgrounds with dark text */
  background: rgba(255, 255, 255, 0.95) !important;
  border: 1px solid var(--border) !important;
}

.card .fleet-alert:hover {
  background: rgba(255, 255, 255, 1) !important;
}

.card .fleet-alert.warning {
  background: #fef9c3 !important;
  border-left: 4px solid #eab308 !important;
}

.card .fleet-alert.warning:hover {
  background: #fef3c7 !important;
}

.card .fleet-alert.critical {
  background: #fee2e2 !important;
  border-left: 4px solid #ef4444 !important;
}

.card .fleet-alert.critical:hover {
  background: #fecaca !important;
}

.card .fleet-alert .alert-title {
  color: #1f2937 !important;
}

.card .fleet-alert .alert-desc {
  color: #6b7280 !important;
}

/* Alternative selectors in case the above doesn't work */
main .card .fleet-alert .alert-title {
  color: #1f2937 !important;
}

main .card .fleet-alert .alert-desc {
  color: #6b7280 !important;
}

/* Additional specific overrides for turbine pages */
.card .fleet-alert .alert-content .alert-title {
  color: #1f2937 !important;
}

.card .fleet-alert .alert-content .alert-desc {
  color: #6b7280 !important;
}

/* Target specific alert IDs if needed */
#alertsT1 .fleet-alert .alert-title,
#alertsT2 .fleet-alert .alert-title,
#alertsT3 .fleet-alert .alert-title,
#alertsT4 .fleet-alert .alert-title,
#alertsT5 .fleet-alert .alert-title,
#alertsT6 .fleet-alert .alert-title,
#alertsT7 .fleet-alert .alert-title,
#alertsT8 .fleet-alert .alert-title,
#alertsT9 .fleet-alert .alert-title,
#alertsT10 .fleet-alert .alert-title {
  color: #1f2937 !important;
}

#alertsT1 .fleet-alert .alert-desc,
#alertsT2 .fleet-alert .alert-desc,
#alertsT3 .fleet-alert .alert-desc,
#alertsT4 .fleet-alert .alert-desc,
#alertsT5 .fleet-alert .alert-desc,
#alertsT6 .fleet-alert .alert-desc,
#alertsT7 .fleet-alert .alert-desc,
#alertsT8 .fleet-alert .alert-desc,
#alertsT9 .fleet-alert .alert-desc,
#alertsT10 .fleet-alert .alert-desc {
  color: #6b7280 !important;
}

/* =========================
   Alert Toggle Button
   ========================= */
.alert-toggle-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
}
.alert-toggle-btn.clear-mode {
  background: var(--bad);
  color: white;
}
.alert-toggle-btn.clear-mode:hover {
  background: #dc2626;
  transform: translateY(-1px);
}
.alert-toggle-btn.show-mode {
  background: var(--accent);
  color: white;
}
.alert-toggle-btn.show-mode:hover {
  background: #16a34a;
  transform: translateY(-1px);
}

/* =========================
   Alerts
   ========================= */
.alerts-section { margin: 16px 0; }
.alert {
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}
.alert.info { background: #e0f2fe; border-left: 4px solid #0284c7; }
.alert.warning { background: #fef9c3; border-left: 4px solid #eab308; }
.alert.critical { background: #fee2e2; border-left: 4px solid #dc2626; }

/* =========================
   AI Chatbot Button & Modal
   ========================= */
.ai-chat-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 25px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 16px;
}

.ai-chat-btn:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.ai-chat-btn::before {
  content: "🤖";
  font-size: 16px;
}

/* AI Chatbot Modal */
.ai-chat-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 10000;
  animation: fadeIn 0.3s ease;
}

.ai-chat-modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-container {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 800px;
  height: 80%;
  max-height: 700px;
  position: relative;
  overflow: hidden;
  animation: slideIn 0.4s ease;
}

.ai-chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ai-chat-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.ai-chat-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s ease;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.ai-chat-content {
  height: calc(100% - 80px);
  overflow: hidden;
}

.ai-chat-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { 
    opacity: 0; 
    transform: translateY(-50px) scale(0.9); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0) scale(1); 
  }
}

/* Mobile responsiveness for AI chat */
@media (max-width: 768px) {
  .ai-chat-container {
    width: 95%;
    height: 90%;
    max-height: none;
    border-radius: 15px;
  }
  
  .ai-chat-btn {
    padding: 10px 16px;
    font-size: 13px;
    margin-left: 8px;
  }
  
  /* Mobile: Hide long text and show short text */
  .ai-chat-btn .full-text {
    display: none;
  }
  
  .ai-chat-btn .mobile-text {
    display: inline;
  }
  
  .ai-chat-header {
    padding: 15px;
  }
  
  .ai-chat-header h3 {
    font-size: 16px;
  }
}

/* Desktop: Show long text and hide short text */
@media (min-width: 769px) {
  .ai-chat-btn .full-text {
    display: inline;
  }
  
  .ai-chat-btn .mobile-text {
    display: none;
  }
}

/* =========================
   Footer
   ========================= */
footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px 16px;
}
