/* === Login Page === */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #442054 0%, #7b3f8e 50%, #592867 100%);
}

.login-card {
  background: white;
  padding: 44px;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(89, 40, 103, 0.2);
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.login-card p {
  color: var(--gray-400);
  margin-bottom: 24px;
}

.login-error {
  background: var(--danger-light);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

/* === Dashboard Layout === */
.dashboard-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: white;
  color: var(--gray-800);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
  border-right: 1px solid var(--gray-200);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--gray-200);
}

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.sidebar-header small {
  color: var(--gray-400);
  font-size: 12px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section {
  padding: 8px 20px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gray-400);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--gray-500);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 14px;
}

.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-200);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.user-details { flex: 1; min-width: 0; }
.user-details .name {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-details .role {
  font-size: 11px;
  color: var(--gray-400);
}

.btn-logout {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 4px;
}
.btn-logout:hover { color: var(--primary); }

/* Main content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.top-bar {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-bar h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
}

.top-bar-subtitle {
  font-size: 13px;
  color: var(--gray-400);
  font-weight: 400;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-content {
  padding: 24px;
}

/* === KPI Cards === */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: white;
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
  border-color: rgba(89, 40, 103, 0.15);
}

.kpi-card-content { flex: 1; min-width: 0; }

.kpi-card .kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-card .kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--gray-900);
  margin: 6px 0 4px;
  line-height: 1.1;
}

.kpi-card .kpi-change {
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 8px;
}

.kpi-change.positive { color: var(--success); background: var(--success-light); }
.kpi-change.negative { color: var(--danger); background: var(--danger-light); }

.kpi-card .kpi-sub {
  font-size: 12px;
  color: var(--gray-400);
  margin-top: 2px;
}

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.kpi-icon.purple { background: var(--primary-light); color: var(--primary); }
.kpi-icon.green { background: var(--success-light); color: var(--success); }
.kpi-icon.amber { background: var(--warning-light); color: var(--warning); }
.kpi-icon.red { background: var(--danger-light); color: var(--danger); }
.kpi-icon.cyan { background: var(--info-light); color: var(--info); }

/* === Chart Cards === */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.charts-grid-2x2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.charts-grid-2x2 .chart-box {
  min-height: 260px;
}

.charts-grid-2x2 .chart-box h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 12px;
}

/* === Auto-refresh timer === */
.auto-refresh {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--gray-400);
}

.auto-refresh select {
  padding: 4px 8px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 12px;
  background: var(--gray-50);
  cursor: pointer;
}

.auto-refresh .refresh-countdown {
  font-variant-numeric: tabular-nums;
  min-width: 28px;
}

.card {
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  transition: box-shadow 0.2s;
}

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

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-800);
}

.card-body {
  padding: 22px;
}

.card-body canvas {
  max-height: 300px;
}

/* === Filters Bar === */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  background: white;
  padding: 14px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-400);
  white-space: nowrap;
}

.filter-group select,
.filter-group input {
  padding: 7px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 13px;
  background: var(--gray-50);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-group select:focus,
.filter-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: white;
}

/* === Insights Panel === */
.insights-panel {
  background: linear-gradient(135deg, #f9f0fc 0%, #f3e8f9 100%);
  border: 1px solid rgba(89, 40, 103, 0.15);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 24px;
}

.insights-panel h3 {
  font-size: 15px;
  color: var(--primary);
  margin-bottom: 12px;
}

.insight-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--gray-700);
}

.insight-item + .insight-item {
  border-top: 1px solid rgba(186, 230, 253, 0.5);
}

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

/* === Responsive === */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--gray-700);
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .sidebar-toggle {
    display: block;
  }
  .chart-grid,
  .charts-grid-2x2 {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .filters-bar {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .page-content {
    padding: 16px;
  }
}

/* === Drawer (Slide Panel) === */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.drawer-overlay.open {
  opacity: 1;
  visibility: visible;
}

.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 600px;
  max-width: 100vw;
  background: white;
  z-index: 201;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

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

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--gray-200);
  background: white;
  flex-shrink: 0;
}

.drawer-header h2 {
  font-size: 16px;
  color: var(--gray-900);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  margin-right: 12px;
}

.drawer-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--gray-500);
  flex-shrink: 0;
  border-radius: var(--radius);
  transition: color 0.2s, background 0.2s;
}

.drawer-close:hover {
  color: var(--gray-800);
  background: var(--gray-100);
}

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

.drawer-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  background: white;
  flex-shrink: 0;
}

/* Collapsible sections */
.drawer-section {
  margin-bottom: 20px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
}

.drawer-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.drawer-section-header:hover {
  background: var(--gray-100);
}

.drawer-section-header h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-700);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0;
}

.drawer-section-header .chevron {
  transition: transform 0.2s;
  color: var(--gray-400);
}

.drawer-section.collapsed .drawer-section-header .chevron {
  transform: rotate(-90deg);
}

.drawer-section-body {
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.drawer-section.collapsed .drawer-section-body {
  display: none;
}

.drawer-section-body .form-group.full-width {
  grid-column: 1 / -1;
}

.drawer-section-body .form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.drawer-section-body .form-control {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px;
  background: white;
  box-sizing: border-box;
}

.drawer-section-body .form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.form-control[readonly] {
  background: var(--gray-50);
  color: var(--gray-500);
  cursor: not-allowed;
}

/* Product image in drawer */
.drawer-product-image {
  width: 80px;
  height: 80px;
  object-fit: contain;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}

.drawer-product-image-placeholder {
  width: 80px;
  height: 80px;
  background: var(--gray-100);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  font-size: 11px;
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--gray-300);
  transition: 0.2s;
  border-radius: 22px;
}

.toggle-slider:before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(18px);
}

/* Clickable table rows */
.table-clickable tbody tr {
  cursor: pointer;
}

.table-clickable tbody tr:hover {
  background: #faf5fc;
}

/* === Section Toggle Chips === */
.section-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding-top: 8px;
  border-top: 1px solid var(--gray-100);
  margin-top: 4px;
}

.section-toggles-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 4px;
}

.section-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--gray-300);
  background: white;
  color: var(--gray-500);
  transition: all 0.15s;
}

.section-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.section-chip.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: rgba(89, 40, 103, 0.25);
  font-weight: 600;
}

/* === ABC Overview with Donut Chart === */
.abc-overview {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.abc-cards-col {
  flex: 1;
  min-width: 0;
}

.abc-overview .abc-cards {
  grid-template-columns: 1fr;
}

.abc-chart-col {
  width: 250px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === Export Dropdown === */
.export-dropdown {
  position: relative;
}

.export-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 20;
  min-width: 200px;
  overflow: hidden;
}

.export-menu button {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  color: var(--gray-700);
  cursor: pointer;
  transition: background 0.1s;
}

.export-menu button:hover {
  background: var(--gray-50);
}

.export-menu button + button {
  border-top: 1px solid var(--gray-100);
}

/* === Date Presets === */
.date-presets {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.btn-outline {
  background: white;
  border: 1px solid var(--gray-200);
  color: var(--gray-500);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

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

/* === KPI Highlight Card === */
.kpi-card-highlight {
  border-left: 4px solid var(--primary);
}

.kpi-badge-new {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 6px;
  vertical-align: middle;
}

/* === Order Items Expandable Row === */
.order-row:hover {
  background: #f8fafc;
}

.order-items-row td {
  padding: 8px 24px !important;
  background: #f8fafc;
}

.items-subtable {
  width: 100%;
  max-width: 700px;
  margin: 4px 0;
  border-collapse: collapse;
  font-size: 12px;
}

.items-subtable th {
  background: #e2e8f0;
  padding: 6px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--gray-600);
}

.items-subtable td {
  padding: 5px 10px;
  border-bottom: 1px solid #e2e8f0;
}

/* === Tabs === */
.tabs-nav {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 20px;
  background: white;
  border-radius: 12px 12px 0 0;
  padding: 0 8px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  border-bottom-width: 2px;
}

.tab-btn {
  position: relative;
  padding: 14px 24px;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-400);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.2s;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--primary);
}

.tab-btn.active {
  color: var(--primary);
  font-weight: 600;
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

@media (max-width: 768px) {
  .drawer-panel {
    width: 100vw;
  }
  .drawer-section-body {
    grid-template-columns: 1fr;
  }
  .abc-overview {
    flex-direction: column;
  }
  .abc-chart-col {
    width: 100%;
    max-width: 280px;
    margin: 0 auto;
  }
  .date-presets {
    flex-wrap: wrap;
  }
  .tabs-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tab-btn {
    padding: 12px 16px;
    font-size: 13px;
  }
}
