/* ==========================================================================
   QR Code Studio Pro — Major Redesign: Design System & App Shell
   ========================================================================== */

:root {
  /* A. PREMIUM DARK MODE */
  --bg-app: #080B14;
  --bg-sidebar: #0D1220;
  --bg-workspace: #101827;
  --bg-card: #151F31;
  --bg-elevated: #1C2940;
  --bg-input: #0B101B;

  --border-subtle: #263650;
  --border-strong: #354A6D;
  --border-focus: #9575FF;
  --inner-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.05);

  --accent-primary: #9575FF;
  --accent-primary-hover: #815CF7;
  --accent-primary-soft: rgba(149, 117, 255, 0.16);
  --accent-blue: #4D8DFF;
  --accent-secondary: #36D7EA;
  --accent-secondary-soft: rgba(54, 215, 234, 0.14);
  --accent-pink: #F472B6;
  --accent-orange: #F5A65B;
  --success: #21C997;
  --success-soft: rgba(33, 201, 151, 0.14);
  --warning: #F5A65B;
  --warning-soft: rgba(245, 166, 91, 0.15);
  --danger: #F87171;
  --danger-soft: rgba(248, 113, 113, 0.14);

  --text-primary: #F5F7FF;
  --text-secondary: #A4B2C8;
  --text-muted: #718096;

  /* 5 Selective Gradients */
  --grad-purple-blue: linear-gradient(135deg, #9575FF 0%, #4D8DFF 100%);
  --grad-blue-cyan: linear-gradient(135deg, #4D8DFF 0%, #36D7EA 100%);
  --grad-pink-purple: linear-gradient(135deg, #F472B6 0%, #9575FF 100%);
  --grad-emerald-cyan: linear-gradient(135deg, #21C997 0%, #36D7EA 100%);
  --grad-orange-pink: linear-gradient(135deg, #F5A65B 0%, #F472B6 100%);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --sidebar-width: 260px;
  --sidebar-collapsed-width: 76px;
  --topbar-height: 66px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --shadow-sm: 0 2px 8px rgba(4, 7, 15, 0.4);
  --shadow-md: 0 12px 32px rgba(4, 7, 15, 0.55);
  --shadow-lg: 0 24px 60px rgba(2, 4, 10, 0.72);
  --transition-fast: 150ms cubic-bezier(0.2, 0.8, 0.2, 1);
  --transition-base: 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* B. PREMIUM LIGHT MODE */
html.light {
  --bg-app: #F5F7FC;
  --bg-sidebar: #FFFFFF;
  --bg-workspace: #F7F8FD;
  --bg-card: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --bg-input: #F5F7FC;

  --border-subtle: #E7EAF2;
  --border-strong: #D5DBE8;
  --border-focus: #7656E8;
  --inner-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.95);

  --accent-primary: #7656E8;
  --accent-primary-hover: #6443D9;
  --accent-primary-soft: rgba(118, 86, 232, 0.1);
  --accent-blue: #3977E8;
  --accent-secondary: #16A6A1;
  --accent-secondary-soft: rgba(22, 166, 161, 0.1);
  --accent-pink: #EC78B8;
  --accent-orange: #F59E0B;
  --success: #1BAA79;
  --success-soft: rgba(27, 170, 121, 0.11);

  --text-primary: #172033;
  --text-secondary: #65728A;
  --text-muted: #94A0B2;

  --grad-purple-blue: linear-gradient(135deg, #7656E8 0%, #3977E8 100%);
  --grad-blue-cyan: linear-gradient(135deg, #3977E8 0%, #55B8E9 100%);
  --grad-pink-purple: linear-gradient(135deg, #EC78B8 0%, #7656E8 100%);
  --grad-emerald-cyan: linear-gradient(135deg, #1BAA79 0%, #16A6A1 100%);
  --grad-orange-pink: linear-gradient(135deg, #F59E0B 0%, #EC78B8 100%);

  --shadow-sm: 0 2px 10px rgba(23, 32, 51, 0.045);
  --shadow-md: 0 10px 28px rgba(23, 32, 51, 0.075);
  --shadow-lg: 0 20px 48px rgba(23, 32, 51, 0.12);
}

html.light .stat-card.grad-purple-blue {
  background: linear-gradient(180deg, rgba(118, 86, 232, 0.06) 0%, #FFFFFF 65%);
}
html.light .stat-card.grad-blue-cyan {
  background: linear-gradient(180deg, rgba(57, 119, 232, 0.06) 0%, #FFFFFF 65%);
}
html.light .stat-card.grad-pink-purple {
  background: linear-gradient(180deg, rgba(236, 120, 184, 0.07) 0%, #FFFFFF 65%);
}
html.light .stat-card.grad-emerald-cyan {
  background: linear-gradient(180deg, rgba(27, 170, 121, 0.06) 0%, #FFFFFF 65%);
}

html.light .dash-hero-banner {
  background:
    radial-gradient(circle at 88% 20%, rgba(85, 184, 233, 0.14), transparent 45%),
    radial-gradient(circle at 12% 85%, rgba(118, 86, 232, 0.12), transparent 48%),
    #FFFFFF;
}

html.light .nav-item.active {
  background: linear-gradient(90deg, rgba(118, 86, 232, 0.1), rgba(57, 119, 232, 0.04));
  border-color: rgba(118, 86, 232, 0.18);
}

html.light .topbar {
  background-color: rgba(255, 255, 255, 0.88);
}

html.light .brand-badge,
html.light .badge-purple,
html.light .step-index {
  color: #6D28D9;
}

html.light .badge-cyan {
  color: #0E7490;
}

html.light .scan-status-badge {
  color: #15803D;
}

html.light .scan-status-badge.is-warning {
  color: #B45309;
}

html.light .alert-warning {
  color: #92400E;
}

html.light .design-thumb,
html.light .template-thumb {
  background: #F1F5F9;
}

/* Compact Density Mode */
html.compact .card-header {
  padding: 12px 16px;
}

html.compact .card-body {
  padding: 16px;
}

html.compact .workspace-content {
  padding: 16px 24px 32px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent-secondary);
  outline-offset: 2px;
}

img,
svg {
  display: block;
  max-width: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
  background-color: var(--bg-app);
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: width var(--transition-base), transform var(--transition-base);
}

.app-shell.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-width);
}

.sidebar-header {
  height: var(--topbar-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  overflow: hidden;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.025em;
}

.brand-badge {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent-primary-soft);
  color: #C4B5FD;
  border: 1px solid rgba(139, 92, 246, 0.35);
}

.app-shell.sidebar-collapsed .brand-text,
.app-shell.sidebar-collapsed .nav-section-label,
.app-shell.sidebar-collapsed .nav-label,
.app-shell.sidebar-collapsed .nav-count,
.app-shell.sidebar-collapsed .sidebar-storage-wrap,
.app-shell.sidebar-collapsed .sidebar-user-meta,
.app-shell.sidebar-collapsed .sidebar-user-chevron {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-header {
  justify-content: center;
  padding: 0 10px;
}

.app-shell.sidebar-collapsed .sidebar-collapse-btn {
  position: absolute;
  right: -14px;
  top: 18px;
  width: 28px;
  height: 28px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.app-shell.sidebar-collapsed .sidebar-collapse-btn svg {
  transform: rotate(180deg);
}

.sidebar-nav {
  flex: 1;
  padding: 20px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-section-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  padding: 0 12px 6px;
}

.nav-item {
  position: relative;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.nav-item svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.nav-item:hover {
  background-color: var(--bg-workspace);
  color: var(--text-primary);
}

.nav-item.active {
  background-color: var(--bg-card);
  border-color: var(--border-subtle);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.nav-item.active svg {
  color: var(--accent-primary);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background-color: var(--accent-primary);
}

.app-shell.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 0;
}

.nav-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.storage-pill {
  background: var(--bg-workspace);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.storage-pill-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  margin-bottom: 6px;
}

.storage-pill-label {
  color: var(--text-secondary);
  font-weight: 500;
}

.storage-pill-value {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.storage-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--bg-app);
  overflow: hidden;
}

.storage-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent-secondary);
  transition: width var(--transition-base);
}

.sidebar-user-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  text-align: left;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.sidebar-user-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
}

.app-shell.sidebar-collapsed .sidebar-user-card {
  justify-content: center;
  padding: 8px;
}

.sidebar-user-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.sidebar-user-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-user-chevron {
  width: 15px;
  height: 15px;
  color: var(--text-muted);
}

/* ==========================================================================
   Main Area & Topbar
   ========================================================================== */

.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-workspace);
  transition: margin-left var(--transition-base);
}

.app-shell.sidebar-collapsed .app-main {
  margin-left: var(--sidebar-collapsed-width);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-height);
  background-color: rgba(13, 16, 23, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.icon-btn.mobile-menu-btn {
  display: none;
}

.page-heading {
  min-width: 0;
}

.page-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-subtitle {
  display: block;
  font-size: 11.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-center {
  flex: 1;
  max-width: 400px;
}

.global-search {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 36px;
  padding: 0 36px 0 35px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-primary-soft);
}

.search-kbd {
  position: absolute;
  right: 9px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 1px 6px;
  pointer-events: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Workspace Content */
.workspace-content {
  flex: 1;
  padding: 24px 28px 40px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
}

.view {
  display: none;
  animation: fadeSlideIn 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.view.active {
  display: block;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.stagger-item {
  animation: cardEnter 320ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.stagger-item:nth-child(1) { animation-delay: 20ms; }
.stagger-item:nth-child(2) { animation-delay: 65ms; }
.stagger-item:nth-child(3) { animation-delay: 110ms; }
.stagger-item:nth-child(4) { animation-delay: 155ms; }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.sidebar-backdrop {
  display: none;
}

/* Branded Preloader Splash */
.app-preloader {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  transition: opacity 280ms ease, visibility 280ms ease;
}

.app-preloader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.preloader-logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--grad-purple-blue);
  display: grid;
  place-items: center;
  box-shadow: 0 12px 32px rgba(149, 117, 255, 0.35);
  animation: pulseLogo 1.4s ease-in-out infinite;
}

.preloader-text {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

@keyframes pulseLogo {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* Breadcrumb Navigation */
.breadcrumb-trail {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 1px;
}

.breadcrumb-trail a {
  color: var(--text-secondary);
}

.breadcrumb-trail a:hover {
  color: var(--accent-primary);
}
