/*
 * UPOS responsive compatibility layer
 * Version: 2026-07-19
 *
 * This file is intentionally separate from the hashed Vite bundle so the
 * current production application and its database integration stay intact.
 */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 0;
  overflow-x: hidden;
  overflow-x: clip;
}

img,
video,
canvas {
  max-width: 100%;
  height: auto;
}

.min-h-screen {
  min-height: 100vh;
  min-height: 100dvh;
}

main,
main > *,
main .grid > * {
  min-width: 0;
}

/* Keep the application clear of iPhone/iPad notches in portrait and landscape. */
@supports (padding: max(0px)) {
  header.app-print-shell {
    height: calc(3.5rem + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-left: max(0.5rem, env(safe-area-inset-left));
    padding-right: max(0.5rem, env(safe-area-inset-right));
  }

  main.app-print-main {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  nav.no-print.fixed.inset-x-0.bottom-0 {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  @media (min-width: 640px) {
    header.app-print-shell {
      padding-left: max(1rem, env(safe-area-inset-left));
      padding-right: max(1rem, env(safe-area-inset-right));
    }

    main.app-print-main {
      padding-left: max(1.5rem, env(safe-area-inset-left));
      padding-right: max(1.5rem, env(safe-area-inset-right));
    }
  }
}

/* All centered Radix dialogs must remain reachable above mobile keyboards. */
[role="dialog"][class*="left-[50%]"][class*="top-[50%]"],
[role="alertdialog"][class*="left-[50%]"][class*="top-[50%]"] {
  box-sizing: border-box;
  width: calc(100vw - 1rem) !important;
  width: calc(
    100vw - 1rem - env(safe-area-inset-left) - env(safe-area-inset-right)
  ) !important;
  max-height: calc(100vh - 1rem);
  max-height: calc(100dvh - 1rem);
  max-height: calc(
    100dvh - 1rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)
  );
  grid-template-columns: minmax(0, 1fr);
  overscroll-behavior: contain;
}

[role="dialog"][class*="left-[50%]"][class*="top-[50%]"]:not(
    [class*="overflow-hidden"]
  ),
[role="alertdialog"][class*="left-[50%]"][class*="top-[50%]"]:not(
    [class*="overflow-hidden"]
  ) {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

[role="dialog"][class*="left-[50%]"][class*="top-[50%]"] > *,
[role="alertdialog"][class*="left-[50%]"][class*="top-[50%]"] > * {
  min-width: 0;
  max-width: 100%;
}

/* Existing tables keep every column accessible instead of clipping at the card edge. */
main .overflow-x-auto,
main div.border.rounded-lg.overflow-hidden {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

main .overflow-x-auto > table,
main div.border.rounded-lg.overflow-hidden > table {
  width: max-content;
  min-width: 100%;
}

main table th,
main table td {
  overflow-wrap: normal;
}

/* The POS uses the dynamic viewport and reserves the fixed mobile navigation. */
.app-print-main > [class*="h-[calc(100vh-3.5rem)]"] {
  height: calc(100vh - 3.5rem);
  height: calc(100dvh - 3.5rem);
  min-height: 0;
}

.app-print-main > [class*="h-[calc(100vh-3.5rem)]"][class*="lg:flex-row"] {
  overflow: hidden;
}

.app-print-main
  > [class*="h-[calc(100vh-3.5rem)]"][class*="lg:flex-row"]
  > [class*="flex-col"] {
  min-height: 0;
}

/* The POS category strip must be swipeable on phones. */
.app-print-main
  > [class*="h-[calc(100vh-3.5rem)]"]
  > .flex-1.min-w-0.flex.flex-col.no-print
  > .p-3.bg-card.border-b
  .relative.overflow-hidden.w-full
  > .h-full.w-full {
  overflow-x: auto !important;
  overflow-y: hidden !important;
  overscroll-behavior-inline: contain;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
}

/* Keep usable product-card widths beside the iPad/compact-laptop cart. */
@media (min-width: 1024px) and (max-width: 1535.98px) {
  .app-print-main
    > [class*="h-[calc(100vh-3.5rem)]"]
    [class*="xl:grid-cols-5"] {
    grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  }
}

@media (max-width: 1023.98px) {
  .app-print-main > [class*="h-[calc(100vh-3.5rem)]"] {
    height: calc(100vh - 3.5rem - 60px);
    height: calc(
      100dvh - 3.5rem - 60px - env(safe-area-inset-top) -
        env(safe-area-inset-bottom)
    );
  }
}

/* At iPad and compact-laptop widths the full utility set is wider than the header. */
@media (min-width: 640px) and (max-width: 1279.98px) {
  header.app-print-shell {
    gap: 0.25rem;
  }

  header.app-print-shell > button[class*="md:flex"],
  header.app-print-shell > [class*="md:inline-flex"] {
    display: none !important;
  }
}

/* The external customer screen also works on phones and small tablets. */
.min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900 {
  min-height: 100dvh;
  min-width: 0;
  padding: clamp(0.75rem, 2.5vw, 1.5rem);
  overflow-x: hidden;
  overflow-x: clip;
}

.min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
  > .flex-1.grid,
.min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
  > .flex-1.grid
  > * {
  min-width: 0;
}

.min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
  table {
  min-width: 32rem;
}

.min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
  .text-3xl,
.min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
  .text-4xl {
  overflow-wrap: anywhere;
}

.min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
  > header
  .text-2xl.font-mono {
  white-space: nowrap;
}

@media (max-width: 639.98px) {
  .min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
    > header {
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
  }

  .min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
    > header
    > .text-right {
    margin-left: auto;
  }

  .min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
    section,
  .min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
    aside {
    padding: 1rem;
  }

  .min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
    .text-3xl {
    font-size: clamp(1.25rem, 7vw, 1.875rem);
    line-height: 1.25;
  }

  .min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
    .text-4xl {
    font-size: clamp(1.5rem, 8vw, 2.25rem);
    line-height: 1.2;
  }
}

/* Phone landscape: keep login fields and the customer payment panel above the fold. */
@media (orientation: portrait) and (max-width: 479.98px) and (max-height: 620px) {
  .bg-metallic > .relative.z-10.flex.justify-end.p-4 {
    padding: 0.5rem;
  }

  .bg-metallic > .relative.z-10.flex-1 {
    padding: 0.5rem 1rem;
  }

  .bg-metallic .h-24.w-24 {
    width: 4rem;
    height: 4rem;
    margin-bottom: 0.5rem;
  }

  .bg-metallic .text-4xl.font-black {
    font-size: 1.75rem;
    line-height: 1;
  }

  .bg-metallic > .relative.z-10.flex-1 > .w-full.max-w-md > .text-center.mb-6 {
    margin-bottom: 0.75rem;
  }

  .bg-metallic .glass-card [class~="p-6"] {
    padding: 1rem;
  }

  .bg-metallic form.space-y-4 > :not(:last-child) {
    margin-bottom: 0.5rem;
  }

  .bg-metallic form .space-y-2 > :not(:last-child) {
    margin-bottom: 0.25rem;
  }

  .bg-metallic > .relative.z-10:last-child {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .bg-metallic > .relative.z-10.flex.justify-end.p-4 {
    position: absolute;
    top: env(safe-area-inset-top);
    right: env(safe-area-inset-right);
    z-index: 20;
    padding: 0.5rem;
  }

  .bg-metallic > .relative.z-10.flex-1 {
    align-items: center;
    padding: 0.5rem max(1rem, env(safe-area-inset-right)) 0.5rem
      max(1rem, env(safe-area-inset-left));
  }

  .bg-metallic > .relative.z-10.flex-1 > .w-full.max-w-md {
    display: grid;
    grid-template-columns: minmax(7.5rem, 0.55fr) minmax(18rem, 1.45fr);
    align-items: center;
    gap: 0.75rem;
    max-width: 50rem;
  }

  .bg-metallic > .relative.z-10.flex-1 > .w-full.max-w-md > .text-center.mb-6 {
    margin-bottom: 0;
  }

  .bg-metallic .h-24.w-24 {
    width: 3.5rem;
    height: 3.5rem;
    margin-bottom: 0.25rem;
  }

  .bg-metallic .text-4xl.font-black {
    font-size: 1.5rem;
  }

  .bg-metallic .glass-card [class~="p-6"] {
    padding: 0.75rem 1rem;
  }

  .bg-metallic form.space-y-4 > :not(:last-child) {
    margin-bottom: 0.375rem;
  }

  .bg-metallic form .space-y-2 > :not(:last-child) {
    margin-bottom: 0.25rem;
  }

  .bg-metallic > .relative.z-10:last-child {
    display: none;
  }
}

@media (orientation: landscape) and (min-width: 568px) and (max-width: 1023.98px) {
  .min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
    > .flex-1.grid {
    grid-template-columns: minmax(0, 1fr) minmax(15rem, 40%);
    gap: 0.75rem;
  }

  .min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
    section,
  .min-h-screen.bg-gradient-to-br.from-slate-950.via-indigo-950.to-slate-900
    aside {
    padding: 0.75rem;
  }
}

/* Very small phones: stack form fields while preserving compact choice grids. */
@media (max-width: 389.98px) {
  [role="dialog"][class*="left-[50%]"] .grid.grid-cols-2,
  [role="alertdialog"][class*="left-[50%]"] .grid.grid-cols-2 {
    grid-template-columns: minmax(0, 1fr);
  }

  [role="dialog"][class*="left-[50%]"] .col-span-2,
  [role="alertdialog"][class*="left-[50%]"] .col-span-2 {
    grid-column: span 1 / span 1;
  }

  [role="dialog"][class*="left-[50%]"] [class*="grid-cols-[1fr_110px]"],
  [role="alertdialog"][class*="left-[50%]"] [class*="grid-cols-[1fr_110px]"] {
    grid-template-columns: minmax(0, 1fr);
  }

  [role="dialog"][class*="left-[50%]"] .grid.grid-cols-4,
  [role="alertdialog"][class*="left-[50%]"] .grid.grid-cols-4,
  [role="dialog"][class*="left-[50%]"] .grid.grid-cols-5,
  [role="alertdialog"][class*="left-[50%]"] .grid.grid-cols-5 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Stat cards remain two-up but no longer truncate common LAK totals. */
  .shadow-card.border-border\/60 > .p-5 {
    padding: 0.75rem;
  }

  .shadow-card.border-border\/60 .text-2xl.font-bold {
    overflow: visible;
    font-size: clamp(0.95rem, 4.8vw, 1.2rem);
    line-height: 1.25;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .shadow-card.border-border\/60 .text-sm.text-muted-foreground {
    font-size: 0.75rem;
  }

  .shadow-card.border-border\/60 .shrink-0.rounded-xl {
    padding: 0.5rem;
  }
}

/* Prevent Safari/iOS focus zoom and improve dense POS controls on touch screens. */
@media (max-width: 1024px) {
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    font-size: 16px !important;
  }

  [role="dialog"][class*="left-[50%]"] > button.absolute.right-4.top-4,
  [role="alertdialog"][class*="left-[50%]"] > button.absolute.right-4.top-4 {
    top: 0.25rem;
    right: 0.25rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
  }

  [role="dialog"][class*="left-[50%]"]
    > .flex.flex-col.space-y-1\.5:first-child,
  [role="alertdialog"][class*="left-[50%]"]
    > .flex.flex-col.space-y-1\.5:first-child {
    padding-right: 1.5rem;
  }

  .toaster button[class*="group-[.toast]"] {
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding-inline: 0.75rem;
  }
}

@media (hover: none) and (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    font-size: 16px !important;
  }

  main button.h-7.w-7,
  main button.h-8.w-8,
  [role="dialog"] button.h-7.w-7,
  [role="dialog"] button.h-8.w-8 {
    min-width: 2.5rem;
    min-height: 2.5rem;
  }

  .bg-metallic a[href="/forgot-password"] {
    display: inline-flex;
    min-height: 2.75rem;
    align-items: center;
  }

  .bg-metallic [role="checkbox"] {
    min-width: 1.5rem;
    min-height: 1.5rem;
  }

  .bg-gradient-hero input,
  .bg-gradient-hero button {
    min-height: 2.75rem;
  }

  .bg-metallic button[aria-label="Show password"],
  .bg-metallic button[aria-label="Hide password"] {
    min-width: 2.75rem;
    min-height: 2.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  body {
    overflow: visible;
  }
}

/* Lao typography v2: force one consistent Lao-capable stack throughout the UI. */
html {
  --font-sans: "Noto Sans Lao", "Inter", "Noto Sans Thai", "Noto Sans SC", "Noto Color Emoji", "Segoe UI Emoji", "Apple Color Emoji", system-ui, sans-serif;
  --default-font-family: var(--font-sans);
  font-family: var(--font-sans) !important;
}

html body,
html body *,
html button,
html input,
html select,
html textarea,
html option,
html [role="button"],
html [role="dialog"],
html [role="menu"],
html [role="menuitem"],
html [role="tab"],
html [role="tooltip"] {
  font-family: var(--font-sans) !important;
  letter-spacing: 0 !important;
}

html body {
  font-synthesis: weight;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

@media print {
  html body,
  html body * {
    font-family: var(--font-sans) !important;
    letter-spacing: 0 !important;
  }
}
