:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #0891b2;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --ok-bg: #d1fae5;   --ok-text: #065f46;
  --warn-bg: #fef3c7; --warn-text: #92400e;
  --err-bg: #fee2e2;  --err-text: #991b1b;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }   /* iOS tidak membesarkan teks sendiri saat rotasi */

body {
  margin: 0;
  /* padding mengikuti area aman layar (poni/rounded corner iPhone) */
  padding: 20px;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  /* system-ui lebih dulu: memakai font asli tiap OS (Roboto di Android,
     SF di iOS/macOS, Segoe di Windows) daripada memaksa satu font */
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}

.container { max-width: 1280px; margin: 0 auto; }

header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
/* wrap: dengan tiga logo, judul tidak muat sebaris di layar sangat
   sempit (mis. 320px) -- dibiarkan turun daripada memaksa halaman
   bisa digeser ke samping */
.header-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logo { height: 44px; width: auto; }

/* Logo bertuliskan nama di bawahnya */
.logo-item { display: flex; flex-direction: column; align-items: center; gap: 1px; }
/* logo3 jauh lebih lebar daripada tinggi, jadi dibatasi tingginya supaya
   tidak mendominasi header */
.logo-wide { height: 32px; }
.logo-caption {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.6px;
  color: var(--text); text-transform: uppercase; line-height: 1;
}
h1 { font-size: 19px; margin: 0; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.btn-install { width: auto; margin-bottom: 0; padding: 8px 14px; font-size: 12px; }
.btn-install[hidden] { display: none; }

.grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  align-items: start;
}
/* Aturan layar sempit ada di BAGIAN PALING BAWAH berkas ini -- kalau
   ditaruh di sini, aturan desktop yang menyusul akan menimpanya. */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 3px 14px rgba(15, 23, 42, 0.06);
  margin-bottom: 14px;
}
.card.compact { padding: 14px 16px; }
aside .card:last-child { margin-bottom: 0; }

.chart-block { margin-bottom: 14px; }
.chart-block:last-child { margin-bottom: 0; }
.chart-title {
  font-size: 11.5px; font-weight: 700; color: var(--muted);
  margin-bottom: 6px; letter-spacing: 0.2px;
}
canvas {
  width: 100%; height: 150px; display: block;
  background: #fafbfc; border-radius: 8px;
}

.badge {
  display: inline-block; padding: 6px 14px; border-radius: 14px;
  font-size: 12px; font-weight: 600;
}
.badge-ok   { background: var(--ok-bg);   color: var(--ok-text); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-err  { background: var(--err-bg);  color: var(--err-text); }

label {
  display: block; font-size: 11.5px; font-weight: 700;
  color: var(--muted); margin-bottom: 5px;
}

input[type=text], select {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; color: var(--text);
  background: #fff;
}
input[type=text]:focus, select:focus { border-color: var(--primary); outline: none; }
input[type=text]:disabled { background: #f8fafc; color: #a0aec0; }
input[type=text].invalid { border-color: var(--danger); background: #fff5f5; }

.req { color: var(--danger); }
.hint { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.hint.warn { color: var(--danger); font-weight: 600; }
.hint:empty { display: none; }

button {
  width: 100%; border: none; border-radius: 8px;
  padding: 11px 20px; font-size: 13px; font-weight: 700;
  font-family: inherit; cursor: pointer; margin-bottom: 8px;
}
button:last-child { margin-bottom: 0; }
button:disabled { background: #eef1f5 !important; color: #a0aec0 !important; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #cbd5e1; }

.live-values { display: flex; justify-content: space-between; gap: 8px; text-align: center; }
.live-item { flex: 1; }
.live-label { font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.live-value { font-size: 22px; font-weight: 700; color: var(--text); margin: 2px 0; }
.live-unit  { font-size: 10px; color: var(--muted); }

/* ---------- INDIKATOR KECEMASAN ---------- */
.anxiety {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 10px;
  border: 1.5px solid transparent;
}
.anxiety-icon { font-size: 22px; line-height: 1; }
.anxiety-label { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }
.anxiety-idle    { background: #f1f5f9; color: var(--muted); border-color: var(--border); }
.anxiety-tenang  { background: var(--ok-bg);   color: var(--ok-text);   border-color: #6ee7b7; }
.anxiety-waspada { background: var(--warn-bg); color: var(--warn-text); border-color: #fcd34d; }
.anxiety-cemas   { background: var(--err-bg);  color: var(--err-text);  border-color: #fca5a5; }

.comment-row { display: flex; gap: 6px; margin-bottom: 8px; }
.comment-row input { flex: 1; }
.btn-small { width: 40px; flex: 0 0 40px; margin-bottom: 0; padding: 9px 0; }

#commentList {
  height: 64px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 11px; color: var(--muted);
  background: #fafbfc;
}
#commentList div { padding: 2px 0; }

/* ---------- DIALOG PANDUAN PASANG ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--card); border-radius: 14px;
  padding: 20px; width: 100%; max-width: 420px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.3);
}
.modal-card h2 { font-size: 17px; margin: 0 0 10px; }
.modal-card ol { margin: 0 0 12px; padding-left: 20px; }
.modal-card li { margin-bottom: 7px; line-height: 1.5; }
.modal-card p { margin: 0 0 12px; line-height: 1.5; }
.modal-card .note {
  background: var(--warn-bg); color: var(--warn-text);
  padding: 10px 12px; border-radius: 8px; font-size: 12.5px;
}
.diag {
  font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--border); padding-top: 10px; margin-bottom: 14px;
}
.diag div { padding: 1px 0; }
.diag .no { color: var(--danger); font-weight: 600; }
.diag .yes { color: var(--ok-text); font-weight: 600; }

/* ============================================================
   LAYAR SEMPIT (HP & TABLET)
   Ditaruh paling akhir supaya menang atas aturan desktop di atas.
   ============================================================ */

/* ---------- TABLET & HP ----------
   Panel kontrol dinaikkan ke atas grafik: di layar sempit, operator lebih
   sering menekan Start/Stop daripada perlu melihat grafik lebih dulu. */
@media (max-width: 900px) {
  body {
    padding: 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .grid { grid-template-columns: 1fr; }
  aside { order: -1; }
  aside .card:last-child { margin-bottom: 14px; }

  /* 16px mencegah iOS Safari otomatis mem-zoom saat kolom isian disentuh */
  input[type=text], select { font-size: 16px; padding: 11px 12px; }
  button { padding: 13px 20px; min-height: 46px; font-size: 14px; }
  .btn-install { min-height: 0; padding: 8px 14px; font-size: 12px; }
  .btn-small { width: 46px; flex: 0 0 46px; padding: 0; }

  #commentList { height: 84px; font-size: 12px; }
  canvas { height: 140px; }
}

/* ---------- HP KECIL ---------- */
@media (max-width: 480px) {
  header { gap: 10px; }
  .header-left { gap: 8px; }
  .logo { height: 34px; }
  .logo-wide { height: 25px; }
  .logo-caption { font-size: 9px; letter-spacing: 0.4px; }
  h1 { font-size: 16px; }
  .card { padding: 14px; border-radius: 12px; }
  .card.compact { padding: 12px 14px; }
  .live-value { font-size: 20px; }
  canvas { height: 130px; }
}
