/* ============================================
   NESTLÉ DMS - Professional Design System
   ============================================ */

/* CSS Variables - Design Tokens */
:root {
  /* Brand Colors */
  --nestle-red: rgb(100, 81, 61);
  --nestle-red-dark: rgb(80, 61, 41);
  --nestle-red-light: rgb(120, 101, 81);
  --nestle-blue: rgb(100, 81, 61);
  --nestle-blue-dark: rgb(80, 61, 41);
  --nestle-brown: rgb(100, 81, 61);
  --nestle-brown-dark: rgb(80, 61, 41);

  /* Semantic Colors */
  --success: #22c55e;
  --success-light: #dcfce7;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --info: #3b82f6;
  --info-light: #dbeafe;

  /* Neutral Palette */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Background Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;

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

  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  /* Spacing */
  --spacing-xs: 0.5rem;
  --spacing-sm: 0.75rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   BASE STYLES
   ============================================ */

* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-secondary);
  color: var(--gray-900);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--gray-900);
}

h2 {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

h5 {
  font-size: 1.125rem;
  font-weight: 600;
}

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

/* Top Bar */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  transition: all var(--transition-base);
}

.menu-toggle {
  background: none;
  border: none;
  width: 40px;
  height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
  padding: 0;
}

.menu-toggle:hover {
  background: var(--gray-100);
}

.menu-toggle span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--gray-700);
  border-radius: 2px;
  transition: all var(--transition-base);
}

.menu-toggle.active span:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

.top-bar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: 1rem;
}

.top-bar-brand .brand-logo {
  height: 40px;
  width: auto;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.05));
}

.brand-title {
  font-weight: 700;
  color: var(--nestle-brown);
  font-size: 1.125rem;
  margin: 0;
  letter-spacing: -0.025em;
}

/* User Info in Top Bar */
#userInfo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--gray-50);
  border-radius: var(--radius-md);
}

.user-role-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--nestle-red);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 64px;
  left: 0;
  width: 260px;
  height: calc(100vh - 64px);
  background: var(--bg-primary);
  border-right: 1px solid var(--gray-200);
  box-shadow: var(--shadow-md);
  z-index: 999;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--transition-slow);
  padding: 1.5rem 0;
}

.sidebar.collapsed {
  transform: translateX(-100%);
}

.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav-item {
  margin: 0.25rem 0;
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1.5rem;
  color: var(--gray-700);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9375rem;
  transition: all var(--transition-base);
  border-left: 3px solid transparent;
  position: relative;
}

.sidebar-nav-link:hover {
  background: var(--gray-50);
  color: var(--nestle-red);
  border-left-color: var(--nestle-red);
}

.sidebar-nav-link.active {
  background: linear-gradient(90deg, rgba(200, 16, 46, 0.08) 0%, transparent 100%);
  color: var(--nestle-red);
  border-left-color: var(--nestle-red);
  font-weight: 600;
}

.sidebar-nav-icon {
  width: 20px;
  height: 20px;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-divider {
  height: 1px;
  background: var(--gray-200);
  margin: 1rem 1.5rem;
}

.sidebar-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1rem 1.5rem;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
  font-size: 0.75rem;
  color: var(--gray-500);
  text-align: center;
}

/* Overlay */
.sidebar-overlay {
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Main Content */
.main-content {
  margin-top: 64px;
  margin-left: 260px;
  transition: margin-left var(--transition-slow);
  min-height: calc(100vh - 64px);
  padding: 2rem;
}

.main-content.expanded {
  margin-left: 0;
}

/* Legacy navbar support (for backward compatibility) */
.navbar {
  display: none;
}

/* ============================================
   CARDS
   ============================================ */

.card {
  background: var(--bg-primary);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
  overflow: hidden;
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-header {
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: var(--gray-900);
}

.card-body {
  padding: 1.5rem;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-subtitle {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
  border-width: 1.5px;
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-xs);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, var(--nestle-red) 0%, var(--nestle-red-dark) 100%);
  border-color: var(--nestle-red);
  color: white;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--nestle-red-dark) 0%, #8b0a1c 100%);
  border-color: var(--nestle-red-dark);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-success {
  background: linear-gradient(135deg, var(--success) 0%, #16a34a 100%);
  border-color: var(--success);
  color: white;
}

.btn-success:hover {
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-outline-primary {
  border-color: var(--nestle-red);
  color: var(--nestle-red);
  background: white;
}

.btn-outline-primary:hover {
  background: var(--nestle-red);
  border-color: var(--nestle-red);
  color: white;
}

.btn-outline-secondary {
  border-color: var(--gray-300);
  color: var(--gray-700);
  background: white;
}

.btn-outline-secondary:hover {
  background: var(--gray-100);
  border-color: var(--gray-400);
  color: var(--gray-900);
}

.btn-outline-danger {
  border-color: var(--danger);
  color: var(--danger);
  background: white;
}

.btn-outline-danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.btn-link {
  color: var(--nestle-blue);
  text-decoration: none;
  font-weight: 500;
}

.btn-link:hover {
  color: var(--nestle-blue-dark);
  text-decoration: underline;
}

/* ============================================
   FORMS
   ============================================ */

.form-label {
  font-weight: 500;
  color: var(--gray-700);
  font-size: 0.9375rem;
  margin-bottom: 0.5rem;
}

.form-control, .form-select {
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-md);
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  transition: all var(--transition-base);
  background: white;
  color: var(--gray-900);
}

.form-control:focus, .form-select:focus {
  border-color: var(--nestle-red);
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.1);
  outline: none;
}

.form-control::placeholder {
  color: var(--gray-400);
}

/* ============================================
   TABLES
   ============================================ */

.table {
  border-collapse: separate;
  border-spacing: 0;
}

.table thead th {
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
  color: var(--gray-700);
  font-weight: 600;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.875rem 1rem;
}

.table tbody td {
  padding: 1rem;
  border-bottom: 1px solid var(--gray-200);
  vertical-align: middle;
}

.table tbody tr {
  transition: background-color var(--transition-fast);
}

.table tbody tr:hover {
  background-color: var(--gray-50);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tfoot td {
  font-weight: 600;
  padding: 1rem;
  background: var(--gray-50);
  border-top: 2px solid var(--gray-300);
}

.table-responsive {
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

.product-name {
  font-weight: 600;
  color: var(--gray-900);
}

/* ============================================
   BADGES
   ============================================ */

.badge {
  font-weight: 600;
  font-size: 0.75rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0.025em;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.badge.bg-primary {
  background: linear-gradient(135deg, var(--nestle-blue) 0%, var(--nestle-blue-dark) 100%);
}

.badge.bg-success {
  background: linear-gradient(135deg, var(--success) 0%, #16a34a 100%);
}

.badge.bg-warning {
  background: linear-gradient(135deg, var(--warning) 0%, #ea580c 100%);
  color: white;
}

.badge.bg-danger {
  background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%);
}

.badge.bg-secondary {
  background: linear-gradient(135deg, var(--gray-500) 0%, var(--gray-600) 100%);
}

.badge.bg-info {
  background: linear-gradient(135deg, var(--info) 0%, #2563eb 100%);
}

/* ============================================
   ALERTS
   ============================================ */

.alert {
  border-radius: var(--radius-lg);
  border: 1px solid;
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.alert-success {
  background: var(--success-light);
  border-color: var(--success);
  color: #166534;
}

.alert-warning {
  background: var(--warning-light);
  border-color: var(--warning);
  color: #92400e;
}

.alert-danger {
  background: var(--danger-light);
  border-color: var(--danger);
  color: #991b1b;
}

.alert-info {
  background: var(--info-light);
  border-color: var(--info);
  color: #1e40af;
}

.alert-heading {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.alert-link {
  font-weight: 600;
  text-decoration: underline;
}

/* ============================================
   CHAT INTERFACE
   ============================================ */

.chat-area {
  background: linear-gradient(180deg, white 0%, var(--gray-50) 100%);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  min-height: 400px;
  max-height: 600px;
  padding: 1rem;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.04);
}

.msg {
  padding: 0.875rem 1rem;
  border-radius: var(--radius-lg);
  margin-bottom: 0.875rem;
  max-width: 85%;
  animation: slideIn var(--transition-base);
  box-shadow: var(--shadow-xs);
}

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

.msg.user {
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
  border: 1px solid #93c5fd;
  margin-left: auto;
  color: #1e40af;
}

.msg.assistant {
  background: white;
  border: 1px solid var(--gray-200);
  color: var(--gray-900);
}

/* ============================================
   QUICK REPLY BUTTONS
   ============================================ */

#quickReplies .btn {
  font-size: 0.8125rem;
  padding: 0.5rem 0.875rem;
  background: white;
  border: 1.5px solid var(--gray-300);
  color: var(--gray-700);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
}

#quickReplies .btn:hover {
  background: var(--nestle-red);
  border-color: var(--nestle-red);
  color: white;
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

/* ============================================
   MODALS
   ============================================ */

.modal-content {
  border-radius: var(--radius-xl);
  border: none;
  box-shadow: var(--shadow-xl);
}

.modal-header {
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.modal-title {
  font-weight: 600;
  color: var(--gray-900);
  font-size: 1.25rem;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
  padding: 1rem 1.5rem;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ============================================
   LOADING STATES
   ============================================ */

.spinner-border {
  width: 1.5rem;
  height: 1.5rem;
  border-width: 2px;
}

.btn .spinner-border {
  width: 1rem;
  height: 1rem;
  border-width: 2px;
}

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-300) 50%, var(--gray-200) 75%);
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ============================================
   PAGE-SPECIFIC STYLES
   ============================================ */

/* Page header */
main > .d-flex.justify-content-between.align-items-center {
  margin-bottom: 2rem;
}

main h2 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Order draft table enhancement */
#orderDraft table, #spotSaleDraft table {
  margin-bottom: 0;
}

/* Stock status badges */
.stock-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
}

.stock-ok {
  background: var(--success-light);
  color: #166534;
}

.stock-low {
  background: var(--warning-light);
  color: #92400e;
}

.stock-critical {
  background: var(--danger-light);
  color: #991b1b;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

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

.border-bottom {
  border-bottom: 1px solid var(--gray-200) !important;
}

.small {
  font-size: 0.875rem;
}

/* Hover lift effect */
.hover-lift {
  transition: transform var(--transition-base);
}

.hover-lift:hover {
  transform: translateY(-2px);
}

/* Focus visible for accessibility */
*:focus-visible {
  outline: 2px solid var(--nestle-red);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.show {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .brand-title {
    font-size: 1rem;
  }

  .card-body {
    padding: 1rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  .main-content {
    padding: 1.5rem;
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 280px;
  }

  .top-bar {
    padding: 0 1rem;
  }

  .main-content {
    padding: 1rem;
  }
}

@media (max-width: 575.98px) {
  .top-bar-brand .brand-logo {
    height: 32px;
  }

  .brand-title {
    font-size: 0.9375rem;
  }

  .sidebar {
    width: 100%;
    max-width: 300px;
  }

  .msg {
    max-width: 95%;
  }

  .card-body {
    padding: 0.875rem;
  }

  h2 {
    font-size: 1.375rem;
  }

  .main-content {
    padding: 1rem 0.75rem;
  }

  .top-bar {
    height: 56px;
    padding: 0 0.75rem;
  }

  .sidebar {
    top: 56px;
    height: calc(100vh - 56px);
  }

  .main-content {
    margin-top: 56px;
  }

  .sidebar-overlay {
    top: 56px;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .navbar,
  .btn,
  #quickReplies {
    display: none !important;
  }

  body {
    background: white;
  }

  .card {
    box-shadow: none;
    page-break-inside: avoid;
  }
}

/* ============================================
   ANIMATIONS
   ============================================ */

/* Fade in animation */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.fade-in {
  animation: fadeIn var(--transition-base);
}

/* Slide up animation */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.slide-up {
  animation: slideUp var(--transition-slow);
}

/* Pulse animation for important elements */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

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