/* ===================================================
   Система складского учёта — Modern UI
   =================================================== */

/* ---- Design Tokens ---- */
:root {
  /* Sidebar */
  --sidebar-width: 256px;
  --topbar-height: 60px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-text-hover: #f1f5f9;
  --sidebar-active-bg: rgba(99, 102, 241, 0.15);
  --sidebar-active-text: #818cf8;
  --sidebar-active-border: #6366f1;
  --sidebar-border: rgba(148, 163, 184, 0.1);

  /* Brand colors */
  --c-primary: #6366f1;
  --c-primary-dark: #4f46e5;
  --c-primary-light: #e0e7ff;
  --c-success: #10b981;
  --c-warning: #f59e0b;
  --c-danger: #ef4444;
  --c-info: #06b6d4;
  --c-secondary: #64748b;

  /* Layout */
  --c-bg: #f0f4f8;
  --c-surface: #ffffff;

  /* Text */
  --c-text: #1e293b;
  --c-text-muted: #64748b;
  --c-heading: #0f172a;
  --c-border: #e2e8f0;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.15);

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 24px;

  /* Bootstrap overrides */
  --bs-primary: #6366f1;
  --bs-primary-rgb: 99, 102, 241;
  --bs-success: #10b981;
  --bs-success-rgb: 16, 185, 129;
  --bs-warning: #f59e0b;
  --bs-warning-rgb: 245, 158, 11;
  --bs-danger: #ef4444;
  --bs-danger-rgb: 239, 68, 68;
  --bs-info: #06b6d4;
  --bs-info-rgb: 6, 182, 212;
  --bs-secondary: #64748b;
  --bs-secondary-rgb: 100, 116, 139;
  --bs-body-bg: #f0f4f8;
  --bs-body-color: #1e293b;
  --bs-border-radius: 10px;
  --bs-border-radius-sm: 6px;
  --bs-border-radius-lg: 16px;
  --bs-font-sans-serif: 'Inter', system-ui, -apple-system, sans-serif;
  --bs-link-color: #6366f1;
  --bs-link-hover-color: #4f46e5;
  --bs-border-color: #e2e8f0;
  --bs-card-border-color: transparent;
  --bs-card-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  --bs-table-bg: #ffffff;
}

/* ---- Base ---- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 0.925rem;
  color: var(--c-text);
  background-color: var(--c-bg);
  height: 100%;
  -webkit-font-smoothing: antialiased;
}

/* =============================================
   APP LAYOUT (authenticated)
   ============================================= */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform 0.3s ease;
  overflow: hidden;
}

.sidebar-brand {
  padding: 0 1.25rem;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-brand-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  color: #f1f5f9;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.sidebar-brand-link:hover {
  color: #ffffff;
}

.sidebar-brand-icon {
  width: 32px;
  height: 32px;
  background: var(--c-primary);
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  color: #fff;
  flex-shrink: 0;
}

/* Sidebar user block */
.sidebar-user {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-dark));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
}

.sidebar-user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.72rem;
  color: var(--sidebar-text);
  margin-top: 1px;
}

/* Sidebar nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 0;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 2px;
}

.sidebar-nav-section {
  padding: 0.5rem 1.25rem 0.25rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.5);
  margin-top: 0.5rem;
}

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

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.sidebar-nav-link:hover {
  color: var(--sidebar-text-hover);
  background: rgba(255, 255, 255, 0.05);
  border-left-color: rgba(99, 102, 241, 0.4);
}

.sidebar-nav-link.active {
  color: var(--sidebar-active-text);
  background: var(--sidebar-active-bg);
  border-left-color: var(--sidebar-active-border);
}

.sidebar-nav-link .nav-icon {
  width: 18px;
  text-align: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  opacity: 0.85;
}

.sidebar-nav-link.active .nav-icon {
  opacity: 1;
}

.sidebar-nav-link--danger:hover {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.1);
  border-left-color: rgba(239, 68, 68, 0.4);
}

/* Sidebar footer */
.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: 0.5rem 0;
  flex-shrink: 0;
}

/* ---- Sidebar overlay (mobile) ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1039;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.show {
  display: block;
}

/* ---- Main wrapper ---- */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  transition: margin-left 0.3s ease;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  z-index: 1030;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.topbar-toggler {
  background: none;
  border: none;
  color: var(--c-text-muted);
  font-size: 1.1rem;
  padding: 0.375rem;
  cursor: pointer;
  border-radius: var(--r-sm);
  display: none;
  transition: background 0.15s;
}

.topbar-toggler:hover {
  background: var(--c-bg);
  color: var(--c-text);
}

.topbar-spacer {
  flex: 1;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--c-text);
}

.topbar-user-avatar {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-dark));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

/* ---- Page content ---- */
.page-content {
  flex: 1;
  padding: 1.75rem 1.5rem;
}

/* ---- Page header ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--c-heading);
  margin: 0;
  letter-spacing: -0.02em;
}

.page-title i {
  color: var(--c-primary);
  margin-right: 0.5rem;
}

/* =============================================
   AUTH LAYOUT
   ============================================= */
.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
  padding: 2rem 1rem;
}

.auth-card-wrapper {
  width: 100%;
  max-width: 440px;
}

.auth-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-brand-icon {
  width: 56px;
  height: 56px;
  background: var(--c-primary);
  border-radius: var(--r-lg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #fff;
  margin-bottom: 0.875rem;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}

.auth-brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: #f1f5f9;
  display: block;
  letter-spacing: -0.01em;
}

.auth-brand-sub {
  font-size: 0.8rem;
  color: rgba(148, 163, 184, 0.8);
  display: block;
  margin-top: 0.25rem;
}

.auth-card {
  background: #ffffff;
  border-radius: var(--r-xl);
  padding: 2.25rem 2rem;
  box-shadow: var(--shadow-xl);
}

.auth-card-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--c-heading);
  margin-bottom: 0.375rem;
  letter-spacing: -0.02em;
}

.auth-card-subtitle {
  font-size: 0.875rem;
  color: var(--c-text-muted);
  margin-bottom: 1.75rem;
}

/* =============================================
   CARDS
   ============================================= */
.card {
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  background: var(--c-surface);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--c-border);
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: var(--c-heading);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-header h5,
.card-header h6 {
  margin: 0;
  font-weight: 600;
  font-size: inherit;
}

.card-header i {
  color: var(--c-primary);
}

.card-body {
  padding: 1.25rem;
}

/* Stats cards */
.stats-card {
  border-radius: var(--r-md);
  padding: 1.25rem 1.25rem 1rem;
  border: none;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stats-card::before {
  content: '';
  position: absolute;
  top: -20px;
  right: -20px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
}

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

.stats-icon {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
  opacity: 0.9;
}

.stats-value {
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 0.25rem;
}

.stats-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.8;
}

/* =============================================
   TABLES
   ============================================= */
.table {
  font-size: 0.875rem;
  margin: 0;
}

.table > thead > tr > th {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-muted);
  border-bottom: 1px solid var(--c-border);
  padding: 0.75rem 1rem;
  white-space: nowrap;
  background: #f8fafc;
}

.table > tbody > tr > td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid #f1f5f9;
  color: var(--c-text);
}

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

.table-hover > tbody > tr:hover > td {
  background-color: #fafbff;
}

.table-dark thead th {
  background: var(--sidebar-bg);
  color: #94a3b8;
  border-bottom-color: rgba(148, 163, 184, 0.1);
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  font-weight: 500;
  font-size: 0.875rem;
  border-radius: var(--r-sm);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.btn-primary {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--c-primary-dark);
  border-color: var(--c-primary-dark);
  color: #fff;
}

.btn-success {
  background: var(--c-success);
  border-color: var(--c-success);
}

.btn-success:hover {
  background: #059669;
  border-color: #059669;
}

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

.btn-warning {
  background: var(--c-warning);
  border-color: var(--c-warning);
  color: #fff;
}

.btn-warning:hover {
  color: #fff;
}

.btn-sm {
  padding: 0.3rem 0.625rem;
  font-size: 0.8rem;
  border-radius: var(--r-sm);
}

.btn-lg {
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  border-radius: var(--r-md);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
}

.btn:active {
  transform: translateY(0);
}

.btn-outline-primary {
  color: var(--c-primary);
  border-color: var(--c-primary);
}

.btn-outline-primary:hover {
  background: var(--c-primary);
  color: #fff;
}

/* =============================================
   BADGES
   ============================================= */
.badge {
  font-weight: 600;
  font-size: 0.7rem;
  padding: 0.3em 0.65em;
  border-radius: 50px;
  letter-spacing: 0.02em;
}

.badge.bg-primary { background: var(--c-primary) !important; }
.badge.bg-success { background: var(--c-success) !important; }
.badge.bg-warning { background: var(--c-warning) !important; color: #fff !important; }
.badge.bg-danger { background: var(--c-danger) !important; }
.badge.bg-info { background: var(--c-info) !important; }
.badge.bg-secondary { background: var(--c-secondary) !important; }

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25em 0.7em;
  border-radius: 50px;
  font-size: 0.72rem;
  font-weight: 600;
}

.status-draft     { background: rgba(100, 116, 139, 0.12); color: var(--c-secondary); }
.status-confirmed { background: rgba(245, 158, 11, 0.12); color: #d97706; }
.status-completed { background: rgba(16, 185, 129, 0.12); color: #059669; }
.status-cancelled { background: rgba(239, 68, 68, 0.12); color: #dc2626; }
.status-in_progress { background: rgba(6, 182, 212, 0.12); color: #0891b2; }

/* =============================================
   FORMS
   ============================================= */
.form-control,
.form-select {
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  color: var(--c-text);
  padding: 0.5rem 0.875rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  background-color: #fff;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
  outline: none;
}

.form-label {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--c-text);
  margin-bottom: 0.375rem;
}

.form-text {
  font-size: 0.775rem;
  color: var(--c-text-muted);
}

.form-check-input:checked {
  background-color: var(--c-primary);
  border-color: var(--c-primary);
}

/* =============================================
   ALERTS / FLASH
   ============================================= */
.alert {
  border: none;
  border-radius: var(--r-md);
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.alert-success {
  background: rgba(16, 185, 129, 0.1);
  color: #065f46;
  border-left: 4px solid var(--c-success);
}

.alert-danger {
  background: rgba(239, 68, 68, 0.1);
  color: #7f1d1d;
  border-left: 4px solid var(--c-danger);
}

.alert-warning {
  background: rgba(245, 158, 11, 0.1);
  color: #78350f;
  border-left: 4px solid var(--c-warning);
}

.alert-info {
  background: rgba(6, 182, 212, 0.1);
  color: #164e63;
  border-left: 4px solid var(--c-info);
}

/* Alert animation */
.alert-message-hidden {
  opacity: 0;
  visibility: hidden;
  max-height: 0;
  overflow: hidden;
  margin: 0;
  padding: 0;
  border: none;
  min-height: 0;
  pointer-events: none;
  transition: opacity 0.3s, max-height 0.4s, visibility 0.3s;
}

.alert-message-visible {
  opacity: 1;
  visibility: visible;
  max-height: 200px;
  pointer-events: auto;
}

/* =============================================
   MODALS
   ============================================= */
.modal-content {
  border: none;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xl);
  color: var(--c-text);
}

.modal-header {
  border-bottom: 1px solid var(--c-border);
  padding: 1.25rem 1.5rem;
}

.modal-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--c-heading);
}

.modal-body {
  padding: 1.25rem 1.5rem;
}

.modal-footer {
  border-top: 1px solid var(--c-border);
  padding: 1rem 1.5rem;
}

/* =============================================
   PAGINATION
   ============================================= */
.pagination {
  gap: 0.25rem;
}

.page-link {
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  color: var(--c-text);
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem;
}

.page-link:hover {
  background: var(--c-primary-light);
  border-color: var(--c-primary);
  color: var(--c-primary);
}

.page-item.active .page-link {
  background: var(--c-primary);
  border-color: var(--c-primary);
}

/* =============================================
   LIST GROUP
   ============================================= */
.list-group-item {
  border-color: var(--c-border);
  color: var(--c-text);
  font-size: 0.875rem;
  padding: 0.75rem 1rem;
}

.list-group-item:first-child { border-top-left-radius: var(--r-md); border-top-right-radius: var(--r-md); }
.list-group-item:last-child { border-bottom-left-radius: var(--r-md); border-bottom-right-radius: var(--r-md); }

/* =============================================
   DROPDOWN
   ============================================= */
.dropdown-menu {
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 0.375rem;
}

.dropdown-item {
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  padding: 0.475rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--c-text);
  transition: background 0.1s;
}

.dropdown-item:hover {
  background: var(--c-bg);
  color: var(--c-primary);
}

.dropdown-item i {
  width: 16px;
  text-align: center;
  opacity: 0.7;
}

/* =============================================
   QR & PRINT
   ============================================= */
.qr-code {
  max-width: 150px;
  height: auto;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 5px;
  background-color: white;
}

.price-label {
  border: 2px solid #000;
  padding: 10px;
  margin: 10px;
  display: inline-block;
  text-align: center;
  font-family: monospace;
  background-color: white;
}

.price-label .product-name {
  font-weight: bold;
  font-size: 14px;
  margin-bottom: 5px;
}

.price-label .price {
  font-size: 18px;
  font-weight: bold;
  color: var(--c-danger);
}

/* =============================================
   UTILITIES
   ============================================= */
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--c-heading);
  font-weight: 700;
  letter-spacing: -0.02em;
}

code {
  background: #f1f5f9;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
  color: #6366f1;
}

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

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

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

  .topbar-toggler {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .page-content {
    padding: 1.25rem 1rem;
  }
}

@media (max-width: 575.98px) {
  .auth-card {
    padding: 1.75rem 1.25rem;
  }

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

  .stats-value {
    font-size: 1.5rem;
  }
}

/* =============================================
   PRINT
   ============================================= */
@media print {
  .sidebar,
  .topbar,
  .sidebar-overlay {
    display: none !important;
  }

  .main-wrapper {
    margin-left: 0 !important;
  }

  .card {
    box-shadow: none;
    border: 1px solid #dee2e6;
  }

  .no-print {
    display: none !important;
  }
}
