:root {
  --primary-from: #4F46E5;
  --primary-to: #0EA5E9;
  --accent-green: #10B981;
  --accent-rose: #F43F5E;
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --text-primary: #1E293B;
  --text-secondary: #64748B;
  --border: #E2E8F0;
  --sidebar-bg: #FFFFFF;
  --hover-bg: rgba(79, 70, 229, 0.05);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #0B1120;
  --card: #151F32;
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --border: #1E2D45;
  --sidebar-bg: #151F32;
  --hover-bg: rgba(79, 70, 229, 0.15);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background-color 0.3s, color 0.3s;
}

.font-mono {
  font-family: 'JetBrains Mono', monospace;
}

/* ===== ANIMATIONS ===== */
@keyframes meshGradient {
  0%, 100% { background-position: 0% 50%; }
  25% { background-position: 100% 0%; }
  50% { background-position: 100% 100%; }
  75% { background-position: 0% 100%; }
}

.mesh-bg {
  background: linear-gradient(-45deg, #1a0533, #0d1b3e, #0a2540, #12062e, #1a0533);
  background-size: 400% 400%;
  animation: meshGradient 15s ease infinite;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}
.shake { animation: shake 0.5s ease-in-out; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.slide-up { animation: slideUp 0.3s ease-out forwards; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.slide-in { animation: slideIn 0.3s ease-out forwards; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.fade-in { animation: fadeIn 0.35s ease-out forwards; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(79, 70, 229, 0); }
}
.otp-active { animation: pulse 1.5s infinite; }

@keyframes countUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.count-up { animation: countUp 0.6s ease-out forwards; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.toast-in { animation: toastIn 0.3s ease-out forwards; }

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-20px) scale(0.95); }
}
.toast-out { animation: toastOut 0.3s ease-out forwards; }

@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--border) 0px, rgba(255,255,255,0.1) 40px, var(--border) 80px);
  background-size: 200px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

@keyframes checkmark {
  0% { stroke-dashoffset: 50; }
  100% { stroke-dashoffset: 0; }
}

@keyframes successCircle {
  0% { stroke-dashoffset: 166; }
  100% { stroke-dashoffset: 0; }
}

@keyframes cardShine {
  0% { left: -100%; }
  100% { left: 200%; }
}

/* ===== UTILITY CLASSES ===== */
.gradient-text {
  background: linear-gradient(135deg, #4F46E5, #0EA5E9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.gradient-btn {
  background: linear-gradient(135deg, #4F46E5, #0EA5E9);
  color: white;
  border: none;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.1s;
}

.gradient-btn:hover {
  box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4);
}

.gradient-btn:active {
  transform: scale(0.97);
}

.card-hover {
  transition: transform 0.2s, box-shadow 0.2s;
}
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] .card-hover:hover {
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

input, select, textarea {
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus {
  outline: none;
  border-color: #4F46E5 !important;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ===== LAYOUT ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-sidebar {
  width: 260px;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 40;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-main {
  margin-left: 260px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  flex: 1;
  width: calc(100% - 260px);
}

.app-topbar {
  height: 68px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.app-content {
  padding: 24px;
  flex: 1;
  max-width: 1200px;
  width: 100%;
}

/* ===== MOBILE BOTTOM NAV ===== */
.mobile-bottom-nav {
  display: none;
}

/* ===== RESPONSIVE GRID HELPERS ===== */
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

/* ===== CREDIT CARD DESIGN ===== */
.credit-card {
  border-radius: 20px;
  padding: 28px 24px;
  color: white;
  position: relative;
  overflow: hidden;
  aspect-ratio: 1.6 / 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.credit-card::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -100%;
  width: 60%;
  height: 200%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
  animation: cardShine 4s ease-in-out infinite;
}

/* ===== TABLET (768px - 1024px) ===== */
@media (max-width: 1024px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
    width: 100%;
  }
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ===== MOBILE (max 768px) ===== */
@media (max-width: 768px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
    width: 100%;
    padding-bottom: calc(70px + var(--safe-bottom));
  }
  .app-topbar {
    height: 60px;
    padding: 0 16px;
  }
  .app-content {
    padding: 16px;
    padding-bottom: calc(16px + 70px + var(--safe-bottom));
  }
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 6px 0;
    padding-bottom: calc(6px + var(--safe-bottom));
    background: var(--card);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .grid-4 {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
  }
  .card-hover:hover {
    transform: none;
  }
}

/* ===== SMALL PHONES (max 380px) ===== */
@media (max-width: 380px) {
  .app-topbar {
    padding: 0 12px;
  }
  .app-content {
    padding: 12px;
    padding-bottom: calc(12px + 70px + var(--safe-bottom));
  }
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}