:root {
  --bg-main: #f5f7fb;
  --bg-surface: #ffffff;
  --bg-surface-2: #f8fbff;

  --navy: #163a70;
  --navy-2: #1d4f91;
  --blue: #2f7ed8;
  --blue-soft: #eaf3ff;

  --text-main: #183153;
  --text-soft: #5f7390;
  --text-light: #ffffff;

  --border: #d7e4f5;
  --border-strong: #bdd3ee;

  --success: #18a957;
  --warning: #f5a623;
  --danger: #e14b4b;
  --info: #2f7ed8;

  --shadow-soft: 0 8px 24px rgba(24, 49, 83, 0.08);
  --shadow-card: 0 4px 14px rgba(24, 49, 83, 0.06);

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(180deg, #eef5ff 0%, #f7faff 100%);
  color: var(--text-main);
  overflow-x: hidden;
}

body {
  min-height: 100vh;
}

/* HEADER */
header {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%);
  color: var(--text-light);
  padding: 18px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: 0 6px 18px rgba(22, 58, 112, 0.18);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

header h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.2px;
}

/* STATUS BADGE */
.status {
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(4px);
}

/* MAIN CONTAINER */
.container {
  max-width: 1300px;
  margin: 18px auto;
  padding: 0 16px 20px;
}

/* TOP BAR */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
}

.selector-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 250px;
}

.selector-wrap label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-soft);
}

#deviceSelect {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  outline: none;
  font-size: 0.95rem;
  background: #ffffff;
  color: var(--text-main);
  font-weight: 600;
  transition: 0.2s ease;
}

#deviceSelect:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 126, 216, 0.14);
}

.mini-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.mini-summary span {
  background: var(--blue-soft);
  color: var(--navy);
  border: 1px solid #d3e5ff;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
}

/* DEVICE BANNER */
.device-banner {
  background: linear-gradient(135deg, #ffffff 0%, #f4f9ff 100%);
  border: 1px solid var(--border);
  border-left: 6px solid var(--blue);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-card);
}

#deviceTitle {
  display: block;
  color: var(--navy);
  font-size: 1.05rem;
  margin-bottom: 4px;
}

#deviceLocation {
  color: var(--text-soft);
  font-size: 0.88rem;
}

.device-state {
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.84rem;
  background: var(--blue-soft);
  color: var(--navy);
  border: 1px solid #d3e5ff;
  white-space: nowrap;
}

/* CARDS */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.card {
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
}

.card h3 {
  margin: 0 0 10px;
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-soft);
}

.card p {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.2;
}

/* CHART BOX */
.chartbox {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.chart-header h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-main);
  font-weight: 800;
}

.chart-header span {
  color: var(--text-soft);
  font-size: 0.84rem;
  font-weight: 600;
}

/* PENTING: JANGAN PAKSA HEIGHT CHART */
.chartbox canvas {
  display: block;
  width: 100% !important;
  max-width: 100%;
}

/* TABLE */
h3 {
  color: var(--navy);
  margin: 0 0 12px;
  font-size: 1.05rem;
}

#logTable {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
}

#logTable thead {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #ffffff;
}

#logTable th,
#logTable td {
  padding: 12px 14px;
  text-align: left;
  font-size: 0.92rem;
  border-bottom: 1px solid #edf3fb;
}

#logTable th {
  font-weight: 700;
  letter-spacing: 0.2px;
}

#logTable tbody tr:nth-child(even) {
  background: #f9fbff;
}

#logTable tbody tr:hover {
  background: #eef5ff;
}

#logTable tbody tr:last-child td {
  border-bottom: none;
}

/* MODAL */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(16, 33, 61, 0.55);
  backdrop-filter: blur(4px);
  padding: 20px;
  overflow-y: auto;
}

.modal-content {
  background: #ffffff;
  max-width: 980px;
  margin: 40px auto;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 18px 48px rgba(12, 32, 66, 0.22);
  border: 1px solid #dbe8f8;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.modal-header h3 {
  margin: 0;
  color: var(--navy);
  font-size: 1.05rem;
}

#closeModalBtn {
  border: none;
  background: #eef5ff;
  color: var(--navy);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 1.4rem;
  cursor: pointer;
  font-weight: 700;
  transition: 0.2s ease;
}

#closeModalBtn:hover {
  background: #dbeafe;
  transform: scale(1.04);
}

.modal-chartbox {
  margin: 0;
  border: none;
  box-shadow: none;
  padding: 0;
  border-radius: 0;
}

/* RESPONSIVE */
@media (max-width: 768px) {
  header {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar,
  .device-banner {
    flex-direction: column;
    align-items: stretch;
  }

  .mini-summary {
    gap: 8px;
  }

  .mini-summary span {
    font-size: 0.8rem;
  }

  .card p {
    font-size: 1.3rem;
  }

  #logTable th,
  #logTable td {
    padding: 10px 10px;
    font-size: 0.85rem;
  }

  .modal-content {
    margin: 20px auto;
    padding: 14px;
  }
}