/**
 * File:        assets/css/jsm-base.css
 * Purpose:     CSS variables (brand palette) + base utility classes (button, notice, modal, toast).
 *              Di-enqueue di semua page yang load JSM asset.
 * Dependencies: none
 * Public:      CSS variables --jsm-*, utility classes .jsm-*
 * Notes:
 *   - Brand: yellow-green (#D4F870) accent + dark blue (#212F8A) primary.
 *   - Scope: CSS variables di-define di :root supaya bisa di-override user via Custom CSS.
 *   - Utility class diawali .jsm- (internal styling). Class .js- adalah hook JS (jangan style di sini).
 *   - Animasi smooth dengan --jsm-transition.
 */

/* ============================================================
   COLOR PALETTE & DESIGN TOKENS
   ============================================================ */
:root {
  /* Brand */
  --jsm-primary:           #212F8A;
  --jsm-primary-hover:     #1a2570;
  --jsm-primary-active:    #141d5c;
  --jsm-primary-soft:      #e8eaf6;

  --jsm-accent:            #D4F870;
  --jsm-accent-hover:      #c4e85f;
  --jsm-accent-active:     #b4d850;
  --jsm-accent-soft:       #f0fbd8;

  /* Text */
  --jsm-text:              #0f172a;
  --jsm-text-muted:        #64748b;
  --jsm-text-on-primary:   #ffffff;
  --jsm-text-on-accent:    #212F8A;

  /* Surface */
  --jsm-bg:                #ffffff;
  --jsm-bg-soft:           #f8fafc;
  --jsm-border:            #cbd5e1;
  --jsm-border-strong:     #94a3b8;

  /* State */
  --jsm-error:             #dc2626;
  --jsm-error-bg:          #fef2f2;
  --jsm-error-border:      #fecaca;
  --jsm-warning:           #ca8a04;
  --jsm-warning-bg:        #fff8e1;
  --jsm-warning-border:    #fde68a;
  --jsm-success:           var(--jsm-accent);
  --jsm-success-bg:        var(--jsm-accent-soft);

  /* Shape */
  --jsm-radius:            14px;
  --jsm-radius-sm:         10px;
  --jsm-radius-xs:         6px;
  --jsm-radius-pill:       999px;

  /* Shadow */
  --jsm-shadow-sm:         0 1px 2px rgba(33,47,138,.06);
  --jsm-shadow:            0 4px 16px rgba(33,47,138,.10);
  --jsm-shadow-lg:         0 14px 32px rgba(33,47,138,.18);
  --jsm-focus-ring:        0 0 0 3px rgba(212,248,112,.45);

  /* Motion */
  --jsm-transition:        all .2s ease;
  --jsm-transition-fast:   all .12s ease;

  /* Layout */
  --jsm-z-modal:           2147483000;
  --jsm-z-toast:           2147483100;
}

/* ============================================================
   BUTTONS — .jsm-btn variants
   Self-contained (appearance:none) supaya tidak inherit theme.
   ============================================================ */
.jsm-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid transparent;
  border-radius: var(--jsm-radius-pill);
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  font-family: inherit;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  transition: var(--jsm-transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  position: relative;
  overflow: hidden;
}
.jsm-btn:focus-visible {
  outline: none;
  box-shadow: var(--jsm-focus-ring);
}
.jsm-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none !important;
}

/* Primary = yellow-green (CTA utama) */
.jsm-btn-primary {
  background: var(--jsm-accent);
  border-color: var(--jsm-accent);
  color: var(--jsm-text-on-accent);
  font-weight: 700;
}
.jsm-btn-primary:hover:not(:disabled) {
  background: var(--jsm-accent-hover);
  border-color: var(--jsm-accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(33,47,138,.18);
}
.jsm-btn-primary:active:not(:disabled) {
  background: var(--jsm-accent-active);
  border-color: var(--jsm-accent-active);
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(33,47,138,.18);
}

/* Secondary = dark blue (action sekunder) */
.jsm-btn-secondary {
  background: var(--jsm-primary);
  border-color: var(--jsm-primary);
  color: var(--jsm-text-on-primary);
}
.jsm-btn-secondary:hover:not(:disabled) {
  background: var(--jsm-primary-hover);
  border-color: var(--jsm-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(33,47,138,.25);
}
.jsm-btn-secondary:active:not(:disabled) {
  background: var(--jsm-primary-active);
  transform: translateY(0);
}

/* Outline = transparent dengan border primary */
.jsm-btn-outline {
  background: transparent;
  border-color: var(--jsm-primary);
  color: var(--jsm-primary);
}
.jsm-btn-outline:hover:not(:disabled) {
  background: var(--jsm-primary-soft);
}

/* Ghost = sangat ringan, untuk action tertiary (Batal, dll) */
.jsm-btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--jsm-text-muted);
}
.jsm-btn-ghost:hover:not(:disabled) {
  background: var(--jsm-bg-soft);
  color: var(--jsm-text);
}

/* Danger = red */
.jsm-btn-danger {
  background: var(--jsm-error);
  border-color: var(--jsm-error);
  color: #fff;
}
.jsm-btn-danger:hover:not(:disabled) {
  background: #b91c1c;
  border-color: #b91c1c;
}

/* Size modifiers */
.jsm-btn-sm { padding: 7px 14px; font-size: 13px; }
.jsm-btn-lg { padding: 14px 28px; font-size: 16px; }
.jsm-btn-block { width: 100%; }

/* Pulse animation — untuk CTA yang perlu attention */
.jsm-btn-pulse {
  animation: jsmPulse 1.4s ease-in-out 2;
}
@keyframes jsmPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(33, 47, 138, .4); }
  50%      { box-shadow: 0 0 0 8px rgba(33, 47, 138, 0); }
}

/* Field highlight (pakai untuk "Pakai Nomor Lain" feedback) */
.jsm-field-highlight {
  animation: jsmFieldPulse 1.5s ease-in-out;
  border-color: var(--jsm-error) !important;
}
@keyframes jsmFieldPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
  30%      { box-shadow: 0 0 0 4px rgba(220, 38, 38, .25); }
  70%      { box-shadow: 0 0 0 4px rgba(220, 38, 38, .15); }
}

/* ============================================================
   ALERT MODAL — generic alert dengan variant warning/error/info
   ============================================================ */
.jsm-modal-alert-dialog { max-width: 400px; text-align: center; }
.jsm-alert-icon {
  width: 56px; height: 56px;
  margin: 4px auto 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.jsm-alert-icon svg { width: 30px; height: 30px; }

/* Variant colors */
.jsm-modal-alert-dialog[data-jsm-alert-variant="info"]    .jsm-alert-icon { background: var(--jsm-primary-soft); color: var(--jsm-primary); }
.jsm-modal-alert-dialog[data-jsm-alert-variant="warning"] .jsm-alert-icon { background: var(--jsm-warning-bg); color: var(--jsm-warning); }
.jsm-modal-alert-dialog[data-jsm-alert-variant="error"]   .jsm-alert-icon { background: var(--jsm-error-bg); color: var(--jsm-error); }
.jsm-modal-alert-dialog[data-jsm-alert-variant="success"] .jsm-alert-icon { background: var(--jsm-accent-soft); color: var(--jsm-text-on-accent); }

.jsm-alert-title { margin: 0 0 8px; font-size: 18px; }
.jsm-alert-body  { margin: 0 0 18px; color: var(--jsm-text); font-size: 14px; line-height: 1.5; }
.jsm-alert-actions { justify-content: center; }

/* ============================================================
   MODAL HELP — "Hubungi Admin" button di footer modal
   ============================================================ */
.jsm-modal-help {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--jsm-border);
  text-align: center;
}
.jsm-btn-help {
  background: transparent;
  border: 0;
  color: var(--jsm-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--jsm-radius-xs);
  transition: var(--jsm-transition-fast);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.jsm-btn-help:hover {
  background: var(--jsm-primary-soft);
}
.jsm-btn-help:disabled {
  opacity: .4;
  cursor: not-allowed;
}
/* Hide help button kalau no support number set (JS akan toggle via .jsm-help-hidden) */
.jsm-modal-help.jsm-help-hidden { display: none; }

/* ============================================================
   SUCCESS MODAL — checkmark icon + countdown progress bar
   ============================================================ */
.jsm-modal-success-dialog {
  max-width: 380px;
  text-align: center;
}
.jsm-success-icon {
  width: 68px;
  height: 68px;
  margin: 6px auto 18px;
  border-radius: 50%;
  background: var(--jsm-accent);
  color: var(--jsm-text-on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: jsmSuccessPop .45s cubic-bezier(.34, 1.56, .64, 1);
  box-shadow: 0 8px 20px rgba(33, 47, 138, .15);
}
.jsm-success-icon svg {
  width: 36px;
  height: 36px;
  stroke-dasharray: 50;
  stroke-dashoffset: 50;
  animation: jsmCheckDraw .5s .2s cubic-bezier(.65, 0, .35, 1) forwards;
}
@keyframes jsmSuccessPop {
  0%   { opacity: 0; transform: scale(.5); }
  60%  { opacity: 1; transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes jsmCheckDraw {
  to { stroke-dashoffset: 0; }
}

.jsm-success-title {
  margin: 0 0 6px;
  font-size: 20px;
  color: var(--jsm-text);
}
.jsm-success-subtitle {
  margin: 0 0 22px;
  color: var(--jsm-text-muted);
  font-size: 14px;
}
.jsm-success-subtitle strong {
  color: var(--jsm-primary);
  font-weight: 700;
}

.jsm-countdown {
  margin-top: 4px;
}
.jsm-countdown-label {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--jsm-text-muted);
}
.jsm-countdown-label span {
  display: inline-block;
  min-width: 1ch;
  font-weight: 700;
  color: var(--jsm-primary);
}

/* Progress bar — bar yang menyusut */
.jsm-progress {
  width: 100%;
  height: 6px;
  background: var(--jsm-bg-soft);
  border-radius: var(--jsm-radius-pill);
  overflow: hidden;
}
.jsm-progress-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--jsm-accent), var(--jsm-accent-hover));
  border-radius: var(--jsm-radius-pill);
  transition: width 3s linear; /* duration di-override via inline style oleh JS */
}

/* ============================================================
   FORM CONTROLS — .jsm-input, .jsm-textarea, .jsm-select, .jsm-label
   ============================================================ */
.jsm-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--jsm-text);
}

.jsm-input,
.jsm-textarea,
.jsm-select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--jsm-border);
  border-radius: var(--jsm-radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--jsm-bg);
  color: var(--jsm-text);
  transition: var(--jsm-transition-fast);
  box-sizing: border-box;
}
.jsm-input:focus,
.jsm-textarea:focus,
.jsm-select:focus {
  outline: none;
  border-color: var(--jsm-primary);
  box-shadow: 0 0 0 3px rgba(33,47,138,.15);
}
.jsm-input::placeholder,
.jsm-textarea::placeholder { color: var(--jsm-text-muted); }
.jsm-input:disabled,
.jsm-textarea:disabled,
.jsm-select:disabled {
  background: var(--jsm-bg-soft);
  color: var(--jsm-text-muted);
  cursor: not-allowed;
}

.jsm-field { margin-bottom: 16px; }
.jsm-field-hint {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--jsm-text-muted);
}
.jsm-field-required { color: var(--jsm-error); margin-left: 2px; }

/* OTP input — large, letter-spaced */
.jsm-input-otp {
  font-size: 26px;
  letter-spacing: 8px;
  text-align: center;
  font-weight: 700;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  padding: 14px;
}

/* ============================================================
   NOTICE — inline alert block (warning, error, info, success)
   ============================================================ */
.jsm-notice {
  padding: 12px 14px;
  border-radius: var(--jsm-radius-sm);
  font-size: 13.5px;
  line-height: 1.45;
  border: 1px solid transparent;
  margin: 12px 0;
}
.jsm-notice strong { display: block; margin-bottom: 2px; font-size: 14px; }

.jsm-notice-warning {
  background: var(--jsm-warning-bg);
  border-color: var(--jsm-warning-border);
  color: #854d0e;
}
.jsm-notice-error {
  background: var(--jsm-error-bg);
  border-color: var(--jsm-error-border);
  color: var(--jsm-error);
}
.jsm-notice-success {
  background: var(--jsm-success-bg);
  border-color: var(--jsm-accent);
  color: var(--jsm-text-on-accent);
}
.jsm-notice-info {
  background: var(--jsm-primary-soft);
  border-color: var(--jsm-primary);
  color: var(--jsm-primary);
}

/* ============================================================
   MODAL — base structure (.jsm-modal + variants)
   ============================================================ */
.jsm-modal {
  position: fixed;
  inset: 0;
  z-index: var(--jsm-z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.jsm-modal.jsm-modal-open { display: flex; }

.jsm-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  cursor: pointer;
  animation: jsmFadeIn .2s ease;
}
.jsm-modal-dialog {
  position: relative;
  z-index: 1;
  background: var(--jsm-bg);
  border-radius: var(--jsm-radius);
  padding: 28px 24px 24px;
  max-width: 440px;
  width: 100%;
  max-height: 92vh;
  overflow: auto;
  box-shadow: var(--jsm-shadow-lg);
  animation: jsmSlideUp .25s cubic-bezier(.16,1,.3,1);
}

.jsm-modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--jsm-text-muted);
  border-radius: 50%;
  transition: var(--jsm-transition-fast);
}
.jsm-modal-close:hover {
  background: var(--jsm-bg-soft);
  color: var(--jsm-text);
}
.jsm-modal-back {
  position: absolute;
  top: 12px;
  left: 14px;
  border: 0;
  background: transparent;
  font-size: 13px;
  color: var(--jsm-text-muted);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--jsm-radius-xs);
  transition: var(--jsm-transition-fast);
}
.jsm-modal-back:hover {
  background: var(--jsm-bg-soft);
  color: var(--jsm-text);
}

.jsm-modal-title {
  margin: 0 28px 6px 0;
  font-size: 19px;
  font-weight: 700;
  color: var(--jsm-text);
}
.jsm-modal-subtitle {
  margin: 0 0 18px;
  color: var(--jsm-text-muted);
  font-size: 13.5px;
  line-height: 1.5;
}

.jsm-modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.jsm-modal-actions .jsm-btn { flex: 1 1 calc(50% - 4px); min-width: 0; }
.jsm-modal-actions .jsm-btn-block { flex: 1 1 100%; }

.jsm-modal-meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--jsm-text-muted);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

/* Body lock saat modal open */
body.jsm-modal-body-lock { overflow: hidden; }

/* Status message di dalam modal */
.jsm-status {
  margin-top: 12px;
  min-height: 18px;
  font-size: 13px;
  line-height: 1.45;
}
.jsm-status-error { color: var(--jsm-error); }
.jsm-status-ok    { color: var(--jsm-primary); }
.jsm-status-info  { color: var(--jsm-text-muted); }

/* Multi-step modal: hide non-active step */
.jsm-modal-step { display: none; }
.jsm-modal-step.jsm-step-active { display: block; }

/* Animations */
@keyframes jsmFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes jsmSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ============================================================
   TOAST — top-center placement, prominent & responsive
   ============================================================ */
.js-toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--jsm-z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  width: 100%;
  max-width: 480px;
  padding: 0 16px;
  box-sizing: border-box;
}
.js-toast {
  padding: 14px 20px;
  border-radius: var(--jsm-radius-sm);
  background: var(--jsm-primary);
  color: var(--jsm-text-on-primary);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: auto;
  box-shadow: var(--jsm-shadow-lg);
  text-align: center;
}
.js-toast.js-toast-visible { opacity: 1; transform: translateY(0); }
.js-toast-success {
  background: var(--jsm-accent);
  color: var(--jsm-text-on-accent);
  font-weight: 600;
}
.js-toast-error {
  background: var(--jsm-error);
  color: #fff;
}
.js-toast-warn {
  background: var(--jsm-warning);
  color: #fff;
}
.js-toast-info {
  background: var(--jsm-primary);
  color: var(--jsm-text-on-primary);
}

/* ============================================================
   UTILITY — loading, hidden, visible
   ============================================================ */
.js-loading { opacity: .6; pointer-events: none; }

/* Display element show/hide pattern (toggle .js-visible) */
.js-display-public-register-error,
.js-display-public-success,
.js-trigger-public-show-login {
  display: none;
}
.js-display-public-register-error.js-visible,
.js-display-public-success.js-visible,
.js-trigger-public-show-login.js-visible {
  display: block;
}

/* ============================================================
   MOBILE RESPONSIVE — bottom sheet modal, full-width top toast
   ============================================================ */
@media (max-width: 600px) {
  /* Modal jadi bottom sheet */
  .jsm-modal {
    padding: 0;
    align-items: flex-end;
  }
  .jsm-modal-dialog {
    max-width: none;
    width: 100%;
    border-radius: var(--jsm-radius) var(--jsm-radius) 0 0;
    padding: 24px 18px 28px;
    max-height: 90vh;
    animation: jsmSlideUpMobile .28s cubic-bezier(.16,1,.3,1);
  }
  .jsm-modal-close { top: 10px; right: 12px; }

  /* Action buttons stack vertical di mobile */
  .jsm-modal-actions { flex-direction: column; gap: 8px; }
  .jsm-modal-actions .jsm-btn { flex: 1 1 100%; width: 100%; }

  /* Toast full-width top */
  .js-toast-container {
    top: 12px;
    max-width: none;
    padding: 0 12px;
  }
  .js-toast { font-size: 13.5px; padding: 12px 16px; }
}
@keyframes jsmSlideUpMobile {
  from { opacity: 0; transform: translateY(100%); }
  to   { opacity: 1; transform: translateY(0); }
}
