/* ==========================================
   ArbiMax Chrome System - Header & Sidebar
   Build: 20260201_CHROME_REDESIGN
   ==========================================
   
   FEATURES:
   - Light-blue professional identity
   - Collapsible sidebar (icon-only mode)
   - Hover-to-expand when collapsed
   - Tooltips for collapsed items
   - Glass blur header/sidebar
   - Mobile drawer mode
   - localStorage persistence
   
   PRESERVES:
   - All data-route attributes
   - All .sidebar-link classes
   - All href navigation paths
   ========================================== */

/* ==========================================
   CHROME TOKENS
   ========================================== */
:root {
  /* Accent colors - Light blue identity */
  --chrome-accent: #2DA4FF;
  --chrome-accent-hover: #5BBBFF;
  --chrome-accent-strong: #1A8FE8;
  --chrome-accent-glow: rgba(45, 164, 255, 0.35);
  --chrome-accent-bg: rgba(45, 164, 255, 0.1);
  --chrome-accent-border: rgba(45, 164, 255, 0.25);
  
  /* Surface colors */
  --chrome-surface: rgba(15, 17, 26, 0.95);
  --chrome-surface-2: rgba(22, 25, 38, 0.98);
  --chrome-surface-hover: rgba(45, 164, 255, 0.08);
  
  /* Border & text */
  --chrome-border: rgba(255, 255, 255, 0.07);
  --chrome-border-strong: rgba(255, 255, 255, 0.12);
  --chrome-text: #f1f5f9;
  --chrome-text-muted: #94a3b8;
  --chrome-text-dim: #64748b;
  
  /* Sidebar dimensions */
  --sidebar-expanded: 280px;
  --sidebar-collapsed: 76px;
  --sidebar-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Header dimensions */
  --header-height: 70px;
}

/* ==========================================
   HEADER - Frosted Glass Bar
   ========================================== */
header.top {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--chrome-surface);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border-bottom: 1px solid var(--chrome-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  gap: 20px;
  transition: box-shadow 0.3s ease, background 0.3s ease;
}

/* Header scrolled state */
header.top.scrolled {
  background: var(--chrome-surface-2);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
  border-bottom-color: var(--chrome-border-strong);
}

/* Brand section */
header.top .brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Brand logo with light-blue glow */
header.top .brand-logo-anim {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--chrome-accent) 0%, var(--chrome-accent-strong) 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 
    0 0 20px var(--chrome-accent-glow),
    0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

header.top .brand-logo-anim:hover {
  transform: scale(1.05) rotate(-2deg);
  box-shadow: 
    0 0 32px var(--chrome-accent-glow),
    0 6px 20px rgba(0, 0, 0, 0.4);
}

header.top .brand-logo-anim img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

/* Brand title */
header.top h1 {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(90deg, var(--chrome-text) 0%, var(--chrome-text-muted) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0;
  letter-spacing: -0.02em;
}

/* ==========================================
   COLLAPSE BUTTON - Hamburger Icon
   ========================================== */
header.top .collapse-btn,
#collapseBtn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  color: var(--chrome-text-muted);
  font-size: 22px;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}

#collapseBtn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--chrome-surface-hover);
  opacity: 0;
  transition: opacity 0.25s ease;
}

#collapseBtn:hover {
  background: var(--chrome-surface-hover);
  border-color: var(--chrome-accent-border);
  color: var(--chrome-accent);
  transform: scale(1.05);
}

#collapseBtn:active {
  transform: scale(0.95);
}

/* Icon rotation on collapsed state */
body.sidebar-collapsed #collapseBtn {
  background: var(--chrome-accent-bg);
  border-color: var(--chrome-accent-border);
  color: var(--chrome-accent);
}

/* Mobile open state - X icon transform */
body.sidebar-open #collapseBtn svg line:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
  transform-origin: center;
}

body.sidebar-open #collapseBtn svg line:nth-child(2) {
  opacity: 0;
}

body.sidebar-open #collapseBtn svg line:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
  transform-origin: center;
}

#collapseBtn svg line {
  transition: all 0.25s ease;
}

/* ==========================================
   ROLE BADGE - Light Blue Pill
   ========================================== */
header.top .pill,
#roleBadge {
  font-size: 10px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--chrome-accent-bg);
  color: var(--chrome-accent);
  border: 1px solid var(--chrome-accent-border);
  transition: all 0.3s ease;
}

#roleBadge.admin {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.25);
}

#roleBadge.trader {
  background: var(--chrome-accent-bg);
  color: var(--chrome-accent);
  border-color: var(--chrome-accent-border);
}

/* ==========================================
   LOGOUT BUTTON
   ========================================== */
#logoutBtn,
.btn-logout-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: transparent;
  color: var(--chrome-text-muted);
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  font-family: inherit;
}

#logoutBtn:hover {
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
  transform: translateY(-1px);
}

#logoutBtn:active {
  transform: translateY(0) scale(0.98);
}

/* ==========================================
   SIDEBAR - Frosted Glass Navigation
   ========================================== */
#arbimax-sidebar {
  width: var(--sidebar-expanded);
  background: var(--chrome-surface);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border-left: 1px solid var(--chrome-border);
  display: flex;
  flex-direction: column;
  padding: 0;
  transition: width var(--sidebar-transition), padding var(--sidebar-transition);
  transform-origin: right;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* ==========================================
   SIDEBAR NAV LIST
   ========================================== */
#arbimax-sidebar ul.sidebar-nav-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 16px;
  margin: 0;
  list-style: none;
}

/* Scrollbar styling */
#arbimax-sidebar ul::-webkit-scrollbar {
  width: 5px;
}

#arbimax-sidebar ul::-webkit-scrollbar-track {
  background: transparent;
}

#arbimax-sidebar ul::-webkit-scrollbar-thumb {
  background: var(--chrome-border-strong);
  border-radius: 5px;
}

#arbimax-sidebar ul::-webkit-scrollbar-thumb:hover {
  background: var(--chrome-accent);
}

/* ==========================================
   SIDEBAR NAV ITEMS
   ========================================== */
.sidebar-link {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  margin-bottom: 4px;
  border-radius: 12px;
  color: var(--chrome-text-muted);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  gap: 14px;
}

/* Navigation dot indicator */
.sidebar-link .am-nav-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chrome-accent);
  box-shadow: 0 0 6px var(--chrome-accent-glow);
  opacity: 0.3;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

/* Navigation text */
.sidebar-link .nav-text {
  flex: 1;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

/* ==========================================
   NAV ITEM - HOVER STATE
   ========================================== */
.sidebar-link:hover {
  background: var(--chrome-surface-hover);
  color: var(--chrome-text);
  border-color: var(--chrome-border);
  transform: translateX(-4px);
}

.sidebar-link:hover .am-nav-dot {
  opacity: 0.7;
  transform: scale(1.2);
  box-shadow: 0 0 12px var(--chrome-accent-glow);
}

/* RTL adjustment */
[dir="rtl"] .sidebar-link:hover {
  transform: translateX(4px);
}

/* ==========================================
   NAV ITEM - ACTIVE STATE
   ========================================== */
.sidebar-link.active {
  background: linear-gradient(135deg, 
    rgba(45, 164, 255, 0.12) 0%, 
    rgba(26, 143, 232, 0.06) 100%
  );
  color: var(--chrome-accent-hover);
  font-weight: 600;
  border: 1px solid var(--chrome-accent-border);
  box-shadow: 
    0 0 24px rgba(45, 164, 255, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* Active indicator bar */
.sidebar-link.active::before {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 55%;
  background: linear-gradient(180deg, var(--chrome-accent) 0%, var(--chrome-accent-strong) 100%);
  border-radius: 4px 0 0 4px;
  box-shadow: 0 0 12px var(--chrome-accent-glow);
}

[dir="ltr"] .sidebar-link.active::before {
  left: 0;
  right: auto;
  border-radius: 0 4px 4px 0;
}

.sidebar-link.active .am-nav-dot {
  opacity: 1;
  background: var(--chrome-accent);
  box-shadow: 
    0 0 12px rgba(45, 164, 255, 0.7),
    0 0 24px rgba(45, 164, 255, 0.4);
  transform: scale(1.3);
}

/* ==========================================
   NAV ITEM - PRESS STATE
   ========================================== */
.sidebar-link:active {
  transform: translateX(-2px) scale(0.98);
  transition: transform 0.1s ease;
}

[dir="rtl"] .sidebar-link:active {
  transform: translateX(2px) scale(0.98);
}

/* ==========================================
   ADMIN SECTION DIVIDER
   ========================================== */
#adminNav {
  margin-top: 12px;
}

#adminNav hr,
.sidebar-nav-list hr {
  border: none;
  border-top: 1px solid var(--chrome-border);
  margin: 16px 8px;
}

.admin-control-label {
  padding: 10px 18px 6px;
  font-size: 10px;
  color: var(--chrome-accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  opacity: 0.8;
}

/* ==========================================
   SIDEBAR - COLLAPSED STATE (76px icon-only)
   ========================================== */
body.sidebar-collapsed #arbimax-sidebar {
  width: var(--sidebar-collapsed);
}

body.sidebar-collapsed #arbimax-sidebar ul.sidebar-nav-list {
  padding: 24px 12px;
}

body.sidebar-collapsed .sidebar-link {
  justify-content: center;
  padding: 14px 12px;
  gap: 0;
}

body.sidebar-collapsed .sidebar-link .nav-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
  transform: translateX(10px);
  position: absolute;
}

body.sidebar-collapsed .sidebar-link .am-nav-dot {
  width: 14px;
  height: 14px;
}

body.sidebar-collapsed .sidebar-link:hover {
  transform: scale(1.05);
}

body.sidebar-collapsed .sidebar-link.active::before {
  display: none;
}

body.sidebar-collapsed .admin-control-label {
  text-align: center;
  padding: 6px 4px;
  font-size: 8px;
  letter-spacing: 0;
}

body.sidebar-collapsed #adminNav hr {
  margin: 12px 4px;
}

/* ==========================================
   COLLAPSED - HOVER TOOLTIP
   ========================================== */
body.sidebar-collapsed .sidebar-link::after {
  content: attr(data-label);
  position: absolute;
  right: calc(100% + 16px);
  left: auto;
  top: 50%;
  transform: translateY(-50%) translateX(8px);
  padding: 10px 16px;
  background: var(--chrome-surface-2);
  color: var(--chrome-text);
  font-size: 13px;
  font-weight: 500;
  border-radius: 10px;
  white-space: nowrap;
  z-index: 1100;
  pointer-events: none;
  border: 1px solid var(--chrome-border);
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

body.sidebar-collapsed .sidebar-link:hover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* LTR tooltip position (sidebar on left, tooltip on right) */
[dir="ltr"] body.sidebar-collapsed .sidebar-link::after {
  left: calc(100% + 16px);
  right: auto;
  transform: translateY(-50%) translateX(-8px);
}

[dir="ltr"] body.sidebar-collapsed .sidebar-link:hover::after {
  transform: translateY(-50%) translateX(0);
}

/* ==========================================
   SIDEBAR - HOVER-TO-EXPAND (COLLAPSED)
   ========================================== */
body.sidebar-collapsed #arbimax-sidebar:hover {
  width: var(--sidebar-expanded);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.4);
}

[dir="ltr"] body.sidebar-collapsed #arbimax-sidebar:hover {
  box-shadow: 8px 0 40px rgba(0, 0, 0, 0.4);
}

body.sidebar-collapsed #arbimax-sidebar:hover ul.sidebar-nav-list {
  padding: 24px 16px;
}

body.sidebar-collapsed #arbimax-sidebar:hover .sidebar-link {
  justify-content: flex-start;
  padding: 14px 18px;
  gap: 14px;
}

body.sidebar-collapsed #arbimax-sidebar:hover .sidebar-link .nav-text {
  opacity: 1;
  width: auto;
  overflow: visible;
  transform: translateX(0);
  position: static;
}

body.sidebar-collapsed #arbimax-sidebar:hover .sidebar-link .am-nav-dot {
  width: 10px;
  height: 10px;
}

body.sidebar-collapsed #arbimax-sidebar:hover .sidebar-link:hover {
  transform: translateX(-4px);
}

[dir="rtl"] body.sidebar-collapsed #arbimax-sidebar:hover .sidebar-link:hover {
  transform: translateX(4px);
}

body.sidebar-collapsed #arbimax-sidebar:hover .sidebar-link.active::before {
  display: block;
}

body.sidebar-collapsed #arbimax-sidebar:hover .admin-control-label {
  text-align: start;
  padding: 10px 18px 6px;
  font-size: 10px;
  letter-spacing: 1.2px;
}

body.sidebar-collapsed #arbimax-sidebar:hover #adminNav hr {
  margin: 16px 8px;
}

/* Hide tooltips when expanded on hover */
body.sidebar-collapsed #arbimax-sidebar:hover .sidebar-link::after {
  display: none;
}

/* ==========================================
   LAYOUT ROOT
   ========================================== */
#layout-root {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

#main-content {
  flex: 1;
  overflow-y: auto;
  background: transparent;
  z-index: 10;
  position: relative;
  padding: 32px 40px;
  transition: margin-right var(--sidebar-transition);
}

/* ==========================================
   MOBILE RESPONSIVE (< 768px)
   ========================================== */
@media (max-width: 768px) {
  :root {
    --header-height: 60px;
  }
  
  header.top {
    padding: 0 16px;
    gap: 12px;
  }
  
  header.top .brand-logo-anim {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }
  
  header.top .brand-logo-anim img {
    width: 24px;
    height: 24px;
  }
  
  header.top h1 {
    font-size: 17px;
  }
  
  #collapseBtn {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }
  
  /* Mobile: Sidebar is fixed drawer from right */
  #arbimax-sidebar {
    position: fixed;
    top: 0;
    right: -100%;
    width: 280px;
    height: 100vh;
    z-index: 200;
    transition: right 0.3s ease;
    border-left: 1px solid var(--chrome-border);
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.5);
  }
  
  /* LTR mobile: drawer from left */
  [dir="ltr"] #arbimax-sidebar {
    right: auto;
    left: -100%;
    border-left: none;
    border-right: 1px solid var(--chrome-border);
  }
  
  /* Sidebar open state */
  body.sidebar-open #arbimax-sidebar {
    right: 0;
  }
  
  [dir="ltr"] body.sidebar-open #arbimax-sidebar {
    left: 0;
  }
  
  /* Mobile overlay backdrop */
  body.sidebar-open::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 199;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
  }
  
  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  
  /* Mobile: No collapsed state (always full width drawer) */
  body.sidebar-collapsed #arbimax-sidebar {
    width: 280px;
  }
  
  /* Mobile content padding */
  #main-content {
    padding: 20px 16px;
  }
  
  /* Mobile logout button */
  #logoutBtn {
    padding: 8px 14px;
    font-size: 12px;
  }
  
  #roleBadge {
    font-size: 9px;
    padding: 3px 8px;
  }
}

/* ==========================================
   HIDE ON AUTH PAGES
   ========================================== */
body.auth-public #arbimax-sidebar,
body.auth-public header.top,
body.auth-public #body-wrapper,
body.auth-public #layout-root {
  display: none !important;
}

/* ==========================================
   REDUCED MOTION PREFERENCE
   ========================================== */
@media (prefers-reduced-motion: reduce) {
  :root {
    --sidebar-transition: 0s;
  }
  
  .sidebar-link,
  #collapseBtn,
  header.top,
  #arbimax-sidebar {
    transition: none !important;
  }
}

/* ==========================================
   ACCESSIBILITY - FOCUS STATES
   ========================================== */
.sidebar-link:focus-visible {
  outline: none;
  box-shadow: 
    0 0 0 2px var(--chrome-surface),
    0 0 0 4px var(--chrome-accent);
}

#collapseBtn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--chrome-accent);
}

#logoutBtn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.5);
}

/* Skip to content link */
.skip-link {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--chrome-accent);
  color: white;
  padding: 12px 24px;
  z-index: 1000;
  border-radius: 0 0 8px 8px;
  font-weight: 600;
  transition: top 0.3s ease;
}

.skip-link:focus {
  top: 0;
}
