/* ==========================================================================
   LeGlamorous Jewels — UI/UX Improvements Layer
   Fixes: responsiveness, cart badge, notification panel, left-filter layout,
   admin content fit, header width, table overflow, mobile layout.
   ========================================================================== */

/* ── 1. Global Responsive Fixes ──────────────────────────────────────────── */
html, body {
  overflow-x: clip;
  max-width: 100vw;
}

/* Ensure containers never cause horizontal scroll */
.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 24px;
  box-sizing: border-box;
}

/* Admin shell — prevent overflow */
.admin-shell {
  width: 100%;
  overflow: visible;
}

.admin-main {
  min-width: 0;
  width: 100%;
  overflow: visible;
}

.admin-content {
  min-width: 0;
  overflow: visible;
}

/* ── 2. Header Responsive Fix ────────────────────────────────────────────── */
.site-header {
  width: 100%;
  overflow: visible;
}

.header-inner {
  width: 100%;
  max-width: var(--container);
  min-width: 0;
}

/* ── 3. Footer Width Fix ─────────────────────────────────────────────────── */
.site-footer {
  width: 100%;
  overflow-x: hidden;
}

/* ── 4. Table Responsive Fixes ───────────────────────────────────────────── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.card {
  min-width: 0;
  overflow: hidden;
}

/* ── 5. KPI Grid — Responsive ────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

/* ── 6. Chart Responsive ─────────────────────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 1rem;
  width: 100%;
}

.chart-box canvas {
  max-width: 100% !important;
}

/* ── 7. Cart Badge Fix — Remove unwanted count below product cards ────────── */
/* The count badge on cart icon is fine; remove any stray count text nodes */
.pc-actions > .count-badge,
.product-card > .count-badge,
.pc-body > .count-badge {
  display: none !important;
}

/* Cart count badge — only show on the icon in header */
.count-badge {
  position: absolute;
  top: 3px;
  right: 1px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--gold-fill);
  color: var(--ink);
  font-size: .68rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  border: 2px solid #FFFDF9;
}

/* Ensure icon-btn is position:relative for badge positioning */
.icon-btn {
  position: relative;
}

/* ── 8. Enhanced Notification Panel ─────────────────────────────────────── */
.notif-panel {
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: min(500px, 80vh);
  overflow-y: auto;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
}

.notif-panel .np-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.notif-panel .np-head strong {
  font-size: .95rem;
}

.notif-item {
  display: block !important;
  padding: .85rem 1.1rem !important;
  border-bottom: 1px solid var(--line);
  border-radius: 0 !important;
  transition: background .1s;
  text-decoration: none !important;
}

.notif-item:hover {
  background: var(--surface-2) !important;
}

.notif-item.unread {
  background: var(--gold-tint) !important;
  border-left: 3px solid var(--gold);
}

.notif-item strong {
  display: block;
  font-size: .88rem;
  color: var(--ink);
  margin-bottom: .15rem;
}

.notif-item span {
  display: block;
  font-size: .82rem;
  color: var(--ink-2);
  line-height: 1.4;
}

.notif-item time {
  display: block;
  font-size: .74rem;
  color: var(--ink-3);
  margin-top: .35rem;
}

.notif-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--ink-3);
  font-size: .9rem;
}

/* Notification panel dropdown — right-aligned */
[data-bell] + .notif-panel.dropdown-menu {
  right: 0;
  left: auto;
  top: calc(100% + 8px);
  min-width: 0;
  padding: 0;
}

/* ── 9. Admin Left-Filter Layout ─────────────────────────────────────────── */
/* Applied via .has-left-filter wrapper class on pages that use it */
.has-left-filter {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.has-left-filter .left-filter-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  position: sticky;
  top: calc(68px + 16px);
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.has-left-filter .left-filter-panel .filter-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  font-size: .9rem;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.has-left-filter .left-filter-panel .filter-section {
  padding: .85rem 1.1rem;
  border-bottom: 1px solid var(--line);
}

.has-left-filter .left-filter-panel .filter-section:last-child {
  border-bottom: 0;
}

.has-left-filter .left-filter-panel .filter-section-title {
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: .65rem;
}

.has-left-filter .left-filter-panel .field {
  margin-bottom: .7rem;
}

.has-left-filter .left-filter-panel .field:last-child {
  margin-bottom: 0;
}

.has-left-filter .main-content-panel {
  min-width: 0;
}

/* ── 10. Admin Orders — filter-bar becomes vertical on left ─────────────── */
/* Responsive: stack filter below content on tablet/mobile */
@media (max-width: 1024px) {
  .has-left-filter {
    grid-template-columns: 1fr;
  }
  .has-left-filter .left-filter-panel {
    position: static;
    max-height: none;
  }
}

/* ── 11. Account Orders Date Filter ──────────────────────────────────────── */
.account-date-filter {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: .65rem 1rem;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
}

.account-date-filter .adf-label {
  font-size: .8rem;
  font-weight: 700;
  color: var(--ink-2);
  margin-right: .25rem;
}

.account-date-filter .chip {
  padding: .28rem .65rem;
  font-size: .78rem;
}

.account-date-filter .adf-custom {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: wrap;
}

.account-date-filter .adf-custom input {
  min-height: 32px;
  width: 140px;
  font-size: .82rem;
  padding: .25rem .5rem;
}

/* ── 12. Consistent Date/Time Display ────────────────────────────────────── */
.dt-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dt-cell .dt-date {
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.dt-cell .dt-time {
  font-size: .78rem;
  color: var(--ink-3);
  white-space: nowrap;
}

/* ── 13. Admin Backup Page Styles ────────────────────────────────────────── */
.backup-list {
  display: grid;
  gap: .6rem;
}

.backup-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .9rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  flex-wrap: wrap;
}

.backup-item .bi-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  background: var(--info-bg);
  color: var(--info);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.backup-item .bi-icon svg {
  width: 20px;
  height: 20px;
}

.backup-item .bi-info {
  flex: 1 1 200px;
  min-width: 0;
}

.backup-item .bi-name {
  font-weight: 700;
  font-size: .92rem;
  color: var(--ink);
  word-break: break-all;
}

.backup-item .bi-meta {
  font-size: .8rem;
  color: var(--ink-3);
  margin-top: .1rem;
}

.backup-item .bi-actions {
  display: flex;
  gap: .5rem;
  flex: 0 0 auto;
}

/* ── 14. Mobile Responsive Improvements ──────────────────────────────────── */
@media (max-width: 900px) {
  /* Notification panel full-width on mobile */
  .notif-panel {
    width: calc(100vw - 24px);
    right: -8px !important;
    left: auto !important;
  }

  /* Admin topbar on mobile */
  .admin-topbar {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  /* KPI grid: 2 columns on mobile */
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .65rem;
  }

  /* Chart grid: full width on mobile */
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-card,
  .chart-card.wide,
  .chart-card.narrow {
    grid-column: 1 / -1;
  }

  /* Notif panel on small mobile */
  .notif-panel {
    width: calc(100vw - 16px);
  }

  /* Backup item stack on mobile */
  .backup-item {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ── 15. Dropdown Menu Positioning Fix ───────────────────────────────────── */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 950;
  min-width: 230px;
}

/* ── 16. Header Actions — Clean Spacing ──────────────────────────────────── */
.header-actions {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-shrink: 0;
}

/* ── 17. Admin sidebar scroll fix ────────────────────────────────────────── */
.sidebar-nav {
  overflow-y: auto;
  flex: 1;
}

/* ── 18. Page-level overflow prevention ──────────────────────────────────── */
main, section, .account-content, .admin-content {
  min-width: 0;
}

/* ── 19. Detail grid responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .account-shell {
    grid-template-columns: 1fr;
  }
}

/* ── 20. Filter bar scrollable on small screens ───────────────────────────── */
.filter-bar {
  min-width: 0;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar .field {
    min-width: 0 !important;
    width: 100%;
  }
}

/* ── 21. Notification badge pulse animation for unread ───────────────────── */
@keyframes notif-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

[data-notif-count]:not(.hidden) {
  animation: notif-pulse 2s ease-in-out 3;
}

/* ── 22. Form grid responsive fix ────────────────────────────────────────── */
@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  .form-grid .span-2 {
    grid-column: 1;
  }
}

/* ── 23. Image manager responsive ────────────────────────────────────────── */
.image-manager {
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}

/* ── 24. Admin left filter toggle (mobile) ───────────────────────────────── */
.left-filter-toggle {
  display: none;
  align-items: center;
  gap: .5rem;
}

@media (max-width: 1024px) {
  .left-filter-toggle {
    display: inline-flex;
  }
}

/* ── 25. Scrollbar styling for panels ────────────────────────────────────── */
.notif-panel::-webkit-scrollbar,
.left-filter-panel::-webkit-scrollbar,
.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.notif-panel::-webkit-scrollbar-track,
.left-filter-panel::-webkit-scrollbar-track,
.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.notif-panel::-webkit-scrollbar-thumb,
.left-filter-panel::-webkit-scrollbar-thumb,
.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 2px;
}

/* ── Notification drawer (right side) ────────────────────────────────────── */
.notif-scrim { position: fixed; inset: 0; background: rgba(28,24,20,.45); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 1200; }
.notif-scrim.open { opacity: 1; pointer-events: auto; }
.notif-drawer { position: fixed; top: 0; right: 0; height: 100dvh; width: 400px; max-width: 100vw; background: var(--surface, #fff);
  box-shadow: -8px 0 32px rgba(0,0,0,.18); transform: translateX(100%); transition: transform .25s ease; z-index: 1210; display: flex; flex-direction: column; }
.notif-drawer.open { transform: none; }
.nd-head { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); }
.nd-head strong { flex: 1; font-size: 1.05rem; }
.nd-filters { display: flex; flex-wrap: wrap; gap: .5rem; padding: .75rem 1.1rem; border-bottom: 1px solid var(--line); font-size: .78rem; }
.nd-filters label { display: flex; flex-direction: column; gap: .15rem; flex: 1 1 110px; color: var(--ink-3); }
.nd-filters select { flex: 1 1 100%; }
.nd-filters input, .nd-filters select { padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 6px; font: inherit; min-width: 0; }
.nd-list { flex: 1; overflow-y: auto; }
.notif-drawer .notif-item { position: relative; text-decoration: none; }
.ni-status { float: right; font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.notif-item.unread .ni-status { color: #8A6A1F; font-weight: 700; }
.notif-item.unread strong::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--gold-fill, #C9A24B); margin-right: .4rem; }
.count-badge { pointer-events: none; }

.site-header .dropdown-menu { z-index: 1000; }
.site-header .header-inner { overflow: visible; }

.pc-actions .pc-qty { flex: 1; justify-content: space-between; }
.pc-actions .pc-qty button { flex: 0 0 44px; }
.pc-actions .pc-qty input { flex: 1; width: auto; min-width: 0; }

/* ── Signed-in shoppers / B2B partners: use the full screen width (like admin) ── */
body.full-width .container,
body.full-width .header-inner,
body.full-width .site-footer .container {
  max-width: none;
  padding-left: clamp(16px, 2.5vw, 40px);
  padding-right: clamp(16px, 2.5vw, 40px);
}
@media (min-width: 901px) { body.full-width .account-shell { grid-template-columns: 260px minmax(0, 1fr); } }
body.full-width .product-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
