/* ================================================
   DKApp - Main Stylesheet
   ================================================ */
:root {
  --sidebar-width: 250px;
  --sidebar-bg: #1a2332;
  --sidebar-text: #a8b2c1;
  --sidebar-hover: #2d3f55;
  --sidebar-active: #0d6efd;
  --topnav-bg: #0d6efd;
  --topnav-height: 56px;
  --content-bg: #f0f2f5;
  --card-radius: 12px;
  --transition: all 0.25s ease;
}

/* ---- Reset & Base ---- */
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', Tahoma, sans-serif; background: var(--content-bg); }

/* ---- Top Navbar ---- */
.dkapp-topnav {
  background: var(--topnav-bg) !important;
  height: var(--topnav-height);
  position: fixed; top: 0; left: 0; right: 0; z-index: 1050;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
/* Hide BU badge on very small screens to save space */
@media (max-width: 480px) {
  .dkapp-topnav .badge.bg-info,
  .dkapp-topnav .badge.bg-warning { display: none !important; }
  .dkapp-topnav .navbar-brand { font-size: 14px; }
}

/* ---- Layout wrapper ---- */
.dkapp-wrapper {
  display: flex;
  padding-top: var(--topnav-height);
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.dkapp-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  min-height: calc(100vh - var(--topnav-height));
  position: fixed;
  top: var(--topnav-height);
  left: 0; bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: var(--transition);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}
.dkapp-sidebar::-webkit-scrollbar { width: 4px; }
.dkapp-sidebar::-webkit-scrollbar-thumb { background: #3a4f6b; border-radius: 2px; }

.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid #2d3f55;
}
.sidebar-logo {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--sidebar-active);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px;
}
.sidebar-title { color: #fff; font-weight: 700; font-size: 16px; }

.sidebar-menu { flex: 1; padding: 10px 0; }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid #2d3f55; }

/* Sidebar links */
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: var(--transition);
  border-radius: 0;
}
.sidebar-link:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-link.active { background: var(--sidebar-active); color: #fff; }
.sidebar-icon { width: 20px; text-align: center; font-size: 14px; }

/* Section toggles */
.sidebar-section-toggle {
  display: flex; align-items: center;
  padding: 10px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px;
  transition: var(--transition);
  cursor: pointer;
}
.sidebar-section-toggle:hover { color: #fff; background: var(--sidebar-hover); }
.sidebar-section-toggle[aria-expanded="true"] .toggle-arrow { transform: rotate(180deg); }
.toggle-arrow { transition: transform .25s; font-size: 11px; }

.sidebar-submenu { padding: 2px 0 6px 0; }
.sidebar-submenu .sidebar-link { padding-left: 44px; font-size: 13.5px; }

/* ---- Main content ---- */
.dkapp-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  transition: var(--transition);
  min-width: 0;
}
body.sidebar-collapsed .dkapp-sidebar { width: 0; overflow: hidden; }
body.sidebar-collapsed .dkapp-content { margin-left: 0; }

/* ---- Cards ---- */
.card {
  border: none;
  border-radius: var(--card-radius);
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
}
.card-header { border-radius: var(--card-radius) var(--card-radius) 0 0 !important; font-weight: 600; }

/* Stat cards */
.stat-card { border-radius: var(--card-radius); color: #fff; padding: 22px 24px; position: relative; overflow: hidden; }
.stat-card .stat-icon { position: absolute; right: 20px; top: 50%; transform: translateY(-50%); font-size: 48px; opacity: .2; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat-card .stat-label { font-size: 13px; opacity: .85; margin-top: 4px; }
.stat-card .stat-change { font-size: 12px; margin-top: 6px; }

/* ---- Tables ---- */
.table th { background: #f8f9fa; font-weight: 600; font-size: 13px; color: #495057; }
.table-hover tbody tr:hover { background-color: #f0f7ff; }

/* ---- Badges ---- */
.badge { font-size: 11.5px; font-weight: 500; padding: 4px 8px; border-radius: 6px; }

/* ---- Forms ---- */
.form-label { font-weight: 500; font-size: 14px; }
.form-control:focus, .form-select:focus { border-color: var(--sidebar-active); box-shadow: 0 0 0 .2rem rgba(13,110,253,.15); }

/* ---- Buttons ---- */
.btn { border-radius: 8px; font-weight: 500; font-size: 14px; }
.btn-sm { font-size: 12px; padding: 4px 10px; border-radius: 6px; }

/* ---- Page header ---- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 10px;
}
.page-header h4 { margin: 0; font-weight: 700; color: #1a2332; }

/* ---- POS Screen ---- */
.pos-wrapper { display: flex; height: calc(100vh - var(--topnav-height) - 10px); gap: 14px; }
.pos-products { flex: 1; min-width: 0; overflow-y: auto; }
.pos-cart { width: 380px; background: #fff; border-radius: var(--card-radius); display: flex; flex-direction: column; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.pos-cart-header { padding: 16px; border-bottom: 1px solid #e9ecef; font-weight: 700; font-size: 16px; }
.pos-cart-items { flex: 1; overflow-y: auto; padding: 10px; }
.pos-cart-footer { padding: 14px; border-top: 1px solid #e9ecef; }
.cart-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; border: 1px solid #e9ecef; margin-bottom: 6px; }
.cart-item-name { flex: 1; font-size: 13px; font-weight: 500; }
.cart-qty-btn { width: 26px; height: 26px; border: 1px solid #dee2e6; background: #f8f9fa; border-radius: 6px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 14px; line-height: 1; }
.cart-qty-btn:hover { background: #e9ecef; }
.product-card { cursor: pointer; border: 2px solid transparent; transition: var(--transition); }
.product-card:hover { border-color: var(--sidebar-active); box-shadow: 0 4px 12px rgba(13,110,253,.15); transform: translateY(-2px); }
.product-card .stock-badge { font-size: 11px; }

/* ---- Alerts ---- */
.alert { border-radius: 10px; border: none; }

/* ---- Login page ---- */
.login-page { min-height: 100vh; background: linear-gradient(135deg, #1a2332 0%, #0d6efd 100%); display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 360px; max-width: 100%; border-radius: 14px; box-shadow: 0 16px 48px rgba(0,0,0,.35); }
.login-logo { text-align: center; margin-bottom: 16px; }
.login-logo i { font-size: 36px; color: var(--sidebar-active); }
.login-logo h5 { font-size: 15px; font-weight: 700; margin: 6px 0 2px; color: #1a2332; }
.login-logo p { font-size: 12px; color: #888; margin: 0; }

/* ---- Responsive ---- */
@media (max-width: 992px) {
  .dkapp-sidebar { transform: translateX(-100%); }
  .dkapp-content { margin-left: 0; }
  body.sidebar-open .dkapp-sidebar { transform: translateX(0); }
  .pos-wrapper { flex-direction: column; height: auto; }
  .pos-cart { width: 100%; }
}
@media (max-width: 576px) {
  .stat-card .stat-value { font-size: 22px; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ---- Misc ---- */
.cursor-pointer { cursor: pointer; }
.text-money { font-weight: 600; color: #198754; }
.required:after { content: ' *'; color: #dc3545; }
.table-actions { white-space: nowrap; }

/* ---- Business Unit Dashboard Tabs ---- */
.dashboard-tabs {
  border-bottom: 2px solid #dee2e6;
  gap: 4px;
}
.dashboard-tabs .nav-link {
  border: 2px solid transparent;
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  color: #495057;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 20px;
  transition: all .2s;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
}
.dashboard-tabs .nav-link:hover {
  background: #f0f7ff;
  color: #0d6efd;
  border-color: #dee2e6 #dee2e6 #fff;
}
.dashboard-tabs .nav-link.active {
  background: #fff;
  color: #0d6efd;
  border-color: #dee2e6 #dee2e6 #fff #dee2e6;
  border-bottom: 2px solid #fff;
  margin-bottom: -2px;
}
.bu-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- BU Comparison Cards ---- */
.bu-compare-card { border-radius: 12px !important; }
.bu-stat-mini {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 8px 10px;
}
.bu-stat-label { font-size: 11px; color: #6c757d; margin-bottom: 2px; }
.bu-stat-val   { font-size: 16px; font-weight: 700; }

/* Combined totals bar */
.divide-x > .col + .col { border-left: 1px solid #e9ecef; }

/* ---- Promotions ---- */
.promo-badge-pct  { background: #0dcaf0; color: #000; }
.promo-badge-fix  { background: #0d6efd; color: #fff; }
.promo-badge-bxgy { background: #ffc107; color: #000; }
.table-secondary td { color: #6c757d; }

/* ---- Settings ---- */
.settings-section { border-left: 4px solid var(--sidebar-active); padding-left: 16px; margin-bottom: 24px; }
.settings-section h6 { font-weight: 700; color: #1a2332; margin-bottom: 14px; }

/* ---- Business Units ---- */
.bu-card { border-left: 4px solid #198754; }
.bu-card .bu-code { font-family: monospace; font-size: 12px; background: #e9ecef; padding: 2px 6px; border-radius: 4px; }

/* ---- Permission Cards ---- */
.perm-card { background: #f8f9fa; border-color: #dee2e6 !important; }
.perm-card:hover { background: #e8f0fe; border-color: #86b7fe !important; }
.perm-card:has(.perm-check:checked) { background: #e6f4ea; border-color: #198754 !important; }

/* ---- Extra color utilities ---- */
.bg-purple { background-color: #6f42c1 !important; }
.bg-pink   { background-color: #d63384 !important; }
.bg-orange { background-color: #fd7e14 !important; }
.bg-teal   { background-color: #0dcaf0 !important; }

/* ---- btn-xs ---- */
.btn-xs { font-size: 11px; padding: 2px 7px; border-radius: 4px; }

/* ---- Print ---- */
@media print {
  .dkapp-topnav, .dkapp-sidebar, .no-print { display: none !important; }
  .dkapp-content { margin-left: 0 !important; }
  .card { box-shadow: none !important; }
}

/* ======================================================
   PAGE TRANSITIONS & ANIMATIONS
   ====================================================== */

/* Page enter */
@keyframes pageEnter {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.container-fluid {
  animation: pageEnter 0.32s cubic-bezier(.22,.61,.36,1);
}
/* Page exit */
.page-leaving .container-fluid {
  transition: opacity .18s ease, transform .18s ease !important;
  animation: none !important;
  opacity: 0 !important;
  transform: translateY(-8px) !important;
}

/* Top progress bar */
#page-progress {
  position: fixed; top: 0; left: 0;
  height: 3px; width: 0%;
  background: linear-gradient(90deg, rgba(255,255,255,.5) 0%, #fff 40%, rgba(168,212,255,.9) 70%, #fff 100%);
  background-size: 200% 100%;
  animation: progressShimmer 1.4s linear infinite;
  z-index: 9999;
  transition: width .3s ease, opacity .4s ease;
  box-shadow: 0 0 10px rgba(255,255,255,.7), 0 0 3px rgba(255,255,255,.5);
  opacity: 0;
  pointer-events: none;
}
#page-progress.active { opacity: 1; }
@keyframes progressShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 998;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
body.sidebar-open .sidebar-overlay {
  display: block;
  animation: overlayFadeIn .22s ease;
}
@keyframes overlayFadeIn {
  from { opacity: 0; } to { opacity: 1; }
}

/* Button ripple */
.btn { position: relative; overflow: hidden; }
.ripple-wave {
  position: absolute; border-radius: 50%;
  background: rgba(255,255,255,.38);
  transform: scale(0);
  animation: rippleAnim .5s ease-out forwards;
  pointer-events: none;
}
@keyframes rippleAnim { to { transform: scale(4.5); opacity: 0; } }

/* Stat cards hover lift */
.stat-card {
  transition: box-shadow .25s ease, transform .25s ease !important;
  cursor: default;
}
.stat-card:hover {
  transform: translateY(-4px) !important;
  box-shadow: 0 12px 28px rgba(0,0,0,.22) !important;
}

/* Sidebar link slide animation */
.sidebar-link {
  transition: background .18s ease, color .18s ease, padding-left .18s ease !important;
}
.sidebar-link:hover { padding-left: 26px !important; }
.sidebar-link.active { padding-left: 20px !important; }

/* Card stagger on dashboard */
@keyframes cardSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.row .col-6:nth-child(1) .stat-card,
.row .col-md-3:nth-child(1) .stat-card { animation: cardSlideUp .35s .05s both; }
.row .col-6:nth-child(2) .stat-card,
.row .col-md-3:nth-child(2) .stat-card { animation: cardSlideUp .35s .12s both; }
.row .col-6:nth-child(3) .stat-card,
.row .col-md-3:nth-child(3) .stat-card { animation: cardSlideUp .35s .19s both; }
.row .col-6:nth-child(4) .stat-card,
.row .col-md-3:nth-child(4) .stat-card { animation: cardSlideUp .35s .26s both; }

/* bu-compare cards animate */
.bu-compare-card { transition: box-shadow .25s, transform .25s; }
.bu-compare-card:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(0,0,0,.14) !important; }

/* ======================================================
   LOGIN PAGE ANIMATION
   ====================================================== */
@keyframes loginCardEnter {
  from { opacity: 0; transform: translateY(32px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.login-card { animation: loginCardEnter .45s cubic-bezier(.22,.61,.36,1); }

@keyframes loginBgPulse {
  0%, 100% { background-position: 0% 50%; }
  50%       { background-position: 100% 50%; }
}
.login-page {
  background: linear-gradient(135deg, #0d1b2a, #1a2332, #0d3d91, #0d6efd, #1a2332);
  background-size: 300% 300%;
  animation: loginBgPulse 12s ease infinite;
}

/* ======================================================
   MOBILE IMPROVEMENTS
   ====================================================== */

/* --- Tablet (≤992px) --- */
@media (max-width: 992px) {
  .dkapp-content { transition: margin-left .25s ease; }

  /* Sidebar slides in as drawer */
  .dkapp-sidebar {
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
    width: 270px;
  }

  /* Page header: stack vertically, smaller */
  .page-header { flex-direction: column; align-items: flex-start; gap: 6px; }
  .page-header h4 { font-size: 17px; }
  .page-header .text-muted.small { display: none; } /* hide clock on tablet */
}

/* --- Mobile (≤576px) --- */
@media (max-width: 576px) {
  /* Content padding */
  .container-fluid { padding-left: 12px !important; padding-right: 12px !important; padding-top: 10px !important; }

  /* Page header */
  .page-header { margin-bottom: 12px; }
  .page-header h4 { font-size: 15px; }

  /* Stat cards — compact, full-width icon, bigger touch area */
  .stat-card {
    padding: 12px 14px 12px 14px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 90px;
  }
  .stat-card .stat-icon {
    font-size: 36px;
    right: 12px;
    opacity: .18;
  }
  .stat-card .stat-value { font-size: 22px; font-weight: 800; }
  .stat-card .stat-label { font-size: 11.5px; opacity: .9; }
  .stat-card .stat-change { font-size: 11px; margin-top: 2px; }

  /* Row gap tighter on mobile */
  .row.g-3 { --bs-gutter-x: 0.6rem; --bs-gutter-y: 0.6rem; }

  /* Cards */
  .card { border-radius: 10px; }
  .card-header { font-size: 13.5px; padding: 10px 14px !important; }
  .card-body { padding: 12px !important; }

  /* Tables: smaller font, hide less-important cols */
  .table { font-size: 12px; }
  .table th { font-size: 11.5px; padding: 6px 8px; }
  .table td { padding: 7px 8px; vertical-align: middle; }
  .table-actions { white-space: nowrap; }

  /* Buttons: bigger tap targets on mobile */
  .btn-sm { font-size: 12px; padding: 6px 10px; }
  .btn    { min-height: 36px; }

  /* Dashboard quick stats card: list items tighter */
  .list-group-item { padding: 8px 0; font-size: 13px; }

  /* Dashboard comparison tabs: scrollable horizontally */
  .dashboard-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 0; }
  .dashboard-tabs::-webkit-scrollbar { height: 0; }
  .dashboard-tabs .nav-link { white-space: nowrap; font-size: 12.5px; padding: 7px 14px; }

  /* BU compare cards: mini stats 3 cols OK, chart height smaller */
  .bu-stat-val { font-size: 14px; }
  .bu-stat-label { font-size: 10.5px; }

  /* Forms */
  .form-label { font-size: 13px; }
  .modal-body { padding: 14px !important; }

  /* Alerts smaller */
  .alert { font-size: 13px; padding: 10px 14px; }

  /* Badges */
  .badge { font-size: 11px; padding: 3px 7px; }

  /* Hide page-header clock */
  .page-header .text-muted.small { display: none; }

  /* Pagination compact */
  .pagination .page-link { padding: 5px 10px; font-size: 12px; }

  /* POS on mobile */
  .pos-wrapper { gap: 8px; }
  .pos-products-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important; gap: 6px !important; }
  .product-tile { padding: 8px 6px !important; }
  .product-tile .pt-name { font-size: 11px !important; }
  .product-tile .pt-price { font-size: 12px !important; }
}

/* --- Small mobile (≤375px) --- */
@media (max-width: 375px) {
  .stat-card .stat-value { font-size: 19px; }
  .stat-card { min-height: 82px; }
  .container-fluid { padding-left: 8px !important; padding-right: 8px !important; }
  .row.g-3 { --bs-gutter-x: 0.4rem; --bs-gutter-y: 0.4rem; }
}

/* --- Bottom navigation bar for mobile (always visible quick access) --- */
.mobile-bottom-nav {
  display: none;
}
@media (max-width: 576px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 56px;
    background: #fff;
    border-top: 1px solid #e9ecef;
    box-shadow: 0 -2px 12px rgba(0,0,0,.10);
    z-index: 1040;
    align-items: stretch;
  }
  .mobile-bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: #6c757d;
    text-decoration: none;
    gap: 2px;
    transition: color .15s, background .15s;
    padding: 4px 2px;
  }
  .mobile-bottom-nav a i { font-size: 18px; }
  .mobile-bottom-nav a.active,
  .mobile-bottom-nav a:hover { color: #0d6efd; background: #f0f7ff; }
  .mobile-bottom-nav a.pos-btn { color: #fff; background: #0d6efd; border-radius: 0; }
  .mobile-bottom-nav a.pos-btn i { font-size: 20px; }
  .mobile-bottom-nav a.pos-btn:hover { background: #0b5ed7; }

  /* Push content above bottom nav */
  .dkapp-content { padding-bottom: 60px; }
}
