/* ==========================================================================
   SMARTFLORA DASHBOARD - TOÀN BỘ CSS ĐÃ TỐI ƯU
   ========================================================================== */

:root {
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-light: #ecfdf5;
  --bg-main: #f1f5f9;
  --card-bg: #ffffff;
  --text-dark: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --danger: #b91c1c;
  --danger-light: #fef2f2;
  --danger-border: #f87171;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-main);
  color: var(--text-dark);
  padding: 24px;
  line-height: 1.5;
}

.dashboard-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ================= BRANDING & FOOTER ================= */
.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-right: 20px;
  border-right: 2px dashed var(--border-color);
}

.brand-info {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-dark);
  letter-spacing: -0.5px;
  margin-bottom: 2px;
  line-height: 1;
}

.brand-title span {
  color: var(--primary);
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dashboard-footer {
  margin-top: 10px;
  padding: 24px 16px;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dashboard-footer strong {
  color: var(--text-dark);
  font-weight: 700;
}

/* ================= HEADER ================= */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  padding: 16px 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.node-select-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.node-select-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.node-dropdown {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  font-weight: 600;
  color: var(--text-dark);
  background: #f8fafc;
  outline: none;
}

.station-actions-inline {
  display: flex;
  gap: 6px;
}

.btn-icon {
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: var(--bg-main);
}

.status-badge {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 20px;
}

.status-badge.online {
  background: #dcfce7;
  color: #15803d;
}

/* ================= CARDS & GRIDS ================= */
.section-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-dark);
}

.section-title.no-margin {
  margin-bottom: 0;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.metric-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #f8fafc;
  transition: background-color 0.3s;
}

.metric-icon {
  font-size: 1.8rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
}

.metric-data .label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.metric-data .value {
  font-size: 1.4rem;
  font-weight: 800;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.control-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #f8fafc;
}

.control-label {
  font-size: 0.9rem;
  font-weight: 600;
}

/* ================= SWITCH TOGGLE ================= */
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: 0.3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* ================= NÚT HÀNH ĐỘNG ================= */
.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.action-btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-action {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  color: white;
  transition: opacity 0.2s;
}

.btn-action:hover {
  opacity: 0.9;
}

.btn-primary { background: var(--primary); }
.btn-amber { background: #f59e0b; }
.btn-purple { background: #8b5cf6; }
.btn-sky { background: #0284c7; }
.btn-slate { background: #475569; }

/* ================= TIẾN TRÌNH & KỊCH BẢN ================= */
.profile-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #0284c7;
  margin-top: 4px;
}

.growth-tracker-box {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 16px;
}

.tracker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.tracker-status-text {
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.text-primary {
  color: var(--primary);
  font-weight: 700;
}

.stage-badge {
  background: #e0e7ff;
  color: #4338ca;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}

.tracker-percent {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-dark);
}

.progress-bar-bg {
  width: 100%;
  height: 10px;
  background: var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 16px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-hover));
  border-radius: 10px;
  transition: width 0.4s ease;
}

/* ================= BIỂU ĐỒ & TIMELINE ================= */
.chart-wrapper {
  background: var(--card-bg);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 140px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 16px;
}

.timeline-steps {
  display: flex;
  gap: 12px;
  width: 100%;
}

.timeline-step {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  opacity: 0.6;
}

.timeline-step.active {
  opacity: 1;
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15);
}

.timeline-step.completed {
  opacity: 0.9;
  background: var(--bg-main);
}

.step-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #94a3b8;
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.timeline-step.active .step-icon {
  background: var(--primary);
}

.timeline-step.completed .step-icon {
  background: var(--text-muted);
}

.step-info {
  display: flex;
  flex-direction: column;
}

.step-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-dark);
}

.step-days {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.profile-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.detail-item {
  background: #f8fafc;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.detail-item.full-width {
  grid-column: 1 / -1;
}

.detail-item .lbl {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.detail-item .val {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-top: 3px;
}

/* ================= MODALS ================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay.hidden {
  display: none !important;
}

.modal-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal-card-lg {
  max-width: 640px;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.form-input {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
}

.form-textarea {
  resize: vertical;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.btn-secondary-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ================= CẢNH BÁO THÔNG MINH ================= */
#system-alert-banner {
  background: var(--danger-light);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  padding: 14px 24px;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 6px -1px rgba(239, 68, 68, 0.2);
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes blink-red {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); border-color: #ef4444; }
  70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); border-color: #fca5a5; }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); border-color: #ef4444; }
}

.metric-card.danger {
  animation: blink-red 1.5s infinite;
  background-color: #fff5f5;
}

.metric-card.danger .value {
  color: var(--danger) !important;
}

/* ================= THỜI TIẾT & AI THỊ GIÁC ================= */
.weather-widget {
  display: flex; 
  align-items: center; 
  gap: 8px;
  background: #f0f9ff; 
  border: 1px solid #bae6fd;
  padding: 6px 14px; 
  border-radius: 20px;
  font-size: 0.85rem; 
  color: #0369a1; 
  font-weight: 700;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.weather-icon { 
  font-size: 1.2rem; 
}

#diagnosis-content {
  background: #f8fafc;
  padding: 16px;
  border-radius: 8px;
  border: 1px dashed #cbd5e1;
  margin: 16px 0;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-dark);
  min-height: 80px;
}

.upload-box {
  border: 2px dashed #94a3b8; 
  border-radius: 8px;
  padding: 16px; 
  text-align: center; 
  margin-top: 15px;
  background: #f8fafc; 
  cursor: pointer; 
  transition: all 0.2s;
  color: var(--text-muted); 
  font-size: 0.9rem; 
  font-weight: 600;
}

.upload-box:hover { 
  border-color: #8b5cf6; 
  background: #f3e8ff; 
  color: #6d28d9; 
}

.image-preview { 
  max-width: 100%; 
  height: auto; 
  max-height: 180px; 
  border-radius: 8px; 
  display: none; 
  margin-top: 10px; 
  border: 1px solid #cbd5e1; 
}

/* ================= CAMERA GIÁM SÁT ================= */
.camera-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--text-dark);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  margin-top: 10px;
}

.camera-feed {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-placeholder {
  position: absolute;
  color: #94a3b8;
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 20px;
}
/* ==========================================================================
   TỐI ƯU HÓA GIAO DIỆN MOBILE (CHỐNG BÓP MÉO)
   ========================================================================== */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }
  
  .dashboard-container {
    gap: 12px;
  }
  
  .dashboard-header {
    flex-direction: column;
    align-items: stretch;
    padding: 14px;
    gap: 12px;
  }

  .brand-wrapper {
    border-right: none;
    border-bottom: 2px dashed var(--border-color);
    padding-right: 0;
    padding-bottom: 12px;
    width: 100%;
    justify-content: center;
  }
  
  .brand-info { 
    align-items: flex-start; 
  }
  
  .header-actions {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 10px;
  }
  
  .header-actions > * {
    width: 100%;
    justify-content: center;
  }
  
  .section-card {
    padding: 16px 14px;
  }
  
  .metrics-grid, .controls-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .metric-icon {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
    flex-shrink: 0;
  }
  
  .timeline-steps {
    flex-direction: column !important;
  }
  
  .timeline-step {
    width: 100%;
  }

  .chart-container {
    height: 180px;
  }
  
  .camera-wrapper {
    aspect-ratio: 4 / 3;
  }
}