/* ================================================================
   JK Bykes — Core System & Global UI Stylesheet
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --color-navy-900: #0f172a;
  --color-navy-800: #1e293b;
  --color-navy-700: #334155;
  --color-brand-600: #2563eb;
  --color-brand-700: #1d4ed8;
  --color-emerald-600: #16a34a;
  --color-amber-500: #f59e0b;
  --color-rose-600: #e11d48;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
  background-color: #f8fafc;
  color: #334155;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.4);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.6);
}

/* ---------- Sidebar Layout: Fixed height flex column ----------
   Header & footer stay pinned; only the nav scrolls (scrollbar hidden). */
#app-sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}
#app-sidebar > div:first-child,
#app-sidebar > div:last-child {
  flex-shrink: 0;
}
#sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}
#sidebar-nav::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

/* ---------- Typography & Base Utility ---------- */
h1 { font-size: 1.5rem; font-weight: 800; color: #0f172a; tracking: -0.02em; }
h2 { font-size: 1.25rem; font-weight: 700; color: #1e293b; }
h3 { font-size: 1.125rem; font-weight: 600; color: #1e293b; }

.page-header {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.card {
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---------- KPI Cards ---------- */
.kpi-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  flex: 1 1 220px;
  min-width: 220px;
  background: #fff;
  border-radius: 14px;
  padding: 18px;
  border: 1px solid #f1f5f9;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.kpi-value {
  font-size: 1.375rem;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.2;
}
.kpi-label {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 2px;
}

/* ---------- Data Tables (EXCEL AUTO-FIT STYLE, NO UNNECESSARY WRAPPING) ---------- */
.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  table-layout: auto; /* EXCEL-LIKE AUTO FIT TO CONTENT */
}
.data-table th {
  background: #f8fafc;
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
  white-space: normal; /* ALLOW MULTI-WORD HEADERS TO WRAP VERTICALLY */
  line-height: 1.25;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  vertical-align: middle;
  max-width: 120px; /* TRIGGER WORD WRAP ON MULTI-WORD HEADERS */
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
  vertical-align: middle;
  white-space: nowrap; /* DEFAULT CLEAN INLINE FIT */
  line-height: 1.35;
}
.data-table td.wrap-cell {
  white-space: normal;
  word-break: break-word;
}
.data-table th.text-right, .data-table td.text-right {
  text-align: right;
}
.data-table th.text-center, .data-table td.text-center {
  text-align: center;
}
.data-table tr:hover td { background: #f8fafc; }

.data-table .empty-row td {
  text-align: center;
  padding: 48px 14px;
  color: #94a3b8;
  white-space: normal;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  white-space: nowrap;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-orange { background: #ffedd5; color: #9a3412; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 9px;
  font-size: 0.875rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff; box-shadow: 0 4px 12px rgba(37,99,235,0.25); }
.btn-primary:hover { background: linear-gradient(135deg, #1d4ed8, #1e40af); box-shadow: 0 6px 16px rgba(37,99,235,0.35); }

.btn-success { background: linear-gradient(135deg, #16a34a, #15803d); color: #fff; box-shadow: 0 4px 12px rgba(22,163,74,0.25); }
.btn-success:hover { box-shadow: 0 6px 16px rgba(22,163,74,0.35); }

.btn-danger { background: linear-gradient(135deg, #dc2626, #b91c1c); color: #fff; box-shadow: 0 4px 12px rgba(220,38,38,0.25); }
.btn-danger:hover { box-shadow: 0 6px 16px rgba(220,38,38,0.35); }

.btn-outline { background: #fff; color: #334155; border: 1px solid #cbd5e1; font-weight: 600; }
.btn-outline:hover { border-color: #64748b; background: #f8fafc; color: #0f172a; }

.btn-sm { padding: 7px 14px; font-size: 0.8125rem; }
.btn-xs { padding: 4px 8px; font-size: 0.75rem; }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 15px;
  flex-shrink: 0;
}
.btn-icon-sm {
  width: 26px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 13px;
  flex-shrink: 0;
}

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 6px;
}
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.8125rem;
  color: #334155;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.form-textarea { resize: vertical; min-height: 80px; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}
.modal-content {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0,0,0,0.15);
  animation: slideUp 0.25s ease;
}
.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 1rem; font-weight: 700; color: #1e293b; margin: 0; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: none;
  background: #f1f5f9;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.modal-close:hover { background: #e2e8f0; }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Sidebar Styles ---------- */
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin: 2px 8px;
  border-radius: 8px;
  font-size: 0.8125rem;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}
.sidebar-nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-nav-item.active {
  background: rgba(59,130,246,0.2);
  color: #fff;
  font-weight: 600;
}
.sidebar-nav-item.highlighted-sales-btn {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(5, 150, 105, 0.3));
  border: 1px solid rgba(52, 211, 153, 0.4);
  color: #a7f3d0 !important;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.15);
  margin-top: 4px;
  margin-bottom: 4px;
}
.sidebar-nav-item.highlighted-sales-btn:hover {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.35), rgba(5, 150, 105, 0.5));
  border-color: rgba(52, 211, 153, 0.7);
  color: #ffffff !important;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.sidebar-nav-item.highlighted-sales-btn.active {
  background: linear-gradient(135deg, #10b981, #059669);
  border-color: #34d399;
  color: #ffffff !important;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.45);
}
.sidebar-nav-item i { font-size: 18px; width: 20px; text-align: center; }

/* ---------- Tab Bar Items ---------- */
.tab-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  font-size: 0.625rem;
  color: #94a3b8;
  cursor: pointer;
  transition: color 0.15s ease;
  flex: 1;
  text-decoration: none;
}
.tab-bar-item:hover, .tab-bar-item.active { color: #2563eb; }
.tab-bar-item i { font-size: 20px; }

/* ---------- Search Bar ---------- */
.search-bar {
  position: relative;
  max-width: 320px;
}
.search-bar input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.8125rem;
  background: #fff;
}
.search-bar input:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.search-bar i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #94a3b8; font-size: 15px; }

/* ---------- Filters ---------- */
.filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 360px;
}
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
.toast-info { background: #2563eb; }

/* ---------- Animations ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(100px); } to { opacity: 1; transform: translateX(0); } }

/* ---------- Print ---------- */
@media print {
  #app-sidebar, #app-topbar, #app-tab-bar, .btn, .search-bar, .filter-bar { display: none !important; }
  #app-main { margin-left: 0 !important; }
  #app-body-content { padding: 0 !important; }
}

/* ---------- Searchable Select Dropdown Stacking Fix ---------- */
.searchable-select-wrapper {
  position: relative;
  z-index: 40;
}
.searchable-select-wrapper > div:last-child {
  z-index: 100 !important;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 10px 10px -5px rgba(0, 0, 0, 0.08) !important;
}
.card:has(.searchable-select-wrapper),
.card.overflow-visible {
  overflow: visible !important;
  position: relative;
  z-index: 30;
}

/* ---------- Fast Spinner Animation for Dev Logo ---------- */
@keyframes spinFast {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.animate-spin-fast {
  animation: spinFast 0.6s linear infinite;
}

/* ---------- Responsive Grid & Layout Enhancements for Mobile & Tablet ---------- */
.overflow-x-auto {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Custom smooth scrollbar for tablet & mobile tables */
.overflow-x-auto::-webkit-scrollbar {
  height: 6px;
}
.overflow-x-auto::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}
.overflow-x-auto::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
.overflow-x-auto::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Base KPI Grid default for Mobile Phone: 2 CARDS PER ROW ON MOBILE (375px)! */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 12px;
}

/* Tablet (640px to 1023px): 3 CARDS PER ROW ON TABLETS! */
@media (min-width: 640px) and (max-width: 1023px) {
  .kpi-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 14px;
  }
}

/* Desktop (>= 1024px): 4 CARDS PER ROW ON DESKTOP! */
@media (min-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 16px;
  }
}

@media (max-width: 1023px) {
  .data-table { font-size: 0.75rem; }
  
  /* Touch target optimizations for tablets */
  .btn { min-height: 38px; }
  .form-input, .form-select { min-height: 38px; }
  
  /* Modal responsiveness */
  .modal-dialog {
    width: 95% !important;
    max-width: 640px !important;
    margin: 12px auto !important;
  }
}

@media (max-width: 767px) {
  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
  }
  
  .page-header > div:last-child {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .page-header button, .page-header a {
    flex: 1;
    justify-content: center;
  }
  
  /* Compact table padding on phones */
  .data-table th, .data-table td {
    padding: 8px 8px !important;
  }
  
  /* Compact KPI Card padding on phone so 2 cards fit side by side cleanly */
  .kpi-card {
    padding: 10px 12px !important;
    gap: 10px !important;
  }
  .kpi-card .kpi-value {
    font-size: 1.1rem !important;
  }
  .kpi-card .kpi-label {
    font-size: 0.68rem !important;
  }
  
  /* Modal full width on phone */
  .modal-dialog {
    width: 98% !important;
    max-width: 100% !important;
    margin: 8px auto !important;
  }

  .toast-container {
    left: 12px !important;
    right: 12px !important;
    top: 12px !important;
  }

  .toast {
    max-width: 100% !important;
  }
}
