/* ============================================================
   DESIGN TOKENS (Standar UI)
   ============================================================ */
:root {
  color-scheme: light;
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --text: #1A2332;
  --text-soft: #6B7785;
  --text-mute: #6B7280;
  --border: #E8E5DF;
  --border-soft: #F0EEE9;
  --navy: #2E4A6B;
  --navy-soft: #E6EBF1;
  --gold: #D4A44A;
  --teal: #5BA8A8;
  --radius: 14px;
  --radius-lg: 24px;
  --header-height: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ref-bg: #faf8f2;
  --ref-text: #6B7785;
  --latar-bg: linear-gradient(135deg, #fafaf7 0%, #f3f1eb 100%);
  --read-scale: 1;
  --read-base: calc(14.5px * var(--read-scale));
  --read-title: calc(15px * var(--read-scale));
  --read-ref: calc(13.5px * var(--read-scale));
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12161C;
  --surface: #1C222B;
  --text: #E8EBF0;
  --text-soft: #9BA5B4;
  --text-mute: #6B7785;
  --border: #2A323C;
  --border-soft: #232A34;
  --navy: #5B8AB8;
  --navy-soft: #1F2B3A;
  --gold: #E0B462;
  --teal: #6FBDBD;
  --ref-bg: #1A2230;
  --ref-text: #C8D1DD;
  --latar-bg: linear-gradient(135deg, #1C222B 0%, #202834 100%);
}

/* ============================================================
   FOUNDATION
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html {
  width: 100%; min-height: 100vh;
  background: var(--bg);
}

body {
  width: 100%; min-height: 100vh; min-height: 100dvh;
  overflow-x: hidden; overscroll-behavior-y: none;
  background: var(--bg); color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

*:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 4px;
}

.hidden { display: none !important; }

.icon { display: block; flex-shrink: 0; }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon-moon { display: block; }
.icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: block; }

/* ============================================================
   DASHBOARD
   ============================================================ */
#dashboard-view {
  position: relative; min-height: 100vh; min-height: 100dvh;
}

.app-container {
  width: 100%; max-width: 600px; min-height: 100vh; min-height: 100dvh;
  margin: 0 auto; background: var(--bg);
  position: relative; display: flex; flex-direction: column;
}

/* Header */
.header {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(24px + var(--safe-top)) 20px 20px;
}
.user-info { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%;
  object-fit: contain; background: var(--surface);
  border: 1.5px solid var(--border); padding: 2px;
}
.greeting p { font-size: 12px; color: var(--text-soft); margin-bottom: 2px; font-weight: 500; }
.greeting h1 { font-size: 20px; font-weight: 800; color: var(--navy); letter-spacing: -0.3px; }

.header-actions { display: flex; gap: 8px; }

/* Utility Button */
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1.5px solid var(--border); background: var(--surface);
  color: var(--text-soft); cursor: pointer; display: flex;
  align-items: center; justify-content: center; transition: all 0.2s;
  text-decoration: none;
}
.icon-btn:hover { border-color: var(--navy); color: var(--navy); background: var(--navy-soft); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 16px; height: 16px; }

.main-content { padding: 0 20px; flex: 1; }

/* Hero Card */
.hero-card {
  background: linear-gradient(135deg, var(--navy), #1e3a56);
  border-radius: var(--radius-lg); padding: 20px; color: #fff;
  margin-bottom: 24px; position: relative; overflow: hidden;
  box-shadow: 0 8px 24px rgba(46, 74, 107, 0.15);
}
.hero-card-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; opacity: 0.8; margin-bottom: 8px; }
.hero-card-value { font-size: 18px; font-weight: 800; margin-bottom: 4px; line-height: 1.3; padding-right: 60px; }
.hero-card-subtitle { font-size: 13.5px; opacity: 0.75; font-weight: 500; }
.hero-card-graphic {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  width: 50px; height: 50px; background: rgba(255,255,255,0.1);
  border-radius: 12px; display: flex; justify-content: center; align-items: center;
  color: var(--gold); border: 1px solid rgba(255,255,255,0.15);
}
.hero-card-graphic svg { width: 24px; height: 24px; }

/* Section Header */
.section-header { margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.section-header h3 { font-size: 11px; font-weight: 800; color: var(--text-mute); text-transform: uppercase; letter-spacing: 1px; }

/* Shortcut Grid */
.shortcut-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 24px; }

.shortcut-card {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; text-decoration: none; color: inherit; transition: all 0.15s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.02); animation: fadeUp 0.25s ease;
}
.shortcut-card:hover { border-color: var(--navy); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(46,74,107,0.08); }
.shortcut-card:active { transform: scale(0.98); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.shortcut-info { display: flex; align-items: center; gap: 16px; }
.shortcut-icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: flex; justify-content: center; align-items: center;
}
.shortcut-icon svg { width: 18px; height: 18px; }

.shortcut-text h4 { font-size: 15px; font-weight: 700; color: var(--navy); }
.more-icon { width: 14px; height: 14px; color: var(--text-mute); opacity: 0.6; transition: all 0.2s; }
.more-icon--external { width: 12px; height: 12px; }
.shortcut-card:hover .more-icon { transform: translate(3px, -3px); color: var(--navy); }

/* Warna Ikon */
.bg-primary { background: var(--navy-soft); color: var(--navy); }
.bg-green   { background: rgba(91, 168, 168, 0.15); color: var(--teal); }
.bg-orange  { background: rgba(212, 164, 74, 0.15); color: var(--gold); }
.bg-red     { background: rgba(229, 62, 62, 0.1); color: #e53e3e; }
.bg-blue    { background: rgba(49, 130, 206, 0.1); color: #3182ce; }

/* Empty State */
.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-soft);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  grid-column: 1 / -1;
}
.empty-state svg { width: 64px; height: 64px; color: var(--border); margin-bottom: 8px; }
.empty-state-title { font-size: 16px; font-weight: 700; color: var(--text); }
.empty-state-desc { font-size: 13.5px; max-width: 300px; line-height: 1.5; }

/* Footer Credit */
.footer-credit {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-mute);
  padding: calc(24px + var(--safe-bottom)) 20px 24px;
  margin-top: auto;
  line-height: 1.6;
  font-weight: 500;
  letter-spacing: 0.2px;
}

/* ============================================================
   IFRAME VIEW (menu internal, external: false)
   ============================================================ */
#iframe-view {
  position: fixed; inset: 0; width: 100vw; height: 100dvh;
  background: var(--bg); z-index: 9999; display: none; flex-direction: column;
}
#iframe-view.active { display: flex; animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }

.detail-header {
  position: absolute !important; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: var(--surface);
  border-bottom: 1.5px solid var(--border);
  padding-top: calc(14px + env(safe-area-inset-top));
  z-index: 10; flex-shrink: 0;
  transition: transform 0.3s ease, background 0.3s ease;
}
.detail-header--static { position: static !important; }
.detail-header--static .detail-title { flex: 1; text-align: center; padding: 0 12px; }

.detail-back {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px;
  border-radius: 10px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text-soft);
  font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  transition: all 0.2s;
}
.detail-back:hover { border-color: var(--navy); color: var(--navy); background: var(--navy-soft); }
.detail-back:active { transform: scale(0.97); }
.detail-back svg { width: 12px; height: 12px; }

.detail-title {
  font-size: 14px; font-weight: 700; color: var(--navy);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.iframe-spacer { width: 80px; flex-shrink: 0; }

#appFrame { flex: 1; width: 100%; border: none; display: block; background: var(--bg); }

/* Overlays */
.overlay-container {
  position: absolute; inset: 0; background: var(--bg);
  display: flex; flex-direction: column;
  justify-content: center; align-items: center; gap: 16px; z-index: 2;
  padding: calc(80px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
}

.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--navy); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { font-size: 13.5px; font-weight: 600; color: var(--text-soft); }

.error-icon {
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(229, 62, 62, 0.1); color: #e53e3e;
  display: flex; justify-content: center; align-items: center;
}
.error-icon svg { width: 24px; height: 24px; }
.overlay-container h2 { font-size: 16px; color: var(--text); font-weight: 800; text-align: center; }
.overlay-container p { font-size: 13.5px; color: var(--text-soft); text-align: center; max-width: 280px; }

.error-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 220px; margin-top: 8px; }
.error-actions .btn-nav-detail { width: 100%; }

/* Primary & secondary actions (Standar UI) */
.btn-install {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 13px; border: none; border-radius: 12px;
  background: var(--navy); color: #fff; font-family: inherit;
  font-size: 13.5px; font-weight: 700; cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}
.btn-install:hover { transform: translateY(-1px); }
.btn-install:active { transform: scale(0.98); }
.btn-install:disabled { background: var(--border) !important; color: var(--text-mute) !important; cursor: not-allowed; transform: none !important; }
.btn-install:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.btn-nav-detail {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 18px; border-radius: 10px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text-soft); font-family: inherit;
  font-size: 13.5px; font-weight: 700; cursor: pointer;
  transition: all 0.2s ease; user-select: none;
}
.btn-nav-detail:hover { border-color: var(--navy); color: var(--navy); background: var(--navy-soft); transform: translateY(-1px); }
.btn-nav-detail:active { transform: scale(0.97); }
.btn-nav-detail:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* Toast */
.toast {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%) translateY(100px); background: var(--navy);
  color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 13px;
  font-weight: 600; z-index: 99999; transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 10px 30px rgba(0,0,0,0.2); pointer-events: none;
}
.toast.visible { transform: translateX(-50%) translateY(0); }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(160, 168, 179, 0.3); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(160, 168, 179, 0.6); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(155, 165, 180, 0.2); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: rgba(155, 165, 180, 0.4); }

/* Responsive & Motion */
@media (min-width: 768px) {
  .shortcut-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .spinner { animation: none !important; border-top-color: var(--navy); }
}
