/* ==========================================================================
   DESKTOP — The Web Vault WebOS
   ==========================================================================
   Wallpaper, icon grid, rubber-band selection, and context menus.
   Depends on: tokens.css
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. WALLPAPER LAYER
   --------------------------------------------------------------------------
   Full-viewport background behind everything.  The wallpaper image is set
   via an inline style (or JS) on the <img> / <video> child; these rules
   simply ensure it covers the viewport.
   -------------------------------------------------------------------------- */
.os-wallpaper {
  position: fixed;
  inset: 0;
  z-index: var(--vault-z-wallpaper);
  overflow: hidden;

  /* Fallback gradient when no wallpaper image is loaded */
  background: var(--vault-bg-gradient);
}

.os-wallpaper img,
.os-wallpaper video {
  width:  100%;
  height: 100%;
  object-fit: cover;
  display: block;

  /* Prevent any visual artifacts during load */
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* Subtle vignette overlay for depth */
.os-wallpaper::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 50%,
    rgba(0, 0, 0, 0.35) 100%
  );
  pointer-events: none;
}


/* --------------------------------------------------------------------------
   2. DESKTOP ICON GRID
   --------------------------------------------------------------------------
   CSS Grid layout for desktop icons.  Each cell is sized to contain a
   48px icon + label underneath.  The grid auto-fills from top-left.
   -------------------------------------------------------------------------- */
.os-desktop-icons {
  position: fixed;
  top:    var(--vault-desktop-padding-top);
  left:   var(--vault-space-4);
  right:  var(--vault-space-4);
  bottom: var(--vault-desktop-padding-bottom);
  z-index: var(--vault-z-desktop-icons);

  display: grid;
  grid-template-columns: repeat(auto-fill, 90px);
  grid-template-rows:    repeat(auto-fill, 96px);
  grid-auto-flow: column;          /* Fill top-to-bottom, then wrap right */
  gap: var(--vault-space-2);
  align-content: start;
  justify-content: start;

  /* Prevent text selection when dragging on the desktop */
  user-select: none;
  -webkit-user-select: none;
}

/* --- Individual Icon ---------------------------------------------------- */
.os-desktop-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: var(--vault-space-1);
  padding: var(--vault-space-2);
  border-radius: var(--vault-radius-control);
  cursor: default;
  outline: none;

  /* Smooth selection / hover transitions */
  transition: background var(--vault-transition-fast),
              box-shadow var(--vault-transition-fast);
}

/* Icon image / SVG container */
.os-desktop-icon__image {
  width:  var(--vault-icon-desktop);
  height: var(--vault-icon-desktop);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  /* Make the icon pop slightly on hover */
  transition: transform var(--vault-transition-fast),
              filter   var(--vault-transition-fast);
}

.os-desktop-icon__image img,
.os-desktop-icon__image svg {
  width:  100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Label */
.os-desktop-icon__label {
  font-family: var(--vault-font-sans);
  font-size: var(--vault-text-xs);
  font-weight: var(--vault-weight-medium);
  color: var(--vault-text-primary);
  text-align: center;
  line-height: var(--vault-leading-tight);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;

  /* Truncate to 2 lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;

  /* Text shadow for readability over busy wallpapers */
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65),
               0 0   6px rgba(0, 0, 0, 0.35);
}

/* --- Hover -------------------------------------------------------------- */
.os-desktop-icon:hover {
  background: rgba(139, 92, 246, 0.10);
}

.os-desktop-icon:hover .os-desktop-icon__image {
  transform: scale(1.06);
  filter: brightness(1.08);
}

/* --- Selected ----------------------------------------------------------- */
.os-desktop-icon.is-selected {
  background: rgba(139, 92, 246, 0.22);
  box-shadow: inset 0 0 0 1.5px var(--vault-border-focused);
}

.os-desktop-icon.is-selected .os-desktop-icon__label {
  color: #ffffff;
}

/* --- Focused (keyboard navigation) -------------------------------------- */
.os-desktop-icon:focus-visible {
  outline: 2px solid var(--vault-accent-primary);
  outline-offset: 2px;
}

/* --- Rename mode -------------------------------------------------------- */
.os-desktop-icon.is-renaming .os-desktop-icon__label {
  display: none;
}

.os-desktop-icon__rename-input {
  font-family: var(--vault-font-sans);
  font-size: var(--vault-text-xs);
  font-weight: var(--vault-weight-medium);
  color: var(--vault-text-primary);
  background: var(--vault-surface-sunken);
  border: 1.5px solid var(--vault-border-focused);
  border-radius: var(--vault-radius-xs);
  padding: 1px 4px;
  text-align: center;
  width: 80px;
  outline: none;
}


/* --------------------------------------------------------------------------
   3. DRAG GHOST
   --------------------------------------------------------------------------
   Semi-transparent clone shown while dragging icons.
   -------------------------------------------------------------------------- */
.os-desktop-icon-ghost {
  position: fixed;
  pointer-events: none;
  opacity: 0.65;
  z-index: calc(var(--vault-z-desktop-icons) + 5);
  transform: scale(1.05);
  filter: brightness(1.12);
  transition: none;  /* No transition during drag — raw pointer tracking */
}


/* --------------------------------------------------------------------------
   4. RUBBER-BAND MARQUEE SELECTION
   --------------------------------------------------------------------------
   Drawn dynamically via JS with absolute positioning & transform.
   -------------------------------------------------------------------------- */
.os-selection-box {
  position: fixed;
  z-index: var(--vault-z-selection);
  background: rgba(139, 92, 246, 0.12);
  border: 1.5px solid rgba(139, 92, 246, 0.50);
  border-radius: 2px;
  pointer-events: none;

  /* Slight bloom for visual flair */
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.15);
}


/* --------------------------------------------------------------------------
   5. CONTEXT MENU (Right-Click)
   --------------------------------------------------------------------------
   Absolutely positioned popup.  JS sets top/left/transform.
   -------------------------------------------------------------------------- */
.os-context-menu {
  position: fixed;
  z-index: var(--vault-z-context-menu);
  min-width: 200px;
  max-width: 320px;
  padding: var(--vault-space-1_5) 0;

  background: var(--vault-surface-elevated);
  backdrop-filter: var(--vault-glass-blur);
  -webkit-backdrop-filter: var(--vault-glass-blur);
  border: 1px solid var(--vault-border-subtle);
  border-radius: var(--vault-radius-control);
  box-shadow: var(--vault-shadow-lg);

  font-family: var(--vault-font-sans);
  font-size: var(--vault-text-sm);
  color: var(--vault-text-primary);
  user-select: none;

  /* Entry animation */
  opacity: 0;
  transform: scale(0.95) translateY(-4px);
  transform-origin: top left;
  transition: opacity   var(--vault-transition-fast),
              transform var(--vault-transition-fast);
  pointer-events: none;
}

.os-context-menu.is-visible {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* --- Menu Item ---------------------------------------------------------- */
.os-context-menu__item {
  display: flex;
  align-items: center;
  gap: var(--vault-space-3);
  padding: var(--vault-space-1_5) var(--vault-space-4);
  cursor: default;
  transition: background var(--vault-transition-instant);
  border-radius: 0;
  min-height: 28px;
}

.os-context-menu__item:hover {
  background: var(--vault-accent-primary);
  color: var(--vault-text-on-accent);
}

.os-context-menu__item:hover .os-context-menu__shortcut {
  color: rgba(255, 255, 255, 0.70);
}

/* Disabled state */
.os-context-menu__item.is-disabled {
  opacity: 0.40;
  pointer-events: none;
}

/* Icon slot */
.os-context-menu__icon {
  width: var(--vault-icon-sm);
  height: var(--vault-icon-sm);
  flex-shrink: 0;
  opacity: 0.75;
}

.os-context-menu__item:hover .os-context-menu__icon {
  opacity: 1;
}

/* Label */
.os-context-menu__label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Keyboard shortcut hint */
.os-context-menu__shortcut {
  font-size: var(--vault-text-xs);
  color: var(--vault-text-muted);
  margin-left: auto;
  flex-shrink: 0;
}

/* Submenu arrow */
.os-context-menu__arrow {
  margin-left: auto;
  font-size: 10px;
  opacity: 0.50;
}

/* --- Separator ---------------------------------------------------------- */
.os-context-menu__separator {
  height: 1px;
  margin: var(--vault-space-1_5) var(--vault-space-3);
  background: var(--vault-border-subtle);
}

/* --- Section Header ----------------------------------------------------- */
.os-context-menu__header {
  padding: var(--vault-space-1) var(--vault-space-4);
  font-size: var(--vault-text-xs);
  font-weight: var(--vault-weight-semibold);
  color: var(--vault-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  pointer-events: none;
}


/* --------------------------------------------------------------------------
   6. DROP TARGET HIGHLIGHTS
   --------------------------------------------------------------------------
   When dragging files / icons onto a droppable area.
   -------------------------------------------------------------------------- */
.os-drop-target {
  outline: 2px dashed var(--vault-accent-primary);
  outline-offset: -2px;
  background: rgba(139, 92, 246, 0.08) !important;
  transition: outline var(--vault-transition-fast),
              background var(--vault-transition-fast);
}
