/* ROLE GATE — layar pilih role (Operator / Production Support). Hanya front-end. */
#roleGate {
  position: fixed; inset: 0; z-index: 10050; display: none;
  background: radial-gradient(1200px 700px at 15% 0%, #1e3a8a 0%, rgba(30,58,138,0) 60%),
              linear-gradient(160deg, #0b1b33 0%, #0d2135 55%, #0a1626 100%);
  color: #fff; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: env(safe-area-inset-top,0) env(safe-area-inset-right,0) env(safe-area-inset-bottom,0) env(safe-area-inset-left,0);
}
#roleGate.open { display: block; }
body.rg-locked { overflow: hidden; }

.rg-view { display: none; min-height: 100%; width: 100%; max-width: 980px; margin: 0 auto;
  padding: 18px 20px 28px; box-sizing: border-box; flex-direction: column; }
.rg-view.on { display: flex; animation: rgIn .22s ease; }
@keyframes rgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.rg-back {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.10); color: #fff; border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px; padding: 9px 16px; font-family: inherit; font-weight: 600; font-size: 14px; line-height: 1; cursor: pointer;
}
.rg-back:hover { background: rgba(255,255,255,.18); }
.rg-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 12px 0; }
.rg-logo { width: 74px; height: 74px; object-fit: contain; border-radius: 16px; background: rgba(255,255,255,.95); padding: 8px; }
.rg-app { font-family: inherit; font-weight: 800; font-size: 13px; line-height: 1; letter-spacing: .16em; color: #93c5fd; text-transform: uppercase; }
.rg-title { margin: 0; font-size: clamp(26px, 5vw, 40px); font-weight: 800; letter-spacing: -.01em; }
.rg-sub { margin: 0 0 14px; color: #cbd5e1; font-size: clamp(14px, 2.2vw, 17px); }

.rg-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; width: 100%; max-width: 760px; }
.rg-card, .rg-btn {
  appearance: none; border: 0; cursor: pointer; color: inherit; font: inherit; text-align: center;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.rg-card {
  background: #fff; color: #0f172a; border-radius: 22px; padding: 34px 18px 28px;
  box-shadow: 0 14px 40px rgba(0,0,0,.35); display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.rg-card:hover, .rg-card:focus-visible { transform: translateY(-4px); box-shadow: 0 20px 50px rgba(0,0,0,.45); outline: 3px solid #60a5fa; }
.rg-card .rg-ico { width: 78px; height: 78px; border-radius: 22px; display: grid; place-items: center; }
.rg-card .rg-ico svg { width: 42px; height: 42px; stroke: #fff; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rg-card.op .rg-ico { background: linear-gradient(135deg,#2563eb,#1d4ed8); }
.rg-card.sp .rg-ico { background: linear-gradient(135deg,#0f766e,#0d9488); }
.rg-card b { font-size: 22px; }
.rg-card small { color: #475569; font-size: 13.5px; line-height: 1.4; }
.rg-card kbd { background: #e2e8f0; color: #334155; border-radius: 6px; padding: 1px 7px; font: 700 12px monospace; }

.rg-btns { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 460px; }
.rg-btn {
  background: #fff; color: #0f2f7f; border-radius: 16px; padding: 20px 18px; font-weight: 800; font-size: 19px;
  box-shadow: 0 8px 24px rgba(0,0,0,.30); display: flex; align-items: center; justify-content: center; gap: 12px;
}
.rg-btn:hover, .rg-btn:focus-visible { transform: translateY(-2px); background: #eff6ff; outline: 3px solid #60a5fa; }
.rg-btn svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.rg-op-badge { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .14em; font-size: 18px; }
.rg-op-badge .rg-ico { width: 52px; height: 52px; border-radius: 16px; background: linear-gradient(135deg,#2563eb,#1d4ed8); display: grid; place-items: center; }
.rg-op-badge svg { width: 30px; height: 30px; stroke: #fff; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rg-lines { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; width: 100%; max-width: 640px; margin-top: 12px; }
.rg-lines .rg-btn { font-size: 17px; padding: 22px 12px; }
.rg-lines .rg-btn.fill { color: #1d4ed8; }
.rg-lines .rg-btn.pack { color: #047857; }

.rg-form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; text-align: left; margin-top: 6px; }
.rg-form label { font-size: 13px; color: #cbd5e1; font-weight: 600; }
.rg-form input {
  width: 100%; box-sizing: border-box; padding: 13px 14px; border-radius: 12px; border: 2px solid transparent;
  font-size: 16px; background: #fff; color: #0f172a; margin-top: 5px;
}
.rg-form input:focus { outline: none; border-color: #60a5fa; }
.rg-pw { position: relative; }
.rg-pw button { position: absolute; right: 8px; top: 50%; transform: translateY(-30%); background: none; border: 0; color: #64748b; font-weight: 700; cursor: pointer; padding: 6px 8px; }
.rg-err { min-height: 20px; color: #fca5a5; font-size: 13.5px; font-weight: 600; }
.rg-err.shake { animation: rgShake .3s; }
@keyframes rgShake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.rg-submit { background: #0d9488; color: #fff; border: 0; border-radius: 12px; padding: 14px; font-weight: 800; font-size: 16px; cursor: pointer; }
.rg-submit:hover { background: #0f766e; }

@media (max-width: 560px) {
  .rg-cards { grid-template-columns: 1fr; gap: 14px; }
  .rg-card { padding: 24px 16px 20px; }
  .rg-lines { gap: 10px; }
  .rg-lines .rg-btn { font-size: 15px; padding: 18px 8px; }
}

/* ---------- Tombol Kembali: Sheet & Dashboard (Operator + Production Support) ---------- */
.rg-sheet-head, .rg-dash-head { display: none; align-items: center; gap: 12px; margin: 0 0 10px; }
body.role-operator.screen-logsheet .rg-sheet-head,
body.role-support.screen-logsheet .rg-sheet-head,
body.rg-sheet .rg-sheet-head { display: flex; }
body.role-operator.screen-weekly .rg-dash-head,
body.role-support.screen-weekly .rg-dash-head,
body.rg-dash .rg-dash-head { display: flex; padding: 8px 12px 0; }
.rg-sheet-head .rg-hback, .rg-dash-head .rg-hback, .rg-dash-back {
  background: #0f2f7f; color: #fff; border: 0; border-radius: 10px; padding: 9px 14px;
  font-family: inherit; font-weight: 700; font-size: 14px; line-height: 1; cursor: pointer; white-space: nowrap;
}
.rg-sheet-head h2 { margin: 0; font-size: clamp(16px, 3.4vw, 24px); font-weight: 800; letter-spacing: .02em; }
/* Judul sheet hanya relevan untuk Operator (sudah memilih line); support cukup tombol Kembali */
body.role-support .rg-sheet-head h2 { display: none; }
.rg-dash-back { display: none; width: calc(100% - 24px); margin: 10px 12px 4px; }
body.role-operator.screen-weekly .rg-dash-back,
body.role-support.screen-weekly .rg-dash-back,
body.rg-dash .rg-dash-back { display: block; }
/* Sidebar sudah punya tombol Kembali sendiri → di layar lebar sembunyikan yang di header agar tidak dobel */
@media (min-width: 900px) { .rg-dash-head { display: none !important; } }
@media (max-width: 899px) { .rg-dash-back { display: none !important; } }

/* ---------- Pembatasan role Operator (front-end) ---------- */
body.role-operator .screen-tab,
body.role-operator .rg-op-hide,
body.role-operator .sheet-process-tabs { display: none !important; }
/* Dashboard baca-saja */
body.role-operator .weekly-nav-item[data-weekly-page="issue"],
body.role-operator .weekly-nav-item[data-weekly-page="rincian-produk"],
body.role-operator .weekly-page[data-weekly-page="issue"],
body.role-operator .weekly-page[data-weekly-page="rincian-produk"],
body.role-operator #btnSpreadsheet,
body.role-operator #picaAddBtn,
body.role-operator #msAddBtn { display: none !important; }
/* Halaman hitungan OEE OPE / OEE 365 (baca-saja) tetap boleh dibuka Operator */
body.role-operator [data-go-screen]:not([data-go-screen="oee"]):not([data-go-screen="oee365"]) { pointer-events: none; }

.rg-fatal { margin: 14px 20px 0; padding: 12px 14px; border-radius: 12px; background: #7f1d1d; color: #fff;
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; font-size: 13.5px; }
.rg-fatal[hidden] { display: none; }
.rg-fatal code { background: rgba(255,255,255,.18); padding: 1px 6px; border-radius: 5px; }
.rg-fatal button { background: #fff; color: #7f1d1d; border: 0; border-radius: 8px; padding: 7px 12px; font-weight: 700; cursor: pointer; }

/* ---------- Production Support: bottom nav dihilangkan (layar penuh) ---------- */
/* Sheet · Dashboard · Speed Standar ada di Sidebar → Menu. Hanya tombol menu kecil yang melayang. */
body.role-support .bottom-nav .screen-tab,
body.role-support .bottom-nav .app-bar-profile { display: none !important; }
/* Operator tidak punya akses menu navigasi ini */
body.role-operator #btnSpeedStandarMenu,
body.role-operator #btnNavSheet,
body.role-operator #btnNavDashboard { display: none !important; }

@media (max-width: 1023px) {
  body.role-support .bottom-nav {
    left: auto !important; right: 10px !important; width: auto !important; max-width: none !important;
    transform: none !important; -webkit-transform: none !important;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    padding: 0 !important; background: transparent !important; border: 0 !important;
    box-shadow: none !important; backdrop-filter: none !important; overflow: visible !important;
    pointer-events: none !important;
  }
  body.role-support .bottom-nav .app-bar-menu-btn {
    pointer-events: auto !important; display: grid !important; place-items: center;
    width: 42px; height: 42px; border-radius: 50%; opacity: .88;
    background: var(--bg-surface, #fff); border: 1px solid rgba(0,0,0,.12);
    box-shadow: 0 2px 10px rgba(0,0,0,.22);
  }
  body.role-support,
  body.role-support #appContainer { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important; }
  body.role-support .install-banner { bottom: 64px; }
}

/* ---------- Operator: elemen Sheet yang disembunyikan ---------- */
body.role-operator #btnIsiMasal,
body.role-operator #btnBulkJson,
body.role-operator #sheetWeekBadge,
body.role-operator #compactProdTypePanel > div.compact-choice-list.compact-choice-prodtype > button:nth-child(2) { display: none !important; }


/* ---------- Ikon & Aksen Warna Tombol Line (Filling / Kemas) ---------- */
.rg-lines .rg-btn.fill {
  color: #0284c7;
  border: 1px solid rgba(6, 182, 212, 0.35);
}

.rg-lines .rg-btn.fill:hover,
.rg-lines .rg-btn.fill:focus-visible {
  background: rgba(6, 182, 212, 0.12);
  border-color: #00f0ff;
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.22);
}

.rg-lines .rg-btn.pack {
  color: #b45309;
  border: 1px solid rgba(245, 124, 0, 0.35);
}

.rg-lines .rg-btn.pack:hover,
.rg-lines .rg-btn.pack:focus-visible {
  background: rgba(245, 124, 0, 0.12);
  border-color: #f59e0b;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.2);
}

.rg-btn .rg-icon {
  flex-shrink: 0;
}

/* ---------- Wizard Operator: Tanggal & Shift / Input Produk ---------- */
.rg-field { width: 100%; max-width: 380px; text-align: left; margin-top: 14px; }
.rg-field label { display: block; font-size: 13px; color: #cbd5e1; font-weight: 600; margin-bottom: 5px; }
.rg-field input, .rg-field select {
  width: 100%; box-sizing: border-box; padding: 13px 14px; border-radius: 12px; border: 2px solid transparent;
  font-size: 16px; background: #fff; color: #0f172a; font-family: inherit;
}
.rg-field input:focus, .rg-field select:focus { outline: none; border-color: #60a5fa; }

.rg-shifts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.rg-shift-btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 800; font-size: 14px;
  background: rgba(255,255,255,.10); color: #fff; border: 2px solid rgba(255,255,255,.28);
  border-radius: 12px; padding: 14px 6px; transition: background .12s ease, border-color .12s ease;
}
.rg-shift-btn:hover { background: rgba(255,255,255,.18); }
.rg-shift-btn.on { background: #2563eb; border-color: #60a5fa; }

.rg-next, .rg-start { width: 100%; max-width: 380px; margin-top: 22px; }
.rg-submit[disabled] { opacity: .45; cursor: not-allowed; }
.rg-submit[disabled]:hover { background: #0d9488; }

.rg-pgroup { width: 100%; max-width: 460px; margin-top: 18px; padding: 14px 16px 6px; border-radius: 16px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.14); }
.rg-pgroup-title { font-weight: 800; font-size: 15px; text-align: left; margin-bottom: 4px; }
.rg-req { color: #fca5a5; font-weight: 700; font-size: 12px; margin-left: 4px; }
.rg-pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.rg-pgrid .rg-field { max-width: none; margin-top: 12px; }

.rg-addcadangan {
  appearance: none; background: none; border: 1px dashed rgba(255,255,255,.4); color: #93c5fd;
  border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 700; font-size: 13.5px; cursor: pointer;
  margin-top: 18px; width: 100%; max-width: 380px;
}
.rg-addcadangan:hover { background: rgba(255,255,255,.08); }
.rg-addcadangan[hidden] { display: none; }

@media (max-width: 560px) {
  .rg-pgrid { grid-template-columns: 1fr; }
}
/* ---------- Header sheet Operator: judul + label navigasi ---------- */
.rg-sheet-titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.rg-sheet-nav {
  align-self: flex-start; display: none; font-size: 12px; font-weight: 800; letter-spacing: .06em;
  padding: 4px 10px; border-radius: 999px; background: #e6f4f1; color: #0b6b5f; border: 1px solid #b7e0d8;
}
body.role-operator .rg-sheet-nav { display: inline-block; }
.rg-sheet-nav.is-unset { background: #fff1f0; color: #b42318; border-color: #f7c1bb; }

/* Warna per Shift */
.rg-sheet-nav.is-shift-1 { background: #f3e8ff; color: #6b21a8; border-color: #d8b4fe; } /* Ungu */
.rg-sheet-nav.is-shift-2 { background: #ffedd5; color: #c2410c; border-color: #fdba74; } /* Oranye */
.rg-sheet-nav.is-shift-3 { background: #fef9c3; color: #854d0e; border-color: #fde047; } /* Kuning */

/* ---------- Kunci tabel sampai Shift/Periode/OPR/Produk lengkap ---------- */
.rg-lock-banner {
  display: flex; align-items: center; gap: 12px; width: 100%; margin: 8px 0; padding: 12px 14px;
  background: #fff7ed; color: #7c2d12; border: 1.5px dashed #f59e0b; border-radius: 12px;
  font-family: inherit; text-align: left; cursor: pointer;
}
.rg-lock-banner[hidden] { display: none; }
.rg-lock-banner svg { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rg-lock-txt { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.rg-lock-txt b { font-size: 14px; }
.rg-lock-txt small { font-size: 12.5px; opacity: .9; }
.rg-lock-go { font-weight: 800; font-size: 13px; white-space: nowrap; }
body.rg-sheet-locked #tblWrap { opacity: .4; filter: grayscale(.5); pointer-events: none; user-select: none; }
.compact-control.rg-missing > .compact-trigger {
  border-color: #ef4444 !important; box-shadow: 0 0 0 2px rgba(239,68,68,.22);
  animation: rgMissingPulse 1.4s ease-in-out infinite;
}
@keyframes rgMissingPulse { 50% { box-shadow: 0 0 0 5px rgba(239,68,68,.08); } }
@media (prefers-reduced-motion: reduce) { .compact-control.rg-missing > .compact-trigger { animation: none; } }

/* Tombol Kembali di halaman hitungan OEE OPE / OEE 365 */
.oee-back-row { margin: 0 0 10px; }
.oee-back-btn { font-weight: 700; }
