/* ==========================================================================
   Apple Design System for FileBrowser
   Authored strictly adhering to Emil Kowalski's Apple Design Guidelines:
   - Materials & Depth: Translucent glass layers, specular top highlights, blur & saturate.
   - Optical Typography: SF Pro system stack, negative tracking on display headings.
   - Direct Response: Instant pointer-down active states (scale 0.97, <100ms response).
   - Apple Color Palette: macOS Sequoia / iOS 18 system tints & tokens.
   - Accessibility: Complete prefers-reduced-motion & prefers-reduced-transparency.
   ========================================================================== */

/* --- 1. Typography & Core Design Tokens --- */
:root {
  --apple-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "SF Pro", -system-ui, sans-serif;
  --apple-mono: "SF Mono", Menlo, Monaco, Consolas, monospace;
  
  /* Apple System Colors */
  --apple-blue: #0071e3;
  --apple-blue-hover: #0077ed;
  --apple-blue-active: #0062cc;
  --apple-blue-glow: rgba(0, 113, 227, 0.35);
  --apple-red: #ff3b30;
  --apple-green: #34c759;
  --apple-amber: #ff9500;
  
  /* Light Theme Surface Materials */
  --apple-bg: #f5f5f7;
  --apple-surface: rgba(255, 255, 255, 0.72);
  --apple-surface-card: rgba(255, 255, 255, 0.82);
  --apple-surface-hover: rgba(0, 0, 0, 0.04);
  --apple-surface-active: rgba(0, 0, 0, 0.08);
  --apple-border: rgba(0, 0, 0, 0.08);
  --apple-border-top-specular: rgba(255, 255, 255, 0.65);
  --apple-shadow: 0 12px 32px -4px rgba(0, 0, 0, 0.08), 0 4px 12px -2px rgba(0, 0, 0, 0.04);
  --apple-text: #1d1d1f;
  --apple-text-secondary: #86868b;
  
  /* Overrides for Filebrowser native vars */
  --blue: var(--apple-blue);
  --dark-blue: var(--apple-blue-active);
}

:root.dark, [data-theme="dark"] {
  /* Dark Theme Surface Materials */
  --apple-bg: #000000;
  --apple-surface: rgba(28, 28, 30, 0.75);
  --apple-surface-card: rgba(36, 36, 38, 0.78);
  --apple-surface-hover: rgba(255, 255, 255, 0.06);
  --apple-surface-active: rgba(255, 255, 255, 0.10);
  --apple-border: rgba(255, 255, 255, 0.12);
  --apple-border-top-specular: rgba(255, 255, 255, 0.25);
  --apple-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  --apple-text: #f5f5f7;
  --apple-text-secondary: #a1a1a6;
  
  --background: #000000;
  --surfacePrimary: #1c1c1e;
  --surfaceSecondary: #2c2c2e;
}

/* Global Font Smoothing & Typography Hierarchy */
body, html, input, button, select, textarea {
  font-family: var(--apple-font) !important;
  -webkit-font-smoothing: antialiased !important;
  -moz-osx-font-smoothing: grayscale !important;
}

/* --- 2. Apple macOS Glassmorphism Login Screen --- */
#login {
  background: radial-gradient(circle at 50% 20%, #1e2638 0%, #0d111a 60%, #05070c 100%) !important;
  width: 100vw !important;
  height: 100vh !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  z-index: 1000 !important;
  overflow: hidden !important;
}

/* Ambient dynamic glow under the floating glass panel */
#login::before {
  content: '' !important;
  position: absolute !important;
  width: 500px !important;
  height: 500px !important;
  background: radial-gradient(circle, rgba(0, 113, 227, 0.22) 0%, rgba(13, 17, 26, 0) 70%) !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  pointer-events: none !important;
  z-index: 0 !important;
}

#login form {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  transform: none !important;
  width: 90% !important;
  max-width: 360px !important;
  padding: 44px 34px !important;
  background: rgba(30, 30, 35, 0.65) !important;
  backdrop-filter: blur(40px) saturate(190%) !important;
  -webkit-backdrop-filter: blur(40px) saturate(190%) !important;
  border-top: 1px solid rgba(255, 255, 255, 0.35) !important; /* Top edge specular highlight */
  border-left: 1px solid rgba(255, 255, 255, 0.12) !important;
  border-right: 1px solid rgba(255, 255, 255, 0.12) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-radius: 28px !important;
  box-shadow: 0 35px 70px -15px rgba(0, 0, 0, 0.65), 0 0 1px 1px rgba(255, 255, 255, 0.05) inset !important;
  z-index: 1 !important;
  box-sizing: border-box !important;
}

/* App Icon / Logo */
#login img {
  width: 76px !important;
  height: 76px !important;
  margin: 0 auto 18px !important;
  display: block !important;
  border-radius: 20px !important;
  filter: drop-shadow(0 12px 24px rgba(0, 113, 227, 0.35)) !important;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

#login img:hover {
  transform: scale(1.04) translateY(-2px) !important;
}

/* Heading: Optical sizing negative tracking for large display text */
#login h1 {
  font-size: 1.55rem !important;
  font-weight: 600 !important;
  letter-spacing: -0.025em !important;
  line-height: 1.15 !important;
  color: #ffffff !important;
  margin: 0 0 26px 0 !important;
  text-align: center !important;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3) !important;
}

/* Input Fields */
#login input[type="text"],
#login input[type="password"] {
  width: 100% !important;
  background: rgba(15, 15, 18, 0.5) !important;
  border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
  border-left: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-right: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
  border-radius: 14px !important;
  padding: 14px 16px !important;
  font-size: 15px !important;
  color: #ffffff !important;
  margin-bottom: 14px !important;
  outline: none !important;
  box-sizing: border-box !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease !important;
}

#login input[type="text"]::placeholder,
#login input[type="password"]::placeholder {
  color: rgba(255, 255, 255, 0.42) !important;
  font-weight: 400 !important;
}

#login input[type="text"]:focus,
#login input[type="password"]:focus {
  background: rgba(20, 20, 26, 0.7) !important;
  border-color: #0071e3 !important;
  box-shadow: 0 0 0 3.5px rgba(0, 113, 227, 0.35) !important;
}

/* Primary Button: Emil Kowalski Pointer-Down Rule (instant scale on :active) */
#login input[type="submit"] {
  width: 100% !important;
  background: linear-gradient(180deg, #0077ed 0%, #0062cc 100%) !important;
  border: 1px solid rgba(255, 255, 255, 0.28) !important;
  border-radius: 14px !important;
  color: #ffffff !important;
  font-size: 15px !important;
  font-weight: 500 !important;
  letter-spacing: -0.01em !important;
  padding: 13px !important;
  margin-top: 10px !important;
  cursor: pointer !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 8px 20px -4px rgba(0, 113, 227, 0.45) !important;
  transition: transform 0.1s ease, box-shadow 0.15s ease !important;
}

#login input[type="submit"]:hover {
  background: linear-gradient(180deg, #1b85f8 0%, #006ee6 100%) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 10px 24px -2px rgba(0, 113, 227, 0.55) !important;
}

#login input[type="submit"]:active {
  transform: scale(0.97) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1) inset, 0 4px 10px rgba(0, 113, 227, 0.3) !important;
  transition: transform 80ms cubic-bezier(0.25, 1, 0.5, 1) !important;
}

/* Feedback & Alerts */
#login .wrong,
#login .logout-message {
  border-radius: 14px !important;
  font-size: 13.5px !important;
  font-weight: 500 !important;
  padding: 12px 16px !important;
  margin-bottom: 16px !important;
  backdrop-filter: blur(15px) !important;
  -webkit-backdrop-filter: blur(15px) !important;
  text-align: center !important;
}

#login .wrong {
  background: rgba(255, 59, 48, 0.22) !important;
  border: 1px solid rgba(255, 59, 48, 0.45) !important;
  color: #ffb4ab !important;
}

#login .logout-message {
  background: rgba(255, 149, 0, 0.22) !important;
  border: 1px solid rgba(255, 149, 0, 0.45) !important;
  color: #ffdcb2 !important;
}

/* --- 3. Apple Translucent Chrome & Navigation --- */
header {
  backdrop-filter: blur(25px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(25px) saturate(180%) !important;
  background: rgba(255, 255, 255, 0.8) !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08) !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02) !important;
}

:root.dark header {
  background: rgba(28, 28, 30, 0.8) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

/* Breadcrumbs Optical Typography */
.breadcrumbs {
  font-size: 14px !important;
  font-weight: 500 !important;
  letter-spacing: -0.005em !important;
}

.breadcrumbs a {
  color: var(--apple-text-secondary) !important;
  text-decoration: none !important;
  border-radius: 6px !important;
  padding: 4px 6px !important;
  transition: background 0.15s ease, color 0.15s ease !important;
}

.breadcrumbs a:hover {
  background: var(--apple-surface-hover) !important;
  color: var(--apple-blue) !important;
}

/* Action Buttons (Top Bar & Floating) */
.action, header .action {
  border-radius: 10px !important;
  transition: transform 0.1s ease, background 0.15s ease, color 0.15s ease !important;
}

.action:hover, header .action:hover {
  background: var(--apple-surface-hover) !important;
}

/* Pointer-down tactile feedback */
.action:active, header .action:active {
  transform: scale(0.92) !important;
  background: var(--apple-surface-active) !important;
  transition: transform 80ms cubic-bezier(0.25, 1, 0.5, 1) !important;
}

/* --- 4. File Items & Directory Listing --- */
#listing .item {
  border-radius: 14px !important;
  border: 1px solid transparent !important;
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), background 0.15s ease, box-shadow 0.15s ease !important;
}

#listing .item:hover {
  background: var(--apple-surface-hover) !important;
  transform: translateY(-1px) !important;
}

/* Touch / Pointer-down feedback */
#listing .item:active {
  transform: scale(0.985) !important;
  background: var(--apple-surface-active) !important;
  transition: transform 80ms cubic-bezier(0.25, 1, 0.5, 1) !important;
}

#listing.list .item[aria-selected="true"],
#listing.mosaic .item[aria-selected="true"] {
  background: rgba(0, 113, 227, 0.12) !important;
  border-color: rgba(0, 113, 227, 0.3) !important;
}

/* --- 5. Floating Modals & Sheets (Apple macOS Popover style) --- */
.card.floating {
  background: var(--apple-surface-card) !important;
  backdrop-filter: blur(35px) saturate(190%) !important;
  -webkit-backdrop-filter: blur(35px) saturate(190%) !important;
  border-radius: 22px !important;
  border-top: 1px solid var(--apple-border-top-specular) !important;
  border-left: 1px solid var(--apple-border) !important;
  border-right: 1px solid var(--apple-border) !important;
  border-bottom: 1px solid var(--apple-border) !important;
  box-shadow: var(--apple-shadow) !important;
}

.card .card-title {
  font-weight: 600 !important;
  letter-spacing: -0.015em !important;
}

/* Buttons inside Modals */
.button {
  border-radius: 12px !important;
  font-weight: 500 !important;
  letter-spacing: -0.005em !important;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease !important;
}

.button:active {
  transform: scale(0.97) !important;
  transition: transform 80ms cubic-bezier(0.25, 1, 0.5, 1) !important;
}

.button--blue {
  background: linear-gradient(180deg, #0077ed 0%, #0062cc 100%) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 4px 12px rgba(0, 113, 227, 0.35) !important;
}

.button--red {
  background: linear-gradient(180deg, #ff453a 0%, #d70015 100%) !important;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 4px 12px rgba(255, 69, 58, 0.35) !important;
}

/* --- 6. Accessibility Overrides (Rule 14 in Emil Kowalski Guidelines) --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 150ms !important;
    transform: none !important;
  }
  
  #login input[type="submit"]:active,
  .button:active,
  .action:active,
  #listing .item:active {
    transform: none !important;
    opacity: 0.8 !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  #login form,
  header,
  .card.floating {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: #1c1c1e !important;
  }
}
