/* ============================================================
   Admin Dashboard Template — Custom CSS
   Design: shadcn/ui inspired
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
  --background: #ffffff;
  --foreground: #09090b;

  --muted: #f4f4f5;
  --muted-foreground: #71717a;

  --primary: #2563eb;
  --primary-foreground: #fafafa;

  --secondary: #f4f4f5;
  --secondary-foreground: #18181b;

  --destructive: #ef4444;
  --destructive-foreground: #fafafa;

  --border: #e4e4e7;
  --ring: #2563eb;

  --card: #ffffff;
  --card-foreground: #09090b;

  --popover: #ffffff;
  --popover-foreground: #09090b;

  --sidebar: var(--background);
  --sidebar-foreground: #334155;

  --radius: 0.5rem;

  --color-transition: 0.3s ease;
}

:root.dark {
  --background: #0a0a0a;
  --foreground: #fafafa;

  --muted: #1e293b;
  --muted-foreground: #94a3b8;

  --primary: #3b82f6;
  --primary-foreground: #0a0a0a;

  --secondary: #1e293b;
  --secondary-foreground: #f8fafc;

  --destructive: #f87171;
  --destructive-foreground: #0a0a0a;

  --border: #27272a;
  --ring: #3b82f6;

  --card: #141414;
  --card-foreground: #fafafa;

  --popover: #141414;
  --popover-foreground: #fafafa;

  --sidebar: var(--background);
  --sidebar-foreground: #e2e8f0;
}

/* ---------- Base ---------- */
* {
  border-color: var(--border);
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  background-color: var(--background);
  color: var(--foreground);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--color-transition),
    color var(--color-transition);
}

/* ---------- Utility helpers ---------- */
.color-mode-transition,
.color-mode-transition * {
  transition: background-color var(--color-transition),
    border-color var(--color-transition),
    color var(--color-transition), fill var(--color-transition),
    stroke var(--color-transition) !important;
}

.bg-background {
  background-color: var(--background);
}
.bg-card {
  background-color: var(--card);
}
.bg-muted {
  background-color: var(--muted);
}
.bg-primary {
  background-color: var(--primary);
}
.bg-secondary {
  background-color: var(--secondary);
}
.bg-sidebar {
  background-color: var(--sidebar);
}

.text-foreground {
  color: var(--foreground);
}
.text-card-foreground {
  color: var(--card-foreground);
}
.text-muted-foreground {
  color: var(--muted-foreground);
}
.text-primary {
  color: var(--primary);
}
.text-secondary-foreground {
  color: var(--secondary-foreground);
}
.text-destructive {
  color: var(--destructive);
}

.border-border {
  border-color: var(--border);
}

.ring-ring {
  --tw-ring-color: var(--ring);
}

/* ---------- Scrollbar (subtle) ---------- */
* {
  scrollbar-width: thin;
}
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--muted-foreground);
  opacity: 0.4;
  border-radius: 9999px;
}

/* Sidebar nav stays scrollable but never shows a scrollbar */
[data-sidebar] nav {
  -ms-overflow-style: none;
  scrollbar-width: none;
}
[data-sidebar] nav::-webkit-scrollbar {
  display: none;
}

/* ---------- Selection ---------- */
::selection {
  background-color: var(--primary);
  color: var(--primary-foreground);
}

/* ---------- Sidebar collapse (desktop only) ---------- */
@media (min-width: 1024px) {
  /* collapsed base */
  html.sidebar-collapsed [data-sidebar] {
    width: 4.5rem;
  }
  html.sidebar-collapsed [data-sidebar-header] {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }
  html.sidebar-collapsed [data-sidebar-collapsed-logo] {
    display: block;
  }
  html.sidebar-collapsed [data-sidebar-brand] {
    display: none;
  }
  html.sidebar-collapsed [data-sidebar-label] {
    display: none;
  }
  html.sidebar-collapsed [data-sidebar-collapse] {
    display: none;
  }
  /* nav > a only aligns the direct top-level links; the collapsible-group
     "buttons" live inside block <div> wrappers, so pad/center them explicitly */
  html.sidebar-collapsed [data-sidebar] nav > a,
  html.sidebar-collapsed [data-sidebar] [data-nav-collapse] {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }
  /* hide collapsible submenus in icon-only mode */
  html.sidebar-collapsed [data-nav-submenu] {
    display: none;
  }
  html.sidebar-collapsed [data-nav-chevron] {
    display: none;
  }
  /* active group stays highlighted in icon mode (text only, no pill) */
  html.sidebar-collapsed [data-nav-group].nav-group-active [data-nav-collapse] {
    color: var(--primary);
    font-weight: 600;
  }
  html.sidebar-collapsed [data-sidebar-footer] {
    justify-content: center;
  }
  html.sidebar-collapsed [data-sidebar-footer-box] {
    width: auto;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }
  html.sidebar-collapsed [data-sidebar-name] {
    display: none;
  }
  html.sidebar-collapsed [data-main] {
    padding-left: 4.5rem;
  }

  /* hover flyout: temporary expand (pure CSS). :not(.flyout-lock) lets JS
     collapse immediately — the sidebar shrinks even while the cursor still
     hovers, instead of snapping back open under the pointer. */
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover {
    width: 16rem;
    box-shadow: 0 0 0 1px var(--border), 0 8px 24px rgba(0, 0, 0, 0.12);
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-sidebar-header] {
    justify-content: space-between;
    padding-left: 1rem;
    padding-right: 1rem;
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-sidebar-collapsed-logo] {
    display: none;
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-sidebar-brand] {
    display: flex;
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-sidebar-label] {
    display: block;
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-sidebar-collapse] {
    display: inline-flex;
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover nav > a,
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-nav-collapse] {
    justify-content: flex-start;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  /* nav > * misses the nested submenu links — restore their pl-11 indent */
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-nav-submenu] [data-nav-link] {
    padding-left: 2.75rem;
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-nav-submenu] {
    display: block;
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-nav-chevron] {
    display: block;
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-sidebar-footer] {
    justify-content: flex-start;
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-sidebar-footer-box] {
    width: 100%;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  html.sidebar-collapsed:not(.flyout-lock) [data-sidebar]:hover [data-sidebar-name] {
    display: block;
  }
}

/* ---------- Fixed overlays inside .space-y-10 content ---------- */
/* main uses space-y-10; its margin-top leaks onto fixed overlays and pushes
   the backdrop down, leaving an unshaded strip at the top. Reset it. */
[data-role-modal],
[data-admin-drawer],
[data-admin-drawer-overlay],
[data-product-drawer],
[data-product-drawer-overlay],
[data-variant-modal],
[data-variant-modal-overlay],
[data-category-modal],
[data-category-modal-overlay],
[data-stock-modal],
[data-return-modal],
[data-customer-modal],
[data-expense-category-modal],
[data-expense-category-modal-overlay],
[data-expense-modal],
[data-expense-modal-overlay],
[data-payment-modal],
[data-payment-modal-overlay] {
  margin-top: 0 !important;
}

/* ---------- Dashboard period filter ---------- */
/* The counters and lists are refetched over AJAX; dim them while the request is
   in flight so a second change cannot be triggered mid-swap. */
[data-dashboard-body][data-loading="1"] {
  opacity: 0.5;
  pointer-events: none;
}

/* ---------- Form validation field errors ---------- */
[data-field-error] {
  border-color: var(--destructive) !important;
}

[data-field-error]:focus {
  border-color: var(--destructive) !important;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--destructive) 30%, transparent) !important;
}

/* ---------- Tooltips (icon-only controls) ----------
   One bubble is appended to <body> and positioned with `fixed`, because every
   table lives inside an `overflow-x-auto` wrapper that would clip an absolutely
   positioned tooltip. `left`/`top` are set in JS; the rest is static. */
[data-tooltip-bubble] {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  max-width: 18rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  background: var(--foreground);
  color: var(--background);
  font-size: 0.75rem;
  line-height: 1rem;
  text-align: left;
  /* Never swallow the click that the tooltip is describing. */
  pointer-events: none;
  opacity: 0;
  transform: translateX(2px);
  transition: opacity 120ms ease, transform 120ms ease;
}

[data-tooltip-bubble].is-visible {
  opacity: 1;
  transform: translateX(0);
}

/* The caret rides the edge facing the control: right edge normally, left edge
   when the bubble had to flip because the control was too close to the viewport. */
[data-tooltip-bubble]::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -3px;
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: var(--foreground);
  transform: translateY(-50%) rotate(45deg);
}

[data-tooltip-bubble].is-flipped {
  transform: translateX(-2px);
}

[data-tooltip-bubble].is-flipped.is-visible {
  transform: translateX(0);
}

[data-tooltip-bubble].is-flipped::after {
  right: auto;
  left: -3px;
}

@media (prefers-reduced-motion: reduce) {
  [data-tooltip-bubble] {
    transition: none;
  }
}

/* ---------- Notification bell + highlighted rows ---------- */
@keyframes bell-shake {
  0%, 100% { transform: rotate(0deg); }
  15% { transform: rotate(10deg); }
  30% { transform: rotate(-8deg); }
  45% { transform: rotate(6deg); }
  60% { transform: rotate(-3deg); }
  75% { transform: rotate(1deg); }
}

.animate-bell-shake {
  animation: bell-shake 0.8s ease-in-out infinite;
  transform-origin: 50% 10%;
}

/* Highlight flash for a freshly-navigated table row (a notification click
   target). The class stays on the row until the page is reloaded/navigated —
   the animation settles into a persistent highlight so it is easy to spot. */
.table-row-flash {
  animation: row-flash 2.8s ease forwards;
}

.table-row-flash td {
  background-color: transparent;
}

@keyframes row-flash {
  0%, 30% {
    background-color: color-mix(in srgb, var(--primary) 45%, transparent);
    box-shadow: inset 0 0 0 2px var(--ring);
  }
  100% {
    background-color: color-mix(in srgb, var(--primary) 18%, transparent);
    box-shadow: inset 0 0 0 1px var(--ring);
  }
}
