/* =========================================================
   ROOT VARIABLES (LIGHT THEME)
========================================================= */
:root {
  --bg-main: #e9f6fb;        /* page background */
  --bg-panel: #ffffff;       /* panels */
  --bg-card: #ffffff;        /* card background */

  --border-soft: rgba(0,0,0,0.08);
  --shadow-soft: 0 6px 20px rgba(0,0,0,0.1);

  --text-main: #1f2933;
  --text-muted: #6b7280;
  --text-dim: #9ca3af;

  --green: #22c55e;
  --blue: #2563eb;
  --red: #ef4444;
  --amber: #f59e0b;
  --thermo-bg: #d1d5db;
}

/* =========================================================
   GLOBAL / BODY
========================================================= */
body {
  font-family: "Inter", Arial, sans-serif;
  margin: 0;
  padding: 18px;
  background: var(--bg-main);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* =========================================================
   HEADER
========================================================= */
header {
  text-align: center;
  margin-bottom: 18px;
  position: relative;
}

header img {
  width: 48px;
  vertical-align: middle;
  margin-right: 8px;
}

header h2 {
  font-size: 1.4rem;
  margin: 0;
  font-weight: 700;
}

.datetime {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.day-night-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: yellow;
  margin: 6px auto 0;
  transition: all 0.5s ease;
  box-shadow: 0 0 10px yellow;
}
.day-night-icon.night {
  background: #f0f0ff;
  box-shadow: 0 0 12px #a0a0ff inset;
}

/* =========================================================
   MAIN LAYOUT
========================================================= */
main.layout {
  display: flex;
  gap: 22px;
  width: 100%;
  max-width: 1400px;
}

/* =========================================================
   LEFT PANEL
========================================================= */
.left-panel {
  flex: 2;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* =========================================================
   SENSOR CARDS
========================================================= */
.sensor-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.sensor-card {
  background: var(--bg-card);
  padding: 14px;
  border-radius: 14px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sensor-card:hover {
  transform: translateY(-2px);
}

.sensor-info {
  display: flex;
  flex-direction: column;
}

.sensor-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.sensor-temp {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-main);
}

.sensor-hum {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.sensor-time {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Thermometer */
.thermometer {
  width: 14px;
  height: 60px;
  background: var(--thermo-bg);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}
.thermo-fill {
  width: 100%;
  height: 0%;
  background: var(--green);
  position: absolute;
  bottom: 0;
  left: 0;
  transition: height 0.5s ease, background 0.5s ease;
}

/* =========================================================
   AMMONIA CARDS
========================================================= */
.ammonia-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.ammonia-card {
  background: var(--bg-card);
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
  text-align: center;
}

.ammonia-card h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.ammonia-gauge {
  height: 14px;
  background: #e5e7eb;
  border-radius: 7px;
  overflow: hidden;
}

.ammonia-gauge div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--amber), var(--red));
  transition: width 0.5s ease, background 0.5s ease;
}

.ammonia-card div[id^="ammoniaStatus"] {
  margin-top: 8px;
  font-weight: 700;
  font-size: 1rem;
}

/* =========================================================
   RIGHT PANEL
========================================================= */
.right-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* =========================================================
   MODE DISPLAY
========================================================= */
.status-box.compact {
  background: var(--bg-panel);
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
  text-align: center;
}

.mode-display span:first-child {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.mode-value {
  display: block;
  font-size: 1.7rem;
  font-weight: 800;
  margin-top: 4px;
}
.mode-manual { color: var(--blue); }
.mode-auto   { color: var(--green); }
.mode-error  { color: var(--red); }

/* =========================================================
   FAN GRID
========================================================= */
.fan-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.fan-card {
  background: var(--bg-card);
  padding: 14px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
  transition: transform 0.2s ease;
}

.fan-card:hover {
  transform: translateY(-1px);
}

.fan-img {
  width: 60px;
  transition: filter 0.3s ease, opacity 0.3s ease, transform 0.5s ease;
}
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.fan-img.spin { animation: spin 1s linear infinite; }
.fan-img.on { filter: drop-shadow(0 0 12px rgba(34,197,94,0.9)); }
.fan-img.warn { filter: drop-shadow(0 0 12px rgba(251,190,36,0.9)); }
.fan-img.off  { filter: grayscale(100%); opacity: 0.45; }

.fan-info h4 {
  margin: 0 0 6px;
  font-size: 0.9rem;
}

/* =========================================================
   FAN ZONE ENABLE / DISABLE CONTROLS
========================================================= */

/* Slightly restructure the fan card so the status area and toggle
   button can sit neatly underneath the existing fan info */
.fan-card {
  position: relative;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}

.fan-card-top {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Zone state badge */
.zone-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  width: fit-content;
  transition: all 0.25s ease;
}

.zone-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Active zone */
.zone-status.enabled {
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
  border: 1px solid rgba(34, 197, 94, 0.25);
}

.zone-status.enabled::before {
  background: var(--green);
  box-shadow: 0 0 8px rgba(34,197,94,0.8);
}

/* Disabled zone */
.zone-status.disabled {
  background: rgba(107, 114, 128, 0.12);
  color: #6b7280;
  border: 1px solid rgba(107, 114, 128, 0.25);
}

.zone-status.disabled::before {
  background: #9ca3af;
}

/* Enable / Disable toggle button */
.zone-toggle-btn {
  margin-top: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    background 0.22s ease,
    color 0.22s ease,
    box-shadow 0.22s ease;
}

/* Button when zone currently active */
.zone-toggle-btn.enabled {
  background: rgba(239, 68, 68, 0.12);
  color: #b91c1c;
  border: 1px solid rgba(239, 68, 68, 0.22);
}

.zone-toggle-btn.enabled:hover {
  background: rgba(239, 68, 68, 0.18);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(239,68,68,0.14);
}

/* Button when zone currently disabled */
.zone-toggle-btn.disabled {
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
  border: 1px solid rgba(34, 197, 94, 0.22);
}

.zone-toggle-btn.disabled:hover {
  background: rgba(34, 197, 94, 0.18);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(34,197,94,0.14);
}

/* =========================================================
   VISUAL STATE FOR A DISABLED FAN ZONE
========================================================= */

/* When the entire zone is disabled, add .zone-disabled to the fan-card */
.fan-card.zone-disabled {
  opacity: 0.72;
  background:
    linear-gradient(
      135deg,
      rgba(156,163,175,0.08),
      rgba(255,255,255,1)
    );
  border-color: rgba(156,163,175,0.35);
}

/* Small sleeping-beast effect: fan image stays faded and never glows */
.fan-card.zone-disabled .fan-img {
  filter: grayscale(100%);
  opacity: 0.28;
  animation: none !important;
  transform: none !important;
}

/* Override any ON/WARN glow if zone disabled */
.fan-card.zone-disabled .fan-img.on,
.fan-card.zone-disabled .fan-img.warn,
.fan-card.zone-disabled .fan-img.spin {
  filter: grayscale(100%);
  opacity: 0.28;
  animation: none !important;
}

/* Node dots also go dormant */
.fan-card.zone-disabled .node-dot {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.fan-card.zone-disabled .node-dot.active {
  background: #d1d5db;
  box-shadow: none;
}

/* Muted text for disabled zone */
.fan-card.zone-disabled .fan-info,
.fan-card.zone-disabled .fan-info h4,
.fan-card.zone-disabled .sensor-time {
  color: var(--text-dim);
}

/* Optional tiny ribbon in the corner */
.fan-card.zone-disabled::after {
  content: "ZONE DISABLED";
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(107,114,128,0.12);
  color: #6b7280;
  border: 1px solid rgba(107,114,128,0.18);
}

/* =========================================================
   NODE DOTS
========================================================= */
.node-row { display: flex; gap: 8px; margin-bottom: 6px; }

.node-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid #cbd5e1;
}

.node-dot.active {
  background: var(--green);
  box-shadow: 0 0 6px rgba(34,197,94,0.9);
}

/* =========================================================
   BUTTONS
========================================================= */
.btn-row button,
.fan-info button {
  padding: 5px 12px;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  background: #91ecb2;
  color: var(--text-main);
  transition: background 0.2s ease, transform 0.15s ease;
}

.btn-row button:hover,
.fan-info button:hover { transform: translateY(-1px); }

.btn-row button:last-child,
.fan-info button:last-child {
  background: #ce3c3c;
  color: #fecaca;
}

/* =========================================================
   CONFIG / THRESHOLDS
========================================================= */
.config-section.compact {
  background: var(--bg-panel);
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-soft);
}

.config-section h3 {
  text-align: center;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.threshold-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.threshold-grid div { font-size: 0.75rem; }

.threshold-grid input {
  padding: 6px;
  border-radius: 6px;
  border: 1px solid #374151;
  background: #ffffff;
  color: var(--text-main);
}

.btn-success {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  font-size: 0.85rem;
  font-weight: 800;
  background: var(--green);
  border: none;
  border-radius: 8px;
  color: #022c22;
  cursor: pointer;
  transition: background 0.2s ease;
}
.btn-success:hover { background: #16a34a; }

/* =========================================================
   MODAL - Modern Scrollable & Responsive
========================================================= */
.modal {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  transition: opacity 0.3s ease;
}

.modal-content {
  background: var(--bg-card);
  margin: 3% auto;
  padding: 20px 24px;
  width: 90%;
  max-width: 900px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 80vh;       /* scrollable if too tall */
  overflow-y: auto;
  scroll-behavior: smooth;
}

.modal-content::-webkit-scrollbar {
  width: 8px;
}
.modal-content::-webkit-scrollbar-thumb {
  background: rgba(100, 100, 100, 0.4);
  border-radius: 4px;
}
.modal-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

.modal h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0 0 12px 0;
  color: var(--text-main);
}

.close {
  align-self: flex-end;
  font-size: 26px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease, transform 0.2s ease;
}
.close:hover {
  color: var(--red);
  transform: scale(1.1);
}

/* Range Buttons */
.range-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.range-buttons button {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: var(--blue);
  color: #fff;
  transition: background 0.2s ease, transform 0.15s ease;
}
.range-buttons button:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

/* Chart Containers */
#tempChart, #humChart, #ammoniaChart {
  width: 100% !important;
  min-height: 260px;
  max-height: 350px;
  margin-bottom: 12px;
}

/* Relay Stats Grid */
.relay-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.stat-item {
  background: var(--bg-panel);
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  font-size: 0.85rem;
  text-align: center;
  color: var(--text-main);
}

/* Responsive Charts */
@media (max-width: 768px) {
  .modal-content { padding: 16px; }
  #tempChart, #humChart, #ammoniaChart { min-height: 220px; }
}

/* =========================================================
   FOOTER
========================================================= */
footer {
  margin-top: 18px;
  font-size: 11px;
  color: var(--text-dim);
}

/* =========================================================
   RESPONSIVE
========================================================= */
@media (max-width: 1100px) {
  main.layout { flex-direction: column; }
  .fan-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sensor-cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .threshold-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}
