/* ============================================
   MediaSnap v3 - Refined Design System (Upgraded)
   Fixes:
   [F1] background-attachment: fixed → pseudo-element (iOS Safari fix)
   [F2] prefers-reduced-motion support
   [F3] Firefox scrollbar styling
   [F4] backdrop-filter @supports fallback
   [F5] clamp() typography untuk mobile
   [F6] CSS custom property untuk radius
   [F7] badge platform contrast fix
   [F8] Transition gradient fix (opacity crossfade)
   [F9] Font display optimization
   ============================================ */

   :root {
    /* Colors */
    --bg-card: rgba(255, 255, 255, 0.75);
    --bg-card-hover: rgba(255, 255, 255, 0.95);
    --bg-input: rgba(255, 255, 255, 0.85);
    --bg-nav: rgba(255, 255, 255, 0.85);
    --bg-elevated: rgba(255, 255, 255, 0.9);
    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.15);
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --accent-from: #ec4899;
    --accent-to: #8b5cf6;
    --accent-shadow: rgba(236, 72, 153, 0.25);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  
    /* [F6] Radius system */
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.25rem;
    --radius-full: 9999px;
  
    /* Background colors untuk pseudo-element */
    --bg-from: #fafbff;
    --bg-mid: #eef2ff;
  }
  
  [data-theme="dark"] {
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --bg-input: rgba(15, 23, 42, 0.55);
    --bg-nav: rgba(10, 14, 26, 0.8);
    --bg-elevated: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.15);
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    --bg-from: #0a0e1a;
    --bg-mid: #1e1b4b;
  }
  
  * {
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
    /* [F3] Firefox scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
  }
  
  html {
    scroll-behavior: smooth;
  }
  
  /* [F1] Fix iOS Safari background-attachment: fixed
     Pakai pseudo-element biar background tidak flicker/rusak di mobile */
  body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: linear-gradient(135deg, var(--bg-from) 0%, var(--bg-mid) 50%, var(--bg-from) 100%);
    /* [F8] Transition via opacity — gradient tidak bisa di-interpolate */
    transition: opacity 0.4s ease;
  }
  
  [data-theme="dark"] body::before {
    opacity: 1;
  }
  
  body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: none; /* background sudah di ::before */
    color: var(--text-primary);
    min-height: 100vh;
    letter-spacing: -0.011em;
    transition: color 0.3s ease;
  }
  
  /* ============ Typography ============ */
  /* [F5] clamp() untuk responsive typography tanpa media query */
  h1 {
    letter-spacing: -0.03em;
    font-weight: 700;
    font-size: clamp(1.625rem, 4vw + 0.5rem, 2.25rem);
  }
  
  h2 {
    letter-spacing: -0.02em;
    font-weight: 700;
    font-size: clamp(1.125rem, 2.5vw + 0.25rem, 1.5rem);
  }
  
  h3 {
    letter-spacing: -0.02em;
    font-weight: 700;
    font-size: clamp(1rem, 2vw + 0.25rem, 1.25rem);
  }
  
  /* ============ Scrollbar (Webkit) ============ */
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  ::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 5px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
  }
  
  /* ============ Components ============ */
  
  /* [F4] backdrop-filter dengan @supports fallback */
  .glass {
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: all 0.25s ease;
  }
  
  @supports (backdrop-filter: blur(1px)) {
    .glass {
      backdrop-filter: blur(16px) saturate(150%);
      -webkit-backdrop-filter: blur(16px) saturate(150%);
    }
  }
  
  .glass:hover {
    border-color: var(--border-strong);
  }
  
  .glass-hover {
    transition: all 0.2s ease;
  }
  
  .glass-hover:hover {
    background: var(--bg-card-hover);
    transform: translateY(-1px);
  }
  
  .input-themed {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    transition: all 0.2s ease;
  }
  
  .input-themed:focus {
    border-color: var(--accent-from);
    box-shadow: 0 0 0 4px var(--accent-shadow);
  }
  
  .input-themed::placeholder {
    color: var(--text-muted);
  }
  
  .text-secondary { color: var(--text-secondary); }
  .text-muted { color: var(--text-muted); }
  
  /* [F4] Nav backdrop-filter fallback */
  .nav-themed {
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border);
  }
  
  @supports (backdrop-filter: blur(1px)) {
    .nav-themed {
      backdrop-filter: blur(20px) saturate(180%);
      -webkit-backdrop-filter: blur(20px) saturate(180%);
    }
  }
  
  /* ============ Buttons ============ */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-weight: 600;
    border-radius: var(--radius-md); /* [F6] */
    transition: all 0.2s ease;
    cursor: pointer;
    border: 1px solid transparent;
  }
  
  .btn-primary {
    background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
    color: white;
    box-shadow: 0 4px 14px var(--accent-shadow);
  }
  
  .btn-primary:hover:not(:disabled) {
    box-shadow: 0 6px 20px var(--accent-shadow);
    transform: translateY(-1px);
  }
  
  .btn-primary:active:not(:disabled) {
    transform: translateY(0);
  }
  
  .btn-secondary {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
  }
  
  .btn-secondary:hover:not(:disabled) {
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
  }
  
  button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
  
  /* ============ Icons ============ */
  .icon {
    display: inline-block;
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
    vertical-align: -0.125em;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  
  .icon-sm { width: 0.875rem; height: 0.875rem; }
  .icon-lg { width: 1.5rem; height: 1.5rem; }
  .icon-xl { width: 2rem; height: 2rem; }
  
  /* ============ Animations ============ */
  @keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
  }
  
  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  
  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
  }
  
  @keyframes shimmer {
    0% { background-position: -1000px 0; }
    100% { background-position: 1000px 0; }
  }
  
  @keyframes spin {
    to { transform: rotate(360deg); }
  }
  
  .animate-in {
    animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  }
  
  .fade-in {
    animation: fadeIn 0.3s ease;
  }
  
  /* [F2] Respek user yang sensitive terhadap animasi */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
  
  /* ============ Skeleton Loader ============ */
  .skeleton {
    background: linear-gradient(
      90deg,
      var(--bg-card) 0%,
      var(--bg-card-hover) 50%,
      var(--bg-card) 100%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite linear;
    border-radius: var(--radius-sm); /* [F6] */
  }
  
  /* ============ Line clamp ============ */
  .line-clamp-2,
  .line-clamp-3 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .line-clamp-2 { -webkit-line-clamp: 2; }
  .line-clamp-3 { -webkit-line-clamp: 3; }
  
  /* ============ Progress bar ============ */
  .progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: var(--radius-full); /* [F6] */
    overflow: hidden;
  }
  .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-from), var(--accent-to));
    border-radius: var(--radius-full); /* [F6] */
    transition: width 0.3s ease;
  }
  
  /* ============ Platform badges ============ */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-full); /* [F6] */
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
  }
  
  /* [F7] Solid color biar contrast terjamin — gradient 5 warna susah dijamin readability-nya */
  .badge-tiktok    { background: #010101; color: white; }
  .badge-instagram { background: #e1306c; color: white; }
  .badge-youtube   { background: #ff0000; color: white; }
  .badge-twitter   { background: #1da1f2; color: white; }
  .badge-unknown   { background: var(--text-muted); color: white; }
  
  /* ============ Toast ============ */
  .toast {
    position: fixed;
    top: 5rem;
    right: 1rem;
    z-index: 100;
    padding: 0.875rem 1.125rem;
    border-radius: var(--radius-md); /* [F6] */
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 0.875rem;
    font-weight: 500;
    max-width: 24rem;
    animation: fadeInUp 0.3s ease;
  }
  
  @supports (backdrop-filter: blur(1px)) {
    .toast {
      backdrop-filter: blur(20px);
      -webkit-backdrop-filter: blur(20px);
    }
  }
  
  .toast-success { border-left: 3px solid #10b981; }
  .toast-error   { border-left: 3px solid #ef4444; }
  .toast-info    { border-left: 3px solid var(--accent-from); }
  .toast-warn    { border-left: 3px solid #f59e0b; }
  
  /* ============ Spinner ============ */
  .spinner {
    display: inline-block;
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--border);
    border-top-color: var(--accent-from);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  
  /* ============ Card hover ============ */
  .card-hover {
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
  
  .card-hover:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }
  
  /* ============ Modal ============ */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
  }
  
  @supports (backdrop-filter: blur(1px)) {
    .modal-backdrop {
      backdrop-filter: blur(4px);
      -webkit-backdrop-filter: blur(4px);
    }
  }
  
  .modal-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg); /* [F6] */
    padding: 1.5rem;
    max-width: 32rem;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
  
  /* ============ Selection ============ */
  ::selection {
    background: var(--accent-from);
    color: white;
  }
  
  /* ============ Focus visible ============ */
  :focus-visible {
    outline: 2px solid var(--accent-from);
    outline-offset: 2px;
  }
  
  button:focus-visible,
  a:focus-visible {
    outline-offset: 4px;
  }
  
  /* ============ Dropdown ============ */
  .dropdown {
    position: relative;
  }
  
  .dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    min-width: 10rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md); /* [F6] */
    box-shadow: var(--shadow-lg);
    padding: 0.375rem;
    z-index: 50;
    display: none;
    animation: fadeInUp 0.2s ease;
  }
  
  .dropdown.open .dropdown-menu {
    display: block;
  }
  
  .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm); /* [F6] */
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.15s ease;
    border: none;
    background: none;
    color: var(--text-primary);
    text-align: left;
  }
  
  .dropdown-item:hover {
    background: var(--bg-card-hover);
  }
  
  /* ============ Stat card ============ */
  .stat-card {
    position: relative;
    overflow: hidden;
  }
  
  .stat-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent-from), var(--accent-to));
    opacity: 0.6;
  }