/* style.css - Mode di atas Relay, Relay horizontal, MQTT di pojok kanan */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: system-ui, 'Segoe UI', 'Inter', sans-serif;
}
body { background: #f0f4f8; padding: 24px 20px; }
.container { max-width: 1500px; margin: 0 auto; }

/* Header */
header {
  margin-bottom: 28px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  background: white;
  padding: 16px 24px;
  border-radius: 32px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.05);
}
header h1 { font-size: 1.7rem; font-weight: 600; background: linear-gradient(135deg, #1e3c72, #2b4c7c); background-clip: text; -webkit-background-clip: text; color: transparent; margin-bottom: 4px; }
.header-sub { font-size: 0.8rem; color: #5b6e8c; margin-top: 4px; }
.header-status { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.badge-realtime { background: #10b981; color: white; padding: 6px 14px; border-radius: 40px; font-size: 0.8rem; font-weight: 600; }
.last-update { font-family: monospace; background: #eef2ff; padding: 4px 12px; border-radius: 24px; font-size: 0.75rem; }
.mqtt-header-badge {
  font-family: monospace;
  background: #eef2ff;
  padding: 4px 12px;
  border-radius: 24px;
  font-size: 0.75rem;
  font-weight: 600;
}
.mqtt-header-badge.connected { background: #dcfce7; color: #15803d; }
.mqtt-header-badge.disconnected { background: #ffe4e2; color: #b91c1c; }

/* Grid kartu sensor */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}
.metric-card {
  background: white;
  border-radius: 28px;
  padding: 20px 16px;
  text-align: center;
  box-shadow: 0 10px 20px rgba(0,0,0,0.05);
}
.metric-title { font-size: 1.2rem; font-weight: 600; color: #2c3e66; margin-bottom: 12px; }
.metric-value { font-size: 2.8rem; font-weight: 800; color: #0f2b3d; }
.metric-unit { font-size: 1rem; color: #5b6e8c; margin-top: 5px; }
.metric-sub { font-size: 0.8rem; color: #6c7f9e; margin-top: 10px; }

/* Dua kolom */
.two-columns {
  display: grid;
  grid-template-columns: 0.9fr 1.3fr;
  gap: 28px;
  margin-bottom: 32px;
}
@media (max-width: 880px) {
  .two-columns { grid-template-columns: 1fr; }
}

.left-panel {
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.panel-card {
  background: white;
  border-radius: 28px;
  padding: 20px 24px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.05);
}

/* Relay Control - tampilan 2 kolom (atas 2, bawah 2) */
.relays-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 8px;
}

.relay-item {
  background: #f9fafc;
  border-radius: 20px;
  padding: 14px 12px;
  text-align: center;
  border: 1px solid #e2e8f0;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.relay-name {
  font-weight: 700;
  font-size: 1rem;
  color: #1f2b48;
  display: block;
}

.relay-status {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 40px;
  font-weight: 700;
  font-size: 0.75rem;
  width: 70px;
  text-align: center;
}

.relay-status.on {
  background: #dcfce7;
  color: #15803d;
}

.relay-status.off {
  background: #ffe4e2;
  color: #b91c1c;
}

.relay-btn {
  background: #2c5f8a;
  border: none;
  color: white;
  font-weight: 600;
  padding: 8px 0;
  border-radius: 40px;
  cursor: pointer;
  font-size: 0.8rem;
  width: 100%;
  max-width: 120px;
  transition: background 0.2s, transform 0.1s;
}

.relay-btn:hover:not(:disabled) {
  background: #1e4462;
  transform: scale(1.02);
}

.relay-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.relay-btn:disabled {
  background: #b9c3d0;
  cursor: not-allowed;
  opacity: 0.6;
}

/* Responsif: untuk layar sangat kecil tetap 1 kolom */
@media (max-width: 480px) {
  .relays-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .relay-btn {
    max-width: 100%;
  }
}

.relay-note {
  display: block;
  margin-top: 16px;
  font-size: 0.7rem;
  color: #6b7b9c;
  text-align: center;
}

/* Mode Control */
.mode-toggle { display: flex; gap: 12px; margin: 15px 0 12px; }
.mode-btn {
  flex: 1;
  background: #eef2ff;
  border: none;
  padding: 10px;
  border-radius: 60px;
  font-weight: 600;
  cursor: pointer;
}
.mode-btn.active-mode { background: #2c5f8a; color: white; }
.mode-hint { display: block; margin-top: 8px; color: #5a6e8a; font-size: 0.7rem; }

/* Info box untuk keterangan relay */
.info-box {
  background: #f0f7ff;
  border-left: 5px solid #2c5f8a;
  border-radius: 16px;
  padding: 14px 18px;
  margin-top: 20px;
  font-size: 0.85rem;
}
.info-box h4 {
  margin: 0 0 8px 0;
  color: #1e3c72;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.info-box ul {
  margin: 0;
  padding-left: 20px;
}
.info-box li {
  margin: 6px 0;
  color: #2c3e66;
}

/* Chart Card */
.chart-card {
  padding: 18px 20px;
}
.chart-card canvas {
  width: 100% !important;
  height: auto !important;
  max-height: 280px;
  min-height: 240px;
  margin-top: 12px;
  background: #fefefe;
  border-radius: 16px;
}
.right-panel .chart-card:last-child {
  margin-bottom: 0;
}

/* Tabel Riwayat */
.history-section {
  background: white;
  border-radius: 28px;
  padding: 20px 24px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.05);
  margin-top: 8px;
}
.history-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.history-buttons { display: flex; gap: 12px; }
.btn-export, .btn-clear { padding: 8px 18px; border-radius: 40px; font-weight: 600; color: white; border: none; cursor: pointer; }
.btn-export { background: #10b981; }
.btn-clear { background: #ef4444; }
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 8px; text-align: left; border-bottom: 1px solid #e2e8f0; }
th { background: #f8fafc; }
footer { text-align: center; margin-top: 30px; color: #5e6e8c; font-size: 0.75rem; }