/* ==========================================================================
   KAMALIG — modern mobile layer
   Loaded LAST (see includes/header.php). Companion script: assets/mobile.js

   What this file adds (all of it phone/tablet only; desktop is untouched):
     1. Off-canvas sidebar drawer: dynamic viewport height, safe areas,
        scroll containment, edge fades, swipe-to-open/close, scroll lock.
     2. Sticky, blurred top bar that hides on scroll-down / returns on scroll-up.
     3. Floating chat bubble + "back to top" that stay out of the way.
     4. Bottom-sheet modals (row actions, confirmations, AI analysis panel).
     5. Data tables that turn into readable cards on phones.
     6. Sticky cart summary bar, sticky bulk-action bar.
     7. Touch polish: no stuck tooltips, no tap delay, 44px targets.
   ========================================================================== */

:root {
  --kg-gutter: 16px;
  --kg-topbar-h: 60px;      /* measured live by mobile.js */
  --kg-stick-top: 8px;      /* where sticky page elements sit under the bar; mobile.js keeps it current */
  --kg-safe-top: env(safe-area-inset-top, 0px);
  --kg-safe-right: env(safe-area-inset-right, 0px);
  --kg-safe-bottom: env(safe-area-inset-bottom, 0px);
  --kg-safe-left: env(safe-area-inset-left, 0px);
  --kg-gl: max(var(--kg-gutter), var(--kg-safe-left));
  --kg-gr: max(var(--kg-gutter), var(--kg-safe-right));
  --kg-drawer-w: min(86vw, 320px);
}

/* Keyboard users: jump past the sidebar. Invisible until focused.
   (Scoped away from the landing page, which ships its own skip link.) */
body:not(.landing-page) .skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 400; padding: 10px 14px; border-radius: 8px;
  background: var(--kg-green-dark, #174D35); color: #fff; font-weight: 700; font-size: .9rem;
  transition: top 160ms ease;
}
body:not(.landing-page) .skip-link:focus { top: max(12px, var(--kg-safe-top)); }

/* ==========================================================================
   Desktop (>= 901px): the sidebar stays put while the page scrolls.
   It used to be a plain flex child, so on a long page the menu scrolled away
   with the content; and with many links it grew taller than the screen with
   no way to reach the last ones except scrolling the whole page.
   Now: pinned to the viewport, only the link list scrolls (thin scrollbar,
   no scroll-chaining into the page).
   ========================================================================== */
@media (min-width: 901px) {
  .sidebar {
    position: sticky; top: 0; align-self: flex-start;
    height: 100vh; height: 100dvh; overflow: hidden;
  }
  .sidebar nav {
    min-height: 0;
    /* Bleed to the sidebar edge so the gold "active" marker (drawn at left:-14px) is no longer clipped. */
    margin: 0 -14px; padding: 0 12px 8px 14px;
    overscroll-behavior: contain;
    scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .22) transparent;
  }
  .sidebar nav::-webkit-scrollbar { width: 6px; }
  .sidebar nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .22); border-radius: 6px; }
  .sidebar nav::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .4); }
  .sidebar.is-collapsed nav { padding-right: 14px; }
  /* Soft fade on whichever side still has links to scroll to (classes toggled by mobile.js). */
  .sidebar nav {
    --kg-fade-top: 0px; --kg-fade-bottom: 0px;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 var(--kg-fade-top), #000 calc(100% - var(--kg-fade-bottom)), transparent 100%);
            mask-image: linear-gradient(to bottom, transparent 0, #000 var(--kg-fade-top), #000 calc(100% - var(--kg-fade-bottom)), transparent 100%);
  }
  .sidebar nav.can-scroll-up { --kg-fade-top: 22px; }
  .sidebar nav.can-scroll-down { --kg-fade-bottom: 28px; }
}

/* Real viewport height on mobile browsers (100vh ignores the collapsing URL bar). */
.app-shell { min-height: 100vh; min-height: 100dvh; }

/* Elements that only exist for mobile are hidden on desktop. */
.sidebar-close-btn, .kg-to-top { display: none; }

/* ---- Touch devices: no stuck hover tooltips, no 300ms tap delay ----------- */
@media (hover: none) {
  .kg-tooltip-bubble { display: none !important; }
  a, button, label, summary, select, input, [role="button"] { touch-action: manipulation; }
  .nav-link, .btn, .icon-btn, .kg-pill, .kg-quick-btn { -webkit-tap-highlight-color: rgba(38, 115, 77, .14); }
  .card:hover, .kg-kpi:hover, .kg-insight:hover { box-shadow: var(--kg-shadow); } /* hover lift would "stick" after a tap */
}

/* ==========================================================================
   Tablet + phone  (<= 900px): drawer, sticky bar, content gutters
   ========================================================================== */
@media (max-width: 900px) {
  html { scroll-padding-top: calc(var(--kg-topbar-h) + 12px); }

  /* Page behind the drawer / a sheet cannot scroll while one is open. */
  html.kg-scroll-locked { overflow: hidden; overscroll-behavior: none; padding-right: var(--kg-sbw, 0px); }
  html.kg-scroll-locked body { overflow: hidden; }

  /* ---------- Sidebar as an off-canvas drawer ---------- */
  .sidebar,
  .sidebar.is-collapsed {
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    width: var(--kg-drawer-w);
    height: 100vh; height: 100dvh;           /* dvh: the bottom link is never hidden behind the URL bar */
    padding: calc(16px + var(--kg-safe-top)) 12px calc(12px + var(--kg-safe-bottom)) calc(12px + var(--kg-safe-left));
    border-radius: 0 22px 22px 0;
    transform: translate3d(-100%, 0, 0);
    visibility: hidden;                      /* closed drawer is not focusable / readable */
    box-shadow: none;
    transition: transform 300ms var(--kg-ease-out), box-shadow 300ms var(--kg-ease-out), visibility 0s linear 300ms;
    overscroll-behavior: contain;
  }
  .sidebar.is-mobile-open {
    transform: none; visibility: visible; transition-delay: 0s;
    box-shadow: 28px 0 56px rgba(8, 28, 18, .34);
  }
  .sidebar.is-dragging { transition: none; visibility: visible; }

  /* A "collapsed" desktop preference (saved in localStorage) must never leak into the drawer. */
  .sidebar.is-collapsed .brand__text { display: block; }
  .sidebar.is-collapsed .nav-label { display: inline; }
  .sidebar.is-collapsed .nav-group-label { display: block; }
  .sidebar.is-collapsed .nav-link { justify-content: flex-start; }
  .sidebar.is-collapsed .nav-badge { position: static; margin-left: auto; min-width: 20px; height: 20px; line-height: 20px; font-size: 11.5px; padding: 0 6px; }

  .sidebar .brand { padding: 4px 4px 14px; gap: 12px; }
  .sidebar-collapse-btn { display: none !important; }
  .sidebar-close-btn {
    display: flex; align-items: center; justify-content: center; margin-left: auto; flex-shrink: 0;
    width: 40px; height: 40px; border: 0; border-radius: 12px; cursor: pointer;
    background: rgba(255, 255, 255, .12); color: #fff;
    transition: background 160ms var(--kg-ease);
  }
  .sidebar-close-btn:active { background: rgba(255, 255, 255, .24); }
  .sidebar-close-btn svg { width: 18px; height: 18px; }

  /* The link list is the only thing that scrolls inside the drawer. */
  .sidebar nav {
    --kg-fade-top: 0px; --kg-fade-bottom: 0px;
    margin: 0 -6px; padding: 2px 6px 10px;
    overflow-y: auto; overflow-x: hidden;
    overscroll-behavior: contain;             /* no scroll chaining into the page behind */
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .28) transparent;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 var(--kg-fade-top), #000 calc(100% - var(--kg-fade-bottom)), transparent 100%);
            mask-image: linear-gradient(to bottom, transparent 0, #000 var(--kg-fade-top), #000 calc(100% - var(--kg-fade-bottom)), transparent 100%);
  }
  /* Soft fades appear only on the side that has more links to scroll to. */
  .sidebar nav.can-scroll-up { --kg-fade-top: 26px; }
  .sidebar nav.can-scroll-down { --kg-fade-bottom: 30px; }
  .sidebar nav::-webkit-scrollbar { width: 4px; }
  .sidebar nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .28); border-radius: 4px; }

  .sidebar .nav-link { min-height: 46px; padding: 10px 12px; border-radius: 12px; font-size: .95rem; }
  .sidebar .nav-link:active { background: rgba(255, 255, 255, .16); }
  .sidebar .nav-link.active:active { background: var(--kg-green-light); }
  .sidebar .nav-icon { width: 20px; height: 20px; }
  .sidebar .nav-group-label { margin: 16px 12px 6px; font-size: .7rem; }

  /* Links glide in one after another when the drawer opens. */
  .sidebar.is-mobile-open .nav-link,
  .sidebar.is-mobile-open .nav-group-label { animation: kg-nav-in 360ms var(--kg-ease-out) both; animation-delay: calc(var(--i, 0) * 18ms + 60ms); }
  @keyframes kg-nav-in { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }

  /* Dimmed + softly blurred backdrop; fades instead of popping. */
  .sidebar-scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(10, 30, 20, .52);
    -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
    opacity: 0; visibility: hidden; pointer-events: none;
    touch-action: none; overscroll-behavior: contain;
    transition: opacity 280ms var(--kg-ease), visibility 0s linear 280ms;
  }
  .sidebar-scrim.is-visible { opacity: 1; visibility: visible; pointer-events: auto; transition-delay: 0s; }
  .sidebar-scrim.is-dragging { transition: none; visibility: visible; }

  /* ---------- Content area ---------- */
  .content {
    padding: var(--kg-gutter) var(--kg-gr) calc(96px + var(--kg-safe-bottom)) var(--kg-gl);
  }
  .content:has(> .topbar) { padding-top: 0; }  /* the sticky bar owns the top spacing */

  /* ---------- Sticky top bar ---------- */
  .topbar {
    position: sticky; top: 0; z-index: 45; isolation: isolate;
    margin: 0 calc(var(--kg-gr) * -1) 14px calc(var(--kg-gl) * -1);
    padding: calc(10px + var(--kg-safe-top)) var(--kg-gr) 10px var(--kg-gl);
    align-items: center; flex-wrap: nowrap; gap: 10px;
    transition: transform 280ms var(--kg-ease-out);
  }
  /* The frosted background lives on a pseudo-element: filter/backdrop-filter on the bar itself
     would re-anchor the position:fixed dropdowns to the bar instead of the screen. */
  .topbar::before {
    content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
    background: rgba(247, 245, 236, .92);
    border-bottom: 1px solid transparent;
    transition: border-color 200ms var(--kg-ease), box-shadow 200ms var(--kg-ease);
  }
  @supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .topbar::before { background: rgba(247, 245, 236, .78); -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px); }
  }
  .topbar.is-stuck::before { border-bottom-color: var(--kg-border); box-shadow: 0 8px 20px -14px rgba(23, 77, 53, .45); }
  .topbar.is-hidden { transform: translate3d(0, -110%, 0); }
  .topbar-heading { flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; gap: 8px; }
  /* Titles may wrap between words onto two lines (then ellipsis), never mid-word: "Dashb|oard" looked broken on tablets. */
  .topbar-heading h1 {
    min-width: 0; font-size: 1.1rem; line-height: 1.2; overflow: hidden; overflow-wrap: break-word; word-break: normal;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  }
  /* The breadcrumb and the full user name compete with the title for room; the account menu still shows both. */
  .topbar-breadcrumb { display: none; }
  .topbar-user__name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-actions { flex: 0 0 auto; align-items: center; gap: 6px; flex-wrap: nowrap; }
  /* One consistent 40px touch size; the bell/profile wrappers are inline boxes by default and drifted off-line. */
  .notif-bell, .profile-menu, .topbar-search { display: flex; align-items: center; }
  /* styles.css gives every <label> a 6px bottom margin; the bell and avatar are labels, which pushed them 3px above their neighbours. */
  .notif-bell__button, .topbar-user { margin: 0; }
  .icon-btn, .notif-bell__button, .topbar-search__btn { width: 40px; height: 40px; border-radius: 12px; }
  .topbar-user__avatar { width: 40px; height: 40px; }
  .profile-menu .topbar-user { padding: 0; gap: 0; border-radius: 50%; }
  .mobile-menu-btn { width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0; }
  .mobile-menu-btn svg { width: 20px; height: 20px; }

  /* Page elements that stick under the bar follow it (bar hidden => they move up). */
  .kg-bulkbar.is-visible {
    position: sticky; top: var(--kg-stick-top); z-index: 30;
    box-shadow: 0 10px 24px -12px rgba(23, 77, 53, .45); background: var(--kg-green-light);
    transition: top 280ms var(--kg-ease-out);
  }

  /* ---------- Analysis side panel: real viewport height ---------- */
  .kg-analysis-panel { height: 100vh; height: 100dvh; padding-bottom: var(--kg-safe-bottom); overscroll-behavior: contain; }
  .kg-analysis-panel__head { padding-top: calc(18px + var(--kg-safe-top)); }
}

/* ==========================================================================
   Phones (<= 700px)
   ========================================================================== */
@media (max-width: 700px) {
  :root { --kg-gutter: 12px; }

  /* Dropdowns hang from the bar, pinned to the screen so they never overflow an edge. */
  .notif-dropdown, .profile-dropdown {
    position: fixed; top: calc(var(--kg-topbar-h) + 6px); left: 10px; right: 10px; width: auto; max-width: 440px; margin-inline: auto;
    max-height: calc(100vh - var(--kg-topbar-h) - 24px); max-height: calc(100dvh - var(--kg-topbar-h) - 24px);
    overflow-y: auto; overscroll-behavior: contain;
  }
  .notif-dropdown__item-btn, .profile-dropdown__item, .notif-dropdown__viewall { min-height: 48px; }
  .profile-dropdown__item { padding-block: 12px; }

  /* Chat bubble + panel. */
  .assistant-widget {
    right: max(14px, var(--kg-safe-right)); bottom: calc(14px + var(--kg-safe-bottom) + var(--kg-bar-h, 0px)); z-index: 52;
    transition: transform 300ms var(--kg-ease-out), opacity 220ms var(--kg-ease), bottom 280ms var(--kg-ease-out);
  }
  .assistant-panel {
    position: fixed; left: 10px; right: 10px; top: auto; bottom: calc(76px + var(--kg-safe-bottom));
    width: auto; max-width: 440px; margin-left: auto;
    max-height: 78vh; max-height: min(78dvh, 580px);
    border-radius: 20px; overscroll-behavior: contain;
  }
  .assistant-panel__body { flex: 1 1 auto; max-height: none; min-height: 140px; overscroll-behavior: contain; }
  .assistant-panel__header { padding-block: 14px; }
  .assistant-panel__close { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.6rem; }
  /* While the page is being scrolled down the bubble tucks away; it returns when scrolling stops. */
  body.kg-scrolling-down .assistant-toggle:not(:checked) ~ .assistant-widget {
    transform: translate3d(0, calc(100% + 28px), 0); opacity: 0; pointer-events: none;
  }

  /* Back-to-top: appears after scrolling, sits above the chat bubble. */
  .kg-to-top {
    display: flex; align-items: center; justify-content: center;
    position: fixed; z-index: 51; right: max(14px, var(--kg-safe-right)); bottom: calc(14px + var(--kg-safe-bottom) + var(--kg-bar-h, 0px));
    width: 44px; height: 44px; border: 1px solid var(--kg-border); border-radius: 50%;
    background: #fff; color: var(--kg-green-dark); box-shadow: 0 8px 22px -8px rgba(23, 77, 53, .5); cursor: pointer;
    opacity: 0; visibility: hidden; transform: translate3d(0, 12px, 0) scale(.9);
    transition: opacity 220ms var(--kg-ease), transform 260ms var(--kg-ease-out), visibility 0s linear 260ms, bottom 280ms var(--kg-ease-out);
  }
  body:has(.assistant-widget) .kg-to-top { bottom: calc(74px + var(--kg-safe-bottom) + var(--kg-bar-h, 0px)); }
  .kg-to-top.is-visible { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
  .kg-to-top svg { width: 20px; height: 20px; }

  /* Bigger, calmer cards and controls. */
  .page-card { border-radius: 14px; }
  .topbar-user__name { display: none; }   /* avatar only; name is in the account menu */
  .btn-sm { min-height: 38px; padding-inline: 12px; }
  .nav-badge { min-width: 22px; }

  /* Metric cards: two per row instead of six tall single cards. */
  .kg-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kg-kpi { padding: 12px; }
  .kg-kpi__top { margin-bottom: 8px; }
  .kg-kpi__value { font-size: 1.2rem; overflow-wrap: anywhere; }
  .kg-kpi__sub { font-size: .72rem; }
  .kg-kpi__trend { font-size: .68rem; padding: 2px 6px; }
  .kg-card__head { margin-bottom: 10px; }
  .kg-pillbar { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .kg-pillbar::-webkit-scrollbar { display: none; }
  .kg-pill { flex: 0 0 auto; }

  /* Long forms: full-width actions are easier to hit with a thumb. */
  .page-card form > .btn,
  .page-card form > .btn-primary,
  .page-card form > .btn-signin { min-height: 46px; }
}
@media (max-width: 480px) {
  /* Settings is also in the account menu; dropping the duplicate icon gives the page title room to breathe. */
  .topbar-actions > a.icon-btn[aria-label="Settings"] { display: none; }
  .topbar-actions { gap: 4px; }
}
@media (max-width: 359px) {
  .kg-kpi-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ==========================================================================
   Bottom sheets (<= 640px): row-actions modal, confirm dialog, AI analysis
   ========================================================================== */
@media (max-width: 640px) {
  .kg-modal-backdrop { align-items: flex-end; padding: 0; }
  .kg-modal {
    max-width: none; width: 100%; border-radius: 22px 22px 0 0;
    max-height: 88vh; max-height: 88dvh; overscroll-behavior: contain;
    padding-bottom: var(--kg-safe-bottom);
    animation: kg-sheet-in 300ms var(--kg-ease-out);
  }
  .kg-modal::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--kg-border); margin: 10px auto 0; }
  .kg-modal__header { padding: 12px 18px 14px; }
  .kg-modal__close { min-width: 44px; min-height: 44px; }
  .kg-modal__body { padding: 12px 14px 16px; gap: 10px; }
  .kg-modal__body .btn { min-height: 48px; display: flex; align-items: center; }
  @keyframes kg-sheet-in { from { transform: translate3d(0, 100%, 0); } to { transform: none; } }

  .kg-confirm-overlay { align-items: flex-end; padding: 0; }
  .kg-confirm-modal {
    max-width: none; border-radius: 22px 22px 0 0;
    padding: 22px 20px calc(18px + var(--kg-safe-bottom));
    transform: translate3d(0, 100%, 0); transition: transform 300ms var(--kg-ease-out);
  }
  .kg-confirm-overlay.is-open .kg-confirm-modal { transform: none; }
  .kg-confirm-modal__actions { flex-direction: column-reverse; gap: 10px; }
  .kg-confirm-modal__actions .btn { width: 100%; min-height: 48px; }

  .kg-analysis-panel { width: 100%; max-width: 100%; }
}

/* ==========================================================================
   Tables -> cards (<= 640px). mobile.js tags eligible tables with .kg-stack
   (4+ columns, a real header row, no merged cells) and labels every cell.
   Other tables keep the scrollable layout with its edge shadows.
   ========================================================================== */
@media (max-width: 640px) {
  .kg-stack-wrap { background: none !important; overflow: visible !important; }
  /* The table's own outer card would frame a stack of cards (card-in-card): let the row cards stand alone. */
  .card:has(> .kg-stack-wrap) { background: none; border: 0; box-shadow: none; padding: 0; }
  table.kg-stack { min-width: 0 !important; width: 100%; border: 0; border-collapse: separate; }
  table.kg-stack thead {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  table.kg-stack, table.kg-stack tbody, table.kg-stack tr, table.kg-stack td { display: block; width: 100%; box-sizing: border-box; }
  table.kg-stack tbody tr {
    position: relative; margin: 0 0 12px; padding: 4px 14px; background: #fff;
    border: 1px solid var(--kg-border); border-radius: 14px; box-shadow: var(--kg-shadow);
  }
  .kg-stack-wrap table.kg-stack tbody tr:hover { background: #fff; }   /* beat the desktop row-hover tint */
  table.kg-stack tbody tr:last-child { margin-bottom: 0; }
  table.kg-stack td {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    width: 100% !important; max-width: none !important; min-width: 0 !important;
    padding: 10px 0; border: 0; border-bottom: 1px solid var(--kg-surface-soft);
    text-align: right; white-space: normal !important; overflow-wrap: anywhere; word-break: normal !important;
    font-size: .88rem !important; line-height: 1.4;
  }
  table.kg-stack td:last-child { border-bottom: 0; }
  table.kg-stack td::before {
    content: attr(data-label); flex: 0 0 auto; max-width: 42%; text-align: left;
    font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--kg-text-secondary);
  }
  /* Unlabelled cell = row-select checkbox: tuck it in the card's corner instead of giving it a row. */
  table.kg-stack td[data-label=""] { position: absolute; top: 12px; left: 14px; width: auto !important; padding: 0; border: 0; }
  table.kg-stack td[data-label=""]::before { content: none; }
  table.kg-stack td[data-label=""] input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; margin: 0; }
  table.kg-stack tbody tr:has(> td[data-label=""]) { padding-top: 42px; }   /* room for the corner checkbox */
  table.kg-stack tbody tr:has(> td[data-label=""]) > td:nth-child(2) { border-top: 1px solid var(--kg-surface-soft); }
  table.kg-stack td.kg-cell-actions { justify-content: flex-end; padding-block: 12px; }
  table.kg-stack td.kg-cell-actions::before { content: none; }
  table.kg-stack .kg-cell { min-width: 0; text-align: right; }
  table.kg-stack td.kg-cell-actions .kg-cell { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; width: 100%; }
  table.kg-stack td.kg-cell-actions .btn { min-height: 42px; }
  table.kg-stack .stock-thumb { margin-left: auto; }
  table.kg-stack .badge, table.kg-stack .kg-status { white-space: normal; }
  /* idfirst tables pinned the first column to 92px; in a card it should read normally. */
  table.kg-stack.table--idfirst td:first-child { width: 100% !important; max-width: none !important; word-break: break-all !important; font-size: .8rem !important; }
}

/* ==========================================================================
   Cart: summary becomes a sticky checkout bar on phones/tablets (class added in cart/index.php)
   ========================================================================== */
@media (max-width: 899px) {
  .cart-layout--sticky { display: block; }          /* sticky needs a block parent (a grid area would trap it) */
  .cart-layout--sticky > .cart-lines { margin-bottom: 14px; }
  .cart-summary--sticky {
    position: sticky; bottom: calc(10px + var(--kg-safe-bottom)); z-index: 40;
    grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px 14px; padding: 12px 14px;
    border-radius: 18px; border-color: rgba(38, 115, 77, .35);
    box-shadow: 0 -2px 0 rgba(255, 255, 255, .9), 0 16px 34px -10px rgba(23, 77, 53, .45);
  }
  .cart-summary--sticky > h4,
  .cart-summary--sticky .cart-summary__note,
  .cart-summary--sticky .btn-secondary { display: none; }
  .cart-summary--sticky .cart-summary__rows { grid-column: 1; grid-row: 1; grid-template-columns: minmax(0, 1fr); gap: 0; min-width: 0; }
  .cart-summary--sticky .cart-summary__rows dt:not(.cart-summary__total),
  .cart-summary--sticky .cart-summary__rows dd:not(.cart-summary__total) { display: none; }
  /* Label above amount, so a long total ("₱1,234,567.00") never gets squeezed behind the checkout button. */
  .cart-summary--sticky dt.cart-summary__total {
    border: 0; padding: 0; font-size: .7rem; letter-spacing: .05em; text-transform: uppercase;
    font-weight: 700 !important; color: var(--kg-text-secondary) !important;
  }
  .cart-summary--sticky dd.cart-summary__total { border: 0; padding: 0; text-align: left; font-size: 1.2rem; line-height: 1.2; overflow-wrap: anywhere; }
  .cart-summary--sticky .btn-primary { grid-column: 2; grid-row: 1; width: auto; min-height: 46px; padding-inline: 20px; white-space: nowrap; }
  .cart-summary--sticky .cart-line__issue { grid-column: 1 / -1; grid-row: 2; margin: 0; }
  /* The chat bubble and back-to-top ride above the bar: mobile.js measures it into --kg-bar-h. */
  .assistant-widget { bottom: calc(20px + var(--kg-bar-h, 0px)); }
}

/* ==========================================================================
   Public landing page: menu panel that fits short screens, notch-safe sides
   ========================================================================== */
html:has(body.modal-open) { overflow: hidden; }
.landing-page { padding-left: var(--kg-safe-left); padding-right: var(--kg-safe-right); }
@media (max-width: 820px) {
  .landing-page .nav { padding-top: var(--kg-safe-top); }
  .landing-page .nav__links.is-open {
    max-height: calc(100vh - 64px - var(--kg-safe-top)); max-height: calc(100dvh - 64px - var(--kg-safe-top));
    overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(var(--s4, 16px) + var(--kg-safe-bottom));
  }
}
@media (max-width: 520px) {
  .landing-page .auth-overlay { padding: 10px; padding-bottom: calc(10px + var(--kg-safe-bottom)); }
  .landing-page .access { max-height: 94vh; max-height: 94dvh; }
}

@media print {
  .kg-to-top, .sidebar-scrim, .skip-link { display: none !important; }
}

/* Skip-link target should not draw a focus ring around the whole page. */
.content:focus { outline: none; }
