/**
 * Dashboard Layout & Splash Overlay Styles
 * Build: 20260115_180000
 */

/* CRITICAL: Reset body & html to ensure no layout offset */
html,
body {
  height: 100%;
  min-height: 100vh;
  margin: 0 !important;
  padding: 0 !important;
}

/* ============================================================
   CRITICAL: Full-screen fixed overlay for splash
   ============================================================ */

#splash-screen,
#splash,
.splash-screen,
[data-splash] {
  position: fixed;
  inset: 0;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--am-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: linear-gradient(135deg, var(--am-bg-grad-from) 0%, var(--am-bg-grad-via) 50%, var(--am-bg-grad-to) 100%);
  pointer-events: auto;
  margin: 0 !important;
  padding: 0 !important;
  border: none;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
}

/* Progress bar container */
#splash-progress,
.splash-progress,
.splash-bar-container {
  position: relative;
  width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
  margin-top: var(--am-space-5);
}

#splash-progress-fill,
.splash-bar-fill,
.splash-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--am-accent, #6AAEFF) 0%, #86BFFF 50%, var(--am-accent, #6AAEFF) 100%);
  width: 0%;
  transition: width 0.08s linear;
  box-shadow: 0 0 10px rgba(106, 174, 255, 0.5);
}

/* Status text */
#splash-status,
.splash-stage,
.splash-status {
  font-family: 'IBM Plex Sans Arabic', 'JetBrains Mono', monospace;
  color: #44f5e2;
  font-size: 12px;
  margin-top: var(--am-space-7);
  min-height: 20px;
  letter-spacing: 0.5px;
}

/* Detail text (optional) */
#splash-detail,
.splash-detail {
  font-family: 'Tajawal', 'JetBrains Mono', monospace;
  color: var(--am-text-muted);
  font-size: var(--am-text-xs);
  margin-top: var(--am-space-sm);
  min-height: var(--am-text-base);
}

/* Logo/branding in splash */
.splash-logo,
.splash-brand {
  margin-bottom: var(--am-space-2xl);
}

.splash-logo img,
.splash-brand img {
  max-width: 120px;
  max-height: 60px;
  filter: drop-shadow(0 0 8px rgba(106, 174, 255, 0.4));
}

/* Main app wrapper fills viewport */
#body-wrapper,
#bodyWrapper,
#app,
#app-root,
main {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-width: 100%;
}

/* Hidden splash state */
.splash-hidden,
#splash-screen.hidden,
#splash.hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ============================================================
   HTML & BODY - NO MARGINS/PADDING (critical for layout)
   ============================================================ */

html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #050507;
}

html.auth-route body,
html.auth-route #body-wrapper {
  overflow: auto;
}

/* CRITICAL: Auth/Login pages - center login card vertically & horizontally */
body.auth-public,
html.auth-route body.auth-public {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: auto;
  background: #050507;
}

/* ============================================================
   MAIN APP CONTAINER - Positioned behind splash, visible after
   ============================================================ */

#app,
#app-root,
#body-wrapper,
.body-wrapper,
.app-wrapper {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-width: 100vw;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  background: #050507;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.3s ease-in-out;
}

/* During boot, hide the main UI */
html.booting #body-wrapper {
  display: none;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

html.booting #app,
html.booting #app-root {
  display: none;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Show main UI when boot complete */
html.booting-complete #body-wrapper,
html.booting-complete #app,
html.booting-complete #app-root {
  display: flex;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ============================================================
   LAYOUT STRUCTURE - Three column: sidebar + main + canvas
   ============================================================ */

.layout-root,
.dashboard-layout,
.main-layout {
  display: flex;
  flex: 1;
  height: 100%;
  background: #050507;
  position: relative;
}

/* Sidebar */
.sidebar,
.left-sidebar,
[data-sidebar] {
  flex: 0 0 280px;
  background: rgba(20, 15, 30, 0.5);
  border-right: 1px solid rgba(68, 245, 226, 0.1);
  overflow-y: auto;
  z-index: 100;
  position: relative;
}

/* Main content area */
.main-content,
.main-panel,
.content-area,
[data-main] {
  flex: 1;
  overflow-y: auto;
  background: #050507;
  z-index: 10;
  position: relative;
}

/* Three.js canvas - BEHIND everything */
canvas[data-three],
canvas#three-bg,
.three-canvas,
#webgl {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  margin: 0;
  padding: 0;
}

/* ============================================================
   HEADER/NAVIGATION BAR
   ============================================================ */

.header,
.navbar,
.top-bar,
[data-header] {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(20, 15, 30, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(68, 245, 226, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 var(--am-space-5);
  gap: var(--am-space-5);
}

/* Auth pill */
.pill,
#roleBadge,
.auth-pill,
[data-pill] {
  display: inline-block;
  padding: var(--am-space-1) var(--am-space-3);
  border-radius: 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
}

.pill.verifying,
.auth-pill.is-wait,
#roleBadge.verifying {
  background: rgba(100, 100, 100, 0.3);
  color: #888;
  border: 1px solid rgba(100, 100, 100, 0.5);
}

.pill.authorized,
.auth-pill.is-ok,
#roleBadge.authorized {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.4);
}

.pill.unauthorized,
.auth-pill.is-bad,
#roleBadge.unauthorized {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

/* Logout button */
.btn-logout,
#logoutBtn,
[data-logout] {
  padding: var(--am-space-1) var(--am-space-3);
  background: var(--am-accent-bg, rgba(106, 174, 255, 0.15));
  color: var(--am-accent, #6AAEFF);
  border: 1px solid var(--am-accent-border, rgba(106, 174, 255, 0.3));
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s ease-out;
  font-family: 'IBM Plex Sans Arabic', sans-serif;
}

.btn-logout:hover,
#logoutBtn:hover {
  background: rgba(106, 174, 255, 0.25);
  border-color: rgba(106, 174, 255, 0.5);
  color: var(--am-accent-2, #86BFFF);
}

.btn-logout:active,
#logoutBtn:active {
  background: rgba(106, 174, 255, 0.35);
  transform: scale(0.98);
}

/* User role label and badge */
#userRoleLabel,
.user-role-label {
  display: inline-block;
  padding: var(--am-space-1) var(--am-space-2);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  font-family: 'JetBrains Mono', monospace;
  background: rgba(0, 240, 255, 0.1);
  color: #00f0ff;
  border: 1px solid rgba(0, 240, 255, 0.3);
  white-space: nowrap;
}

#userRoleBadge,
.role-badge {
  display: inline-block;
  padding: var(--am-space-1) var(--am-space-2);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  background: var(--am-accent-bg, rgba(106, 174, 255, 0.12));
  color: var(--am-accent-2, #86BFFF);
  border: 1px solid var(--am-accent-border, rgba(106, 174, 255, 0.25));
  white-space: nowrap;
}

#userRoleLabel.hidden,
#userRoleBadge.hidden,
.role-badge.hidden,
.user-role-label.hidden {
  display: none !important;
}

/* ============================================================
   SIDEBAR TABS/NAVIGATION
   ============================================================ */

.nav-item,
.sidebar-item,
[data-nav-item] {
  display: block;
  padding: var(--am-space-3) var(--am-space-4);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.2s ease-out;
  text-decoration: none;
  font-family: 'IBM Plex Sans Arabic', sans-serif;
}

.nav-item:hover,
.sidebar-item:hover {
  background: rgba(68, 245, 226, 0.05);
  color: #44f5e2;
}

.nav-item.active,
.sidebar-item.active,
.nav-item[data-route].active {
  background: linear-gradient(92deg, rgba(106, 174, 255, 0.12) 40%, rgba(134, 191, 255, 0.08) 120%);
  color: var(--am-accent-2, #86BFFF);
  border-left-color: var(--am-accent, #6AAEFF);
  font-weight: 500;
}

/* ============================================================
   SCROLLBARS - Custom styling
   ============================================================ */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(10, 14, 20, 0.5);
}

::-webkit-scrollbar-thumb {
  background: rgba(106, 174, 255, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(106, 174, 255, 0.5);
}

/* ============================================================
   ACCESSIBILITY & RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
  .sidebar,
  .left-sidebar {
    flex: 0 0 200px;
  }

  .header,
  .navbar {
    height: 50px;
    padding: 0 var(--am-space-3);
    gap: var(--am-space-3);
  }

  .pill,
  .btn-logout {
    font-size: 10px;
    padding: var(--am-space-1) var(--am-space-2);
  }
}

/* Prevent layout shift from scrollbars */
html {
  overflow-y: scroll;
}

html.auth-route {
  overflow-y: auto;
}

/* ============================================================
   PREVENT BLACK BAND - Ensure no splash remnants
   ============================================================ */

#splash-screen::after,
#splash::after,
.splash-screen::after {
  content: '';
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: transparent;
}

/* Remove splash completely after fade */
.splash-removed,
.splash-hidden {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  height: 0 !important;
  width: 0 !important;
  overflow: hidden !important;
}


/* ============================================================
   OPERATIONS PAGE STYLES (Phase 1)
   ============================================================ */

.operations-list {
  display: flex;
  flex-direction: column;
  gap: var(--am-list-gap);
}

.operation-item {
  padding: var(--am-space-4);
  background: var(--am-panel, rgba(18, 22, 30, 0.55));
  border: 1px solid var(--am-accent-border, rgba(106, 174, 255, 0.18));
  border-radius: 8px;
  transition: all 0.2s ease;
}

.operation-item:hover {
  background: var(--am-panel-2, rgba(12, 16, 24, 0.72));
  border-color: var(--am-border-strong, rgba(106, 174, 255, 0.3));
  transform: translateX(2px);
}

.operation-header {
  display: flex;
  align-items: center;
  gap: var(--am-space-2);
  margin-bottom: var(--am-space-2);
  font-size: 13px;
}

.operation-icon {
  font-size: 18px;
}

.operation-type {
  font-weight: 500;
  color: var(--brand-cyan);
}

.operation-status {
  margin-left: auto;
  font-weight: 500;
  font-size: 11px;
}

.operation-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.operation-body {
  display: flex;
  flex-direction: column;
  gap: var(--am-control-gap);
}

.operation-message {
  color: var(--text-primary);
  line-height: 1.5;
}

.operation-details {
  display: flex;
  gap: var(--am-control-gap);
  flex-wrap: wrap;
}

.operation-pnl {
  font-weight: 600;
  font-size: 14px;
}

.operation-error {
  padding: var(--am-space-2);
  background: rgba(255, 79, 79, 0.1);
  border: 1px solid var(--danger-base);
  border-radius: 4px;
  font-size: 12px;
  color: var(--danger-base);
}

.operation-meta {
  display: flex;
  gap: var(--am-space-4);
  font-size: 11px;
  color: var(--text-secondary);
  padding-top: var(--am-space-2);
  border-top: 1px solid var(--am-border-subtle, rgba(106, 174, 255, 0.1));
}

.stat-card {
  padding: var(--am-space-4);
  background: var(--am-accent-bg, rgba(106, 174, 255, 0.06));
  border: 1px solid var(--am-accent-border, rgba(106, 174, 255, 0.18));
  border-radius: 6px;
  text-align: center;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--brand-cyan);
  margin-bottom: var(--am-space-1);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.empty-state {
  text-align: center;
  padding: var(--am-space-8) var(--am-space-5);
  color: var(--text-secondary);
}

.badge {
  display: inline-block;
  padding: var(--am-space-1) var(--am-space-2);
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  background: var(--am-accent-bg, rgba(106, 174, 255, 0.15));
  color: var(--am-accent, #6AAEFF);
}

.badge.success {
  background: rgba(0, 255, 0, 0.1);
  color: var(--success-base);
}

.badge.danger {
  background: rgba(255, 79, 79, 0.1);
  color: var(--danger-base);
}

