/**
 * ==============================================================================
 * 3A Lighting Enterprise ERP (Beta 2.0 - Workflow-First)
 * CSS Main Design System & Global Layout
 * ==============================================================================
 * Visual Tokens:
 *   --bg-main: #F8FAFC (Light slate canvas ~75%)
 *   --sidebar-bg: #1E293B (Deep slate blue ~25%)
 *   --accent-gold: #FACC15 (Royal Gold CTA)
 *   --accent-emerald: #10B981 (Positive KPI / Validated concessions)
 *   --accent-rose: #EF4444 (Critical alerts / Overdue / Violation)
 *   --accent-blue: #0284C7 (Informational / SKU badges)
 * ==============================================================================
 */

:root {
  /* Color Palette */
  --bg-main: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-surface-alt: #F1F5F9;
  --sidebar-bg: #1E293B;
  --sidebar-surface: #0F172A;
  --sidebar-text: #94A3B8;
  --sidebar-text-active: #F8FAFC;
  --sidebar-border: rgba(255, 255, 255, 0.08);

  --accent-gold: #FACC15;
  --accent-gold-hover: #EAB308;
  --accent-gold-light: rgba(250, 204, 21, 0.12);

  --accent-emerald: #10B981;
  --accent-emerald-dark: #059669;
  --accent-emerald-light: rgba(16, 185, 129, 0.12);

  --accent-rose: #EF4444;
  --accent-rose-dark: #DC2626;
  --accent-rose-light: rgba(239, 68, 68, 0.12);

  --accent-blue: #0284C7;
  --accent-blue-dark: #0369A1;
  --accent-blue-light: rgba(2, 132, 199, 0.12);

  --accent-amber: #F59E0B;
  --accent-amber-light: rgba(245, 158, 11, 0.12);

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;

  --border-subtle: #E2E8F0;
  --border-medium: #CBD5E1;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, "Liberation Mono", Menlo, monospace;

  /* Layout dimensions */
  --sidebar-width: 220px;
  --topbar-height: 60px;
  --drawer-width: 480px;

  /* Elevation Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-main);
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

/* Monospace Helpers */
.font-mono,
.mono-val,
.sku-badge,
.amount-val {
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

/* App Shell Layout */
#app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar Navigation */
.app-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  z-index: 100;
  user-select: none;
}

.sidebar-header {
  height: auto;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 10px 14px 8px 14px;
  gap: 8px;
  background-color: rgba(15, 23, 42, 0.4);
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  color: #FFFFFF;
  text-decoration: none;
}

.brand-badge {
  background: linear-gradient(135deg, #FACC15, #EAB308);
  color: #0F172A;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px;
}

.nav-section-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748B;
  padding: 10px 10px 4px 10px;
  margin-top: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 6px;
  transition: background var(--transition-fast), color var(--transition-fast);
  margin-bottom: 2px;
}

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

.nav-item.active {
  background-color: rgba(250, 204, 21, 0.15);
  color: var(--accent-gold);
  font-weight: 600;
}

.nav-item .nav-badge {
  margin-left: auto;
  background-color: rgba(239, 68, 68, 0.2);
  color: #F87171;
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
}

.nav-item .nav-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
}

.sidebar-footer {
  padding: 12px 14px;
  background-color: rgba(15, 23, 42, 0.6);
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.role-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #E2E8F0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.role-pill .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
}

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-main);
}

/* Topbar Header */
.app-topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
  z-index: 90;
}

/* Search Box (Intent-Aware Global Search) */
.global-search-container {
  position: relative;
  flex: 1;
  max-width: 460px;
}

.global-search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.global-search-input {
  width: 100%;
  height: 36px;
  padding: 0 36px 0 34px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background-color: var(--bg-main);
  font-size: 13px;
  color: var(--text-primary);
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.global-search-input:focus {
  outline: none;
  background-color: #FFFFFF;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px var(--accent-blue-light);
}

.search-shortcut {
  position: absolute;
  right: 10px;
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--border-medium);
  border-radius: 4px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Global Search Dropdown Popup */
.search-results-dropdown {
  position: absolute;
  top: 42px;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: var(--shadow-xl);
  max-height: 420px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
}

.search-group-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 8px 12px 4px 12px;
  background-color: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border-subtle);
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #F1F5F9;
  transition: background var(--transition-fast);
}

.search-result-item:hover,
.search-result-item.selected {
  background-color: #F8FAFC;
}

.search-result-left {
  display: flex;
  flex-direction: column;
}

.search-result-title {
  font-weight: 600;
  font-size: 12.5px;
  color: var(--text-primary);
}

.search-result-sub {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.search-result-badge {
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

/* Topbar Actions Area */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Quick Create Dropdown */
.quick-create-container {
  position: relative;
}

.btn-quick-create {
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: var(--accent-gold);
  color: #0F172A;
  border: 1px solid #EAB308;
  padding: 0 14px;
  height: 34px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.btn-quick-create:hover {
  background-color: var(--accent-gold-hover);
}

.btn-quick-create:active {
  transform: translateY(1px);
}

.quick-create-menu {
  position: absolute;
  top: 40px;
  right: 0;
  width: 170px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  padding: 4px 0;
  z-index: 1000;
  display: none;
}

.quick-create-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.quick-create-item:hover {
  background-color: var(--bg-surface-alt);
  color: var(--accent-blue);
}

/* Role Selector Toggle */
.role-toggle-group {
  display: flex;
  background: var(--bg-surface-alt);
  border-radius: 6px;
  padding: 2px;
  border: 1px solid var(--border-subtle);
}

.role-toggle-btn {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.role-toggle-btn.active {
  background: #FFFFFF;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Notification Bell */
.notification-bell-btn {
  position: relative;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.notification-bell-btn:hover {
  background-color: var(--bg-surface-alt);
  color: var(--text-primary);
}

.notification-badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background-color: var(--accent-rose);
  border: 2px solid #FFFFFF;
  border-radius: 50%;
}

/* Notifications Popover */
.notifications-popover {
  position: absolute;
  top: 50px;
  right: 24px;
  width: 320px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: var(--shadow-xl);
  z-index: 1000;
  display: none;
}

.notifications-header {
  padding: 10px 14px;
  font-weight: 700;
  font-size: 12px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.notifications-list {
  max-height: 300px;
  overflow-y: auto;
}

.notification-item {
  padding: 10px 14px;
  border-bottom: 1px solid #F1F5F9;
  display: flex;
  gap: 10px;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.notification-item:hover {
  background-color: #F8FAFC;
}

.notif-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}

.notif-icon.warn {
  background-color: var(--accent-rose-light);
  color: var(--accent-rose);
}

.notif-icon.info {
  background-color: var(--accent-blue-light);
  color: var(--accent-blue);
}

.notif-content {
  flex: 1;
}

.notif-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-primary);
}

.notif-time {
  font-size: 10.5px;
  color: var(--text-muted);
}

/* View Container */
.view-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}

/* Common UI Components: Buttons, Cards, Badges, Tables */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 5px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--accent-gold);
  color: #0F172A;
  border-color: #EAB308;
}
.btn-primary:hover {
  background-color: var(--accent-gold-hover);
}

.btn-secondary {
  background-color: #FFFFFF;
  color: var(--text-primary);
  border-color: var(--border-medium);
}
.btn-secondary:hover {
  background-color: var(--bg-surface-alt);
  border-color: var(--text-muted);
}

.btn-success {
  background-color: var(--accent-emerald);
  color: #FFFFFF;
}
.btn-success:hover {
  background-color: var(--accent-emerald-dark);
}

.btn-danger {
  background-color: var(--accent-rose);
  color: #FFFFFF;
}
.btn-danger:hover {
  background-color: var(--accent-rose-dark);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11.5px;
  border-radius: 4px;
}

.btn-lg {
  padding: 8px 16px;
  font-size: 13.5px;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Pulse Amber Glow Animation for Primary Action */
@keyframes pulseAmberGlow {
  0% { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.7), 0 2px 6px rgba(250, 204, 21, 0.3); }
  70% { box-shadow: 0 0 0 8px rgba(250, 204, 21, 0), 0 3px 8px rgba(250, 204, 21, 0.4); }
  100% { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0), 0 2px 6px rgba(250, 204, 21, 0.3); }
}

.btn-pulse-gold {
  animation: pulseAmberGlow 2s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  line-height: 1.3;
}

.badge-emerald {
  background-color: var(--accent-emerald-light);
  color: var(--accent-emerald-dark);
}

.badge-rose {
  background-color: var(--accent-rose-light);
  color: var(--accent-rose-dark);
}

.badge-blue {
  background-color: var(--accent-blue-light);
  color: var(--accent-blue-dark);
}

.badge-amber {
  background-color: var(--accent-amber-light);
  color: #B45309;
}

.badge-slate {
  background-color: #F1F5F9;
  color: var(--text-secondary);
}

/* Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #FFFFFF;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 18px;
}

/* Clean ERP Data Table */
.data-table-container {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 12.5px;
}

.data-table th {
  background-color: #F8FAFC;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-medium);
  white-space: nowrap;
}

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background-color: #F8FAFC;
}

.data-table .text-right {
  text-align: right;
}

.data-table .text-center {
  text-align: center;
}

/* Drawer / Slide-Over Panel (for Invoicing without page leave) */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.drawer-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--drawer-width);
  max-width: 90vw;
  background: var(--bg-surface);
  box-shadow: var(--shadow-xl);
  z-index: 1200;
  transform: translateX(100%);
  transition: transform var(--transition-normal);
  display: flex;
  flex-direction: column;
}

.drawer-panel.active {
  transform: translateX(0);
}

.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.drawer-close-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.drawer-close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface-alt);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.drawer-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: #F8FAFC;
}

/* Modal Dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-surface);
  border-radius: 10px;
  box-shadow: var(--shadow-xl);
  width: 580px;
  max-width: 92vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(10px) scale(0.98);
  transition: transform var(--transition-fast);
}

.modal-overlay.active .modal-dialog {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  background: #F8FAFC;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #1E293B;
  color: #FFFFFF;
  padding: 10px 16px;
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
  pointer-events: auto;
  animation: toastSlideIn 0.2s ease-out;
  border-left: 4px solid var(--accent-gold);
}

.toast.toast-success {
  border-left-color: var(--accent-emerald);
}
.toast.toast-error {
  border-left-color: var(--accent-rose);
}
.toast.toast-info {
  border-left-color: var(--accent-blue);
}

@keyframes toastSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive Styles */
@media (max-width: 900px) {
  .app-sidebar {
    width: 64px;
    min-width: 64px;
  }
  .sidebar-header .brand-text,
  .nav-section-title,
  .nav-item span,
  .sidebar-footer {
    display: none;
  }
  .nav-item {
    justify-content: center;
    padding: 10px 0;
  }
  .nav-item .nav-badge {
    position: absolute;
    top: 4px;
    right: 4px;
  }
}
