/* 
  Premium Glassmorphism 2.0 Design System
  Optimized for Trading Terminals - Final Contrast Pass
*/

:root {
  --color-primary: #6366f1;
  --color-primary-glow: rgba(99, 102, 241, 0.5);
  --color-success: #10b981;
  --color-danger: #ef4444;
  --color-warning: #f59e0b;
  --color-bg: #0a0e17;
  --color-surface: #151b28;
  --color-surface-bright: #1e293b;
  --color-border: rgba(255, 255, 255, 0.1);
  --color-text: #ffffff;
  --color-text-muted: #cbd5e1; /* Increased brightness for readability */
  --color-text-label: #e2e8f0; /* Ultra high contrast for labels */
  
  --glass-blur: 24px;
  --radius-lg: 1.25rem;
  --radius-md: 0.75rem;
  --radius-sm: 0.5rem;
  
  --font-main: 'Inter', -apple-system, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  --shadow-premium: 0 10px 30px -5px rgba(0, 0, 0, 0.4);
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@700;800;900&display=swap');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background-color: var(--color-bg) !important;
  color: var(--color-text) !important;
  font-family: var(--font-main);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Background Blobs */
body::before, body::after {
  content: '';
  position: fixed;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  filter: blur(120px);
  z-index: -1;
  opacity: 0.1;
  pointer-events: none;
}

body::before { background: var(--color-primary); top: -100px; right: -100px; }
body::after { background: var(--color-success); bottom: -100px; left: -100px; }

/* Layout Shell */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 280px;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  background: rgba(10, 14, 23, 0.95) !important;
  backdrop-filter: blur(var(--glass-blur));
  border-right: 1px solid var(--color-border);
  padding: 2.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform 0.3s ease;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-primary) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--color-primary);
  border-radius: 10px;
}

.sidebar > * {
  flex-shrink: 0;
}

.app-main-wrapper {
  flex: 1;
  margin-left: 280px;
  padding: 2.5rem;
  width: calc(100% - 280px);
  min-height: 100vh;
  background-color: transparent !important;
}

@media (max-width: 992px) {
  .app-shell { flex-direction: column; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.active { transform: translateX(0); }
  .app-main-wrapper { margin-left: 0; width: 100%; padding: 1.5rem; }
}

/* Nav & Sidebar Brand */
.sidebar-brand {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.5rem;
  color: white !important;
  text-decoration: none !important;
  margin-bottom: 3.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(135deg, #818cf8, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  color: #94a3b8 !important;
  text-decoration: none !important;
  font-weight: 500;
  transition: all 0.3s ease;
  margin-bottom: 0.5rem;
}

.nav-link:hover, .nav-link.active {
  background: rgba(255, 255, 255, 0.05);
  color: white !important;
}

.nav-link.active {
  background: var(--color-primary) !important;
  box-shadow: 0 4px 15px var(--color-primary-glow);
}

/* Bento Grid System */
.bento-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1.5rem;
  margin-top: 1rem;
}

.bento-card {
  background: var(--color-surface) !important;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bento-card:hover {
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-4px);
  box-shadow: var(--shadow-premium);
}

.col-span-12 { grid-column: span 12; }
.col-span-8 { grid-column: span 8; }
.col-span-6 { grid-column: span 6; }
.col-span-4 { grid-column: span 4; }

@media (max-width: 1200px) {
  .col-span-8, .col-span-6, .col-span-4 { grid-column: span 12; }
}

/* Typography Overrides for Visibility */
.page-title {
  font-family: var(--font-heading);
  font-weight: 900;
  font-size: 2.75rem;
  letter-spacing: -0.04em;
  margin-bottom: 0.75rem;
  color: white !important;
}

.section-title {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: #cbd5e1 !important; /* Brighter for headers */
  margin-bottom: 1.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* High Contrast Labels */
.premium-label {
  color: #cbd5e1 !important;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
}

.text-muted {
  color: var(--color-text-muted) !important;
}

.text-secondary {
  color: #94a3b8 !important;
}

/* Fix for White Cards in Dashboard */
.bg-white { background-color: rgba(255, 255, 255, 0.05) !important; color: white !important; }
.bg-opacity-5 { background-opacity: 1 !important; } /* Force opacity reset if leaking */

/* Tables */
.premium-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 0.5rem;
}

.table-responsive .premium-table {
  min-width: 720px;
}

.premium-table--wide {
  min-width: 900px;
}

.premium-table thead th {
  padding: 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--color-text-label);
  border: none;
  letter-spacing: 0.05em;
}

.premium-table tbody td {
  padding: 1.25rem 1rem;
  background: rgba(255, 255, 255, 0.03);
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  color: white;
}

.badge {
  font-weight: 700 !important;
  padding: 0.5rem 0.85rem !important;
  letter-spacing: 0.02em;
  border-radius: var(--radius-sm) !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
}

.badge.bg-success { 
  background-color: rgba(16, 185, 129, 0.15) !important; 
  color: #10b981 !important; 
  border: 1px solid rgba(16, 185, 129, 0.2) !important;
}

.badge.bg-danger { 
  background-color: rgba(239, 68, 68, 0.15) !important; 
  color: #ef4444 !important; 
  border: 1px solid rgba(239, 68, 68, 0.2) !important;
}

.badge.bg-primary { 
  background-color: rgba(99, 102, 241, 0.15) !important; 
  color: #818cf8 !important; 
  border: 1px solid rgba(99, 102, 241, 0.2) !important;
}

.badge.bg-warning {
  background-color: rgba(245, 158, 11, 0.15) !important;
  color: #f59e0b !important;
  border: 1px solid rgba(245, 158, 11, 0.2) !important;
}

.badge.bg-white {
  background-color: rgba(255, 255, 255, 0.08) !important;
  color: #cbd5e1 !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.badge.bg-secondary {
  background-color: rgba(148, 163, 184, 0.15) !important;
  color: #94a3b8 !important;
  border: 1px solid rgba(148, 163, 184, 0.2) !important;
}

.badge.bg-info {
  background-color: rgba(6, 182, 212, 0.15) !important;
  color: #22d3ee !important;
  border: 1px solid rgba(6, 182, 212, 0.2) !important;
}

/* Buttons & Interactions */
.btn-modern {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.75rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none !important;
}

.btn-primary-modern {
  background: var(--color-primary);
  color: white !important;
  box-shadow: 0 4px 15px var(--color-primary-glow);
}

.btn-primary-modern:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--color-primary-glow); }

.btn-outline-modern {
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--color-border);
  color: white !important;
}

.btn-outline-modern:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.3); }

/* Loading States */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.btn-modern { opacity: 0.7; cursor: not-allowed; }

/* Status Indicators */
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--color-success); box-shadow: 0 0 12px var(--color-success); }
.dot.red { background: var(--color-danger); box-shadow: 0 0 12px var(--color-danger); }

/* Nifty Pulse */
.nifty-spot-card { background: linear-gradient(135deg, #1e293b, #0f172a); border: 1px solid rgba(255, 255, 255, 0.1); }
.price-value { font-family: var(--font-heading); font-weight: 800; letter-spacing: -0.02em; }

/* Analytics / PNL Cards */
.dashboard-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.pnl-card {
  padding: 1.25rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  min-width: 0;
}

/* Mobile Sidebar Backdrop */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  display: none;
}

@media (max-width: 992px) {
  .sidebar.active ~ .sidebar-overlay { display: block; }
}

@media (max-width: 768px) {
  .col-span-4, .col-span-6, .col-span-8 { grid-column: span 12 !important; }
  .dashboard-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (max-width: 576px) {
  .page-title { font-size: 1.75rem; }
  .page-header-row {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 1rem;
  }
  .page-header-actions {
    align-items: flex-start !important;
    width: 100%;
    text-align: left !important;
  }
  .bento-card { padding: 1.25rem; }
  .bento-grid { gap: 1rem; }
  .dashboard-stats-grid { grid-template-columns: 1fr; }
  .display-4 { font-size: calc(1.425rem + 2.1vw); }
  .app-main-wrapper { padding: 1rem; }
}
