/**
 * Design Tokens & Theme Variables: Portal Pemberkasan Tunjangan Guru
 * Kemenag Kab. Bolaang Mongondow Utara
 * Standar Aksesibilitas WCAG AA (Kontras Min 4.5:1)
 * Perbaikan Anti-Overlap, Anti-Covered Header & Seamless Floating Layout
 */

:root {
  /* =========================================================================
     1. BRAND COLORS (KEMENAG GREEN THEME)
     ========================================================================= */
  --color-primary-950: #052e16;
  --color-primary-900: #14532d;
  --color-primary-800: #166534;
  --color-primary-700: #15803d; /* Warna Utama Resmi Kemenag */
  --color-primary-600: #16a34a; /* Accent Hijau Segar */
  --color-primary-500: #22c55e;
  --color-primary-400: #4ade80;
  --color-primary-200: #bbf7d0;
  --color-primary-100: #dcfce7;
  --color-primary-50:  #f0fdf4;

  /* Theme Dynamic Default (bisa di-override per jenis form TPG/TUKIN/Inpassing) */
  --theme-primary: #15803d;
  --theme-accent: #16a34a;
  --theme-soft: #dcfce7;
  --theme-bg: #f0fdf4;
  --theme-dark: #14532d;

  /* Neutral & Grayscale */
  --color-white: #ffffff;
  --color-slate-50: #f8fafc;
  --color-slate-100: #f1f5f9;
  --color-slate-200: #e2e8f0;
  --color-slate-300: #cbd5e1;
  --color-slate-400: #94a3b8;
  --color-slate-500: #64748b;
  --color-slate-600: #475569;
  --color-slate-700: #334155;
  --color-slate-800: #1e293b;
  --color-slate-900: #0f172a;

  /* Base Typography */
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-inverse: #ffffff;
  --card-border: #e2e8f0;

  /* =========================================================================
     2. STATUS COLORS (WCAG AA COMPLIANT)
     ========================================================================= */
  --status-approved-bg: #ecfdf5;
  --status-approved-border: #86efac;
  --status-approved-text: #065f46;
  --status-approved-icon: #059669;

  --status-pending-bg: #fffbeb;
  --status-pending-border: #fde68a;
  --status-pending-text: #92400e;
  --status-pending-icon: #d97706;

  --status-rejected-bg: #fff1f2;
  --status-rejected-border: #fecdd3;
  --status-rejected-text: #9f1239;
  --status-rejected-icon: #e11d48;

  --status-info-bg: #f0f9ff;
  --status-info-border: #bae6fd;
  --status-info-text: #0369a1;
  --status-info-icon: #0284c7;

  /* =========================================================================
     3. SPACING, ELEVATION, RADIUS
     ========================================================================= */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.12);
  --shadow-sticky: 0 4px 20px rgba(15, 23, 42, 0.08);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* =========================================================================
   SCROLL MARGIN FIX & VIEWPORT OVERFLOW PROTECTION (ANTI-HORIZONTAL BLOWOUT)
   ========================================================================= */
html {
  scroll-behavior: smooth;
  overflow-x: hidden !important;
  max-width: 100vw !important;
  width: 100% !important;
}

body {
  overflow-x: hidden !important;
  max-width: 100vw !important;
  width: 100% !important;
  position: relative;
}

*, *::before, *::after {
  box-sizing: border-box;
}

.gform-card,
.gform-header-card,
.action-center-card,
.stepper-nav-container,
.ecommerce-timeline-card,
.recipient-banner,
.berkas-tracker-card,
.doc-item-card,
#step3ReviewCard,
#cardStatusLkhPengawas,
#cardIdentitasPeriode {
  scroll-margin-top: 115px !important;
  max-width: 100%;
  box-sizing: border-box;
}

#sectionRingkasan,
#sectionUploadBerkas {
  scroll-margin-top: 115px !important;
}

/* Container Utama Dashboard Guru (Desktop: Terpusat, Proporsional ~900px, Tidak Melar Ekstrem) */
.gform-container {
  max-width: 900px;
  margin: 1.5rem auto 0;
  padding: 0 1rem;
  width: 100%;
  box-sizing: border-box;
}

/* Step 3: Desktop Table vs Mobile Cards */
.step3-table-desktop {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.step3-cards-mobile {
  display: none;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* =========================================================================
   4. UNIFIED STICKY HEADER & COMPACT COUNTDOWN (DEKLUTTERING MOBILE & BALANCED DESKTOP)
   ========================================================================= */
.top-bar-unified {
  background: #ffffff;
  border-bottom: 1px solid var(--color-slate-200);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.top-bar-unified-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  width: 100%;
  box-sizing: border-box;
}

/* Sub-header Countdown Pill Kompak (Setinggi ~34px, Tidak Memotong Layar) */
.compact-countdown-subbar {
  background: linear-gradient(90deg, #14532d 0%, #15803d 100%);
  color: #ffffff;
  padding: 0.35rem 1rem;
  font-size: 0.78rem;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.compact-countdown-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem;
  width: 100%;
  box-sizing: border-box;
}

.compact-cd-timer {
  font-weight: 800;
  color: #fef08a;
  letter-spacing: 0.2px;
}

.compact-cd-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.18);
  font-size: 0.72rem;
  font-weight: 700;
}

/* =========================================================================
   5. PWA NON-INTRUSIVE BOTTOM SHEET / FLOATING ACTION PILL
   ========================================================================= */
.pwa-bottom-pill {
  position: fixed;
  bottom: 5.5rem;
  right: 1.25rem;
  z-index: 999;
  background: linear-gradient(135deg, #14532d 0%, #16a34a 100%);
  color: #ffffff;
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius-full);
  box-shadow: 0 8px 24px rgba(21, 128, 61, 0.35);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  animation: slideUpFloat 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.pwa-bottom-pill:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(21, 128, 61, 0.45);
}

.pwa-btn-install {
  background: #ffffff;
  color: #15803d;
  font-weight: 800;
  border: none;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 0.76rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.pwa-btn-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #ffffff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

@keyframes slideUpFloat {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================================================================
   6. ACTION CENTER (KOTAK TINDAKAN CEPAT PRIORITAS GURU)
   ========================================================================= */
.action-center-card {
  margin-bottom: 1.15rem;
  border-radius: var(--radius-md);
  padding: 1.15rem 1.4rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
  position: relative;
  z-index: 10;
}

.action-center-card.has-urgent {
  background: linear-gradient(135deg, #fff1f2 0%, #ffffff 100%);
  border: 2px solid var(--status-rejected-border);
  border-left: 6px solid var(--status-rejected-icon);
}

.action-center-card.all-clear {
  background: linear-gradient(135deg, #ecfdf5 0%, #ffffff 100%);
  border: 1.5px solid var(--status-approved-border);
  border-left: 6px solid var(--status-approved-icon);
}

.action-center-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.45rem;
}

.action-badge-urgent {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #fee2e2;
  color: var(--status-rejected-text);
  font-weight: 800;
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
}

.action-item-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.65rem;
}

.action-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: #ffffff;
  border: 1px solid var(--color-slate-200);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
}

.btn-action-jump {
  background: var(--status-rejected-icon);
  color: #ffffff;
  border: none;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition-fast);
}

.btn-action-jump:hover,
.btn-action-jump:active {
  background: #be123c;
  transform: translateY(-1px);
}

/* =========================================================================
   7. STEPPER WIZARD WORKFLOW (3 TAHAP UTAMA GURU)
   ========================================================================= */
.stepper-nav-container {
  background: #ffffff;
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 10;
}

.stepper-nav-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.stepper-tab-btn {
  background: var(--color-slate-50);
  border: 1.5px solid var(--color-slate-200);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-normal);
  position: relative;
  width: 100%;
}

.stepper-tab-btn:hover:not(:disabled) {
  border-color: var(--color-primary-600);
  background: #ffffff;
  transform: translateY(-1px);
}

.stepper-tab-btn.active {
  background: var(--color-primary-50);
  border-color: var(--color-primary-700);
  box-shadow: 0 0 0 2px rgba(21, 128, 61, 0.18);
}

.stepper-tab-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--color-slate-100);
}

.stepper-num-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.88rem;
  flex-shrink: 0;
  background: var(--color-slate-200);
  color: var(--color-slate-700);
  transition: all var(--transition-fast);
}

.stepper-tab-btn.active .stepper-num-badge {
  background: var(--color-primary-700);
  color: #ffffff;
}

.stepper-tab-btn.is-completed .stepper-num-badge {
  background: var(--color-primary-600);
  color: #ffffff;
}

.stepper-text-group {
  flex: 1;
  min-width: 0;
}

.stepper-step-label {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-slate-500);
}

.stepper-tab-btn.active .stepper-step-label {
  color: var(--color-primary-700);
}

.stepper-step-title {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--color-slate-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================================
   8. STICKY BOTTOM ACTION BAR (ANTI-OVERLAP DENGAN FAB WA & NAVBAR MOBILE)
   ========================================================================= */
.sticky-bottom-action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border-top: 1.5px solid var(--color-slate-200);
  padding: 0.65rem 1.25rem;
  z-index: 9980;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
}

.sticky-bottom-action-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  width: 100%;
  box-sizing: border-box;
}

.bottom-progress-info {
  display: flex;
  flex-direction: column;
}

.bottom-progress-title {
  font-size: 0.86rem;
  font-weight: 800;
  color: var(--color-slate-900);
}

.bottom-progress-sub {
  font-size: 0.74rem;
  color: var(--color-slate-500);
}

.bottom-actions-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* FAB Tanya Petugas WA di Desktop: geser ke atas agar TIDAK MENUTUPI tombol bottom action bar! */
@media (min-width: 769px) {
  .fab-wa-helpdesk {
    bottom: 82px !important;
    right: 24px !important;
    z-index: 9995 !important;
  }
}

/* =========================================================================
   9. HAPTIC & TOAST NOTIFICATIONS (MUNCUL DI POJOK KANAN ATAS, TIDAK MENUTUPI TOMBOL BAWAH)
   ========================================================================= */
.toast-container-corner {
  position: fixed;
  top: 105px;
  right: 1.25rem;
  bottom: auto;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast-micro {
  pointer-events: auto;
  background: #ffffff;
  color: var(--color-slate-900);
  border: 1px solid var(--color-slate-200);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.15);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.84rem;
  font-weight: 600;
  min-width: 280px;
  max-width: 420px;
  transform: translateY(-20px);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  opacity: 0;
}

.toast-micro.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-micro.success {
  border-left: 4px solid var(--status-approved-icon);
}

.toast-micro.danger {
  border-left: 4px solid var(--status-rejected-icon);
}

.toast-micro.warning {
  border-left: 4px solid var(--status-pending-icon);
}

.toast-micro.info {
  border-left: 4px solid var(--status-info-icon);
}

/* WA Helpdesk floating button lift on desktop so it doesn't overlap bottom action bar */
.fab-wa-helpdesk {
  position: fixed !important;
  bottom: 84px !important;
  right: 24px !important;
  z-index: 995 !important;
}

/* =========================================================================
   10. RESPONSIVE BREAKPOINTS (MOBILE & TABLET ADAPTATION)
   ========================================================================= */
@media (max-width: 768px) {
  body {
    padding-bottom: calc(9.2rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Unified Header: Sangat Kompak & Pas di Layar Smartphone */
  .top-bar-unified-inner {
    padding: 0.45rem 0.75rem;
    gap: 0.5rem;
  }

  .brand-mini {
    gap: 0.5rem;
  }

  .brand-mini img {
    width: 32px;
    height: 32px;
  }

  .brand-mini-text h4 {
    font-size: 0.84rem;
    line-height: 1.15;
  }

  .brand-mini-text span {
    font-size: 0.68rem;
  }

  .user-bar-actions {
    gap: 0.35rem;
  }

  .btn-topbar-petunjuk,
  .teacher-chip,
  .btn-logout {
    height: 32px;
    padding: 0 0.55rem;
    font-size: 0.74rem;
  }

  .teacher-chip {
    max-width: 120px;
  }

  .teacher-chip-name {
    max-width: 90px;
  }

  /* Countdown Stripe Kompak */
  .top-bar-countdown-inner {
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
  }

  /* Stepper Bar: 3-Kolom Wizard Kompak Ala Mobile App (Menghemat 120px layar vertikal) */
  .stepper-nav-container {
    padding: 0.4rem;
    margin-bottom: 0.75rem;
    border-radius: var(--radius-sm);
  }

  .stepper-nav-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.3rem !important;
  }

  .stepper-tab-btn {
    padding: 0.45rem 0.25rem !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    min-height: 52px;
    gap: 0.2rem !important;
    border-radius: 8px !important;
  }

  .stepper-num-badge {
    width: 22px !important;
    height: 22px !important;
    font-size: 0.7rem !important;
  }

  .stepper-step-label {
    display: none !important;
  }

  .stepper-step-title {
    font-size: 0.66rem !important;
    font-weight: 700 !important;
    line-height: 1.15 !important;
    white-space: normal !important;
    text-align: center !important;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Action Center Mobile */
  .action-center-card {
    padding: 0.85rem 1rem !important;
    margin-bottom: 0.85rem !important;
  }

  .action-center-card h3 {
    font-size: 0.92rem !important;
  }

  .action-item-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.5rem !important;
  }

  .btn-action-jump {
    width: 100% !important;
    justify-content: center !important;
    padding: 0.55rem !important;
  }

  /* PWA Floating Pill: Tepat di Atas Action Bar */
  .pwa-bottom-pill {
    bottom: calc(118px + env(safe-area-inset-bottom, 0px)) !important;
    right: 0.65rem !important;
    left: 0.65rem !important;
    padding: 0.45rem 0.8rem !important;
    z-index: 9975 !important;
    justify-content: space-between;
  }

  /* Sticky Bottom Action Bar: Tepat di Atas Mobile Bottom Navbar (~56px) */
  .sticky-bottom-action-bar {
    bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
    padding: 0.45rem 0.75rem !important;
    border-bottom: 1px solid var(--color-slate-200);
    z-index: 9980 !important;
  }

  .sticky-bottom-action-inner {
    gap: 0.45rem !important;
  }

  .bottom-progress-title {
    font-size: 0.76rem !important;
    font-weight: 800;
  }

  .bottom-progress-sub {
    font-size: 0.68rem !important;
    max-width: 135px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .bottom-actions-group button {
    padding: 0.45rem 0.8rem !important;
    font-size: 0.78rem !important;
    white-space: nowrap;
  }

  /* Toast Notification: Di Bawah Header, Tidak Menutupi Action Bar */
  .toast-container-corner {
    top: calc(96px + env(safe-area-inset-top, 0px)) !important;
    right: 0.65rem !important;
    left: 0.65rem !important;
    bottom: auto !important;
    z-index: 99999 !important;
  }

  .toast-micro {
    min-width: unset;
    max-width: 100%;
    padding: 0.65rem 0.85rem;
    font-size: 0.8rem;
  }

  .fab-wa-helpdesk {
    display: none !important;
  }
}

/* =========================================================================
   11. EXTRA SMALL PHONES (iPhone SE, Galaxy A series < 440px)
   ========================================================================= */
@media (max-width: 440px) {
  .brand-mini-text span {
    display: none !important;
  }

  .btn-topbar-petunjuk span,
  .btn-logout span {
    display: none !important;
  }

  .btn-topbar-petunjuk,
  .btn-logout {
    padding: 0 0.5rem !important;
  }

  .teacher-chip {
    max-width: 95px !important;
  }

  .teacher-chip-name {
    max-width: 65px !important;
  }

  #stickyCountdownLabel {
    display: none !important;
  }

  .countdown-sub-badge {
    font-size: 0.64rem !important;
    padding: 0.12rem 0.35rem !important;
  }

  .bottom-progress-sub {
    max-width: 105px !important;
  }
}
