/* ux.css — Duskyr UX layer: mobile bottom nav, wallet pill, animations, footer fix.
   Loaded AFTER kit.css so it can refine. Uses existing design tokens. v1 2026-06-02 */

/* ============ utilities ============ */
.du-hide-mobile { }              /* visible on desktop, hidden on mobile (see media query) */
.du-show-mobile { display: none !important; }

/* ============ wallet balance pill (top bar) ============ */
.du-wallet-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-strong); font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: border-color .16s ease, background .16s ease, transform .1s ease;
  white-space: nowrap;
}
.du-wallet-pill:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.du-wallet-pill:active { transform: scale(.96); }
.du-wallet-pill svg { color: var(--accent); }

.du-avatar-btn { background: none; border: 0; padding: 0; cursor: pointer; border-radius: 99px; line-height: 0; transition: transform .12s ease; }
.du-avatar-btn:hover { transform: scale(1.06); }
.du-avatar-btn:active { transform: scale(.94); }

/* ============ search: make it usable on mobile ============ */
@media (max-width: 900px) {
  /* let search take the row; it was squeezed to "Search produc…" */
  .du-search { flex: 1 1 auto; max-width: none; min-width: 0; }
  .du-search input { height: 40px; font-size: 14px; }
  /* dropdown breaks out of the tiny search box to almost full width, under the topbar */
  .du-search-pop {
    position: fixed; left: 8px; right: 8px; top: calc(var(--topbar-h, 60px) + 6px);
    max-height: 70vh; border-radius: 14px; z-index: 70;
  }
  .du-search-row { padding: 10px 10px; }
  .du-search-tt { font-size: 14px; }
  .du-search-thumb { width: 50px; height: 34px; }
}
/* tiny phones: hide the (non-functional) language switch so search + account fit */
@media (max-width: 480px) {
  .du-lang { display: none !important; }
}

/* ============ mobile bottom tab bar ============ */
.du-mobilenav { display: none; }

@media (max-width: 900px) {
  /* sidebar is already hidden by kit.css @900; the burger drawer still works */
  .du-hide-mobile { display: none !important; }
  .du-show-mobile { display: inline-flex !important; }

  /* give content room above the bar */
  .du-content { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 12px) !important; }

  .du-mobilenav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 800;
    height: calc(60px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in oklab, var(--canvas) 88%, transparent);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--line);
  }
  .du-mtab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: none; border: 0; cursor: pointer; padding: 6px 0 4px;
    color: var(--subtle); font-size: 10.5px; font-weight: 600;
    transition: color .16s ease; position: relative; -webkit-tap-highlight-color: transparent;
  }
  .du-mtab-ic { position: relative; display: grid; place-items: center; height: 26px; transition: transform .18s cubic-bezier(.2,.8,.2,1); }
  .du-mtab-lbl { line-height: 1; }
  .du-mtab[data-on="true"] { color: var(--accent); }
  .du-mtab[data-on="true"] .du-mtab-ic { transform: translateY(-1px); }
  .du-mtab:active .du-mtab-ic { transform: scale(.84); }
  .du-mtab-badge {
    position: absolute; top: -3px; right: 50%; margin-right: -16px;
    min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px;
    background: var(--accent); color: #fff; font-size: 9.5px; font-weight: 700;
    display: grid; place-items: center; box-shadow: 0 0 0 2px var(--canvas);
  }
  /* active-tab top indicator */
  .du-mtab[data-on="true"]::before {
    content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 24px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
  }

  /* topbar a touch tighter on phones */
  .du-topbar { gap: 8px; }
  .du-wallet-pill { height: 32px; padding: 0 10px; font-size: 13px; }
}

/* ============ footer: keep it at the end, no giant empty gap ============ */
/* .du-main is already a flex column (kit.css). Make .du-content fill the leftover
   height and lay out as a column so the footer can be pushed to the bottom on
   short pages — killing the big black gap under the footer. */
.du-content { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.du-content > * { flex-shrink: 0; }
.du-content > .du-footer:last-child { margin-top: auto; }
.du-footer { width: 100%; }

/* ============ pro micro-animations ============ */
@media (prefers-reduced-motion: no-preference) {
  /* tactile press on all buttons */
  .btn:active, .icon-btn:active, .du-side-link:active, .du-fchip:active { transform: scale(.97); }
  .btn, .icon-btn { transition: transform .1s ease, background .16s ease, border-color .16s ease, box-shadow .16s ease; }

  /* card lift */
  .du-pcard { transition: transform .18s cubic-bezier(.2,.8,.2,1), box-shadow .18s ease, border-color .18s ease; }
  .du-pcard:hover { transform: translateY(-3px); box-shadow: 0 12px 28px -12px rgba(0,0,0,.35); }

  /* page enter */
  .app-enter { animation: duFadeUp .34s cubic-bezier(.2,.8,.2,1); }
  @keyframes duFadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

  /* staggered grid items */
  .du-grid > * { animation: duPop .4s both cubic-bezier(.2,.8,.2,1); }
  .du-grid > *:nth-child(1){animation-delay:.02s} .du-grid > *:nth-child(2){animation-delay:.05s}
  .du-grid > *:nth-child(3){animation-delay:.08s} .du-grid > *:nth-child(4){animation-delay:.11s}
  .du-grid > *:nth-child(5){animation-delay:.14s} .du-grid > *:nth-child(6){animation-delay:.17s}
  .du-grid > *:nth-child(7){animation-delay:.2s}  .du-grid > *:nth-child(8){animation-delay:.23s}
  @keyframes duPop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
}

/* ============ Messages — full-screen chat app (Telegram-style) ============ */
/* Hide the page footer whenever the Messages page is mounted (no footer under a chat). */
.du-content:has(.du-msg-page) > .du-footer { display: none !important; }
.du-content:has(.du-msg-page) { padding-bottom: 0 !important; }

.du-msg-page { display: flex; flex-direction: column; width: 100%; max-width: 1180px; margin: 0 auto; padding: 22px 24px 0; flex: 1 1 auto; min-height: 0; }
.du-msg-title { flex-shrink: 0; }
.du-msg-page .du-msg {
  display: grid; grid-template-columns: 320px 1fr; gap: 16px;
  flex: 1 1 auto; min-height: 0;
  /* fill the viewport minus the topbar + title row; keeps the composer at the bottom */
  height: calc(100dvh - var(--topbar-h, 60px) - 78px);
}
.du-msg-page .du-msg-list {
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); padding: 8px;
}
.du-msg-page .du-msg-main {
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface);
}
.du-msg-page .du-msg-body { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.du-convo { animation: duConvoIn .3s both ease; }
.du-convo:nth-child(1){animation-delay:.02s} .du-convo:nth-child(2){animation-delay:.05s}
.du-convo:nth-child(3){animation-delay:.08s} .du-convo:nth-child(4){animation-delay:.11s}
@keyframes duConvoIn { from { opacity:0; transform: translateX(-6px); } to { opacity:1; transform:none; } }
.du-msg-back { display: none; }   /* desktop: no back button */

/* MOBILE: full-screen, single pane, slide between list <-> chat */
@media (max-width: 900px) {
  .du-msg-page {
    position: fixed; left: 0; right: 0;
    top: var(--topbar-h, 60px);                              /* sit BELOW the real topbar */
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));   /* sit ABOVE the bottom tab-bar */
    z-index: 30;                                             /* BELOW topbar(40) & bottom-nav(800) so neither is covered */
    max-width: none; margin: 0; padding: 0;
    background: var(--canvas);
  }
  .du-msg-title { display: none; }   /* the chat header carries the title on mobile */
  .du-msg-page .du-msg {
    grid-template-columns: 1fr; gap: 0; height: 100%; border-radius: 0;
  }
  .du-msg-page .du-msg-list, .du-msg-page .du-msg-main {
    border: 0; border-radius: 0; background: var(--canvas);
    grid-column: 1; grid-row: 1;   /* stack both in the same cell, toggle visibility */
  }
  /* default = show list, hide chat */
  .du-msg-page[data-chat="0"] .du-msg-main { display: none; }
  .du-msg-page[data-chat="0"] .du-msg-list { display: flex; animation: duSlideL .26s ease both; }
  /* opened a chat = hide list, show chat full-screen */
  .du-msg-page[data-chat="1"] .du-msg-list { display: none; }
  .du-msg-page[data-chat="1"] .du-msg-main { display: flex; animation: duSlideR .26s ease both; }
  .du-msg-back { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; background: none; color: var(--ink); cursor: pointer; border-radius: 8px; flex-shrink: 0; margin-right: 2px; }
  .du-msg-back:active { background: var(--sunken); }
  .du-msg-page .du-msg-list { padding: 6px; }
  .du-convo { padding: 12px 12px; border-radius: 12px; }
  @keyframes duSlideR { from { opacity:.4; transform: translateX(24px); } to { opacity:1; transform:none; } }
  @keyframes duSlideL { from { opacity:.4; transform: translateX(-24px); } to { opacity:1; transform:none; } }
}

/* ============ mobile: compact product grid (2 per row) + smaller banner ============ */
@media (max-width: 560px) {
  /* 2 columns, tighter — instead of 1 giant card per row */
  .du-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
  .du-pcard-title { font-size: 13px !important; line-height: 1.25; }
  .du-pcard .du-price { font-size: 15px !important; }
  .du-pcard-body { padding: 10px !important; gap: 5px; }
  /* shorter hero banner so products are visible above the fold */
  .du-banner { min-height: 190px !important; padding: 20px !important; border-radius: 16px; }
  .du-banner-copy h1 { font-size: clamp(20px, 6vw, 26px) !important; }
  .du-banner-copy p { font-size: 13px !important; -webkit-line-clamp: 2; }
  .du-banner-art { inset: 0 0 0 50% !important; }
  /* tighten section headings + page padding on phones */
  .du-wrap { padding-left: 14px !important; padding-right: 14px !important; }
  h1, h2 { letter-spacing: -.01em; }
}
/* ============ product DETAIL page: stack to one column on mobile ============ */
/* The main grid uses an inline style (minmax 1.1fr 1fr), so override needs !important. */
@media (max-width: 760px) {
  .du-detail-grid { grid-template-columns: 1fr !important; gap: 16px !important; }
  /* poster: keep its overlay (description/trust/seller) but make it a tidy card, not a 460px monster */
  .du-detail-poster { min-height: 0 !important; aspect-ratio: 4 / 5; }
  .du-detail-pinfo { padding: 14px !important; gap: 10px !important; }
  .du-detail-tagline { font-size: 13px !important; }
  .du-detail-grid > div { min-width: 0; }
}
/* ============ CART: stack items + summary on mobile (was 1fr | 340px inline) ============ */
@media (max-width: 760px) {
  .du-cart-grid { grid-template-columns: 1fr !important; gap: 16px !important; }
  /* the order-summary card sits below the items, full width */
  .du-cart-grid > * { min-width: 0; }
}
/* very small phones still get 2 cols but a hair tighter */
@media (max-width: 360px) {
  .du-grid { gap: 8px !important; }
  .du-pcard-title { font-size: 12.5px !important; }
}

/* ============ product poster placeholder (no uploaded image) ============ */
.du-poster-ph-title {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
@media (max-width: 560px) {
  .du-poster-ph { padding: 9px 10px !important; }
  .du-poster-ph-title { -webkit-line-clamp: 2; font-size: 13px !important; }
}

/* ============ auth page: logo above the form on mobile ============ */
.du-auth-mobilelogo { display: none; }
@media (max-width: 760px) {
  /* the brand panel is hidden when du-auth collapses; show a logo over the form */
  .du-auth-brand { display: none !important; }
  .du-auth { grid-template-columns: 1fr !important; }
  .du-auth-mobilelogo {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    margin: 0 0 26px; animation: duFadeUp .4s both cubic-bezier(.2,.8,.2,1);
  }
  .du-auth-mobilelogo img { height: 38px; }
  .du-auth-mobilelogo span { font-family: var(--font-display); font-weight: 700; font-size: 26px; letter-spacing: -.03em; color: var(--ink-strong); }
}

