/* ==========================================================================
   Dashboard monitoring — tema visual terang & gelap.

   Catatan penting: warna seri data (--seri-*) sudah lolos uji keterbacaan
   buta warna (CVD) pada kedua mode. Jangan diubah tanpa menjalankan ulang
   validator palet.
   ========================================================================== */

:root {
  /* Permukaan & teks */
  --page:        #f2f3f0;
  --page-2:      #e7e9e3;
  --surface:     #fcfcfb;
  --surface-2:   #f4f4f1;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --border:      rgba(11, 11, 11, 0.10);
  --border-2:    rgba(11, 11, 11, 0.055);

  /* Seri data (tervalidasi) */
  --seri-aktual: #2a78d6;   /* biru  : suhu aktual   */
  --seri-pred:   #1baf7a;   /* aqua  : suhu prediksi */
  --seri-rh:     #eda100;   /* kuning: kelembapan    */
  --status-good: #0ca30c;
  --status-bad:  #d13c2f;

  /* Bayangan berlapis + cincin fokus */
  --shadow-1: 0 1px 2px rgba(11, 11, 11, .05), 0 3px 10px rgba(11, 11, 11, .05);
  --shadow-2: 0 2px 4px rgba(11, 11, 11, .05), 0 16px 34px rgba(11, 11, 11, .10);
  --ring:     0 0 0 3px rgba(42, 120, 214, .22);

  /* Cahaya latar (aurora) */
  --glow-1: rgba(42, 120, 214, .20);
  --glow-2: rgba(27, 175, 122, .16);
  --glow-3: rgba(237, 161, 0, .12);

  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;
  --r-pil: 999px;
}

/* Mode gelap: dipilih manual (data-theme) atau mengikuti sistem */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="terang"]) {
    --page:        #0b0b0b;
    --page-2:      #131312;
    --surface:     #1a1a19;
    --surface-2:   #232322;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --grid:        #2c2c2a;
    --border:      rgba(255, 255, 255, 0.11);
    --border-2:    rgba(255, 255, 255, 0.06);

    --seri-aktual: #3987e5;
    --seri-pred:   #199e70;
    --seri-rh:     #c98500;
    --status-good: #21bd4b;
    --status-bad:  #ec5f52;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .40), 0 3px 12px rgba(0, 0, 0, .34);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, .44), 0 18px 40px rgba(0, 0, 0, .48);
    --ring:     0 0 0 3px rgba(57, 135, 229, .34);

    --glow-1: rgba(57, 135, 229, .22);
    --glow-2: rgba(25, 158, 112, .16);
    --glow-3: rgba(201, 133, 0, .12);
  }
}

:root[data-theme="gelap"] {
  --page:        #0b0b0b;
  --page-2:      #131312;
  --surface:     #1a1a19;
  --surface-2:   #232322;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --muted:       #898781;
  --grid:        #2c2c2a;
  --border:      rgba(255, 255, 255, 0.11);
  --border-2:    rgba(255, 255, 255, 0.06);

  --seri-aktual: #3987e5;
  --seri-pred:   #199e70;
  --seri-rh:     #c98500;
  --status-good: #21bd4b;
  --status-bad:  #ec5f52;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .40), 0 3px 12px rgba(0, 0, 0, .34);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, .44), 0 18px 40px rgba(0, 0, 0, .48);
  --ring:     0 0 0 3px rgba(57, 135, 229, .34);

  --glow-1: rgba(57, 135, 229, .22);
  --glow-2: rgba(25, 158, 112, .16);
  --glow-3: rgba(201, 133, 0, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Atribut hidden harus menang atas display:grid/flex milik .hasil & .plots */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Cahaya latar lembut di belakang seluruh halaman */
.aurora {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(58vw 42vh at 12% -8%,  var(--glow-1), transparent 70%),
    radial-gradient(52vw 40vh at 92% 4%,   var(--glow-2), transparent 72%),
    radial-gradient(46vw 38vh at 50% 108%, var(--glow-3), transparent 74%);
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.ico {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}

.wrap { max-width: 1140px; margin: 0 auto; padding: 22px 18px 48px; }

/* ---------------------------------------------------------------- Header */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 14px; flex-wrap: wrap;
  padding: 14px 18px; margin-bottom: 22px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  backdrop-filter: blur(14px) saturate(1.4);
  position: sticky; top: 12px; z-index: 20;
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center;
  width: 42px; height: 42px; flex: none;
  border-radius: var(--r-md);
  color: #fff;
  background: linear-gradient(145deg, var(--seri-aktual), var(--seri-pred));
  box-shadow: 0 6px 16px -6px var(--seri-aktual);
}
.brand-mark .ico { width: 23px; height: 23px; stroke-width: 1.9; }

h1 {
  font-size: 1.08rem; font-weight: 680; letter-spacing: -0.015em;
  line-height: 1.25;
}
.sub { color: var(--ink-2); font-size: 0.79rem; }

.topbar-aksi { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 0.75rem; font-weight: 500;
  padding: 6px 12px; border-radius: var(--r-pil);
  border: 1px solid var(--border); color: var(--ink-2);
  background: var(--surface-2); white-space: nowrap;
}
.chip.ok {
  color: var(--status-good);
  border-color: color-mix(in srgb, var(--status-good) 42%, transparent);
  background: color-mix(in srgb, var(--status-good) 11%, var(--surface));
}
.chip .ico { width: 14px; height: 14px; }

/* Titik "denyut" penanda data langsung */
.pulse {
  position: relative; width: 8px; height: 8px; flex: none;
  border-radius: 50%; background: var(--seri-pred);
}
.pulse::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: inherit; animation: denyut 2s ease-out infinite;
}
@keyframes denyut {
  0%   { transform: scale(1);   opacity: .65; }
  100% { transform: scale(3.2); opacity: 0; }
}
.chip.diam .pulse { background: var(--muted); }
.chip.diam .pulse::after { animation: none; }

.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: none;
  color: var(--ink-2); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  cursor: pointer; transition: color .18s, background .18s, transform .18s;
}
.icon-btn:hover { color: var(--ink); transform: translateY(-1px); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.icon-btn .ico { grid-area: 1 / 1; transition: opacity .2s, transform .3s; }
/* Matahari tampil di mode terang, bulan di mode gelap */
.ico-moon { opacity: 0; transform: rotate(-70deg) scale(.6); }
:root[data-theme="gelap"] .ico-sun { opacity: 0; transform: rotate(70deg) scale(.6); }
:root[data-theme="gelap"] .ico-moon { opacity: 1; transform: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="terang"]) .ico-sun  { opacity: 0; transform: rotate(70deg) scale(.6); }
  :root:not([data-theme="terang"]) .ico-moon { opacity: 1; transform: none; }
}

/* ------------------------------------------------------ Kartu ringkasan */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 14px; margin-bottom: 18px;
}

.tile {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 16px 18px 15px;
  box-shadow: var(--shadow-1);
  transition: transform .2s ease, box-shadow .2s ease;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }

/* Garis aksen tipis di sisi atas kartu */
.tile::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--aksen);
}
/* Semburat warna aksen di sudut kanan atas */
.tile::after {
  content: ""; position: absolute; top: -46px; right: -46px;
  width: 118px; height: 118px; border-radius: 50%;
  background: var(--aksen); opacity: .10; filter: blur(6px);
}

.tile[data-accent="aktual"] { --aksen: var(--seri-aktual); }
.tile[data-accent="rh"]     { --aksen: var(--seri-rh); }
.tile[data-accent="pred"]   { --aksen: var(--seri-pred); }
.tile[data-accent="status"] { --aksen: var(--muted); }
.tile[data-accent="status"].on { --aksen: var(--status-good); }

.tile-top {
  display: flex; align-items: center; gap: 9px; margin-bottom: 10px;
  position: relative; z-index: 1;
}
.tile-ikon {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border-radius: var(--r-sm); color: var(--aksen);
  background: color-mix(in srgb, var(--aksen) 14%, transparent);
}
.tile .label {
  font-size: 0.76rem; font-weight: 550; color: var(--ink-2);
  letter-spacing: .01em;
}

.tile .value {
  position: relative; z-index: 1;
  display: flex; align-items: baseline; gap: 5px;
  font-size: 2.15rem; font-weight: 680; letter-spacing: -0.03em;
  line-height: 1.1; font-variant-numeric: tabular-nums;
}
.tile .satuan { font-size: 0.92rem; font-weight: 550; color: var(--muted); }
.tile .unit {
  position: relative; z-index: 1;
  font-size: 0.73rem; color: var(--muted); margin-top: 5px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}

/* Selisih terhadap pembacaan sebelumnya. Arah sudah dibawa oleh panah,
 * jadi teksnya memakai warna teks biasa — warna status disimpan khusus
 * untuk keadaan sistem (mis. kipas aktif). */
.delta {
  display: inline-flex; align-items: center; gap: 3px;
  color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums;
}
.delta.rata { color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 9px;
  font-size: 1.5rem; font-weight: 680; letter-spacing: -0.02em;
}
.badge .dot {
  position: relative; width: 11px; height: 11px; flex: none;
  border-radius: 50%; background: var(--muted);
}
.tile-kipas.on .badge .dot { background: var(--status-good); }
.tile-kipas.on .badge .dot::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: inherit; animation: denyut 1.8s ease-out infinite;
}
.tile-kipas.on .ico-fan {
  animation: putar 2.6s linear infinite; transform-origin: 50% 50%;
}
@keyframes putar { to { transform: rotate(360deg); } }

/* -------------------------------------------------------------- Kartu isi */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 18px 20px 20px; margin-bottom: 18px;
  box-shadow: var(--shadow-1);
}
.card-top {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.card-ikon {
  display: grid; place-items: center; width: 28px; height: 28px; flex: none;
  border-radius: var(--r-sm); color: var(--ink-2); background: var(--surface-2);
  border: 1px solid var(--border-2);
}
.card h2 { font-size: 0.94rem; font-weight: 620; letter-spacing: -0.01em; }
.card-top .chip { margin-left: auto; }

.chart-box { position: relative; height: 300px; }

/* Baris alat: judul bagian + pemilih rentang waktu */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin: 26px 4px 12px;
}
.toolbar-judul {
  font-size: 0.86rem; font-weight: 620; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .09em;
}

.seg {
  display: flex; gap: 3px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-pil);
}
.seg-btn {
  font: inherit; font-size: 0.76rem; font-weight: 550;
  color: var(--ink-2); background: none; border: none;
  padding: 5px 13px; border-radius: var(--r-pil); cursor: pointer;
  transition: color .16s, background .16s;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.seg-btn.is-aktif {
  color: var(--ink); background: var(--surface);
  box-shadow: var(--shadow-1);
}

/* ------------------------------------------------- Panel pelatihan model */
.hint { color: var(--ink-2); font-size: 0.81rem; margin-bottom: 14px; }
.hint.err { color: var(--status-bad); }

.form-row {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  padding: 14px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border-2);
}
.form-row label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 0.72rem; font-weight: 550; color: var(--muted);
  letter-spacing: .02em; text-transform: uppercase;
}
.form-row select, .form-row input {
  font: inherit; font-size: 0.85rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 8px 10px;
  transition: border-color .16s, box-shadow .16s;
}
.form-row select:focus, .form-row input:focus {
  outline: none; border-color: var(--seri-aktual); box-shadow: var(--ring);
}
.form-row input { width: 100px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-size: 0.85rem; font-weight: 620;
  color: #fff; border: none; border-radius: var(--r-sm);
  padding: 10px 18px; cursor: pointer;
  background: linear-gradient(140deg, var(--seri-aktual), color-mix(in srgb, var(--seri-aktual) 66%, var(--seri-pred)));
  box-shadow: 0 6px 16px -8px var(--seri-aktual);
  transition: transform .16s, box-shadow .16s, filter .16s;
}
.btn:hover:not(:disabled) {
  transform: translateY(-1px); filter: brightness(1.07);
  box-shadow: 0 10px 22px -10px var(--seri-aktual);
}
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled {
  background: var(--muted); box-shadow: none; cursor: progress; opacity: .8;
}
.btn .ico { width: 16px; height: 16px; }
.btn:disabled .ico { animation: putar 1.1s linear infinite; }

.progress {
  position: relative; overflow: hidden;
  height: 8px; border-radius: var(--r-pil); background: var(--grid);
  margin: 16px 0 9px;
}
.progress .bar {
  height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--seri-aktual), var(--seri-pred));
  transition: width .35s ease;
}
/* Kilau berjalan selama pelatihan */
.progress .bar::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 20%,
              rgba(255, 255, 255, .38) 50%, transparent 80%);
  animation: kilau 1.5s linear infinite;
}

@keyframes kilau {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

/* Ringkasan metrik hasil pelatihan */
.hasil {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin-top: 16px;
}
.hasil .metrik {
  display: flex; flex-direction: column; gap: 2px;
  padding: 11px 13px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border-2);
}
.hasil .metrik span {
  font-size: 0.68rem; font-weight: 550; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.hasil .metrik b {
  font-size: 1rem; font-weight: 650; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.hasil .metrik b small { font-size: 0.72rem; color: var(--muted); font-weight: 550; }

.plots {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px; margin-top: 18px;
}
.plots figure { margin: 0; }
.plots img {
  width: 100%; height: auto; border-radius: var(--r-md);
  border: 1px solid var(--border); background: #fff;
  box-shadow: var(--shadow-1);
}
.plots figcaption {
  font-size: 0.74rem; color: var(--muted); margin-top: 7px; text-align: center;
}

/* ------------------------------------------------------------------ Tabel */
.table-box {
  overflow-x: auto; border: 1px solid var(--border-2);
  border-radius: var(--r-md);
}
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
thead th {
  position: sticky; top: 0;
  text-align: left; white-space: nowrap;
  font-size: 0.71rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border); padding: 9px 13px;
}
td {
  padding: 9px 13px; border-bottom: 1px solid var(--border-2);
  color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--surface-2); }
td.utama { color: var(--ink); font-weight: 550; }

.pil {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.71rem; font-weight: 620; letter-spacing: .03em;
  padding: 3px 9px; border-radius: var(--r-pil);
  color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border);
}
.pil::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.pil.on {
  color: var(--status-good);
  border-color: color-mix(in srgb, var(--status-good) 40%, transparent);
  background: color-mix(in srgb, var(--status-good) 12%, var(--surface));
}
.pil.tipis { font-weight: 550; letter-spacing: 0; }
.pil.tipis::before { display: none; }

/* ----------------------------------------------------------------- Footer */
footer {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap;
  color: var(--muted); font-size: 0.76rem;
  padding: 14px 18px; margin-top: 6px;
  border: 1px solid var(--border-2); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--surface) 62%, transparent);
}
footer b { color: var(--ink-2); font-weight: 620; }

/* ------------------------------------------------------------ Animasi masuk */
.masuk { animation: naik .45s cubic-bezier(.22, .8, .3, 1) both; }
.tiles .tile:nth-child(2) { animation-delay: .05s; }
.tiles .tile:nth-child(3) { animation-delay: .10s; }
.tiles .tile:nth-child(4) { animation-delay: .15s; }
@keyframes naik {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

@media (max-width: 640px) {
  .wrap { padding: 14px 12px 34px; }
  .topbar { position: static; padding: 14px; }
  h1 { font-size: 1rem; }
  .tile .value { font-size: 1.85rem; }
  .chart-box { height: 240px; }
  .card { padding: 15px; }
}

/* Hormati preferensi "kurangi gerakan" */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
