/* ═══════════════════════════════════════════════════
   main.css — Design tokens, fonts, layout shell
   ═══════════════════════════════════════════════════ */

/* ── Fonts ──────────────────────────────────────── */
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/inter.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ── Tokens ─────────────────────────────────────── */
:root {
  --primary:        #1765D8;
  --primary-dark:   #1353B4;
  --primary-light:  #EBF2FF;
  --success:        #22C55E;
  --success-bg:     #DCFCE7;
  --danger:         #EF4444;
  --danger-bg:      #FEE2E2;
  --warning:        #F59E0B;
  --warning-bg:     #FEF3C7;
  --info:           #3B82F6;
  --info-bg:        #DBEAFE;

  --bg:             #F5F6FA;
  --card:           #FFFFFF;
  --sidebar-bg:     #FFFFFF;
  --topbar-bg:      #FFFFFF;

  --text:           #1A1A2E;
  --text-2:         #374151;
  --muted:          #6B7387;
  --subtle:         #9CA3AF;

  --border:         #E5E7EB;
  --border-light:   #F3F4F6;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.10), 0 4px 6px rgba(0,0,0,.05);

  --sidebar-w:      210px;
  --topbar-h:       64px;

  --r-sm:   6px;
  --r:      10px;
  --r-lg:   14px;
  --r-full: 9999px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --ease: 0.18s ease;
}

/* ── Reset ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}
a { text-decoration: none; color: inherit; }
ul, ol { list-style: none; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: var(--font); }
img { max-width: 100%; display: block; }
svg { flex-shrink: 0; }

/* ── Utility ─────────────────────────────────────── */
.hidden   { display: none !important; }
.sr-only  { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.flex     { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.w-full { width: 100%; }
.text-sm  { font-size: 12px; }
.text-xs  { font-size: 11px; }
.fw-500   { font-weight: 500; }
.fw-600   { font-weight: 600; }
.fw-700   { font-weight: 700; }
.text-muted  { color: var(--muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Layout Shell ───────────────────────────────── */
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #1353B4 0%, #1765D8 50%, #2979E8 100%);
  position: relative;
  z-index: 900;
}

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-logo-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.sidebar-logo-text { line-height: 1.2; }
.sidebar-logo-text strong { font-size: 13px; font-weight: 700; color: var(--text); display: block; }
.sidebar-logo-text span   { font-size: 10px; color: var(--muted); }

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 16px 4px;
}

.sidebar-nav { padding: 6px 10px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
  white-space: nowrap;
  user-select: none;
}
.nav-item:hover { background: var(--border-light); color: var(--text); }
.nav-item.active {
  background: var(--primary);
  color: #fff;
}
.nav-item.active svg { color: #fff; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-light);
  padding: 12px 10px;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--ease);
}
.sidebar-user:hover { background: var(--border-light); }
.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--r-full);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-info strong { font-size: 12px; font-weight: 600; display: block; }
.sidebar-user-info span   { font-size: 11px; color: var(--muted); display: block; }
.sidebar-logout { padding: 4px; border-radius: var(--r-sm); color: var(--muted); transition: color var(--ease); }
.sidebar-logout:hover { color: var(--danger); }

.sidebar-shop-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--ease);
  margin-top: 2px;
}
.sidebar-shop-btn:hover { background: var(--border-light); color: var(--text); }

/* ── Topbar ──────────────────────────────────────── */
.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar {
  height: var(--topbar-h);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}
.topbar-title { font-size: 18px; font-weight: 700; flex-shrink: 0; }
.topbar-search {
  flex: 1;
  max-width: 380px;
  margin: 0 auto;
  position: relative;
}
.topbar-search input {
  width: 100%;
  padding: 8px 14px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--bg);
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color var(--ease);
}
.topbar-search input:focus { border-color: var(--primary); }
.topbar-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; position: relative; }
.topbar-icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
  position: relative;
}
.topbar-icon-btn:hover { background: var(--bg); color: var(--text); }
.notif-badge {
  position: absolute; top: 5px; right: 5px;
  width: 8px; height: 8px;
  background: var(--danger);
  border-radius: var(--r-full);
  border: 2px solid #fff;
}
.topbar-avatar {
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
  cursor: pointer;
  overflow: hidden;
}

/* Toggle (dark mode switch style) */
.toggle-switch {
  width: 40px; height: 22px;
  background: var(--border);
  border-radius: var(--r-full);
  position: relative;
  cursor: pointer;
  transition: background var(--ease);
}
.toggle-switch.on { background: var(--primary); }
.toggle-switch::after {
  content: '';
  width: 16px; height: 16px;
  background: #fff;
  border-radius: var(--r-full);
  position: absolute;
  top: 3px; left: 3px;
  transition: left var(--ease);
  box-shadow: var(--shadow-sm);
}
.toggle-switch.on::after { left: 21px; }

/* ── Page Content ────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  padding: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.page-content::-webkit-scrollbar { width: 6px; }
.page-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 20px; font-weight: 700; }

/* ── Overlay & Toast ─────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.toast-container {
  position: fixed; top: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 2000;
}

/* ── Global Watermark (simple DOM layer; below modal 1000 / toast 2000) ── */
.global-watermark {
  position: fixed;
  inset: 0;
  z-index: 800;
  pointer-events: none;
  user-select: none;
  opacity: 0.16;
  background-repeat: repeat;
  background-size: 340px 240px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='340' height='240'%3E%3Cstyle%3Etext%7Bfont-family:system-ui,-apple-system,sans-serif;font-size:17px;font-weight:700;fill:%231a1a2e%3B%7D%3C/style%3E%3Cg transform='translate(50,160) rotate(-28)'%3E%3Ctext%3EDEVELOPED BY KB%C2%B2%3C/text%3E%3C/g%3E%3C/svg%3E");
}

/* ── Scrollbar global ────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ═══════════════════════════════════════════════════
   RESPONSIVE DESIGN — Mobile, Tablet, Desktop
   ═══════════════════════════════════════════════════ */

/* ── Topbar Mobile Menu Toggle Button ────────────── */
.topbar-menu-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  color: var(--muted);
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
  align-items: center;
  justify-content: center;
  margin-right: auto;
}

aside#sidebar.open ~ .main-wrapper .topbar-actions {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.topbar-menu-toggle:hover { background: var(--bg); color: var(--text); }
.topbar-menu-toggle svg { width: 20px; height: 20px; }

/* -- Tablet (768px - 1024px) ────────────────────── */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: 240px;
    --topbar-h: 60px;
  }

  html { font-size: 13px; }
  
  .topbar { padding: 0 18px; gap: 12px; }
  .topbar-title { font-size: 16px; }
  .topbar-search { max-width: 300px; }
  .topbar-search input { padding: 7px 12px 7px 32px; font-size: 12px; }
  
  .sidebar-logo-text strong { font-size: 12px; }
  .sidebar-logo-text span { font-size: 9px; }
  .nav-item { font-size: 12px; padding: 7px 9px; gap: 8px; }
  .nav-item svg { width: 16px; height: 16px; }
  
  .page-content { padding: 18px; }
  .page-header { margin-bottom: 18px; }
  .page-header h1 { font-size: 18px; }
  
  .card-body { padding: 16px; }
  .card-header { padding: 14px 16px; }
  .card-header h3 { font-size: 14px; }
  
  .btn { padding: 7px 14px; font-size: 12px; }
  .btn-icon { width: 32px; height: 32px; padding: 6px; }
  .btn-icon svg { width: 14px; height: 14px; }
  
  .input, .textarea, .select { padding: 7px 10px; font-size: 12px; }
  .form-label { font-size: 11px; }
  
  table { font-size: 12px; }
  thead th { padding: 10px 12px; font-size: 11px; }
  tbody td { padding: 10px 12px; font-size: 12px; }
  
  .toast { min-width: 240px; max-width: 320px; }
  .modal-box { max-width: 420px; }
  .modal-header { padding: 14px 16px; }
  .modal-header h3 { font-size: 15px; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; gap: 8px; }
}

/* -- Mobile (< 768px) ──────────────────────────── */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 0;
    --topbar-h: 56px;
    font-size: 12px;
  }

  body { overflow: hidden; }
  html { font-size: 12px; }
  
  /* ── App Shell - Stack on Mobile ────────────────── */
  .app-shell { flex-direction: column; }
  
  /* ── Sidebar - Overlay/Hidden on Mobile ────────── */
  .sidebar {
    position: fixed;
    left: -100%;
    top: var(--topbar-h);
    width: 280px;
    height: calc(100vh - var(--topbar-h));
    background: #fff;
    border-right: 1px solid var(--border);
    z-index: 960;
    transition: left 0.3s ease;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
    opacity: 1;
    filter: none;
  }

  .sidebar.open { left: 0; }
  .sidebar-logo { padding: 14px 12px 10px; }
  .sidebar-logo-icon { width: 32px; height: 32px; }
  .sidebar-logo-text strong { font-size: 11px; }
  .sidebar-logo-text span { font-size: 8px; }
  .sidebar-nav { padding: 4px 8px; }
  .nav-item { 
    font-size: 11px; 
    padding: 6px 8px; 
    gap: 8px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
  }
  .nav-item svg { width: 15px; height: 15px; }
  .sidebar-section-label { padding: 10px 12px 2px; font-size: 9px; }
  .sidebar-footer { padding: 8px 8px; }
  .sidebar-user { padding: 6px 8px; }
  .sidebar-user-avatar { width: 28px; height: 28px; font-size: 10px; }
  .sidebar-user-info strong { font-size: 11px; }
  .sidebar-user-info span { font-size: 10px; }
  .sidebar-shop-btn { font-size: 11px; padding: 6px 8px; }
  
  /* ── Sidebar Overlay ────────────────────────────── */
  .sidebar-overlay {
    position: fixed;
    top: var(--topbar-h);
    left: 280px;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,.12);
    z-index: 940;
    display: none;
    pointer-events: none;
  }
  .sidebar-overlay.open {
    display: block;
    pointer-events: auto;
  }
  
  /* ── Topbar - Mobile Adjustments ────────────────── */
  .main-wrapper { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    min-width: 0;
    order: -1;
  }
  
  .topbar {
    position: relative;
    z-index: 970;
    background: var(--card);
    padding: 0 12px;
    gap: 8px;
    height: var(--topbar-h);
  }
  .sidebar,
  .sidebar.open {
    background: var(--card) !important;
  }
  .topbar-menu-toggle { display: flex; }
  .topbar-title { font-size: 14px; flex: 1; min-width: 0; }
  .topbar-search { display: none; }
  .topbar-actions { gap: 6px; }
  .topbar-icon-btn { width: 32px; height: 32px; }
  .topbar-icon-btn svg { width: 16px; height: 16px; }
  .topbar-avatar { width: 32px; height: 32px; font-size: 11px; }
  
  /* ── Page Content - Mobile ──────────────────────── */
  .page-content {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
  }
  .page-header { 
    flex-direction: column; 
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
  }
  .page-header h1 { font-size: 16px; }
  .page-header-actions { width: 100%; }
  .page-header-actions .btn { width: 100%; }
  
  /* ── Login Page - Mobile ────────────────────────── */
  .login-view { padding: 20px; }
  .login-card {
    padding: 24px 16px;
    max-width: 100%;
  }
  .login-logo { margin-bottom: 20px; }
  .login-logo-icon { width: 36px; height: 36px; }
  .login-logo-text h2 { font-size: 16px; }
  .login-card h1 { font-size: 20px; }
  .login-card .sub { font-size: 12px; margin-bottom: 18px; }
  .login-form { gap: 12px; }
  .login-form .btn { padding: 10px; }
  
  /* ── Cards - Mobile ────────────────────────────── */
  .card { border-radius: 8px; }
  .card-body { padding: 12px; }
  .card-header { padding: 12px; }
  .card-header h3 { font-size: 13px; }
  
  /* ── Buttons - Mobile ───────────────────────────── */
  .btn {
    padding: 8px 12px;
    font-size: 11px;
    border-radius: 6px;
  }
  .btn-icon { 
    width: 32px; 
    height: 32px; 
    padding: 5px;
    border-radius: 6px;
  }
  .btn-icon svg { width: 14px; height: 14px; }
  
  /* ── Forms - Mobile ────────────────────────────── */
  .form-group { gap: 4px; }
  .form-label { font-size: 10px; }
  .input, .textarea, .select {
    padding: 8px 10px;
    font-size: 11px;
    border-radius: 6px;
  }
  .textarea { min-height: 80px; }
  .input-group .input { padding-left: 32px; }
  .input-addon { right: 10px; }
  .form-toggle-label { font-size: 12px; }
  
  /* ── Tables - Mobile ────────────────────────────– */
  .table-wrap { border-radius: 8px; overflow-x: auto; }
  .table-toolbar {
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .table-toolbar h3 { font-size: 13px; }
  .table-toolbar-right { 
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }
  
  table { font-size: 11px; }
  thead th { 
    padding: 8px 10px; 
    font-size: 10px;
    white-space: nowrap;
  }
  tbody td {
    padding: 8px 10px;
    font-size: 11px;
  }
  .td-actions button { 
    width: 28px; 
    height: 28px;
  }
  .td-product-img { 
    width: 32px; 
    height: 32px;
  }
  
  /* ── Badges & Chips - Mobile ────────────────────– */
  .badge { padding: 2px 8px; font-size: 10px; }
  .chip { padding: 2px 8px; font-size: 11px; }
  
  /* ── Modals - Mobile ────────────────────────────– */
  .modal-overlay { padding: 16px; }
  .modal-box {
    max-width: 100%;
    width: 100%;
    max-height: 85vh;
  }
  .modal-header { padding: 12px; }
  .modal-header h3 { font-size: 14px; }
  .modal-body { padding: 12px; }
  .modal-footer { 
    padding: 10px 12px;
    gap: 6px;
    flex-wrap: wrap;
  }
  .modal-footer .btn { flex: 1; min-width: 80px; }
  
  /* ── Toast - Mobile ────────────────────────────── */
  .toast {
    min-width: auto;
    width: calc(100vw - 24px);
    max-width: 100%;
  }
  .toast-container {
    top: 12px;
    right: 12px;
    left: 12px;
  }
  
  /* ── Pagination - Mobile ────────────────────────– */
  .pagination {
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
  }
  .pagination-pages { 
    overflow-x: auto;
    width: 100%;
  }
  .pagination-info { font-size: 11px; }
  
  /* ── Empty State - Mobile ────────────────────────– */
  .empty-state { padding: 40px 16px; }
  .empty-state svg { width: 40px; height: 40px; }
  .empty-state h4 { font-size: 13px; }
  .empty-state p { font-size: 12px; }
  
  /* ── Dropzone ────────────────────────────────────– */
  .dropzone { padding: 20px 16px; border-radius: 8px; }
  .dropzone p { font-size: 12px; }
  
  /* ── Utilities ────────────────────────────────── */
  .gap-1 { gap: 2px; }
  .gap-2 { gap: 4px; }
  .gap-3 { gap: 8px; }
  .gap-4 { gap: 12px; }
  .mt-1 { margin-top: 2px; }
  .mt-2 { margin-top: 4px; }
  .mt-3 { margin-top: 8px; }
  .mt-4 { margin-top: 12px; }
  .mb-4 { margin-bottom: 12px; }
  .mb-6 { margin-bottom: 16px; }
  .text-sm { font-size: 11px; }
  .text-xs { font-size: 10px; }
}

/* -- Small Mobile (< 480px) ────────────────────── */
@media (max-width: 480px) {
  .sidebar { width: 260px; }
  .sidebar-overlay { left: 260px; }
  .topbar { padding: 0 10px; }
  .page-content { padding: 10px; }
  .page-header { margin-bottom: 10px; }
  
  .modal-box { border-radius: 12px; }
  .login-card { padding: 20px 12px; }
  .login-logo { margin-bottom: 16px; }
  .login-card h1 { font-size: 18px; }
  
  .btn { padding: 8px 10px; font-size: 10px; }
  .input, .textarea, .select { padding: 8px 10px; font-size: 10px; }
  
  table { font-size: 10px; }
  thead th { padding: 6px 8px; font-size: 9px; }
  tbody td { padding: 6px 8px; font-size: 10px; }
  
  .toast { font-size: 11px; }
  .toast-title { font-size: 12px; }
  .toast-msg { font-size: 11px; }
}
