/* ==========================================================================
   Key Huy System - Main Design System & Tokens
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&family=Noto+Sans+Thai:wght@300;400;500;600;700;800;900&family=Outfit:wght@400;500;600;700;800;900&display=swap');

:root {
  /* Color Palette */
  --bg-main: #0b0f19;
  --bg-card: rgba(18, 26, 43, 0.75);
  --bg-card-hover: rgba(26, 38, 62, 0.85);
  --bg-surface: #111827;
  --bg-sidebar: rgba(11, 15, 25, 0.96);
  --bg-input: #151d30;
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #f43f5e;
  --border-subtle: rgba(255, 255, 255, 0.04);

  /* Primary Brand Gradients */
  --primary: #f43f5e;
  --primary-hover: #fb7185;
  --primary-light: rgba(244, 63, 94, 0.15);
  --primary-gradient: linear-gradient(135deg, #f43f5e 0%, #ec4899 50%, #d946ef 100%);
  --gold-gradient: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
  --purple-gradient: linear-gradient(135deg, #8b5cf6 0%, #a855f7 100%);
  --emerald-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --cyan-gradient: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);

  /* Status Colors */
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.12);

  /* Typography */
  --font-sans: 'Noto Sans Thai', 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 24px rgba(244, 63, 94, 0.35);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  min-height: 100vh;
  background-color: var(--bg-main);
  color: #f1f5f9;
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(244, 63, 94, 0.6);
}

/* Application Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
  background: radial-gradient(circle at 10% 20%, rgba(244, 63, 94, 0.08) 0%, transparent 40%),
              radial-gradient(circle at 90% 80%, rgba(139, 92, 246, 0.07) 0%, transparent 40%),
              var(--bg-main);
}

/* Sidebar */
.app-sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  transition: transform var(--transition-normal);
}

.sidebar-header {
  height: 72px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  box-shadow: 0 0 16px rgba(244, 63, 94, 0.4);
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.brand-badge {
  font-size: 0.68rem;
  color: #94a3b8;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* House Switcher Chip in Sidebar */
.sidebar-house-box {
  margin: 16px 14px 8px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: var(--transition-fast);
}

.sidebar-house-box:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(244, 63, 94, 0.4);
}

.house-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.house-label {
  font-size: 0.7rem;
  color: #94a3b8;
  font-weight: 500;
}

.house-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.house-code {
  font-size: 0.68rem;
  color: var(--primary);
  font-family: var(--font-mono);
  font-weight: 600;
}

/* Navigation Links */
.sidebar-nav {
  flex: 1;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-section-title {
  font-size: 0.68rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 12px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
  position: relative;
}

.nav-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(244, 63, 94, 0.2) 0%, rgba(236, 72, 153, 0.08) 100%);
  border-left: 3px solid var(--primary);
  box-shadow: 0 4px 12px rgba(244, 63, 94, 0.15);
}

.nav-item.active .nav-icon {
  color: var(--primary);
  filter: drop-shadow(0 0 6px rgba(244, 63, 94, 0.5));
}

.nav-icon {
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: #94a3b8;
  transition: var(--transition-fast);
}

.nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(244, 63, 94, 0.2);
  color: #fb7185;
}

/* Sidebar Footer / User Profile & Role Switcher */
.sidebar-footer {
  padding: 16px 14px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.role-switcher-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px;
}

.role-label {
  font-size: 0.68rem;
  color: #64748b;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}

.role-select {
  width: 100%;
  background: transparent;
  color: #f1f5f9;
  border: none;
  font-size: 0.85rem;
  font-weight: 700;
  outline: none;
  cursor: pointer;
}

.role-select option {
  background: #1e293b;
  color: #fff;
}

.user-profile-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 0.9rem;
}

.user-details {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.user-role-tag {
  font-size: 0.68rem;
  font-weight: 600;
  color: #10b981;
}

/* Main Content Area */
.app-main {
  flex: 1;
  margin-left: 260px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-normal);
}

/* Top App Header */
.app-header {
  height: 72px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: rgba(11, 15, 25, 0.8);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.menu-toggle-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border-color);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.page-title-box {
  display: flex;
  flex-direction: column;
}

.page-heading {
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.3px;
}

.page-subheading {
  font-size: 0.78rem;
  color: #94a3b8;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Market Selector & Countdown */
.active-market-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: 999px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 10px #10b981;
  animation: pulseAnimation 1.8s infinite;
}

@keyframes pulseAnimation {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.market-pill-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
}

.market-pill-timer {
  font-size: 0.82rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--primary);
  background: rgba(244, 63, 94, 0.12);
  padding: 2px 8px;
  border-radius: 6px;
}

/* Quick Action Header Buttons */
.btn-header-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.03);
  color: #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: var(--transition-fast);
}

.btn-header-icon:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-header-icon.active {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
}

/* Page Content Viewport */
.app-content {
  flex: 1;
  padding: 28px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* Page Panel View Switcher */
.view-panel {
  display: none;
  animation: fadeInView 0.2s ease-out;
}

.view-panel.active {
  display: block;
}

@keyframes fadeInView {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Universal Card */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(16px);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.glass-card:hover {
  border-color: rgba(255, 255, 255, 0.14);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-icon {
  font-size: 1.3rem;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
}

.card-subtitle {
  font-size: 0.8rem;
  color: #94a3b8;
}

/* Responsive Breakpoints */
@media (max-width: 1024px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
  }
  .menu-toggle-btn {
    display: flex;
  }
}

@media (max-width: 768px) {
  .app-header {
    padding: 0 16px;
    height: 64px;
  }
  .app-content {
    padding: 16px;
  }
  .active-market-pill .market-pill-title {
    display: none;
  }
}
