/* Diamond Infinity — Advanced Responsive UI */
/* Load after responsive.css */

:root {
  --fluid-xs: clamp(0.5rem, 1.2vw, 0.75rem);
  --fluid-sm: clamp(0.75rem, 1.8vw, 1rem);
  --fluid-md: clamp(1rem, 2.5vw, 1.5rem);
  --fluid-lg: clamp(1.5rem, 3.5vw, 2.25rem);
  --fluid-xl: clamp(2rem, 5vw, 3.5rem);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --mobile-nav-h: 62px;
  --drawer-width: min(320px, 92vw);
  --touch-target: 44px;
  --scroll-fade: 28px;
}

html { font-size: clamp(15px, 0.9rem + 0.25vw, 17px); }

body {
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ── Scroll progress ── */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, #d4af37, #f4d03f, #00e676);
  z-index: 10002;
  pointer-events: none;
  transition: width 0.08s linear;
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.5);
}

/* ── Compact header on scroll ── */
.site-header.header-compact .header-inner {
  padding-top: 10px !important;
  padding-bottom: 10px !important;
}
.site-header.header-compact .logo { font-size: 1rem !important; }

.panel-topbar.topbar-compact {
  height: 52px !important;
  backdrop-filter: blur(28px);
}

/* ── Enhanced mobile drawer ── */
.mobile-drawer-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.mobile-drawer-head .logo { font-size: 1.1rem; }
.drawer-close {
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: 12px;
  border: 1px solid rgba(212, 175, 55, 0.25);
  background: rgba(212, 175, 55, 0.1);
  color: var(--gold);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

@media (max-width: 1023px) {
  .main-nav .mobile-drawer-head { display: flex; }
  .main-nav {
    width: var(--drawer-width) !important;
    padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)) !important;
    background: linear-gradient(180deg, rgba(10, 22, 40, 0.98), rgba(5, 11, 20, 0.99)) !important;
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.45);
  }
  .main-nav > li > a {
    min-height: var(--touch-target);
    transition: background 0.2s, transform 0.2s;
  }
  .main-nav.open > li {
    animation: navItemIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
  .main-nav.open > li:nth-child(2) { animation-delay: 0.04s; }
  .main-nav.open > li:nth-child(3) { animation-delay: 0.08s; }
  .main-nav.open > li:nth-child(4) { animation-delay: 0.12s; }
  .main-nav.open > li:nth-child(5) { animation-delay: 0.16s; }
  .main-nav.open > li:nth-child(6) { animation-delay: 0.2s; }
  .main-nav.open > li:nth-child(7) { animation-delay: 0.24s; }

  .panel-sidebar {
    width: var(--drawer-width) !important;
    padding-bottom: var(--safe-bottom);
  }
  .sidebar-header::after {
    content: '';
    display: block;
    height: 1px;
    margin-top: 12px;
    background: linear-gradient(90deg, transparent, rgba(244, 196, 48, 0.3), transparent);
  }
}

@keyframes navItemIn {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Mobile bottom navigation (member/admin) ── */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1090;
  height: calc(var(--mobile-nav-h) + var(--safe-bottom));
  padding: 6px calc(8px + var(--safe-left)) calc(6px + var(--safe-bottom)) calc(8px + var(--safe-right));
  background: rgba(8, 16, 30, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
}
.mobile-bottom-nav-inner {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  max-width: 520px;
  margin: 0 auto;
  height: 100%;
}
.mobile-bottom-nav a,
.mobile-bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px 2px;
  border: none;
  background: none;
  color: #94a3b8;
  font-size: 0.62rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: 12px;
  cursor: pointer;
  min-height: var(--touch-target);
  transition: color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.mobile-bottom-nav a i,
.mobile-bottom-nav button i {
  font-size: 1.15rem;
  transition: transform 0.2s;
}
.mobile-bottom-nav a.active,
.mobile-bottom-nav button.active {
  color: #f4c430;
  background: rgba(244, 196, 48, 0.1);
}
.mobile-bottom-nav a.active i,
.mobile-bottom-nav button.active i {
  transform: scale(1.1);
}
.mobile-bottom-nav .nav-menu-btn { color: #448aff; }

@media (max-width: 1023px) {
  body.has-mobile-nav .mobile-bottom-nav { display: block; }
  body.has-mobile-nav .panel-content {
    padding-bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 20px) !important;
  }
  body.has-mobile-nav .member-ai-btn,
  body.has-mobile-nav .ai-assistant-btn {
    bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 14px) !important;
  }
  body.has-mobile-nav .ai-toast,
  body.has-mobile-nav .member-toast {
    bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 16px) !important;
  }
}

/* ── KPI horizontal carousel (phones) ── */
@media (max-width: 599px) {
  .kpi-grid {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding-left: 12px;
    gap: 12px !important;
    padding: 4px 12px 8px;
    margin-left: -12px;
    margin-right: -12px;
    width: calc(100% + 24px);
    max-width: none !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .kpi-grid::-webkit-scrollbar { display: none; }
  .kpi-grid .kpi-card {
    flex: 0 0 min(82vw, 280px);
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }
  .kpi-scroll-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.7rem;
    color: #64748b;
    margin: -8px 0 12px;
  }
  .kpi-scroll-hint i { color: #f4c430; animation: hintPulse 1.5s ease infinite; }
}

@keyframes hintPulse {
  0%, 100% { transform: translateX(0); opacity: 0.6; }
  50% { transform: translateX(4px); opacity: 1; }
}

.kpi-scroll-hint { display: none; }

/* ── Quick actions scroll snap ── */
@media (max-width: 599px) {
  .quick-actions {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    gap: 10px !important;
    padding-bottom: 6px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .quick-actions::-webkit-scrollbar { display: none; }
  .quick-actions .quick-action {
    flex: 0 0 calc(33.33% - 8px);
    min-width: 100px;
    scroll-snap-align: start;
  }
}

/* ── Table card view (mobile) ── */
@media (max-width: 767px) {
  .table-scroll.has-card-view,
  .panel-table-wrap.has-card-view {
    overflow-x: visible;
    max-width: 100%;
  }
  table.table-cards {
    min-width: 0 !important;
    width: 100% !important;
    border-collapse: separate;
    border-spacing: 0 10px;
    display: block;
  }
  table.table-cards thead { display: none; }
  table.table-cards tbody,
  table.table-cards tfoot {
    display: block;
    width: 100%;
  }
  table.table-cards tbody tr {
    display: block;
    width: 100%;
    margin-bottom: 10px;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  }
  table.table-cards tbody td {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0 !important;
    border: none !important;
    font-size: 0.85rem;
    text-align: right;
    white-space: normal;
    width: 100%;
    box-sizing: border-box;
  }
  table.table-cards tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    text-align: left;
    flex-shrink: 0;
    max-width: 42%;
  }
  table.table-cards tbody td:first-child { padding-top: 0 !important; }
  table.table-cards tbody td:last-child { padding-bottom: 0 !important; }
  table.table-cards tbody td:last-child {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  /* Single-cell empty / colspan message rows */
  table.table-cards tbody tr td[colspan] {
    display: block !important;
    text-align: center !important;
    padding: 20px 8px !important;
  }
  table.table-cards tbody tr td[colspan]::before {
    content: none !important;
  }
  /* Footer totals as compact summary cards */
  table.table-cards tfoot tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    width: 100%;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(212, 175, 55, 0.08);
    border: 1px solid rgba(212, 175, 55, 0.28);
  }
  table.table-cards tfoot td {
    display: block !important;
    padding: 0 !important;
    border: none !important;
    width: auto !important;
    white-space: nowrap;
  }
  table.table-cards tfoot td:empty,
  table.table-cards tfoot td[colspan]:not(:first-child):empty {
    display: none !important;
  }
}

/* ── Table scroll fade edges ── */
.table-scroll-wrap {
  position: relative;
}
.table-scroll-wrap::before,
.table-scroll-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: var(--scroll-fade);
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.25s;
}
.table-scroll-wrap::before {
  left: 0;
  background: linear-gradient(90deg, rgba(5, 11, 20, 0.9), transparent);
}
.table-scroll-wrap::after {
  right: 0;
  background: linear-gradient(-90deg, rgba(5, 11, 20, 0.9), transparent);
}
.table-scroll-wrap.can-scroll-left::before { opacity: 1; }
.table-scroll-wrap.can-scroll-right::after { opacity: 1; }
.table-scroll-hint {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: #64748b;
  margin-top: 6px;
}
@media (max-width: 767px) {
  .table-scroll-wrap .table-scroll-hint { display: flex; }
}

/* ── Collapsible widgets (mobile) ── */
@media (max-width: 767px) {
  .widget.widget-collapsible .widget-header {
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .widget.widget-collapsible .widget-header::after {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 0.75rem;
    color: #64748b;
    transition: transform 0.3s;
  }
  .widget.widget-collapsible.is-collapsed .widget-header::after {
    transform: rotate(-90deg);
  }
  .widget.widget-collapsible.is-collapsed .widget-body {
    display: none;
  }
  .widget.widget-collapsible .widget-header h3 { font-size: 0.95rem; }
}

/* ── Mobile search overlay (panel) ── */
.mobile-search-btn {
  display: none;
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: #94a3b8;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.mobile-search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(5, 11, 20, 0.95);
  backdrop-filter: blur(16px);
  padding: calc(16px + var(--safe-top)) 16px 16px;
  flex-direction: column;
  gap: 12px;
}
.mobile-search-overlay.open { display: flex; }
.mobile-search-overlay input {
  width: 100%;
  padding: 14px 18px 14px 44px;
  border-radius: 14px;
  border: 1px solid rgba(244, 196, 48, 0.25);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 1rem;
}
.mobile-search-overlay .search-close {
  align-self: flex-end;
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.25rem;
  padding: 8px;
  cursor: pointer;
}

@media (max-width: 1023px) {
  .mobile-search-btn { display: flex; }
}

/* ── Stats / stat cards polish ── */
@media (max-width: 599px) {
  .stats-grid {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 12px !important;
    padding-bottom: 6px;
    scrollbar-width: none;
  }
  .stats-grid::-webkit-scrollbar { display: none; }
  .stats-grid .stat-card {
    flex: 0 0 min(75vw, 260px);
    scroll-snap-align: start;
  }
}

/* ── Hero & sections fluid ── */
.hero-content h1 {
  font-size: clamp(1.75rem, 5vw + 0.5rem, 3.5rem) !important;
}
.section-title {
  font-size: clamp(1.5rem, 3.5vw + 0.5rem, 2.5rem) !important;
}

/* ── Glass cards — subtle press on touch ── */
@media (hover: none) and (pointer: coarse) {
  .glass-card:active,
  .kpi-card:active,
  .quick-action:active,
  .feature-card:active {
    transform: scale(0.98);
    transition: transform 0.1s;
  }
  .btn:active { transform: scale(0.97); }
}

/* ── FAB stack offset ── */
@media (max-width: 1023px) {
  .panel-topbar {
    padding-top: var(--safe-top) !important;
    height: calc(58px + var(--safe-top)) !important;
  }
}

/* ── Login polish ── */
@media (max-width: 767px) {
  .login-visual-content h1 {
    font-size: clamp(1.4rem, 5vw, 2rem) !important;
  }
  .login-feature {
    padding: 12px 14px;
  }
}

/* ── Page banner swipe stats ── */
@media (max-width: 599px) {
  .welcome-hero-stats {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px !important;
  }
  .welcome-stat {
    min-width: 0 !important;
    text-align: center;
  }
  .page-banner-stat {
    margin-top: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
  }
}

/* ── Ultra-wide screens ── */
@media (min-width: 1440px) {
  .container { max-width: 1320px; }
  .header-inner { max-width: 1320px; }
}

@media (min-width: 1600px) {
  .container { max-width: 1440px; }
  .panel-content { max-width: 1400px; margin: 0 auto; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .main-nav.open > li,
  .kpi-scroll-hint i { animation: none !important; }
  .scroll-progress { transition: none; }
}
