/* ================================================================
   SOP-SAPI – Design System
   Fonts: Bricolage Grotesque (headings), Instrument Sans (body),
          JetBrains Mono (data/numbers)
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,600;12..96,700&family=Instrument+Sans:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ── Design Tokens ─────────────────────────────────────────────── */
:root {
    /* Brand */
  --brand-primary:   #5F7D4F;
  --brand-hover:     #4C6840;

  /* Neutrals (hangat) */
  --gray-50:  #F8F3E4;
  --gray-100: #EFE8D2;
  --gray-200: #E2D8BC;
  --gray-300: #CFC4A2;
  --gray-400: #A9A58B;
  --gray-500: #7A7559;
  --gray-600: #5F5B44;
  --gray-700: #3B4B36;
  --gray-800: #2A3727;
  --gray-900: #1E2A1C;

  /* Semantic surface / text */
  --surface-bg:      #F1EAD6;
  --surface-card:    #F8F3E4;
  --surface-header:  #F8F3E4;
  --text-primary:    #3F3C2C;
  --text-secondary:  #5A5640;
  --text-muted:      #6B6650;
  --border-color:    #E2D8BC;
  --border-subtle:   #EBE3CA;

  /* Accent / Status */
  --brand-accent:    #4C6840;
  --accent-cyan:     #0284C7;
  --accent-cyan-bg:  rgba(2, 132, 199, 0.12);
  --accent-violet:   #7C3AED;
  --accent-violet-bg:rgba(124, 58, 237, 0.12);
  --surface-elevated:#E4F0DC;
  --color-on:        #2F9E6B;
  --color-on-bg:     #DCEFE2;
  --color-off:       var(--gray-500);
  --color-off-bg:    #EAE2CB;
  --color-offline:   #C2452D;
  --color-offline-bg:#F5DDD3;
  --color-warn:      #B8691A;
  --color-warn-bg:   #F6E6C6;

  /* THI Categories */
  --thi-comfort:     #2F9E6B;
  --thi-mild:        #A8860F;
  --thi-moderate:    #C8621A;
  --thi-severe:      #B83227;

  /* Schedule bar */
  --sched-done:      #D8CCA8;
  --sched-upcoming:  #E8DFC4;

  /* Typography */
  --font-heading:    'Bricolage Grotesque', system-ui, sans-serif;
  --font-body:       'Instrument Sans', system-ui, sans-serif;
  --font-mono:       'JetBrains Mono', 'Courier New', monospace;

  /* Sizing */
  --radius-sm:   6px;
  --radius-md:   12px;
  --radius-lg:   18px;
  --radius-xl:   24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:   0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:   0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.04);
  --shadow-lg:   0 10px 40px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.06);

  /* Layout */
  --header-h: 64px;
  --nav-h:    60px;

  /* Transitions */
  --tr-fast:   120ms ease;
  --tr-normal: 200ms ease;
  --tr-slow:   350ms ease;
}

/* Dark mode via media query (kecuali user memaksa light) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-primary:   #1F9D68 !important;
    --brand-hover:     #178255 !important;
    --brand-accent:    #4ADE80 !important;
    --accent-cyan:     #38BDF8 !important;
    --accent-cyan-bg:  rgba(56, 189, 248, 0.15) !important;
    --accent-violet:   #A78BFA !important;
    --accent-violet-bg:rgba(167, 139, 250, 0.15) !important;

    --surface-bg:      #0B1511 !important;
    --surface-card:    #12211B !important;
    --surface-elevated:#192D25 !important;
    --surface-header:  #101D17 !important;
    --text-primary:    #ECFDF5 !important;
    --text-secondary:  #A8CEBC !important;
    --text-muted:      #759D8A !important;
    --border-color:    #234034 !important;
    --border-subtle:   #1A3127 !important;

    --color-on:        #34D399 !important;
    --color-on-bg:     rgba(52, 211, 153, 0.14) !important;
    --color-off:       #86A998 !important;
    --color-off-bg:    #1A2E25 !important;
    --color-offline:   #FB7185 !important;
    --color-offline-bg:rgba(251, 113, 133, 0.14) !important;
    --color-warn:      #FBBF24 !important;
    --color-warn-bg:   rgba(251, 191, 36, 0.14) !important;

    --thi-comfort:     #34D399 !important;
    --thi-mild:        #FACC15 !important;
    --thi-moderate:    #FB923C !important;
    --thi-severe:      #F87171 !important;

    --sched-done:      #1D392D !important;
    --sched-upcoming:  #152920 !important;
    --shadow-sm:       0 2px 8px rgba(0,0,0,.35) !important;
    --shadow-md:       0 8px 24px rgba(0,0,0,.45) !important;
    --shadow-lg:       0 14px 44px rgba(0,0,0,.55) !important;
  }
}

/* Manual theme overrides */
[data-theme="dark"] {
  --brand-primary:   #1F9D68 !important;
  --brand-hover:     #178255 !important;
  --brand-accent:    #4ADE80 !important;
  --accent-cyan:     #38BDF8 !important;
  --accent-cyan-bg:  rgba(56, 189, 248, 0.15) !important;
  --accent-violet:   #A78BFA !important;
  --accent-violet-bg:rgba(167, 139, 250, 0.15) !important;

  --surface-bg:      #0B1511 !important;
  --surface-card:    #12211B !important;
  --surface-elevated:#192D25 !important;
  --surface-header:  #101D17 !important;
  --text-primary:    #ECFDF5 !important;
  --text-secondary:  #A8CEBC !important;
  --text-muted:      #759D8A !important;
  --border-color:    #234034 !important;
  --border-subtle:   #1A3127 !important;

  --color-on:        #34D399 !important;
  --color-on-bg:     rgba(52, 211, 153, 0.14) !important;
  --color-off:       #86A998 !important;
  --color-off-bg:    #1A2E25 !important;
  --color-offline:   #FB7185 !important;
  --color-offline-bg:rgba(251, 113, 133, 0.14) !important;
  --color-warn:      #FBBF24 !important;
  --color-warn-bg:   rgba(251, 191, 36, 0.14) !important;

  --thi-comfort:     #34D399 !important;
  --thi-mild:        #FACC15 !important;
  --thi-moderate:    #FB923C !important;
  --thi-severe:      #F87171 !important;

  --sched-done:      #1D392D !important;
  --sched-upcoming:  #152920 !important;
  --shadow-sm:       0 2px 8px rgba(0,0,0,.35) !important;
  --shadow-md:       0 8px 24px rgba(0,0,0,.45) !important;
  --shadow-lg:       0 14px 44px rgba(0,0,0,.55) !important;
}

[data-theme="light"] {
  --brand-primary:   #7A3420 !important;
  --brand-hover:     #5E2616 !important;
  --surface-bg:      #FBF8F1 !important;
  --surface-card:    #FFFEFB !important;
  --surface-header:  #FFFEFB !important;
  --text-primary:    #2B1A14 !important;
  --text-secondary:  #5E4A3F !important;
  --text-muted:      #7D6A5E !important;
  --border-color:    #EADFD0 !important;
  --border-subtle:   #F1E8DA !important;
  --color-on:        #2F9E6B !important;
  --color-on-bg:     #DDF0E4 !important;
  --color-off:       #85715F !important;
  --color-off-bg:    #F1E9DC !important;
  --color-offline:   #C2452D !important;
  --color-offline-bg:#F7DED6 !important;
  --color-warn:      #B8691A !important;
  --color-warn-bg:   #F8E8C8 !important;
  --thi-comfort:     #2F9E6B !important;
  --thi-mild:        #A8860F !important;
  --thi-moderate:    #C8621A !important;
  --thi-severe:      #B83227 !important;
  --sched-done:      #DCCDB8 !important;
  --sched-upcoming:  #EFE5D4 !important;
  --shadow-sm:       0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04) !important;
  --shadow-md:       0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.04) !important;
  --shadow-lg:       0 10px 40px rgba(0,0,0,.12), 0 4px 6px rgba(0,0,0,.06) !important;
}

/* ── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--surface-bg);
  min-height: 100dvh;
  transition: background var(--tr-slow), color var(--tr-slow);
}

:focus-visible {
  outline: 2.5px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

h1, h2, h3, h4 { font-family: var(--font-heading); line-height: 1.2; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ================================================================
   LOGIN PAGE
   ================================================================ */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 1rem;
}

.login-bg {
  position: absolute;
  inset: 0;
  background-image: url('bg.jpg');
  background-size: cover;
  background-position: center;
  filter: brightness(0.55) saturate(1.2);
  z-index: 0;
}

.login-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(15,23,42,0.6) 0%, rgba(30,64,120,0.4) 100%);
  z-index: 1;
}

.login-card {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 420px;
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(24px) saturate(1.8);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255,255,255,0.05) inset;
  animation: cardIn 0.5s cubic-bezier(0.34,1.56,0.64,1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1.5rem;
}

.login-logo-icon {
  width: 44px; height: 44px;
  background: var(--brand-primary);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(95,125,79,0.4);
}

.login-logo-icon svg { color: white; }

.login-logo-name {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.25rem;
  color: #ffffff;
  line-height: 1;
}

.login-logo-sub {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.65);
  margin-top: 2px;
}

.login-title {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 0.25rem;
}

.login-subtitle { font-size: 0.875rem; color: rgba(255,255,255,0.65); margin-bottom: 2rem; }

.login-form { display: flex; flex-direction: column; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: rgba(255,255,255,0.8);
  letter-spacing: 0.02em;
}

.form-input {
  background: rgba(255,255,255,0.12);
  border: 1.5px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: #ffffff;
  outline: none;
  transition: border-color var(--tr-normal), background var(--tr-normal), box-shadow var(--tr-normal);
}

.form-input::placeholder { color: rgba(255,255,255,0.35); }
.form-input:hover { border-color: rgba(255,255,255,0.35); background: rgba(255,255,255,0.16); }
.form-input:focus { border-color: var(--brand-primary); background: rgba(255,255,255,0.18); box-shadow: 0 0 0 3px rgba(37,99,235,0.35); }

.btn-login {
  margin-top: 0.5rem;
  padding: 0.875rem;
  background: var(--brand-primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--tr-normal);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
}

.btn-login:hover:not(:disabled) { background: var(--brand-hover); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(95,125,79,0.4); }
.btn-login:active { transform: translateY(0); }
.btn-login:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-login .spinner { display: none; }
.btn-login.loading .btn-text { display: none; }
.btn-login.loading .spinner { display: inline-block; }

.login-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.75rem 1rem;
  background: rgba(220,38,38,0.2);
  border: 1px solid rgba(220,38,38,0.4);
  border-radius: var(--radius-md);
  color: #fca5a5;
  font-size: 0.875rem;
  animation: shakeIn 0.3s ease;
}

.login-error[hidden] { display: none; }

@keyframes shakeIn {
  0%,100% { transform: translateX(0); }
  20%,60%  { transform: translateX(-6px); }
  40%,80%  { transform: translateX(6px); }
}

.login-footer { text-align: center; margin-top: 1.5rem; font-size: 0.75rem; color: rgba(255,255,255,0.4); }

/* ================================================================
   DASHBOARD LAYOUT
   ================================================================ */
.app-wrapper { display: flex; flex-direction: column; min-height: 100dvh; }

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface-header);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  transition: background var(--tr-slow), border-color var(--tr-slow);
}

.header-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.header-logo {
  width: 36px; height: 36px;
  background: var(--brand-primary);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37,99,235,0.3);
}

.header-logo svg { color: white; }
.header-brand-text { display: flex; flex-direction: column; }

.header-label {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1;
  margin-bottom: 1px;
}

.header-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  line-height: 1.1;
}

.header-spacer { flex: 1; }

.header-meta { display: flex; align-items: center; gap: 0.75rem; }

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  transition: all var(--tr-normal);
}

.conn-pill .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.conn-pill.online  { background: var(--color-on-bg); color: var(--color-on); }
.conn-pill.online .dot { background: var(--color-on); animation: pulse-dot 2s ease-in-out infinite; }
.conn-pill.offline { background: var(--color-offline-bg); color: var(--color-offline); }
.conn-pill.offline .dot { background: var(--color-offline); }
.conn-pill.waiting { background: var(--color-off-bg); color: var(--text-muted); }
.conn-pill.waiting .dot { background: var(--text-muted); }

@keyframes pulse-dot {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(0.8); }
}

.header-last-updated {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  padding: 6px 14px;
  background: transparent;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: all var(--tr-normal);
  white-space: nowrap;
}

.btn-logout:hover { background: var(--color-offline-bg); border-color: var(--color-offline); color: var(--color-offline); }

.btn-theme {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1.5px solid var(--border-color);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all var(--tr-normal);
  flex-shrink: 0;
}

.btn-theme:hover { background: var(--surface-bg); color: var(--text-primary); }

/* Main layout */
.main-content {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.5rem;
  align-items: start;
}

.left-column { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }
.right-column { display: flex; flex-direction: column; gap: 1.5rem; min-width: 0; }

/* Card */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: background var(--tr-slow), border-color var(--tr-slow), box-shadow var(--tr-normal);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.125rem 1.25rem 0;
}

.card-title {
  font-family: var(--font-heading);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex; align-items: center; gap: 8px;
}

.card-title svg { color: var(--brand-primary); flex-shrink: 0; }
.card-body { padding: 1rem 1.25rem 1.25rem; }

/* Fan Cards */
.fan-cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.fan-card {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: 22px;
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 0.875rem;
  transition: all var(--tr-slow);
  position: relative;
  overflow: hidden;
}

.fan-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--brand-primary);
  border-radius: 22px 22px 0 0;
  transition: background var(--tr-normal);
}

.fan-card.is-on::before  { background: var(--color-on); }
.fan-card.is-off::before { background: var(--border-color); }
.fan-card.is-offline     { opacity: 0.55; filter: grayscale(0.4); pointer-events: none; }
.fan-card:hover          { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.fan-card-header { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }

.fan-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.fan-name {
  font-family: var(--font-heading);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2px;
}

.fan-badge-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.5rem;
}

.fan-duty-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Circular radial duty ring around fan hub */
.fan-radial-wrap {
  position: relative;
  width: 78px;
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.fan-duty-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.fan-ring-track {
  fill: none;
  stroke: var(--border-subtle);
  stroke-width: 5.5;
}

.fan-ring-fill {
  fill: none;
  stroke: var(--brand-primary);
  stroke-width: 5.5;
  stroke-linecap: round;
  stroke-dasharray: 213.63;
  stroke-dashoffset: 213.63;
  transition: stroke-dashoffset 0.7s cubic-bezier(0.4,0,0.2,1), stroke var(--tr-normal);
}

/* Kipas 1 (Sky Cyan) & Kipas 2 (Violet) agar warna lingkaran & aksen bervariasi */
#fan-card-1 { --fan-accent: var(--accent-cyan); --fan-accent-bg: var(--accent-cyan-bg); }
#fan-card-2 { --fan-accent: var(--accent-violet); --fan-accent-bg: var(--accent-violet-bg); }

#fan-card-1 .fan-ring-fill,
#fan-card-2 .fan-ring-fill {
  stroke: var(--fan-accent);
}

#fan-card-1.is-on .fan-ring-fill {
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.45));
}
#fan-card-2.is-on .fan-ring-fill {
  filter: drop-shadow(0 0 6px rgba(167, 139, 250, 0.45));
}

.fan-icon-wrap {
  width: 50px; height: 50px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--fan-accent-bg, var(--color-off-bg));
  flex-shrink: 0;
  transition: background var(--tr-normal), box-shadow var(--tr-normal);
}

.fan-card.is-on .fan-icon-wrap {
  background: var(--fan-accent-bg, var(--color-on-bg));
  box-shadow: 0 0 0 4px var(--fan-accent-bg, rgba(52, 211, 153, 0.12));
}

.fan-blade {
  width: 32px; height: 32px;
  color: var(--fan-accent, var(--gray-400));
  opacity: 0.72;
  transition: color var(--tr-normal), opacity var(--tr-normal);
}

.fan-card.is-on .fan-blade { color: var(--fan-accent, var(--color-on)); opacity: 1; }

#fan-card-1 .fan-duty-pill,
#fan-card-2 .fan-duty-pill {
  background: var(--fan-accent-bg);
  color: var(--fan-accent);
  border-color: transparent;
}

@media (prefers-reduced-motion: no-preference) {
  .fan-card.is-on .fan-blade { animation: rotate 1.2s linear infinite; }
}

@keyframes rotate {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.fan-status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  transition: all var(--tr-normal);
}

.fan-status-badge.on  { background: var(--color-on-bg); color: var(--color-on); }
.fan-status-badge.off { background: var(--color-off-bg); color: var(--color-off); }

/* Open capsule metric strip (replaces double nested boxes) */
.fan-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 0.55rem 0.25rem;
  position: relative;
}

.fan-stat {
  display: flex; flex-direction: column; gap: 2px;
  padding: 0.2rem 0.75rem;
  background: transparent;
  border: none;
  border-radius: 0;
}

.fan-stat + .fan-stat {
  border-left: 1px solid var(--border-color);
}

.fan-stat-label { font-size: 0.6875rem; color: var(--text-muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fan-stat-value { font-family: var(--font-mono); font-size: 0.9375rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }

/* ── Analytics / Diagram Lingkaran Card ────────────────────────── */
.analytics-pill {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--accent-cyan-bg);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.28);
}

.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 1.25rem;
  align-items: center;
}

.analytics-divider {
  width: 1px;
  height: 92px;
  background: var(--border-subtle);
}

.donut-widget {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.donut-wrap {
  position: relative;
  width: 112px;
  height: 112px;
  flex-shrink: 0;
}

.donut-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.donut-center-val {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.05;
}

.donut-center-sub {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-top: 2px;
}

.donut-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.donut-heading {
  font-family: var(--font-heading);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
}

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.donut-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.donut-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.donut-leg-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.donut-leg-val {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.donut-leg-val small {
  color: var(--text-muted);
  font-weight: 500;
}

/* Schedule Bar + 24h Circular Clock */
.schedule-bar-card .card-body { padding-bottom: 1.125rem; }

.schedule-visual-layout {
  display: grid;
  grid-template-columns: 156px 1fr;
  gap: 1.25rem;
  align-items: center;
  margin-top: 0.35rem;
}

.schedule-clock-wrap {
  position: relative;
  width: 156px;
  height: 156px;
  margin: 0 auto;
  flex-shrink: 0;
}

.schedule-clock-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.schedule-clock-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.clock-now-time {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

.clock-now-state {
  margin-top: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--surface-elevated);
  color: var(--text-muted);
}

.clock-now-state.is-active {
  background: var(--color-on-bg);
  color: var(--color-on);
}

.schedule-timeline-col { min-width: 0; }

.schedule-track {
  position: relative;
  height: 40px;
  background: var(--surface-elevated);
  border-radius: var(--radius-full);
  overflow: visible;
  border: 1px solid var(--border-color);
  margin: 1rem 0 0.5rem;
}

.schedule-segment {
  position: absolute;
  top: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  transition: all var(--tr-normal);
  overflow: hidden;
  border-radius: var(--radius-full);
}

.schedule-segment.done     { background: var(--sched-done); color: var(--text-muted); }
.schedule-segment.active   { background: var(--brand-primary); color: white; z-index: 2; box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.35); }
.schedule-segment.upcoming { background: var(--sched-upcoming); color: var(--text-secondary); }

.schedule-segment span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px; }

.now-line {
  position: absolute;
  top: -8px; bottom: -8px;
  width: 2px;
  background: var(--color-offline);
  z-index: 10;
  pointer-events: none;
}

.now-line::before {
  content: '';
  position: absolute;
  top: 8px;
  left: -4px;
  width: 10px; height: 10px;
  background: var(--color-offline);
  border-radius: 50%;
  border: 2px solid var(--surface-card);
  box-shadow: var(--shadow-sm);
}

.now-label {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--color-offline);
  white-space: nowrap;
  background: var(--surface-card);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-offline);
}

.schedule-labels { display: flex; justify-content: space-between; padding: 0 4px; }
.schedule-label { font-family: var(--font-mono); font-size: 0.625rem; color: var(--text-muted); }

.schedule-windows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 0.875rem;
}

.schedule-window-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  transition: background var(--tr-slow);
  min-width: 0;
}

.schedule-window-row.active { background: var(--color-on-bg); border-color: var(--color-on); }

.sched-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.schedule-window-row.done .sched-dot     { background: var(--text-muted); }
.schedule-window-row.active .sched-dot   { background: var(--color-on); animation: pulse-dot 2s infinite; }
.schedule-window-row.upcoming .sched-dot { background: var(--accent-cyan); }

.sched-time { font-family: var(--font-mono); font-size: 0.75rem; font-weight: 700; color: var(--text-primary); white-space: nowrap; }
.sched-status { font-size: 0.6875rem; color: var(--text-secondary); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sched-badge { font-size: 0.625rem; font-weight: 700; padding: 2px 7px; border-radius: var(--radius-full); white-space: nowrap; }
.schedule-window-row.done .sched-badge     { background: var(--color-off-bg); color: var(--text-muted); }
.schedule-window-row.active .sched-badge   { background: var(--brand-primary); color: white; }
.schedule-window-row.upcoming .sched-badge { background: var(--sched-upcoming); color: var(--text-secondary); border: 1px solid var(--border-color); }

.schedule-next-msg {
  margin-top: 0.875rem;
  padding: 0.625rem 0.95rem;
  background: var(--color-on-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--brand-accent);
  display: flex; align-items: center; gap: 8px;
}

.schedule-next-msg[hidden] { display: none; }

/* Climate */
.climate-panel .card-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.125rem;
  align-items: center;
}

.thi-display {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 132px;
}

.thi-ring { position: relative; width: 124px; height: 124px; }
.thi-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.thi-ring-ticks { fill: none; stroke: var(--border-color); stroke-width: 1.5; stroke-dasharray: 2 5; }
.thi-ring-track { fill: none; stroke: var(--border-subtle); stroke-width: 9; }
.thi-ring-fill { fill: none; stroke: var(--thi-comfort); stroke-width: 9; stroke-linecap: round; stroke-dasharray: 283; stroke-dashoffset: 283; transition: stroke-dashoffset 0.8s cubic-bezier(0.4,0,0.2,1), stroke var(--tr-slow); }

.thi-ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}

.thi-value { font-family: var(--font-mono); font-size: 1.55rem; font-weight: 700; color: var(--text-primary); line-height: 1; }
.thi-unit  { font-size: 0.6875rem; color: var(--text-muted); margin-top: 2px; font-weight: 600; letter-spacing: 0.06em; }

.thi-category {
  margin-top: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  padding: 3px 12px;
  border-radius: var(--radius-full);
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
}
.thi-category.comfort  { color: var(--thi-comfort); }
.thi-category.mild     { color: var(--thi-mild); }
.thi-category.moderate { color: var(--thi-moderate); }
.thi-category.severe   { color: var(--thi-severe); }

.climate-readings { display: flex; flex-direction: column; gap: 0.625rem; }

.reading-row {
  display: flex; flex-direction: column; gap: 4px;
  padding: 0.75rem 1rem;
  background: var(--surface-elevated);
  border-radius: 16px;
  border: 1px solid var(--border-subtle);
  transition: background var(--tr-slow);
}

.reading-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.reading-sub { font-size: 0.65rem; color: var(--text-muted); }
.reading-val-line { display: flex; align-items: baseline; }

.thermal-bar {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--border-subtle);
  overflow: hidden;
  margin-top: 4px;
}

.thermal-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--accent-cyan), var(--color-on), var(--color-warn));
  transition: width 0.6s cubic-bezier(0.4,0,0.2,1);
}

.reading-rh {
  flex-direction: row;
  align-items: center;
  gap: 0.875rem;
}

.rh-mini-ring {
  position: relative;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rh-mini-ring svg:first-child {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.rh-ring-track { fill: none; stroke: var(--border-subtle); stroke-width: 4.5; }
.rh-ring-fill  { fill: none; stroke: var(--accent-cyan); stroke-width: 4.5; stroke-linecap: round; stroke-dasharray: 138.23; stroke-dashoffset: 138.23; transition: stroke-dashoffset 0.7s ease; }
.rh-drop-ico   { color: var(--accent-cyan); position: relative; z-index: 1; }
.rh-text       { display: flex; flex-direction: column; gap: 2px; }

.reading-label { font-size: 0.6875rem; color: var(--text-muted); font-weight: 600; display: flex; align-items: center; gap: 4px; }
.reading-value { font-family: var(--font-mono); font-size: 1.3rem; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.reading-unit  { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }

.sparkline-section {
  margin-top: 0.5rem;
  padding-top: 0.875rem;
  border-top: 1px solid var(--border-subtle);
  grid-column: 1 / -1;
}

.sparkline-title { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.5rem; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.sparkline-stats { display: flex; align-items: center; gap: 0.375rem; }
.spark-pill {
  font-size: 0.6875rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.spark-pill strong { color: var(--text-primary); }
.sparkline-canvas { width: 100%; height: 150px; display: block; }

/* History Table */
.history-filters {
  display: flex; gap: 0.375rem;
  padding: 0 1.25rem 0.75rem;
}

.history-summary {
  margin: 0 1.25rem 0.75rem;
  padding: 0.55rem 0.85rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.history-summary-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.hist-sum-counts {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hist-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.hist-dot.on  { background: var(--color-on); }
.hist-dot.off { background: var(--color-warn); margin-left: 4px; }

.history-ratio-bar {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-warn);
  overflow: hidden;
}

.history-ratio-on {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-on);
  transition: width 0.5s ease;
}

.filter-btn {
  padding: 5px 13px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--tr-normal);
}

.filter-btn:hover { border-color: var(--accent-cyan); color: var(--accent-cyan); }
.filter-btn.active { background: var(--brand-primary); border-color: var(--brand-primary); color: white; }
.filter-btn[data-filter="kipas1"].active { background: var(--accent-cyan); border-color: var(--accent-cyan); color: #ffffff; }
.filter-btn[data-filter="kipas2"].active { background: var(--accent-violet); border-color: var(--accent-violet); color: #ffffff; }

.history-table-wrap { overflow-x: auto; max-height: 520px; overflow-y: auto; border-top: 1px solid var(--border-subtle); }

.history-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.history-table thead { position: sticky; top: 0; z-index: 5; }

.history-table th {
  background: var(--surface-bg);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.625rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  transition: background var(--tr-slow);
}

.history-table td { padding: 0.625rem 1rem; border-bottom: 1px solid var(--border-subtle); color: var(--text-primary); vertical-align: middle; transition: background var(--tr-slow); }
.history-table tbody tr { transition: background var(--tr-fast); }
.history-table tbody tr:hover { background: var(--surface-bg); }
.history-table tbody tr:last-child td { border-bottom: none; }
.history-table .time-cell { font-family: var(--font-mono); font-size: 0.8125rem; color: var(--text-secondary); white-space: nowrap; }

.badge-on  { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-full); background: var(--color-on-bg); color: var(--color-on); font-size: 0.6875rem; font-weight: 700; font-family: var(--font-mono); }
.badge-off { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-full); background: var(--color-warn-bg); color: var(--color-warn); font-size: 0.6875rem; font-weight: 700; font-family: var(--font-mono); }

.fan-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  font-size: 0.78rem;
  white-space: nowrap;
}
.fan-chip::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.fan-chip-1::before { background: var(--accent-cyan); }
.fan-chip-2::before { background: var(--accent-violet); }

.source-tag { font-size: 0.6875rem; font-weight: 600; color: var(--text-muted); background: var(--surface-bg); border: 1px solid var(--border-color); padding: 2px 8px; border-radius: var(--radius-full); white-space: nowrap; }
.source-tag.src-jadwal    { background: var(--accent-violet-bg); color: var(--accent-violet); border-color: transparent; }
.source-tag.src-dashboard { background: var(--accent-cyan-bg); color: var(--accent-cyan); border-color: transparent; }
.source-tag.src-manual    { background: var(--color-warn-bg); color: var(--color-warn); border-color: transparent; }
.history-empty { text-align: center; color: var(--text-muted); padding: 2rem 1rem; font-size: 0.875rem; }

/* Demo Banner */
.demo-banner {
  background: linear-gradient(90deg, #7c3aed, #2563eb);
  color: white;
  text-align: center;
  padding: 6px 1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}

.demo-banner[hidden] { display: none; }

.demo-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 160px; height: 4px;
  background: rgba(255,255,255,0.3);
  border-radius: var(--radius-full);
  outline: none;
  cursor: pointer;
}

.demo-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.demo-time-label { font-family: var(--font-mono); font-size: 0.875rem; min-width: 50px; }

/* Waiting state */
.waiting-overlay {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.75rem;
  padding: 3rem 1rem;
  color: var(--text-muted);
  grid-column: 1 / -1;
}

.waiting-overlay[hidden] { display: none; }

.spinner-lg {
  width: 40px; height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Control Buttons */
.fan-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
  padding-top: 0.625rem;
  border-top: 1px dashed var(--border-color);
}
.fan-controls[hidden] { display: none !important; }

.btn-control {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border-color);
  background: var(--surface-elevated);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--tr-normal);
  user-select: none;
}

.btn-control:hover:not(:disabled) {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  background: var(--surface-card);
}

.btn-control.on-btn:hover:not(:disabled) {
  background: var(--color-on-bg);
  border-color: var(--color-on);
  color: var(--color-on);
}

.btn-control.off-btn:hover:not(:disabled) {
  background: var(--color-offline-bg);
  border-color: var(--color-offline);
  color: var(--color-offline);
}

.btn-control.on-btn.active {
  background: var(--color-on);
  border-color: var(--color-on);
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(22, 163, 74, 0.35);
}

.btn-control.off-btn.active {
  background: var(--surface-bg);
  border-color: var(--border-color);
  color: var(--text-muted);
}

.btn-control:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Mobile Nav */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface-header);
  border-top: 1px solid var(--border-color);
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
}

.mobile-nav-tabs { display: flex; height: 100%; align-items: stretch; position: relative; }

.mobile-nav-tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: all var(--tr-normal);
  padding: 0;
}

.mobile-nav-tab.active { color: var(--brand-primary); }

/* Dialog */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.2s ease;
}

.dialog-backdrop[hidden] { display: none; }

.dialog-box {
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  max-width: 380px;
  width: 90%;
  animation: cardIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

.dialog-title { font-family: var(--font-heading); font-size: 1.1rem; font-weight: 700; margin-bottom: 0.5rem; }
.dialog-body  { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 1.5rem; line-height: 1.6; }
.dialog-actions { display: flex; gap: 0.75rem; justify-content: flex-end; }

.btn-dialog {
  padding: 8px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  transition: all var(--tr-normal);
}

.btn-dialog.confirm { background: var(--brand-primary); border-color: var(--brand-primary); color: white; }
.btn-dialog:hover { filter: brightness(0.9); }

/* Animations */
.fade-in { animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .main-content {
    grid-template-columns: 1fr;
    padding: 1rem 0.875rem calc(var(--nav-h) + 1rem);
  }

  .mobile-nav { display: block; }

  [data-tab-panel] { display: none; }
  [data-tab-panel].active { display: flex; flex-direction: column; gap: 1rem; }

  .header-last-updated { display: none; }
  .btn-logout span { display: none; }
  .btn-logout { padding: 6px 10px; }
  .header { padding: 0 1rem; }
  .header-title { font-size: 0.9375rem; }
}

/* On desktop, panels are always visible inside their column */
@media (min-width: 861px) {
  [data-tab-panel] { display: flex !important; flex-direction: column; gap: 1.5rem; }

  .main-content {
    grid-template-columns: 1fr 380px;
    grid-template-rows: auto;
    align-items: stretch;
  }

  /* Baris 1: kipas (kiri) + riwayat (kanan) */
  [data-tab-panel="kipas"]   { grid-column: 1; grid-row: 1; }
  [data-tab-panel="riwayat"] { grid-column: 2; grid-row: 1; }

  /* Baris 2: Cuaca membentang dari kiri sampai ujung kanan Riwayat */
  [data-tab-panel="suhu"] {
    grid-column: 1 / -1;
    grid-row: 2;
  }

    /* Panel Riwayat ikut tinggi kolom kiri; isinya tidak boleh mendorong baris */
  [data-tab-panel="riwayat"] {
    position: relative;
    min-height: 0;
  }

  [data-tab-panel="riwayat"] > .card {
    position: absolute;
    inset: 0;                 /* penuhi panel, tinggi = tinggi kolom kiri */
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* Hanya tabel yang scroll */
  .history-table-wrap {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
  }

  /* Kartu Cuaca selebar penuh: 3 kolom horizontal */
  .climate-panel .card-body {
    grid-template-columns: auto minmax(260px, 1fr) minmax(320px, 1.4fr);
    gap: 1.5rem;
    align-items: stretch;
  }

  .climate-panel .sparkline-section {
    grid-column: auto;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    padding-left: 1.5rem;
    border-left: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
  }

  .climate-panel .sparkline-canvas {
    flex: 1;
    min-height: 130px;
  }
}   /* <- penutup @media, jangan sampai hilang */

@media (max-width: 720px) {
  .analytics-grid {
    grid-template-columns: 1fr;
    gap: 1.125rem;
  }
  .analytics-divider {
    width: 100%;
    height: 1px;
  }
  .schedule-visual-layout {
    grid-template-columns: 1fr;
    gap: 0.875rem;
  }
}

@media (max-width: 500px) {
  .fan-cards-row { grid-template-columns: 1fr; }
  .climate-panel .card-body { grid-template-columns: 1fr; }
  .thi-display { flex-direction: row; gap: 1rem; min-width: 0; }
  .schedule-windows { grid-template-columns: 1fr; }
  .login-card { padding: 1.75rem 1.25rem; }
  .header-label { display: none; }
}

.btn-login { -webkit-tap-highlight-color: transparent; }
.btn-login:active:not(:disabled) { background: var(--brand-hover); }

/* ── Kartu kipas saat alat offline: redup tapi tetap terbaca ── */
.fan-card.is-offline { opacity: 0.8; filter: none; }

/* ── Login: susunan warna tetap persis seperti semula ── */
.login-page {
  --brand-primary: #5F7D4F !important;
  --brand-hover:   #4C6840 !important;
  --shadow-lg:     0 10px 40px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.06) !important;
  background: transparent !important;
}

.login-overlay {
  background: linear-gradient(135deg, rgba(15,23,42,0.6) 0%, rgba(30,64,120,0.4) 100%);
}

.login-logo-icon { box-shadow: 0 4px 12px rgba(95,125,79,0.4); }
.form-input:focus { box-shadow: 0 0 0 3px rgba(95,125,79,0.35); }
.btn-login:hover:not(:disabled) { box-shadow: 0 6px 20px rgba(95,125,79,0.4); }

/* Motif sapi hanya untuk dashboard */
body:has(.login-page)::before { display: none; }

/* ── Header bermotif kulit sapi ───────────────────────────────── */
.header {
  background-color: var(--surface-header);
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400'><g fill='black' fill-opacity='0.7'><path d='M30 70C15 45 45 20 80 28C105 34 100 58 120 72C138 86 122 108 95 108C72 108 66 92 48 90C28 88 38 80 30 70Z'/><path d='M250 30C290 10 335 30 340 70C344 100 320 112 300 100C280 88 290 70 270 62C250 54 232 42 250 30Z'/><path d='M60 200C40 180 70 160 100 170C130 180 150 165 170 185C190 205 165 225 150 245C135 265 100 270 85 250C70 232 78 220 60 200Z'/><path d='M215 120C230 105 260 115 260 140C260 160 240 170 225 160C210 150 205 130 215 120Z'/><path d='M280 190C300 170 335 180 340 205C345 230 320 245 300 240C280 235 265 205 280 190Z'/><path d='M200 320C230 295 285 300 320 320C355 340 370 375 335 388C300 398 270 372 240 376C205 380 175 345 200 320Z'/><path d='M25 320C40 300 75 305 85 330C95 355 70 385 45 380C20 375 10 340 25 320Z'/></g></svg>");
  background-size: 180px 180px;
  background-position: center;
  border-bottom: 3px solid #5F7D4F;
}

/* ── Tema hijau mode terang ──────────────────────────────────── */
:root:not([data-theme="dark"]) {
  --brand-primary:   #5F7D4F !important;
  --brand-hover:     #4C6840 !important;
  --brand-accent:    #3F6B3A !important;
  --surface-bg:      #DCEBD3 !important;
  --surface-card:    #FCFFFA !important;
  --surface-elevated:#E4F0DC !important;
  --surface-header:  #FCFFFA !important;
  --text-primary:    #1C2618 !important;
  --text-secondary:  #34452F !important;
  --text-muted:      #4F5E49 !important;
  --border-color:    #B5CCA7 !important;
  --border-subtle:   #C9DCBC !important;
  --color-off-bg:    #D3E3C8 !important;
  --sched-done:      #A9C49A !important;
  --sched-upcoming:  #C9DCBC !important;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-primary:   #1F9D68 !important;
    --brand-hover:     #178255 !important;
    --brand-accent:    #4ADE80 !important;
    --accent-cyan:     #38BDF8 !important;
    --accent-cyan-bg:  rgba(56, 189, 248, 0.15) !important;
    --accent-violet:   #A78BFA !important;
    --accent-violet-bg:rgba(167, 139, 250, 0.15) !important;
    --surface-bg:      #0B1511 !important;
    --surface-card:    #12211B !important;
    --surface-elevated:#192D25 !important;
    --surface-header:  #101D17 !important;
    --text-primary:    #ECFDF5 !important;
    --text-secondary:  #A8CEBC !important;
    --text-muted:      #759D8A !important;
    --border-color:    #234034 !important;
    --border-subtle:   #1A3127 !important;
    --color-on:        #34D399 !important;
    --color-on-bg:     rgba(52, 211, 153, 0.14) !important;
    --color-off:       #86A998 !important;
    --color-off-bg:    #1A2E25 !important;
    --color-offline:   #FB7185 !important;
    --color-offline-bg:rgba(251, 113, 133, 0.14) !important;
    --color-warn:      #FBBF24 !important;
    --color-warn-bg:   rgba(251, 191, 36, 0.14) !important;
    --thi-comfort:     #34D399 !important;
    --thi-mild:        #FACC15 !important;
    --thi-moderate:    #FB923C !important;
    --thi-severe:      #F87171 !important;
    --sched-done:      #1D392D !important;
    --sched-upcoming:  #152920 !important;
  }
}

[data-theme="dark"] {
  --brand-primary:   #1F9D68 !important;
  --brand-hover:     #178255 !important;
  --brand-accent:    #4ADE80 !important;
  --accent-cyan:     #38BDF8 !important;
  --accent-cyan-bg:  rgba(56, 189, 248, 0.15) !important;
  --accent-violet:   #A78BFA !important;
  --accent-violet-bg:rgba(167, 139, 250, 0.15) !important;
  --surface-bg:      #0B1511 !important;
  --surface-card:    #12211B !important;
  --surface-elevated:#192D25 !important;
  --surface-header:  #101D17 !important;
  --text-primary:    #ECFDF5 !important;
  --text-secondary:  #A8CEBC !important;
  --text-muted:      #759D8A !important;
  --border-color:    #234034 !important;
  --border-subtle:   #1A3127 !important;
  --color-on:        #34D399 !important;
  --color-on-bg:     rgba(52, 211, 153, 0.14) !important;
  --color-off:       #86A998 !important;
  --color-off-bg:    #1A2E25 !important;
  --color-offline:   #FB7185 !important;
  --color-offline-bg:rgba(251, 113, 133, 0.14) !important;
  --color-warn:      #FBBF24 !important;
  --color-warn-bg:   rgba(251, 191, 36, 0.14) !important;
  --thi-comfort:     #34D399 !important;
  --thi-mild:        #FACC15 !important;
  --thi-moderate:    #FB923C !important;
  --thi-severe:      #F87171 !important;
  --sched-done:      #1D392D !important;
  --sched-upcoming:  #152920 !important;
}

/* Label hijau di mode terang */
.card-title,
.fan-label,
.header-label,
.history-table th,
.sparkline-title,
.reading-label,
.fan-stat-label {
  color: #24401F;
}

/* ── Pil header: hijau tua, isi cerah ── */
.header-brand {
  background: #2F4A2A;
  border: 2px solid #FFFFFF;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
  padding: 6px 16px 6px 8px;
  border-radius: 14px;
}
.header-brand .header-label { color: #FFFFFF !important; }
.header-brand .header-title { color: #FFFFFF !important; }
.header-logo  { background: #DFF0D4; }
.header-logo svg { color: #2F4A2A; }

.header-meta {
  background: #2F4A2A;
  border: 2px solid #FFFFFF;
  border-radius: var(--radius-md);
  padding: 5px 10px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
}
.header-last-updated { color: #F4FBEF; font-weight: 500; }

.btn-logout,
.btn-theme {
  background: transparent;
  color: #F4FBEF;
  border: 1.5px solid rgba(244,251,239,0.55);
}
.btn-logout:hover,
.btn-theme:hover {
  background: rgba(255,255,255,0.15);
  border-color: #FFFFFF;
  color: #FFFFFF;
}

.conn-pill { border: 1.5px solid rgba(0,0,0,0.08); }
.conn-pill.online  { background: #FFFFFF; color: #1F7A4D; }
.conn-pill.offline { background: #FFFFFF; color: #B83227; }
.conn-pill.waiting { background: #FFFFFF; color: #5A5640; }

/* ── List bermotif sapi di atas setiap kartu ── */
:root {
  --cow-pattern: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400'><g fill='black' fill-opacity='0.7'><path d='M30 70C15 45 45 20 80 28C105 34 100 58 120 72C138 86 122 108 95 108C72 108 66 92 48 90C28 88 38 80 30 70Z'/><path d='M250 30C290 10 335 30 340 70C344 100 320 112 300 100C280 88 290 70 270 62C250 54 232 42 250 30Z'/><path d='M60 200C40 180 70 160 100 170C130 180 150 165 170 185C190 205 165 225 150 245C135 265 100 270 85 250C70 232 78 220 60 200Z'/><path d='M215 120C230 105 260 115 260 140C260 160 240 170 225 160C210 150 205 130 215 120Z'/><path d='M280 190C300 170 335 180 340 205C345 230 320 245 300 240C280 235 265 205 280 190Z'/><path d='M200 320C230 295 285 300 320 320C355 340 370 375 335 388C300 398 270 372 240 376C205 380 175 345 200 320Z'/><path d='M25 320C40 300 75 305 85 330C95 355 70 385 45 380C20 375 10 340 25 320Z'/></g></svg>");
  --cow-pattern-dark: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400'><g fill='black' fill-opacity='0.6'><path d='M30 70C15 45 45 20 80 28C105 34 100 58 120 72C138 86 122 108 95 108C72 108 66 92 48 90C28 88 38 80 30 70Z'/><path d='M250 30C290 10 335 30 340 70C344 100 320 112 300 100C280 88 290 70 270 62C250 54 232 42 250 30Z'/><path d='M60 200C40 180 70 160 100 170C130 180 150 165 170 185C190 205 165 225 150 245C135 265 100 270 85 250C70 232 78 220 60 200Z'/><path d='M215 120C230 105 260 115 260 140C260 160 240 170 225 160C210 150 205 130 215 120Z'/><path d='M280 190C300 170 335 180 340 205C345 230 320 245 300 240C280 235 265 205 280 190Z'/><path d='M200 320C230 295 285 300 320 320C355 340 370 375 335 388C300 398 270 372 240 376C205 380 175 345 200 320Z'/><path d='M25 320C40 300 75 305 85 330C95 355 70 385 45 380C20 375 10 340 25 320Z'/></g></svg>");
}

.card { position: relative; overflow: hidden; }

.card::before,
.fan-card::before,
.fan-card.is-on::before,
.fan-card.is-off::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 15px;
  background-color: #FFFFFF;
  background-image: var(--cow-pattern);
  background-size: 50px 50px;
  background-position: center;
  border-bottom: 2px solid #2F4A2A;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  pointer-events: none;
}

.fan-card.is-offline { opacity: 1; filter: none; }
.fan-card.is-offline > * { opacity: 0.92; }
.btn-control:disabled { opacity: 0.72; }

.card-header { padding-top: 1.5rem; }
.fan-card { padding-top: 1.75rem; }

.card,
.fan-card {
  border: 1.5px solid #6D8E5B;
  box-shadow: 0 3px 12px rgba(47, 74, 42, 0.12);
}

.card:hover,
.fan-card:hover {
  border-color: #2F4A2A;
  box-shadow: 0 6px 20px rgba(47, 74, 42, 0.20);
}

/* ── Mode Gelap Segar (Emerald & Mint Slate) ── */
[data-theme="dark"] body:not(.login-page) {
  background:
    radial-gradient(circle at 12% 0%, rgba(52, 211, 153, 0.10), transparent 40%),
    radial-gradient(circle at 88% 12%, rgba(56, 189, 248, 0.08), transparent 36%),
    var(--surface-bg);
}

[data-theme="dark"] .header {
  background-color: #0a5238 !important;
  background-image: var(--cow-pattern-dark) !important;
  border-bottom: 2px solid rgba(52, 211, 153, 0.35) !important;
}

[data-theme="dark"] .header-brand,
[data-theme="dark"] .header-meta {
  background: rgba(18, 36, 28, 0.92);
  border: 1.5px solid rgba(74, 222, 128, 0.40);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] .header-logo { background: rgba(52, 211, 153, 0.18); }
[data-theme="dark"] .header-logo svg { color: #34D399; }

[data-theme="dark"] .conn-pill.online  { background: rgba(52, 211, 153, 0.16); color: #34D399; border-color: rgba(52, 211, 153, 0.35); }
[data-theme="dark"] .conn-pill.offline { background: rgba(251, 113, 133, 0.16); color: #FB7185; border-color: rgba(251, 113, 133, 0.35); }
[data-theme="dark"] .conn-pill.waiting { background: rgba(168, 206, 188, 0.14); color: #A8CEBC; border-color: rgba(168, 206, 188, 0.25); }

[data-theme="dark"] .card,
[data-theme="dark"] .fan-card {
  border: 1.5px solid rgba(52, 211, 153, 0.24);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] .card:hover,
[data-theme="dark"] .fan-card:hover {
  border-color: rgba(74, 222, 128, 0.48);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] .card::before,
[data-theme="dark"] .fan-card::before,
[data-theme="dark"] .fan-card.is-on::before,
[data-theme="dark"] .fan-card.is-off::before {
  background-color: #0a5238;
  background-image: var(--cow-pattern-dark);
  border-bottom: 1.5px solid rgba(52, 211, 153, 0.32);
}

[data-theme="dark"] .card-title,
[data-theme="dark"] .fan-label,
[data-theme="dark"] .fan-stat-label,
[data-theme="dark"] .reading-label,
[data-theme="dark"] .sparkline-title,
[data-theme="dark"] .history-table th {
  color: #9EE4BF;
}

[data-theme="dark"] .card-title svg {
  color: #34D399;
}

[data-theme="dark"] .fan-stats,
[data-theme="dark"] .reading-row,
[data-theme="dark"] .schedule-window-row,
[data-theme="dark"] .history-summary {
  background: var(--surface-elevated);
  border-color: var(--border-color);
}

[data-theme="dark"] .schedule-window-row.active {
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.5);
}

[data-theme="dark"] .schedule-next-msg {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.30);
  color: #6EE7B7;
}

/* Auto dark mode (OS prefers dark tanpa data-theme="light") */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body:not(.login-page) {
    background:
      radial-gradient(circle at 12% 0%, rgba(52, 211, 153, 0.10), transparent 40%),
      radial-gradient(circle at 88% 12%, rgba(56, 189, 248, 0.08), transparent 36%),
      var(--surface-bg);
  }
  :root:not([data-theme="light"]) .header {
    background-color: #0E1B16 !important;
    background-image: var(--cow-pattern-dark) !important;
    border-bottom: 2px solid #2F4A2A !important;
  }
  :root:not([data-theme="light"]) .header-brand,
  :root:not([data-theme="light"]) .header-meta {
    background: rgba(18, 36, 28, 0.92);
    border-bottom: 1.5px solid #2F4A2A;
  }
  :root:not([data-theme="light"]) .header-logo { background: rgba(52, 211, 153, 0.18); }
  :root:not([data-theme="light"]) .header-logo svg { color: #34D399; }
  :root:not([data-theme="light"]) .conn-pill.online  { background: rgba(52, 211, 153, 0.16); color: #34D399; border-color: rgba(52, 211, 153, 0.35); }
  :root:not([data-theme="light"]) .conn-pill.offline { background: rgba(251, 113, 133, 0.16); color: #FB7185; border-color: rgba(251, 113, 133, 0.35); }
  :root:not([data-theme="light"]) .conn-pill.waiting { background: rgba(168, 206, 188, 0.14); color: #A8CEBC; border-color: rgba(168, 206, 188, 0.25); }
  :root:not([data-theme="light"]) .card,
  :root:not([data-theme="light"]) .fan-card {
    border: 1.5px solid rgba(52, 211, 153, 0.24);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  }
  :root:not([data-theme="light"]) .card::before,
  :root:not([data-theme="light"]) .fan-card::before,
  :root:not([data-theme="light"]) .fan-card.is-on::before,
  :root:not([data-theme="light"]) .fan-card.is-off::before {
    background-color: #162B22;
    background-image: var(--cow-pattern-dark);
    border-bottom: 1.5px solid rgba(52, 211, 153, 0.32);
  }
  :root:not([data-theme="light"]) .card-title,
  :root:not([data-theme="light"]) .fan-label,
  :root:not([data-theme="light"]) .fan-stat-label,
  :root:not([data-theme="light"]) .reading-label,
  :root:not([data-theme="light"]) .sparkline-title,
  :root:not([data-theme="light"]) .history-table th {
    color: #9EE4BF;
  }
  :root:not([data-theme="light"]) .card-title svg { color: #34D399; }
  :root:not([data-theme="light"]) .schedule-window-row.active {
    background: rgba(52, 211, 153, 0.16);
    border-color: rgba(52, 211, 153, 0.5);
  }
  :root:not([data-theme="light"]) .schedule-next-msg {
    background: rgba(52, 211, 153, 0.12);
    border-color: rgba(52, 211, 153, 0.30);
    color: #6EE7B7;
  }
}

/* ── Dialog pengaturan jadwal ── */
#settings-dialog { z-index: 450; }
.settings-box { max-width: 440px; max-height: 90vh; overflow-y: auto; }
.settings-help { font-size: 0.8125rem; color: var(--text-secondary); margin-bottom: 1rem; }

.sched-edit-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.75rem; }
.sched-edit-row { display: flex; align-items: center; gap: 0.5rem; }
.sched-edit-no { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); width: 2rem; }

.sched-time-input,
.sched-dur-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--surface-bg);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9375rem;
}
.sched-dur-input { flex: 0 0 90px; }
.sched-time-input:focus,
.sched-dur-input:focus { outline: 2px solid var(--brand-primary); outline-offset: 1px; }

.btn-icon-sm {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.25rem; line-height: 1;
  cursor: pointer;
}
.btn-icon-sm:hover { background: var(--color-offline-bg); border-color: var(--color-offline); color: var(--color-offline); }

.btn-add-sched {
  width: 100%;
  padding: 0.5rem;
  border: 1.5px dashed var(--border-color);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-add-sched:hover:not(:disabled) { border-color: var(--brand-primary); color: var(--brand-primary); }
.btn-add-sched:disabled { opacity: 0.5; cursor: not-allowed; }

.settings-field { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin: 1rem 0 1.5rem; font-size: 0.875rem; }

.settings-error {
  padding: 0.625rem 0.875rem;
  margin-bottom: 1rem;
  background: var(--color-offline-bg);
  color: var(--color-offline);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
}
.settings-error[hidden] { display: none; }