/* Gerak, kaca overlay, dan tombol tema. Berlaku di kedua mode.
   html.mx        = animasi aktif (flag motion, bukan prefers-reduced-motion)
   html.no-glass  = kaca dimatikan (perangkat lemah / tanpa blur / kurangi transparansi / flag)
   html.lite-glass= perangkat menengah: blur lebih ringan
   Kurva: keluar cepat, masuk lembut (ease-out-expo). */
:root {
  --mx-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --mx-ease-io: cubic-bezier(0.65, 0, 0.35, 1);
  --mx-ease-pop: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* 1. Tombol tema Auto / Light / Dark */
.theme-toggle-slot { display: flex; align-items: center; }
.theme-toggle {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 30px;
  align-items: center;
  padding: 3px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  isolation: isolate;
}
.theme-toggle .tt-thumb {
  position: absolute;
  z-index: 0;
  top: 3px;
  left: 3px;
  width: 30px;
  height: calc(100% - 6px);
  border-radius: 9px;
  background: rgba(16, 185, 129, 0.22);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.45);
  transition: transform 0.38s var(--mx-ease);
}
html[data-theme-pref="light"] .theme-toggle .tt-thumb { transform: translateX(30px); }
html[data-theme-pref="dark"] .theme-toggle .tt-thumb { transform: translateX(60px); }
.theme-toggle .tt-opt {
  position: relative;
  z-index: 1;
  width: 30px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  color: #cfe3d6;
  font-size: 13px;
  cursor: pointer;
  border-radius: 9px;
  transition: color 0.2s ease, transform 0.15s ease;
}
.theme-toggle .tt-opt:hover { color: #ffffff; }
.theme-toggle .tt-opt[aria-checked="true"] { color: #6ee7b7; }
.theme-toggle .tt-opt:active { transform: scale(0.92); }
.theme-toggle .tt-opt:focus-visible { outline: 2px solid #34d399; outline-offset: 1px; }
.theme-toggle .tt-lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
html[data-theme="light"] .theme-toggle:not(.tt-drawer) { background: #ffffff; border-color: rgba(20, 32, 26, 0.10); box-shadow: 0 1px 2px rgba(15, 35, 25, 0.05); }
html[data-theme="light"] .theme-toggle:not(.tt-drawer) .tt-thumb { background: rgba(11, 107, 58, 0.10); box-shadow: inset 0 0 0 1px rgba(11, 107, 58, 0.30); }
html[data-theme="light"] .theme-toggle:not(.tt-drawer) .tt-opt { color: #52645a; }
html[data-theme="light"] .theme-toggle:not(.tt-drawer) .tt-opt:hover { color: #14201a; }
html[data-theme="light"] .theme-toggle:not(.tt-drawer) .tt-opt[aria-checked="true"] { color: #0b6b3a; }
.theme-toggle.tt-drawer { margin: 6px 0 2px; }
@media (max-width: 768px) {
  header .theme-toggle-slot { display: none; }
}

/* Pergantian tema: lingkaran membesar dari tombol yang ditekan (View Transitions API). */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
html.theme-vt::view-transition-new(root) {
  animation: mxThemeReveal 0.62s var(--mx-ease-io) both;
}
@keyframes mxThemeReveal {
  from { clip-path: circle(0 at var(--tt-x, 90%) var(--tt-y, 40px)); }
  to { clip-path: circle(var(--tt-r, 150vmax) at var(--tt-x, 90%) var(--tt-y, 40px)); }
}

/* 2. Perpindahan modul (view) dan muncul berurutan */
/* Modul sendiri tidak dipudarkan agar tidak terjadi pudar ganda. Yang bergerak hanya blok isi yang ditandai theme.js
   dengan .mx-i (blok yang tampil normal di alur halaman); modal/laci tersembunyi, elemen fixed/absolute, dan elemen
   yang tidak tampil tidak ditandai agar tidak dipaksa terlihat. Tanpa filter blur karena blur area besar berat;
   hanya opacity dan transform yang dijalankan compositor. */
html.mx .view-section.active { animation: none; }
html.mx .view-section.mx-enter > .mx-i,
html.mx #scmMain.mx-enter > .mx-i {
  animation-name: mxRise;
  animation-duration: 0.46s;
  animation-timing-function: var(--mx-ease);
  animation-fill-mode: both;
}
html.mx .mx-enter > .mx-i.mx-d1 { animation-delay: 0.05s; }
html.mx .mx-enter > .mx-i.mx-d2 { animation-delay: 0.10s; }
html.mx .mx-enter > .mx-i.mx-d3 { animation-delay: 0.15s; }
html.mx .mx-enter > .mx-i.mx-d4 { animation-delay: 0.19s; }
html.mx .mx-enter > .mx-i.mx-d5 { animation-delay: 0.22s; }
html.mx .mx-enter > .mx-i.mx-d6 { animation-delay: 0.25s; }
@keyframes mxRise {
  from { opacity: 0; transform: translate3d(0, 12px, 0); }
  to { opacity: 1; transform: none; }
}
/* Kartu KPI dan kartu breakdown muncul berurutan saat modul dibuka. */
html.mx .mx-enter .kpi-grid-6 > *,
html.mx .mx-enter .kpi-grid > *,
html.mx .mx-enter .live-grid > .bkd-card { animation: mxRise 0.65s var(--mx-ease) both; }
html.mx .mx-enter .kpi-grid-6 > *:nth-child(1), html.mx .mx-enter .kpi-grid > *:nth-child(1) { animation-delay: 0.10s; }
html.mx .mx-enter .kpi-grid-6 > *:nth-child(2), html.mx .mx-enter .kpi-grid > *:nth-child(2) { animation-delay: 0.16s; }
html.mx .mx-enter .kpi-grid-6 > *:nth-child(3), html.mx .mx-enter .kpi-grid > *:nth-child(3) { animation-delay: 0.22s; }
html.mx .mx-enter .kpi-grid-6 > *:nth-child(4), html.mx .mx-enter .kpi-grid > *:nth-child(4) { animation-delay: 0.28s; }
html.mx .mx-enter .kpi-grid-6 > *:nth-child(5), html.mx .mx-enter .kpi-grid > *:nth-child(5) { animation-delay: 0.34s; }
html.mx .mx-enter .kpi-grid-6 > *:nth-child(6), html.mx .mx-enter .kpi-grid > *:nth-child(6) { animation-delay: 0.40s; }
/* Baris tabel muncul halus hanya saat modul baru dibuka (bukan pada tiap refresh). */
html.mx .mx-enter .imrs-table tbody tr { animation: mxFade 0.45s var(--mx-ease) both; }
html.mx .mx-enter .imrs-table tbody tr:nth-child(2) { animation-delay: 0.03s; }
html.mx .mx-enter .imrs-table tbody tr:nth-child(3) { animation-delay: 0.06s; }
html.mx .mx-enter .imrs-table tbody tr:nth-child(4) { animation-delay: 0.09s; }
html.mx .mx-enter .imrs-table tbody tr:nth-child(5) { animation-delay: 0.12s; }
html.mx .mx-enter .imrs-table tbody tr:nth-child(6) { animation-delay: 0.15s; }
html.mx .mx-enter .imrs-table tbody tr:nth-child(7) { animation-delay: 0.18s; }
html.mx .mx-enter .imrs-table tbody tr:nth-child(n+8) { animation-delay: 0.21s; }
@keyframes mxFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Panel/tab di dalam modul yang baru ditampilkan (dari display none) ikut muncul lembut. */
html.mx [role="tabpanel"]:not([hidden]),
html.mx .scm-view,
html.mx .eh-pane,
html.mx .tab-pane.active { animation: mxFade 0.42s var(--mx-ease) both; }

/* 3. Interaksi mikro: tombol, kartu */
html.mx .btn, html.mx .btn-secondary, html.mx .btn-danger { transition: transform 0.16s var(--mx-ease-pop), box-shadow 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, filter 0.2s ease; }
html.mx .btn:active, html.mx .btn-secondary:active, html.mx .btn-danger:active { transform: translateY(0) scale(0.97); }
html.mx .card, html.mx .kpi-card-v2 { transition: box-shadow 0.25s ease, transform 0.25s var(--mx-ease), border-color 0.25s ease; }
html.mx .kpi-card-v2:hover { transform: translateY(-2px); }
html.mx nav button { transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.25s ease, padding 0.25s var(--mx-ease); }
html.mx nav button i { transition: transform 0.25s var(--mx-ease); }
html.mx nav button:hover i { transform: translateX(2px); }

/* 4. Overlay kaca: modal, timeline, dropdown, toast (bingkai kaca, isi solid) */
.modal-overlay, .timeline-overlay { transition: opacity 0.16s ease, backdrop-filter 0.26s ease, -webkit-backdrop-filter 0.26s ease; }
.modal-overlay.active, .timeline-overlay.active { transition-duration: 0.26s; }
html.mx .modal-window {
  transform: translateY(10px) scale(0.96);
  transition: transform 0.16s ease;
}
html.mx .modal-overlay.active .modal-window {
  transform: none;
  transition: transform 0.26s var(--mx-ease-pop);
}
html.mx .timeline-content { transform: translateY(10px) scale(0.96); transition: transform 0.16s ease; }
html.mx .timeline-overlay.active .timeline-content { transform: none; transition: transform 0.26s var(--mx-ease-pop); }

/* Kaca: scrim */
html:not(.no-glass) .modal-overlay.active, html:not(.no-glass) .timeline-overlay.active {
  -webkit-backdrop-filter: blur(6px) saturate(1.1);
  backdrop-filter: blur(6px) saturate(1.1);
}
html.lite-glass .modal-overlay.active, html.lite-glass .timeline-overlay.active { -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }

/* Dark: bingkai kaca hijau gelap berasap, isi solid */
html[data-theme="dark"]:not(.no-glass) .modal-overlay { background-color: rgba(0, 0, 0, 0.45); }
html[data-theme="dark"]:not(.no-glass) .modal-window,
html[data-theme="dark"]:not(.no-glass) .timeline-content {
  background-color: rgba(18, 32, 23, 0.72);
  -webkit-backdrop-filter: blur(22px) saturate(1.5);
  backdrop-filter: blur(22px) saturate(1.5);
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  border-radius: 18px;
}
html[data-theme="dark"]:not(.no-glass) .modal-header { background: linear-gradient(135deg, rgba(18, 32, 23, 0.55) 0%, rgba(26, 46, 34, 0.55) 100%); border-radius: 18px 18px 0 0; }
html[data-theme="dark"]:not(.no-glass) .modal-body { background-color: #122017; }
html[data-theme="dark"]:not(.no-glass) .modal-footer { background-color: rgba(11, 20, 16, 0.55); border-radius: 0 0 18px 18px; }
html[data-theme="dark"]:not(.no-glass) .tl-header { background: rgba(11, 20, 16, 0.55); border-radius: 18px 18px 0 0; }
html[data-theme="dark"]:not(.no-glass) .tl-body { background-color: #122017; border-radius: 0 0 18px 18px; }

/* Light: bingkai kaca putih, isi solid */
html[data-theme="light"] .modal-overlay { background-color: rgba(12, 30, 22, 0.28); }
html[data-theme="light"] .modal-window,
html[data-theme="light"] .timeline-content {
  background-color: #ffffff;
  border: 1px solid rgba(20, 32, 26, 0.08);
  border-radius: 20px;
  box-shadow: 0 2px 6px rgba(15, 35, 25, 0.06), 0 30px 70px rgba(15, 35, 25, 0.20);
}
html[data-theme="light"]:not(.no-glass) .modal-window,
html[data-theme="light"]:not(.no-glass) .timeline-content {
  background-color: rgba(255, 255, 255, 0.66);
  -webkit-backdrop-filter: blur(22px) saturate(1.6);
  backdrop-filter: blur(22px) saturate(1.6);
  border-color: rgba(255, 255, 255, 0.7);
}
html[data-theme="light"] .modal-header { background: transparent; border-bottom: 1px solid rgba(20, 32, 26, 0.08); border-radius: 20px 20px 0 0; }
html[data-theme="light"] .modal-header h3, html[data-theme="light"] .modal-header h2 { color: #14201a; }
html[data-theme="light"] .modal-body { background-color: #ffffff; }
html[data-theme="light"] .modal-footer { background-color: transparent; border-top: 1px solid rgba(20, 32, 26, 0.08); border-radius: 0 0 20px 20px; }
html[data-theme="light"] .modal-close { color: #52645a; }
html[data-theme="light"] .tl-header { background: transparent; border-bottom-color: rgba(20, 32, 26, 0.08); }
html[data-theme="light"] .tl-body { background: #ffffff; border-radius: 0 0 20px 20px; }

/* Dropdown notifikasi dan pencarian: membesar dari pemicunya */
html.mx .notif-drop { animation: mxDrop 0.22s var(--mx-ease-pop) both; transform-origin: top right; }
html.mx .gsearch-drop { animation: mxDrop 0.2s var(--mx-ease-pop) both; transform-origin: top left; }
@keyframes mxDrop { from { opacity: 0; transform: translateY(-6px) scale(0.97); } to { opacity: 1; transform: none; } }
html:not(.no-glass) .notif-drop, html:not(.no-glass) .gsearch-drop {
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
}
html[data-theme="dark"]:not(.no-glass) .notif-drop, html[data-theme="dark"]:not(.no-glass) .gsearch-drop { background-color: rgba(18, 32, 23, 0.86); }
html[data-theme="light"] .notif-drop, html[data-theme="light"] .gsearch-drop {
  background-color: #ffffff;
  border: 1px solid rgba(20, 32, 26, 0.08);
  border-radius: 16px;
  box-shadow: 0 24px 50px rgba(15, 35, 25, 0.16);
}
html[data-theme="light"]:not(.no-glass) .notif-drop, html[data-theme="light"]:not(.no-glass) .gsearch-drop { background-color: rgba(255, 255, 255, 0.86); }
html.mx .notif-badge { animation: mxBadge 0.5s var(--mx-ease-pop) both; }
@keyframes mxBadge { 0% { transform: scale(0.4); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* Toast: geser masuk dari kanan, kaca */
html.mx .toast-card { transition: transform 0.26s var(--mx-ease-pop), opacity 0.22s ease; }
html[data-theme="light"] .toast-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(20, 32, 26, 0.08);
  box-shadow: 0 18px 40px rgba(15, 35, 25, 0.16);
  border-radius: 14px;
}
html[data-theme="light"] .toast-title, html[data-theme="light"] .toast-msg { color: #14201a; }
html[data-theme="light"] .toast-close { color: #52645a; }

/* 5. Kurangi animasi: hanya pudar */
@media (prefers-reduced-motion: reduce) {
  .view-section.active, .view-section.mx-enter > .mx-i, #scmMain.mx-enter > .mx-i, .notif-drop, .gsearch-drop { animation: none !important; }
  .modal-window, .timeline-content, .toast-card { transform: none !important; }
}

/* Halaman SCM: isi #scmMain berganti per menu; blok isinya bergerak lewat aturan .mx-i di bagian 2. */

/* Sorotan mengikuti kursor pada kartu KPI (perangkat ber-mouse saja). */
@media (hover: hover) and (pointer: fine) {
  html.mx .scm-kpi { position: relative; overflow: hidden; }
  html.mx .scm-kpi::after, html.mx .kpi-card-v2::after {
    content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
    opacity: 0; transition: opacity 0.35s ease;
    background: radial-gradient(260px circle at var(--mx-x, 50%) var(--mx-y, 0%), rgba(16, 185, 129, 0.13), transparent 62%);
  }
  html.mx[data-theme="light"] .scm-kpi::after, html.mx[data-theme="light"] .kpi-card-v2::after {
    background: radial-gradient(260px circle at var(--mx-x, 50%) var(--mx-y, 0%), rgba(11, 107, 58, 0.08), transparent 62%);
  }
  html.mx .scm-kpi:hover::after, html.mx .kpi-card-v2:hover::after { opacity: 1; }
}

/* Modal yang dibuat langsung dalam keadaan .active (mis. imrsConfirm) tetap punya animasi masuk. */
html.mx .modal-overlay.active { animation: mxScrim 0.22s ease both; }
html.mx .modal-overlay.active .modal-window { animation: mxPop 0.3s var(--mx-ease-pop) both; }
html.mx .timeline-overlay.active .timeline-content { animation: mxPop 0.3s var(--mx-ease-pop) both; }
@keyframes mxScrim { from { opacity: 0; } to { opacity: 1; } }
@keyframes mxPop { from { opacity: 0; transform: translateY(12px) scale(0.96); } to { opacity: 1; transform: none; } }

/* Laci samping Equipment Health / Backlog (.eh-wd.open): geser masuk, isi berurutan; di ponsel naik dari bawah. */
html.mx .eh-wd.open .eh-drawer { animation: mxDrawer 0.34s var(--mx-ease) both; }
@keyframes mxDrawer { from { opacity: 0; transform: translateX(22px); } to { opacity: 1; transform: none; } }
html.mx .eh-wd.open .eh-drawer-body > * { animation: mxFade 0.42s var(--mx-ease) both; }
html.mx .eh-wd.open .eh-drawer-body > *:nth-child(2) { animation-delay: 0.05s; }
html.mx .eh-wd.open .eh-drawer-body > *:nth-child(3) { animation-delay: 0.10s; }
html.mx .eh-wd.open .eh-drawer-body > *:nth-child(n+4) { animation-delay: 0.15s; }
@media (max-width: 768px) {
  html.mx .eh-wd.open .eh-drawer { animation-name: mxSheet; }
  @keyframes mxSheet { from { opacity: 0; transform: translateY(28px); } to { opacity: 1; transform: none; } }
}

/* Laci entitas SCM (.ent-drawer.on): kurva lebih lembut dan kaca. */
html.mx .ent-drawer { transition: transform 0.32s var(--mx-ease); }
html.mx .ent-drawer:not(.on) { transition-duration: 0.18s; }
html.mx .ent-drawer.on .ent-db > *, html.mx .ent-drawer.on .ent-body > * { animation: mxFade 0.4s var(--mx-ease) both; }
html:not(.no-glass) .ent-overlay.on { -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); }
html[data-theme="dark"]:not(.no-glass) .ent-drawer { background-color: rgba(18, 32, 23, 0.86); -webkit-backdrop-filter: blur(22px) saturate(1.4); backdrop-filter: blur(22px) saturate(1.4); }
html[data-theme="light"] .ent-overlay { background-color: rgba(12, 30, 22, 0.24); }
html[data-theme="light"] .ent-drawer { background-color: #ffffff; border-left: 1px solid rgba(20, 32, 26, 0.08); box-shadow: -24px 0 60px rgba(15, 35, 25, 0.16); }
html[data-theme="light"]:not(.no-glass) .ent-drawer { background-color: rgba(255, 255, 255, 0.9); -webkit-backdrop-filter: blur(22px) saturate(1.5); backdrop-filter: blur(22px) saturate(1.5); }
html[data-theme="light"] .ent-dh { background: transparent; }
