/**
 * apple-design-system.css
 * System-Wide Apple.com-grade UI/UX Design System for AUTOGRADING AI.
 * Follows Apple Human Interface Guidelines (HIG).
 * Enforces SOLID + SoC + Hard Ceiling (<= 800 lines).
 */

/* ==========================================================================
   1. APPLE CORE DESIGN TOKENS & TYPOGRAPHY
   ========================================================================== */
:root {
  /* Apple Typography Stack (Vietnamese-complete webfonts ahead of Helvetica Neue) */
  --apple-font: "Be Vietnam Pro", "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --apple-font-mono: "SF Mono", "JetBrains Mono", Menlo, Monaco, Consolas, monospace;

  /* Brand-Aligned chamnhanh.net Palette (Electric Cyan, Deep Navy, Signal Coral) */
  --apple-blue: #00c5df;
  --apple-blue-hover: #00b4d8;
  --apple-blue-active: #082850;
  --apple-blue-tint: rgba(0, 197, 223, 0.08);
  --apple-blue-ring: rgba(0, 197, 223, 0.25);

  --apple-purple: #082850;
  --apple-purple-tint: rgba(8, 40, 80, 0.08);
  --apple-green: #10b981;
  --apple-green-tint: rgba(16, 185, 129, 0.12);
  --apple-orange: #ff6b6b;
  --apple-orange-tint: rgba(255, 107, 107, 0.12);
  --apple-red: #fa5252;
  --apple-red-tint: rgba(250, 82, 82, 0.1);

  /* Apple Canvas & Surface Colors (Light Mode) */
  --apple-canvas: #f5f5f7;
  --apple-surface: #ffffff;
  --apple-surface-elevated: #ffffff;
  --apple-surface-secondary: #fbfbfd;
  --apple-border: rgba(0, 0, 0, 0.08);
  --apple-border-subtle: rgba(0, 0, 0, 0.04);
  --apple-border-hover: rgba(0, 0, 0, 0.14);
  --apple-divider: rgba(0, 0, 0, 0.06);

  /* Apple Typography Colors */
  --apple-text-primary: #1d1d1f;
  --apple-text-secondary: #6e6e73;
  --apple-text-tertiary: #86868b;
  --apple-text-quaternary: #aeaeb2;

  /* Apple Shadows & Vibrancy */
  --apple-shadow-subtle: 0 1px 2px rgba(0, 0, 0, 0.04);
  --apple-shadow-card: 0 2px 10px rgba(0, 0, 0, 0.04), 0 0 1px rgba(0, 0, 0, 0.08);
  --apple-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
  --apple-shadow-float: 0 20px 48px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);

  /* Apple Timing Curves */
  --apple-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --apple-ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --apple-transition-fast: all 0.18s var(--apple-ease);
  --apple-transition-medium: all 0.28s var(--apple-ease);
}

/* Apple Dark Mode Overrides */
[data-theme="dark"] {
  --apple-canvas: #000000;
  --apple-surface: #1c1c1e;
  --apple-surface-elevated: #2c2c2e;
  --apple-surface-secondary: #141416;
  --apple-border: rgba(255, 255, 255, 0.12);
  --apple-border-subtle: rgba(255, 255, 255, 0.06);
  --apple-border-hover: rgba(255, 255, 255, 0.2);
  --apple-divider: rgba(255, 255, 255, 0.08);

  --apple-text-primary: #f5f5f7;
  --apple-text-secondary: #a1a1a6;
  --apple-text-tertiary: #86868b;
  --apple-text-quaternary: #636366;

  --apple-blue: #00e5ff;
  --apple-blue-hover: #38efff;
  --apple-blue-active: #00b4d8;
  --apple-blue-tint: rgba(0, 229, 255, 0.14);
  --apple-blue-ring: rgba(0, 229, 255, 0.32);

  --apple-shadow-card: 0 2px 12px rgba(0, 0, 0, 0.4), 0 0 1px rgba(255, 255, 255, 0.12);
  --apple-shadow-hover: 0 10px 28px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.3);
  --apple-shadow-float: 0 24px 60px rgba(0, 0, 0, 0.75);
}

/* Global Font & Antialiasing */
html, body {
  font-family: var(--apple-font) !important;
  background-color: var(--apple-canvas) !important;
  color: var(--apple-text-primary) !important;
  -webkit-font-smoothing: antialiased !important;
  -moz-osx-font-smoothing: grayscale !important;
  text-rendering: optimizeLegibility !important;
  letter-spacing: -0.01em;
}

/* ==========================================================================
   2. FROSTED GLASS STUDIO TOPBAR & HEADER
   ========================================================================== */
.studio-topbar,
.app-header {
  position: sticky !important;
  top: 0 !important;
  z-index: 2000 !important;
  background: rgba(255, 255, 255, 0.8) !important;
  backdrop-filter: blur(20px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
  border-bottom: 1px solid var(--apple-border) !important;
  transition: var(--apple-transition-medium) !important;
  box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.02) !important;
}

.studio-topbar.has-open-dropdown,
.studio-topbar:has(#topbar-utilities-container.open),
.studio-topbar:has(#user-profile-menu-container.open),
.studio-topbar:has(#topbar-utilities-menu:not([style*="display: none"]):not([style*="display:none"])) {
  z-index: 3500 !important;
}

.topbar-utilities-wrapper.open,
.user-profile-menu-container.open {
  position: relative !important;
  z-index: 3550 !important;
}

@media (max-width: 1024px) {
  .sidebar-backdrop { z-index: 3800 !important; }
  .cockpit-sidebar { z-index: 3900 !important; }
}

/* Workspace Container Stacking Context Isolation */
.workspace-container {
  position: relative !important;
  z-index: 100 !important;
}

[data-theme="dark"] .studio-topbar,
[data-theme="dark"] .app-header {
  background: rgba(28, 28, 30, 0.82) !important;
  border-bottom-color: var(--apple-border) !important;
}

/* Topbar Action Buttons (Crisp Apple Pill Styling) */
.studio-topbar {
  overflow: visible !important;
}
.studio-topbar::-webkit-scrollbar {
  display: none !important;
}

.topbar-left,
.topbar-right {
  flex-shrink: 0 !important;
}

.topbar-right {
  display: flex !important;
  align-items: center !important;
  gap: 0.5rem !important;
}

.topbar-right button,
.topbar-right .btn {
  flex-shrink: 0;
  white-space: nowrap;
  height: 36px;
  padding: 0 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 980px;
}

@media (min-width: 769px) {
  #btn-quick-create-exam,
  #btn-batch-grade,
  #btn-topbar-utilities-toggle,
  #topbar-utilities-container,
  .topbar-right .teacher-action:not(.btn-mobile-more-actions) {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    height: 36px !important;
    padding: 0 0.85rem !important;
    font-size: 0.82rem !important;
    font-weight: 600 !important;
    line-height: 1 !important;
    border-radius: 980px !important;
  }
}

@media (min-width: 769px) and (max-width: 1180px) {
  .breadcrumb-trail #bc-school,
  .breadcrumb-trail #bc-year,
  .breadcrumb-trail .breadcrumb-sep:nth-of-type(-n+2) {
    display: none !important;
  }
  .spotlight-trigger-box {
    flex: 0 1 180px !important;
    min-width: 120px !important;
    max-width: 200px !important;
    padding: 0 0.65rem !important;
  }
  .topbar-right {
    gap: 0.35rem !important;
  }
  .topbar-right .btn-sm {
    padding: 0 0.6rem !important;
    font-size: 0.78rem !important;
  }
}

@media (max-width: 768px) {
  .studio-topbar {
    overflow: visible !important;
    justify-content: space-between !important;
  }
  .spotlight-trigger-box {
    display: none !important;
  }
  .topbar-left {
    flex-shrink: 1 !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }
  .breadcrumb-trail {
    max-width: 125px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
  .breadcrumb-trail #bc-school,
  .breadcrumb-trail #bc-year,
  .breadcrumb-trail #bc-subject,
  .breadcrumb-trail .breadcrumb-sep {
    display: none !important;
  }
  .breadcrumb-active,
  #bc-class {
    max-width: 120px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    display: inline-block !important;
    vertical-align: middle !important;
  }
  #btn-quick-create-exam,
  #btn-batch-grade,
  #btn-topbar-utilities-toggle,
  #topbar-utilities-container,
  .topbar-right .teacher-action:not(.btn-mobile-more-actions) {
    display: none !important;
  }
  .btn-mobile-more-actions {
    display: inline-flex !important;
  }
  .topbar-right {
    gap: 0.3rem !important;
  }
}

/* Smart Breadcrumb Trail */
.breadcrumb-trail {
  display: flex !important;
  align-items: center !important;
  gap: 0.4rem !important;
  font-size: 0.84rem !important;
  font-weight: 500 !important;
  color: var(--apple-text-secondary) !important;
  letter-spacing: -0.012em !important;
}

.breadcrumb-trail .breadcrumb-sep {
  color: var(--apple-text-tertiary) !important;
  font-size: 0.75rem !important;
  opacity: 0.6 !important;
}

.breadcrumb-trail .breadcrumb-active {
  color: var(--apple-text-primary) !important;
  font-weight: 600 !important;
}

/* Center Spotlight Trigger Box */
.spotlight-trigger-box {
  background: rgba(0, 0, 0, 0.04) !important;
  border: 1px solid var(--apple-border) !important;
  border-radius: 980px !important;
  padding: 0.42rem 0.95rem !important;
  font-size: 0.82rem !important;
  color: var(--apple-text-secondary) !important;
  transition: var(--apple-transition-fast) !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  height: 36px !important;
  box-sizing: border-box !important;
  display: inline-flex !important;
  align-items: center !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

.spotlight-trigger-box span:not(.kbd-chip) {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

.spotlight-trigger-box:hover {
  background: rgba(0, 0, 0, 0.07) !important;
  border-color: var(--apple-border-hover) !important;
  color: var(--apple-text-primary) !important;
  transform: translateY(-0.5px) !important;
}

[data-theme="dark"] .spotlight-trigger-box {
  background: rgba(255, 255, 255, 0.07) !important;
  border-color: var(--apple-border) !important;
}

[data-theme="dark"] .spotlight-trigger-box:hover {
  background: rgba(255, 255, 255, 0.12) !important;
}

.spotlight-trigger-box .kbd-chip {
  background: rgba(0, 0, 0, 0.06) !important;
  border: 1px solid rgba(0, 0, 0, 0.08) !important;
  border-radius: 6px !important;
  padding: 2px 6px !important;
  font-size: 0.68rem !important;
  font-weight: 600 !important;
  font-family: var(--apple-font-mono) !important;
  color: var(--apple-text-tertiary) !important;
}

[data-theme="dark"] .spotlight-trigger-box .kbd-chip {
  background: rgba(255, 255, 255, 0.1) !important;
  border-color: rgba(255, 255, 255, 0.14) !important;
  color: var(--apple-text-secondary) !important;
}

/* ==========================================================================
   3. APPLE COCKPIT SIDEBAR & NAVIGATION RAIL
   ========================================================================== */
.cockpit-sidebar {
  background: rgba(255, 255, 255, 0.85) !important;
  backdrop-filter: blur(24px) saturate(190%) !important;
  -webkit-backdrop-filter: blur(24px) saturate(190%) !important;
  border-right: 1px solid var(--apple-border) !important;
  transition: var(--apple-transition-medium) !important;
}

[data-theme="dark"] .cockpit-sidebar {
  background: rgba(24, 24, 26, 0.88) !important;
  border-right-color: var(--apple-border) !important;
}

/* Sidebar Brand */
.sidebar-brand {
  padding: 1rem 1.15rem !important;
  border-bottom: 1px solid var(--apple-divider) !important;
}

.brand-icon-box {
  border-radius: 10px !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}

.brand-meta h1 {
  font-size: 1.05rem !important;
  font-weight: 700 !important;
  letter-spacing: -0.022em !important;
  color: var(--apple-text-primary) !important;
}

.brand-meta p {
  font-size: 0.72rem !important;
  font-weight: 500 !important;
  color: var(--apple-text-tertiary) !important;
  letter-spacing: 0.02em !important;
  text-transform: uppercase !important;
}

/* Smart Context Capsule */
.sidebar-smart-context-capsule {
  position: relative !important;
  z-index: 100 !important;
  background: rgba(0, 0, 0, 0.03) !important;
  border: 1px solid var(--apple-border) !important;
  border-radius: 14px !important;
  padding: 0.65rem 0.85rem !important;
  transition: var(--apple-transition-fast) !important;
}

.sidebar-smart-context-capsule.popover-open,
.sidebar-smart-context-capsule[aria-expanded="true"] {
  z-index: 1200 !important;
}

.sidebar-smart-context-capsule:hover {
  background: rgba(0, 0, 0, 0.06) !important;
  border-color: var(--apple-border-hover) !important;
  transform: translateY(-0.5px) !important;
}

[data-theme="dark"] .sidebar-smart-context-capsule {
  background: rgba(255, 255, 255, 0.05) !important;
}

[data-theme="dark"] .sidebar-smart-context-capsule:hover {
  background: rgba(255, 255, 255, 0.09) !important;
}

/* Sidebar Navigation Items */
.nav-section-title-modern {
  font-size: 0.68rem !important;
  font-weight: 600 !important;
  letter-spacing: 0.06em !important;
  text-transform: uppercase !important;
  color: var(--apple-text-tertiary) !important;
  padding: 0.6rem 1rem 0.3rem !important;
}

.nav-item-card {
  border-radius: 12px !important;
  padding: 0.55rem 0.85rem !important;
  font-size: 0.88rem !important;
  font-weight: 500 !important;
  color: var(--apple-text-secondary) !important;
  transition: var(--apple-transition-fast) !important;
  border: 1px solid transparent !important;
}

.nav-item-card:hover {
  background: rgba(0, 0, 0, 0.04) !important;
  color: var(--apple-text-primary) !important;
}

.nav-item-card.active {
  background: var(--apple-blue-tint) !important;
  color: #082850 !important;
  font-weight: 750 !important;
  border-left: 3.5px solid #00c5df !important;
}

[data-theme="dark"] .nav-item-card:hover {
  background: rgba(255, 255, 255, 0.06) !important;
}

[data-theme="dark"] .nav-item-card.active {
  background: var(--apple-blue-tint) !important;
  color: #00e5ff !important;
  border-left: 3.5px solid #00e5ff !important;
}

/* ==========================================================================
   4. APPLE FLOATING ISLAND BOTTOM DOCK (MOBILE)
   ========================================================================== */
.mobile-bottom-dock {
  background: rgba(255, 255, 255, 0.82) !important;
  backdrop-filter: blur(28px) saturate(190%) !important;
  -webkit-backdrop-filter: blur(28px) saturate(190%) !important;
  border: 1px solid var(--apple-border) !important;
  border-radius: 980px !important;
  box-shadow: var(--apple-shadow-float) !important;
  bottom: 16px !important;
  margin: 0 auto !important;
  max-width: calc(100% - 32px) !important;
  transition: var(--apple-transition-medium) !important;
}

[data-theme="dark"] .mobile-bottom-dock {
  background: rgba(28, 28, 30, 0.85) !important;
  border-color: var(--apple-border) !important;
}

.dock-item {
  color: var(--apple-text-tertiary) !important;
  transition: var(--apple-transition-fast) !important;
}

.dock-item.active {
  color: var(--apple-blue) !important;
  transform: scale(1.04) !important;
}

.mobile-fab {
  background: var(--apple-blue) !important;
  border-radius: 50% !important;
  box-shadow: 0 8px 24px rgba(0, 113, 227, 0.38) !important;
  transition: var(--apple-transition-fast) !important;
}

.mobile-fab:active {
  transform: scale(0.92) !important;
}

/* ==========================================================================
   5. UNIVERSAL APPLE BUTTONS & FORM CONTROLS
   ========================================================================== */
/* Primary Action Buttons */
.btn-primary,
.btn-apple-primary,
.btn-hub-create,
.btn-submit-hero,
#btn-quick-create-exam {
  background: var(--apple-blue) !important;
  color: #082850 !important;
  border: 1px solid rgba(8, 40, 80, 0.15) !important;
  border-radius: 980px !important;
  font-weight: 750 !important;
  font-size: 0.88rem !important;
  letter-spacing: -0.012em !important;
  padding: 0.55rem 1.15rem !important;
  box-shadow: 0 2px 10px rgba(0, 197, 223, 0.35) !important;
  transition: var(--apple-transition-fast) !important;
  cursor: pointer !important;
}

.btn-primary:hover,
.btn-apple-primary:hover,
.btn-hub-create:hover,
.btn-submit-hero:hover,
#btn-quick-create-exam:hover {
  background: var(--apple-blue-hover) !important;
  color: #082850 !important;
  box-shadow: 0 4px 18px rgba(0, 197, 223, 0.48) !important;
  transform: translateY(-1px) !important;
}

.btn-primary:active,
.btn-apple-primary:active,
.btn-hub-create:active,
.btn-submit-hero:active,
#btn-quick-create-exam:active {
  background: var(--apple-blue-active) !important;
  color: #ffffff !important;
  transform: scale(0.97) !important;
}

/* Secondary & Outline Buttons */
.btn-outline,
.btn-secondary {
  background: rgba(0, 0, 0, 0.04) !important;
  color: var(--apple-text-primary) !important;
  border: 1px solid var(--apple-border) !important;
  border-radius: 980px !important;
  font-weight: 500 !important;
  font-size: 0.85rem !important;
  letter-spacing: -0.01em !important;
  padding: 0.5rem 1rem !important;
  transition: var(--apple-transition-fast) !important;
}

.btn-outline:hover,
.btn-secondary:hover {
  background: rgba(0, 0, 0, 0.07) !important;
  border-color: var(--apple-border-hover) !important;
  transform: translateY(-0.5px) !important;
}

[data-theme="dark"] .btn-outline,
[data-theme="dark"] .btn-secondary {
  background: rgba(255, 255, 255, 0.08) !important;
  color: var(--apple-text-primary) !important;
  border-color: var(--apple-border) !important;
}

[data-theme="dark"] .btn-outline:hover,
[data-theme="dark"] .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14) !important;
}

/* Universal Apple Form Controls */
input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="date"],
input[type="search"],
select,
textarea {
  background: #ffffff !important;
  border: 1px solid var(--apple-border) !important;
  border-radius: 12px !important;
  color: var(--apple-text-primary) !important;
  font-family: var(--apple-font) !important;
  font-size: 0.9rem !important;
  padding: 0.55rem 0.85rem !important;
  transition: var(--apple-transition-fast) !important;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--apple-blue) !important;
  box-shadow: 0 0 0 4px var(--apple-blue-ring) !important;
  outline: none !important;
}

[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="search"],
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: #2c2c2e !important;
  border-color: var(--apple-border) !important;
}

/* Segmented Capsule Controls */
.bento-segmented-group,
.bento-view-switcher {
  background: rgba(0, 0, 0, 0.05) !important;
  border: 1px solid var(--apple-border-subtle) !important;
  border-radius: 980px !important;
  padding: 3px !important;
  display: inline-flex !important;
  gap: 2px !important;
}

[data-theme="dark"] .bento-segmented-group,
[data-theme="dark"] .bento-view-switcher {
  background: rgba(255, 255, 255, 0.08) !important;
  border-color: var(--apple-border) !important;
}

.bento-filter-pill,
.btn-bento-view {
  border-radius: 980px !important;
  padding: 0.35rem 0.85rem !important;
  font-size: 0.8rem !important;
  font-weight: 500 !important;
  color: var(--apple-text-secondary) !important;
  transition: var(--apple-transition-fast) !important;
}

.bento-filter-pill.active,
.hub-filter-pill.active,
.btn-bento-view.active {
  background: #ecfeff !important;
  border: 1px solid rgba(0, 197, 223, 0.45) !important;
  color: #082850 !important;
  font-weight: 750 !important;
  box-shadow: 0 1px 4px rgba(0, 197, 223, 0.18) !important;
}

[data-theme="dark"] .bento-filter-pill.active,
[data-theme="dark"] .btn-bento-view.active {
  background: #3a3a3c !important;
  color: #ffffff !important;
}

/* Universal Apple Badges & Pills */
.badge,
.badge-submitted,
.status-badge {
  border-radius: 980px !important;
  font-size: 0.74rem !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em !important;
  padding: 0.22rem 0.65rem !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 0.25rem !important;
}

/* Universal Apple Drag & Drop and Clipboard Ingestion States */
.apple-dropzone.drag-active,
.rubric-dropzone.drag-active,
.upload-field-card.drag-active,
.upload-dropzone-box.drag-active,
.scanned-thumbnails.drag-active,
.dropzone-modern.drag-active,
[data-upload-dropzone="true"].drag-active {
  border-color: var(--apple-blue, #00c5df) !important;
  background: var(--apple-blue-tint, rgba(0, 197, 223, 0.08)) !important;
  border-style: solid !important;
  box-shadow: 0 0 0 4px var(--apple-blue-ring, rgba(0, 197, 223, 0.25)) !important;
  transform: scale(1.012) !important;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

[data-theme="dark"] .apple-dropzone.drag-active,
[data-theme="dark"] .rubric-dropzone.drag-active,
[data-theme="dark"] .upload-field-card.drag-active,
[data-theme="dark"] .upload-dropzone-box.drag-active,
[data-theme="dark"] .scanned-thumbnails.drag-active,
[data-theme="dark"] .dropzone-modern.drag-active,
[data-theme="dark"] [data-upload-dropzone="true"].drag-active {
  border-color: #00e5ff !important;
  background: rgba(0, 229, 255, 0.14) !important;
  box-shadow: 0 0 0 4px rgba(0, 229, 255, 0.32) !important;
}

.upload-clipboard-cue {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--apple-blue, #00c5df);
  background: var(--apple-blue-tint, rgba(0, 197, 223, 0.08));
  border: 1px solid rgba(0, 197, 223, 0.25);
  border-radius: 980px;
  padding: 0.18rem 0.55rem;
  margin-top: 0.35rem;
  letter-spacing: -0.01em;
  user-select: none;
}

[data-theme="dark"] .upload-clipboard-cue {
  color: #2997ff;
  background: rgba(41, 151, 255, 0.15);
  border-color: rgba(41, 151, 255, 0.3);
}
