/* Backdrop defaults (hide on desktop and mobile unless opened) */
.sidebar-backdrop { display: none; width: 0; height: 0; }

/* Responsive container widths */
@media (min-width: 1280px) {
  .dashboard-container { max-width: 1280px; }
  .topbar-inner { max-width: 1280px; }
}
@media (min-width: 1440px) {
  .dashboard-container { max-width: 1440px; }
  .topbar-inner { max-width: 1440px; }
}
@media (min-width: 1600px) {
  .dashboard-container { max-width: 1600px; }
  .topbar-inner { max-width: 1600px; }
}
@media (min-width: 1760px) {
  .dashboard-container { max-width: 1760px; }
  .topbar-inner { max-width: 1760px; }
}
/* 815 Screens - Dashboard Shell with Sidebar */
:root {
  --primary-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  --bg-primary: linear-gradient(135deg, #0a0a0f 0%, #1a1a2e 50%, #16213e 100%);
  --text-primary: #ffffff;
  --text-secondary: #a0a9c0;
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(79, 172, 254, 0.2);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --topbar-height: 88px; /* approx topbar + subnav combined height */
}

html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* Brand text gradient (from branding.md) */
.text-gradient,
.gradient-text {
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text; /* standard property for broader support */
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

/* Topbar (full-width header) */
.topbar {
  position: fixed; top: 0; left: 260px; right: 0; height: 64px; z-index: 1500; /* start after sidebar */
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--glass-border);
}
.topbar-inner {
  max-width: 1760px; margin: 0 auto; padding: 8px 20px; /* compact */
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar .brand-logo { height: 28px; width: auto; display: block; }
.topbar .brand-name {
  font-weight: 800; background: var(--primary-gradient);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
/* Temporarily hide subnav to simplify header height until design finalized */
.subnav { display: none; }

/* --- Header User Section (brand-aligned) --- */
.topbar .brand-pill {
  background-image: var(--primary-gradient);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 22px rgba(79,172,254,.32);
}
.topbar .brand-pill .material-icons { color: #fff; opacity: 0.95; }
.topbar .user-label { color: #fff; opacity: 0.95; }
.topbar .brand-pill:hover { filter: brightness(1.05); box-shadow: 0 10px 26px rgba(79,172,254,.42); }
.topbar .brand-pill:active { transform: translateY(1px); }

/* Make the dropdown caret visible on dark background */
.topbar .dropdown-toggle.brand-pill::after {
  border-top-color: #fff;
}

/* Accessible focus ring */
.topbar .brand-pill:focus-visible {
  outline: 2px solid rgba(79,172,254,.85);
  outline-offset: 2px;
}

/* Dropdown menu styling to match dark glass */
.topbar .dropdown-menu {
  background: rgba(10,10,15,0.92);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
}
.topbar .dropdown-menu .dropdown-item { color: #e5e7eb; }
.topbar .dropdown-menu .dropdown-item:hover { background: rgba(79,172,254,.12); color: #fff; }
.topbar .dropdown-menu .dropdown-divider { border-color: var(--glass-border); }

/* Sidebar */
.sidebar {
  grid-column: 1; /* ensure left column */
  position: sticky;
  top: 0;
  height: 100vh; /* full viewport height */
  min-height: 100vh;
  display: flex;               /* allow footer to pin to bottom */
  flex-direction: column;
  overflow-y: auto;            /* independent scrolling when content exceeds viewport */
  background: rgba(10, 10, 15, 0.92);
  border-right: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  padding: 20px 16px;
  transition: transform .25s ease;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; margin: 14px 6px 10px; }
.sidebar .brand .brand-logo { height: 26px; width: auto; display: block; filter: drop-shadow(0 6px 18px rgba(79,172,254,.35)); }
.sidebar .brand .title { font-weight: 800; background: var(--primary-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.sidebar-account { margin: 6px 6px 12px; padding: 10px; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid var(--glass-border); }
.sidebar-account .user-email { display: block; color: var(--text-secondary); font-size: 12px; word-break: break-all; }
.sidebar-footer { margin-top: auto; }

.nav-group { margin-top: 12px; }
.nav-group-title {
  color: var(--text-secondary);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin: 18px 12px 8px;
}
.sidebar-nav { list-style: none; margin: 0; padding: 0; }
.sidebar-nav li { margin-bottom: 6px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text-primary);
  padding: 10px 12px; border-radius: 10px;
  transition: all .2s ease;
}
.sidebar-nav a .material-icons { font-size: 20px; opacity: .9; }
.sidebar-nav a:hover { background: rgba(255,255,255,.06); transform: translateX(2px); }
.sidebar-nav a.active { background: rgba(79,172,254,.12); border: 1px solid var(--glass-border); box-shadow: 0 12px 28px rgba(79,172,254,.12) inset; }

/* Content */
.dashboard-container {
  width: 100%;
  grid-column: 2; /* ensure right content column */
  padding: 80px 40px 88px; /* add bottom padding to clear fixed bottombar */
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
  max-width: 100%;
  margin: 0 auto;
}
.dashboard-header {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 12px; margin: 0 0 16px 0; /* remove any top margin */
}
/* Ensure first element inside container never pushes content down with top margin */
.dashboard-container > *:first-child { margin-top: 0; }
.dashboard-container h1 { margin-top: 0; }

/* Custom scrollbar (branding.md) */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: rgba(26, 26, 46, 0.3); border-radius: 10px; }
::-webkit-scrollbar-thumb { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); border-radius: 10px; transition: all 0.3s ease; }
::-webkit-scrollbar-thumb:hover { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); box-shadow: 0 0 10px rgba(79, 172, 254, 0.3); }
html { scrollbar-width: thin; scrollbar-color: #4facfe rgba(26, 26, 46, 0.3); }

.sidebar-toggle {
  display: none;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 8px 10px;
}

/* Branded gradient button (used on dashboard cards and actions) */
.btn-gradient {
  background-image: var(--primary-gradient);
  color: #fff !important;
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  box-shadow: 0 8px 22px rgba(79,172,254,.28);
}
.btn-gradient:hover {
  filter: brightness(1.06);
  color: #fff !important;
  box-shadow: 0 10px 26px rgba(79,172,254,.38);
}
.btn-gradient:focus-visible {
  outline: 2px solid rgba(79,172,254,.85);
  outline-offset: 2px;
}

/* Text-style button for secondary actions on dark bg */
.btn-text {
  background: transparent;
  color: #e5e7eb;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  padding: 6px 12px;
}
.btn-text:hover {
  color: #fff;
  border-color: rgba(255,255,255,.28);
  background: rgba(255,255,255,.06);
}
.btn-text:focus-visible {
  outline: 2px solid rgba(255,255,255,.6);
  outline-offset: 2px;
}

/* Device card actions row */
.device-actions { display: flex; gap: 8px; margin-top: 8px; }

/* Improve icon button legibility on dark imagery */
.quick-actions .btn-icon { background: rgba(10,10,15,0.7); border-color: rgba(255,255,255,.18); }

/* Cards and grids already styled by existing CSS in the page; keep enhancements minimal */
.badge-success { background: rgba(16,185,129,.15); color: #34d399; border: 1px solid rgba(16,185,129,.35); }
.badge-approval { background: rgba(79,70,229,.15); color: #a5b4fc; border: 1px solid rgba(79,70,229,.35); }

/* Overview cards */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.overview-card {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(79,172,254,.35);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 14px 40px rgba(0,0,0,.28);
}
.overview-card .actions { display:flex; gap:8px; flex-wrap:wrap; }

/* Section heading treatment with gradient underline */
.dashboard-content > h2,
.dashboard-content .section-title,
.devices-section > h2,
.playlists-section > h2 {
  color:#fff;
  position: relative;
}
.dashboard-content > h2::after,
.devices-section > h2::after,
.playlists-section > h2::after {
  content: "";
  display: block;
  width: 72px;
  height: 4px;
  border-radius: 999px;
  margin-top: 6px;
  background: var(--primary-gradient);
}
.overview-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px; min-width: 0; /* allow grid to wrap to multiple columns */
}
.overview-card .count { font-size: 28px; font-weight: 700; }
.overview-card .actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Explicit breakpoints to guarantee multi-column on desktop */
@media (min-width: 768px) {
  .overview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1200px) {
  .overview-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1600px) {
  .overview-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Modern thumbnail grids */
.playlists-grid,
.media-grid,
.devices-grid,
.layouts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}

/* Card styling */
.playlist-card,
.media-card,
.device-card,
.layout-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.playlist-card:hover,
.media-card:hover,
.device-card:hover,
.layout-card:hover {
  transform: translateY(-4px);
  border-color: rgba(79,172,254,.35);
  box-shadow: 0 16px 36px rgba(79,172,254,.18);
}

/* Thumbnail wrapper with fixed aspect ratios */
.layout-preview,
.media-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
}
.layout-preview.portrait,
.media-preview.portrait {
  aspect-ratio: 3 / 4; /* friendlier for phone shots */
}
.layout-preview img,
.media-preview img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scale(1.02);
  transition: transform .25s ease;
  display: block;
}
.thumb-overlay {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0) 55%, rgba(0,0,0,0.35) 100%);
}
.overlay-bottom {
  position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; gap: 6px; flex-wrap: wrap;
}
.quick-actions {
  position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; opacity: 0; transform: translateY(-4px);
  transition: opacity .18s ease, transform .18s ease; pointer-events: auto; /* allow clicks */
}
.quick-actions .btn-icon {
  pointer-events: auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 10px; border: 1px solid var(--glass-border);
  background: rgba(10,10,15,0.6); color: #fff;
}
.chip {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: 999px; font-size: 12px;
  background: rgba(10,10,15,0.6); color: #fff; border: 1px solid var(--glass-border);
}
.playlist-card:hover .layout-preview img,
.media-card:hover .media-preview img,
.device-card:hover .layout-preview img,
.layout-card:hover .layout-preview img { transform: scale(1.06); }
.playlist-card:hover .quick-actions,
.media-card:hover .quick-actions,
.device-card:hover .quick-actions,
.layout-card:hover .quick-actions { opacity: 1; transform: translateY(0); }

/* Titles and meta */
.playlist-card h3,
.media-card h3,
.device-card h3,
.layout-card h3 {
  margin: 12px 4px 8px;
  font-size: 17px;
}
.playlist-description,
.layout-description,
.device-meta,
.media-meta { color: var(--text-secondary); font-size: 13px; }

/* Section description text */
.section-description { color: var(--text-secondary); margin: 4px 0 16px; }

/* Responsive */
@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 220px 1fr; }
  .sidebar .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
}
@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  /* Allow header controls to wrap neatly on small screens */
  .dashboard-header { flex-wrap: wrap; gap: 10px; }
  .sidebar-toggle { display: inline-flex; align-items: center; gap: 6px; }
  .sidebar { 
    position: fixed; left: 0; top: 0; height: 100vh; width: 80%; max-width: 320px; 
    transform: translateX(-100%); z-index: 1200; border-right: 1px solid var(--glass-border);
    /* Ensure bottom account/logout area is not hidden behind the fixed bottombar */
    padding-bottom: calc(120px + env(safe-area-inset-bottom));
  }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1190; width: auto; height: auto; }
  .sidebar-open .sidebar-backdrop { display: block; }
  .topbar { left: 0; right: 0; } /* full width header on mobile */
  .dashboard-container { padding-top: 80px; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  /* Hide the fixed bottom bar while the sidebar is open for unobstructed navigation */
  .sidebar-open .bottombar { display: none; }
  /* Utility: hide elements on mobile */
  .hide-on-mobile { display: none !important; }
}

/* Bottom footer bar (shared in includes/footer.php) */
.bottombar {
  position: fixed;
  left: 260px;
  right: 0;
  bottom: 0;
  background: rgba(10,10,15,0.88);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--glass-border);
  z-index: 1400; /* below topbar(1500), above sidebar(1200) */
}
.bottombar-inner {
  max-width: 1760px;
  margin: 0 auto;
  padding: 10px 20px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.bottombar-logo { display: none; }
.bottombar-left { display: flex; align-items: center; gap: 8px; }
.bottombar .brand-name { font-weight: 800; }
.bottombar .divider { color: var(--text-secondary); opacity: .9; }
.bottombar .muted { color: var(--text-secondary); }
.bottombar-right { display: flex; align-items: center; gap: 14px; }
.bottombar-right .link { color: #cfe1ff; text-decoration: none; }
.bottombar-right .link:hover { color: #fff; text-decoration: underline; }

@media (max-width: 768px) {
  .bottombar { left: 0; }
  .bottombar-inner { padding: 10px 14px; }
  .bottombar-logo { display: block; margin: 0 auto; }
  .bottombar-left, .bottombar-right { display: none; }
}

/* --- Branded Modal Styling (uses brand.md) --- */
/* Darker, blurred backdrop */
.modal-backdrop.show {
  /* Deep navy overlay with slight gradient and stronger opacity */
  background: radial-gradient(1200px 800px at 20% 10%, rgba(21,34,66,0.85), rgba(10,10,15,0.9)) !important;
  backdrop-filter: blur(3px);
  z-index: 1990; /* ensure backdrop sits below modal but above topbar (1500) */
}

/* Upload Modal content: dark glass with gradient glow */
#uploadModal .modal-content {
  position: relative;
  background: linear-gradient(180deg, rgba(15,23,42,0.98), rgba(10,10,15,0.98)); /* #0f172a to deep navy */
  border: 1px solid rgba(79,172,254,0.35); /* brand blue border */
  border-radius: 14px;
  box-shadow:
    0 20px 60px rgba(0,0,0,0.5),
    0 0 0 1px rgba(79,172,254,0.25) inset,
    0 0 24px rgba(79,172,254,0.25); /* soft brand glow */
}

/* Ensure all modals appear above the fixed topbar (z-index:1500) */
.modal { z-index: 2000; }

/* Subtle top accent bar in brand gradient */
#uploadModal .modal-content::before {
  content: "";
  position: absolute; left: 8px; right: 8px; top: 8px; height: 3px;
  border-radius: 999px;
  background: var(--primary-gradient);
  opacity: .9;
}

#uploadModal .modal-header {
  border-bottom: 1px solid rgba(79,172,254,0.22);
}
#uploadModal .modal-footer {
  border-top: 1px solid rgba(79,172,254,0.22);
}

#uploadModal .btn-primary {
  background-image: var(--primary-gradient);
  border: none;
  box-shadow: 0 10px 24px rgba(79,172,254,0.35);
}
#uploadModal .btn-primary:hover {
  filter: brightness(1.06);
  box-shadow: 0 12px 28px rgba(79,172,254,0.45);
}

/* Pulsing glow for Start Upload when enabled */
#uploadModal #startUploadBtn:not([disabled]) {
  animation: uploadPulse 1.4s ease-in-out infinite;
}
@keyframes uploadPulse {
  0% { box-shadow: 0 0 0 0 rgba(79,172,254,0.45), 0 10px 24px rgba(79,172,254,0.35); }
  70% { box-shadow: 0 0 0 12px rgba(79,172,254,0), 0 12px 28px rgba(79,172,254,0.45); }
  100% { box-shadow: 0 0 0 0 rgba(79,172,254,0), 0 10px 24px rgba(79,172,254,0.35); }
}

#uploadModal #startUploadBtn[disabled] {
  opacity: .65;
  box-shadow: none;
}

/* Improve contrast for form controls inside modal */
#uploadModal .form-select,
#uploadModal .form-control {
  background: rgba(255,255,255,0.06);
  color: #fff;
  border: 1px solid var(--glass-border);
}
