@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
  --color-light: #ffffff;
  --color-dark: #171717;
  --auth-glass: rgba(255, 255, 255, 0.7);
  --auth-border: rgba(255, 255, 255, 0.4);
  color-scheme: light;
}

.dark,
:root.dark,
html.dark {
  --color-light: #1a1a1a;
  --color-dark: #f8fafc;
  --auth-glass: rgba(15, 23, 42, 0.8);
  --auth-border: rgba(255, 255, 255, 0.1);
  color-scheme: dark;
}

/* Paint the page background so PWA safe-areas and overscroll never fall
   through to the browser's default white behind the app. */
html,
body,
#root {
  background-color: #f9fafb;
}

html.dark,
html.dark body,
html.dark #root,
.dark body {
  background-color: #1a1a1a;
}

.accent-text {
  @apply text-slate-600;
}

body {
  font-family:
    "Inter Variable",
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    "Noto Sans",
    sans-serif,
    "Apple Color Emoji",
    "Segoe UI Emoji",
    "Segoe UI Symbol",
    "Noto Color Emoji";
  color: var(--color-dark);
  background: var(--color-light);
}

/* Apple-style loading spinner */
@keyframes appleSpinnerFade {
  0%,
  39%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

.apple-spinner {
  position: relative;
  display: inline-block;
  color: currentColor;
}

.apple-spinner__bar {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12%;
  height: 28%;
  background: currentColor;
  border-radius: 9999px;
  transform-origin: center;
  animation: appleSpinnerFade 1.2s infinite ease-in-out;
}

/* Auto-scrolling animation for horizontal cards */
.auto-scroll-container {
  display: flex;
  overflow-x: hidden;
  gap: 1rem;
  padding: 0.5rem 0 1rem 0;
}

.auto-scroll-content {
  display: flex;
  gap: 1rem;
  animation: scroll-left 30s linear infinite;
}

@keyframes scroll-left {
  0% {
    transform: translateX(0);
  }

  100% {
    transform: translateX(-50%);
  }
}

.auto-scroll-content:hover {
  animation-play-state: paused;
}

/* Tab transition animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(10px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.animate-fadeIn {
  animation: fadeIn 0.3s ease-in-out forwards;
}

.animate-fadeInLeft {
  animation: fadeInLeft 0.3s ease-in-out forwards;
}

.animate-fadeInRight {
  animation: fadeInRight 0.3s ease-in-out forwards;
}

/* Auth entrance: staggered rise — strong ease-out, starts from opacity 0
   + subtle translateY (never scale(0)); honors prefers-reduced-motion. */
@keyframes authRise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.auth-rise {
  opacity: 0;
  animation: authRise 250ms cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@media (prefers-reduced-motion: reduce) {
  .auth-rise {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* refined auth styles */
.auth-input-field {
  @apply w-full px-5 py-3.5 rounded-2xl bg-white/50 dark:bg-slate-900/50 border border-slate-200 dark:border-slate-800 focus:border-blue-500 dark:focus:border-blue-500 focus:ring-4 focus:ring-blue-500/10 outline-none transition-all duration-300 shadow-sm text-slate-900 dark:text-slate-100 placeholder:text-slate-400 dark:placeholder:text-slate-500 backdrop-blur-sm hover:border-slate-300 dark:hover:border-slate-700 font-sans text-base;
}

.auth-button {
  @apply w-full px-6 py-4 rounded-2xl bg-gradient-to-r from-blue-600 to-indigo-600 text-white font-bold text-base hover:from-blue-700 hover:to-indigo-700 active:scale-[0.98] transition-all duration-300 shadow-xl shadow-blue-500/25 disabled:opacity-50 disabled:grayscale disabled:scale-100 flex items-center justify-center gap-2 font-sans;
}

.auth-card {
  @apply bg-transparent dark:bg-transparent shadow-none border-none font-sans;
}

.auth-heading {
  @apply text-2xl sm:text-3xl font-sans font-black tracking-tight text-slate-900 dark:text-white leading-tight;
}

.auth-subheading {
  @apply text-slate-500 dark:text-slate-400 font-sans text-[13px] sm:text-sm font-medium leading-relaxed;
}

.auth-label {
  @apply block text-xs sm:text-sm font-semibold text-slate-600 dark:text-slate-300 mb-1.5 font-sans tracking-wide;
}

/* Pulse light animation for disabled access control */
.animate-pulse-light {
  animation: pulseLight 2s infinite;
}

@keyframes pulseLight {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(156, 163, 175, 0.3);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(156, 163, 175, 0);
  }
}

.dark .animate-pulse-light {
  animation: pulseLightDark 2s infinite;
}

@keyframes pulseLightDark {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(200, 200, 200, 0.15);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(200, 200, 200, 0);
  }
}

/* Blue pulse animation for disabled access control */
.animate-pulse-blue {
  animation: pulseBlue 2s infinite;
}

@keyframes pulseBlue {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.3); /* blue-500 */
  }
  50% {
    box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); /* blue-500 */
  }
}

.dark .animate-pulse-blue {
  animation: pulseBlueDark 2s infinite;
}

@keyframes pulseBlueDark {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.2); /* blue-400 */
  }
  50% {
    box-shadow: 0 0 0 6px rgba(96, 165, 250, 0); /* blue-400 */
  }
}

@keyframes ios-popover-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ios-popover {
  animation: ios-popover-in 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top center;
}

@media (prefers-reduced-motion: reduce) {
  .ios-popover {
    animation-duration: 0.01ms;
  }
}

/* Toast (sileo) styling */
/* Keep toasts within the viewport on small screens. sileo's injected :root
   var is overridden with higher specificity so the width shrinks on mobile. */
:root:root {
  --sileo-width: min(350px, calc(100vw - 1.5rem));
}

/* Ensure toasts stack above every modal/drawer in the app. Modals portal to
   body with z-[100], so the toast viewport (also on body) sits above them. */
[data-sileo-viewport] {
  z-index: 110;
}

/* Focus mode: only detailed toasts (description or action) blur the page for
   focus. src/lib/toast.ts adds .sileo-focus-blur to <body> when such a toast
   fires and removes it when the toast summarizes, dismisses, or the user
   clicks the page.

   The blur is a single additive layer (body::after), not a filter on #root or
   on each popup. It sits above page content and portals (z-[100] modals/slide
   panels) but below the toast viewport (z-index 110), so a popup keeps its
   own backdrop blur exactly as launched and the toast's blur simply
   composites on top of it — then drops away on the toast's own timing.
   Nothing gets re-filtered to "its own preference". The pseudo-element
   always exists with backdrop-filter: none (zero idle cost) so the 300ms
   transition covers both directions; pointer-events keeps the page clickable
   (clicking it summarizes the toast). */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 109;
  pointer-events: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  transition: backdrop-filter 300ms ease;
}

body.sileo-focus-blur::after {
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

/* Elements above the focus layer (z-index > 109) that must still blur with
   the page — the connection banner (z-[9999]) lives inside #root, which used
   to carry the filter directly. */
body.sileo-focus-blur .sileo-focus-under {
  filter: blur(2px);
  transition: filter 300ms ease;
}

/* Light-mode toasts sit on a white page, so give the soft surface a gentle
   shadow so it doesn't disappear into the background. */
[data-sileo-viewport][data-theme="light"] [data-sileo-toast] {
  filter: drop-shadow(0 12px 28px rgba(15, 23, 42, 0.12));
}

.print-bill,
.print-ticket,
.print-receipt {
  display: none;
}

/* Stock location print report: hidden on screen, visible only when printing */
.print-only {
  display: none;
}

@media print {
  /* Every print block is portaled outside #root, so drop the app page itself —
     otherwise it occupies layout and prints as blank pages before the report. */
  #root {
    display: none !important;
  }

  html,
  body {
    background: #fff !important;
    margin: 0 !important;
  }

  /* Hide everything by default when printing */
  body * {
    visibility: hidden !important;
  }

  /* Show only the inline print report */
  .print-only,
  .print-only * {
    visibility: visible !important;
  }

  .print-only {
    display: block !important;
    position: static !important;
    overflow: visible !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    background: #fff !important;
  }

  table {
    page-break-inside: auto;
  }

  tr {
    page-break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }

  @page {
    size: auto;
    margin: 10mm;
  }
}

@media print {
  .print-bill,
  .print-ticket,
  .print-receipt,
  .print-bill *,
  .print-ticket *,
  .print-receipt * {
    visibility: visible;
  }

  .print-bill,
  .print-ticket,
  .print-receipt {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 80mm;
    padding: 2mm;
    color: #000;
    background: #fff;
  }
}

/* Slim scrollbars (Settings panes, dashboard, dropdowns) */
.custom-scrollbar {
  scrollbar-width: thin;
  scrollbar-color: rgba(156, 163, 175, 0.45) transparent;
}

.custom-scrollbar::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background-color: rgba(156, 163, 175, 0.45);
  border-radius: 9999px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: rgba(156, 163, 175, 0.7);
}

.dark .custom-scrollbar {
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.dark .custom-scrollbar::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.25);
}

.dark .custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.4);
}

/* Mobile tab bar selection: one glass capsule that stretches as it travels. */
.liquid-tab-pill {
  position: absolute;
  top: 4px;
  left: 0;
  z-index: 0;
  border-radius: 16px;
  overflow: hidden;
  pointer-events: none;
  transform-origin: center;
  will-change: transform;
  background:
    radial-gradient(
      120% 120% at 20% 0%,
      rgba(255, 255, 255, 0.95) 0%,
      rgba(255, 255, 255, 0) 55%
    ),
    linear-gradient(
      120deg,
      rgba(59, 130, 246, 0.2) 0%,
      rgba(59, 130, 246, 0.1) 100%
    ),
    rgba(255, 255, 255, 0.22);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 -10px 18px rgba(37, 99, 235, 0.06),
    0 6px 16px rgba(37, 99, 235, 0.14);
}

.dark .liquid-tab-pill {
  background:
    radial-gradient(
      140% 120% at 20% 0%,
      rgba(255, 255, 255, 0.14) 0%,
      rgba(255, 255, 255, 0) 55%
    ),
    linear-gradient(
      120deg,
      rgba(59, 130, 246, 0.16) 0%,
      rgba(59, 130, 246, 0.08) 100%
    ),
    rgba(255, 255, 255, 0.055);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -12px 20px rgba(0, 0, 0, 0.22),
    0 10px 24px rgba(0, 0, 0, 0.45);
}

/* Top catch-light, clipped by the capsule's radius. */
.liquid-tab-pill::before {
  content: "";
  position: absolute;
  top: 0;
  left: 18%;
  right: 18%;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.95),
    transparent
  );
}

.dark .liquid-tab-pill::before {
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.38),
    transparent
  );
}

/* 1px blue rim on brand — matches the capsule tint. */
.liquid-tab-pill::after {
  content: "";
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  padding: 1px;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    115deg,
    rgba(96, 165, 250, 0.9) 0%,
    rgba(59, 130, 246, 0.85) 45%,
    rgba(37, 99, 235, 0.7) 100%
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask-composite: exclude;
}

.dark .liquid-tab-pill::after {
  background: linear-gradient(
    115deg,
    rgba(255, 255, 255, 0.20) 0%,
    rgba(96, 165, 250, 0.32) 45%,
    rgba(255, 255, 255, 0.12) 100%
  );
}

/* Shared page sub-tabs. PillNav ships inline fills, opacity and transitions,
   so the app's capsule colours are applied with !important; its stretch
   animation itself is left intact. */
.mbika-subtabs {
  justify-content: center;
  background: rgb(243 244 246) !important;
  border: 1px solid rgb(229 231 235 / 0.7);
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.06);
  color: #111827;
}

.mbika-subtabs > span[aria-hidden="true"] {
  background: #ffffff !important;
  box-shadow:
    inset 0 0 0 1px rgb(37 99 235 / 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 1px 3px rgba(15, 23, 42, 0.12);
}

.mbika-subtabs > button {
  display: inline-flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 10px 14px !important;
  font-size: 13px !important;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  color: #4b5563 !important;
  opacity: 1 !important;
  transition: color 160ms cubic-bezier(0.23, 1, 0.32, 1) !important;
}

.mbika-subtabs > button[aria-current="page"] {
  color: #1d4ed8 !important;
  font-weight: 700;
}

.mbika-subtabs > button:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .mbika-subtabs > button:hover {
    color: #1f2937 !important;
  }
}

.dark .mbika-subtabs {
  background: #121212 !important;
  border-color: rgb(255 255 255 / 0.1);
  box-shadow: none;
  color: #f4f4f5;
}

.dark .mbika-subtabs > span[aria-hidden="true"] {
  background: #262626 !important;
  box-shadow:
    inset 0 0 0 1px rgb(147 197 253 / 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 4px 12px rgba(0, 0, 0, 0.35);
}

.dark .mbika-subtabs > button {
  color: #d4d4d8 !important;
}

.dark .mbika-subtabs > button[aria-current="page"] {
  color: #bfdbfe !important;
}

@media (hover: hover) and (pointer: fine) {
  .dark .mbika-subtabs > button:hover {
    color: #ffffff !important;
  }
}

@media (min-width: 640px) {
  .mbika-subtabs > button {
    flex: 0 1 auto;
    padding: 10px 24px !important;
    font-size: 14px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mbika-subtabs > button {
    transition: color 120ms linear !important;
  }
}
