/* BioStudio AI — taskbar enhancements (js/core/taskbar-plus.js, taskbar-shelf.js).
 *
 * Look-and-feel rules are gated by html.fx-tb-* classes that
 * js/platform/visual-effects.js sets from Settings → Visual effects:
 *   fx-tb-float     floating glass Windows taskbar
 *   fx-tb-magnify   macOS Dock magnification
 *   fx-tb-adaptive  compact while a window is maximized, tint from the focused window
 *   fx-tb-motion    launch bounce, attention pulse, reorder animation
 * Live progress, attention rings, preview actions and the shelf are functional
 * and always present. The mobile shell is excluded from every visual rule.
 */

/* --- 17. Floating glass taskbar -----------------------------------------------
   The macOS Dock and every BioStudioAI / tone shell already float; this lifts
   the conventional Windows bar off the bottom edge. The desktop reserves the
   extra gap so maximized and snapped windows stay clear of it. */
html.fx-tb-float #os.theme-windows:not(.shell-mobile) {
  --taskbar-clearance: calc(var(--taskbar-h) + 10px);
}

html.fx-tb-float #os.theme-windows:not(.shell-mobile) .taskbar:not(.dock):not(.bs-dock) {
  left: 10px;
  right: 10px;
  bottom: 8px;
  border: 1px solid var(--taskbar-border);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

html.fx-tb-float #os.theme-windows.taskbar-autohide:not(.taskbar-revealed):not(.shell-mobile) .taskbar:not(.dock):not(.bs-dock):not(:hover):not(:focus-within) {
  transform: translateY(calc(100% + 4px));
}

/* --- 19. Adaptive taskbar --------------------------------------------------------
   Visual only: the bar keeps its height, so no window resizes when it compacts. */
html.fx-tb-adaptive #os:not(.shell-mobile) .taskbar .task-btn-icon,
html.fx-tb-adaptive #os:not(.shell-mobile) .taskbar .taskbar-start > .icon {
  transition: transform 0.2s ease;
}

html.fx-tb-adaptive #os:not(.shell-mobile) .taskbar.tb-compact:not(:hover):not(:focus-within) .task-btn-icon,
html.fx-tb-adaptive #os:not(.shell-mobile) .taskbar.tb-compact:not(:hover):not(:focus-within) .taskbar-start > .icon {
  transform: scale(0.86);
}

/* Windows bar: a faint wash of the focused window's accent. Docks keep their
   own backgrounds; they get the accent on the active indicator only. */
html.fx-tb-adaptive #os.theme-windows:not(.shell-mobile) .taskbar.tb-tinted:not(.dock):not(.bs-dock) {
  background-image: linear-gradient(90deg, transparent 10%, color-mix(in srgb, var(--tb-follow-accent) 12%, transparent) 50%, transparent 90%);
}

html.fx-tb-adaptive #os:not(.shell-mobile) .taskbar.tb-tinted .task-btn.active .task-btn-indicator {
  background: var(--tb-follow-accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--tb-follow-accent) 70%, transparent);
}

/* --- 18. macOS Dock magnification -------------------------------------------- */
html.fx-tb-magnify #os.theme-macos:not(.shell-mobile) .taskbar.dock :is(.task-btn, .taskbar-start) {
  transform: translateY(calc((var(--tb-mag, 1) - 1) * -12px)) scale(var(--tb-mag, 1));
  transform-origin: 50% 100%;
  margin-inline: calc((var(--tb-mag, 1) - 1) * 14px);
  transition: transform 0.12s ease-out, margin 0.12s ease-out;
}

/* --- 20. Micro-animations -------------------------------------------------------- */
@keyframes tb-launch-bounce {
  0%, 100% { transform: translateY(0); }
  22% { transform: translateY(-11px); }
  44% { transform: translateY(0); }
  64% { transform: translateY(-5px); }
  82% { transform: translateY(0); }
}

html.fx-tb-motion #os:not(.shell-mobile) .task-btn.tb-launch .task-btn-icon {
  animation: tb-launch-bounce 0.9s cubic-bezier(0.3, 0.7, 0.4, 1) 1;
}

.tb-attention-ring {
  position: absolute;
  inset: 2px;
  z-index: 2;
  border-radius: inherit;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #2f6bff) 75%, transparent);
  pointer-events: none;
}

@keyframes tb-attention-pulse {
  0%, 100% { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #2f6bff) 75%, transparent), 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 0 2px var(--accent, #2f6bff), 0 0 16px 4px color-mix(in srgb, var(--accent, #2f6bff) 45%, transparent); }
}

html.fx-tb-motion #os:not(.shell-mobile) .tb-attention-ring {
  animation: tb-attention-pulse 1.6s ease-in-out infinite;
}

.taskbar .task-btn.tb-dragging {
  z-index: 4;
  cursor: grabbing;
  opacity: 0.92;
  transition: none !important;
}

/* --- 1. Live progress on app buttons ------------------------------------------ */
.tb-progress {
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 1px;
  z-index: 3;
  height: 3px;
  overflow: hidden;
  border-radius: 3px;
  background: color-mix(in srgb, var(--ink, #64748b) 20%, transparent);
  pointer-events: none;
}

.tb-progress-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-radius: inherit;
  background: var(--tb-follow-accent, var(--accent, #2f6bff));
  transition: width 0.25s ease;
}

@keyframes tb-progress-slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(260%); }
}

.task-btn.tb-indeterminate .tb-progress-fill {
  width: 40%;
  animation: tb-progress-slide 1.1s ease-in-out infinite;
}

.task-btn.tb-error .tb-progress-fill {
  width: 100%;
  background: #ef4444;
}

.tb-progress.tb-progress-done .tb-progress-fill {
  width: 100%;
  background: #22c55e;
  animation: none;
}

#os .task-btn.tb-busy .task-btn-indicator {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .task-btn.tb-indeterminate .tb-progress-fill {
    width: 100%;
    opacity: 0.6;
    animation: none;
  }
}

/* --- 4. Preview actions --------------------------------------------------------- */
.tb-thumb-wrap { position: relative; }

.tb-preview-actions {
  position: absolute;
  left: 50%;
  bottom: 6px;
  z-index: 2;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 9px;
  background: var(--menu-bg, rgba(245, 246, 250, 0.94));
  border: 1px solid var(--menu-border, rgba(0, 0, 0, 0.08));
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translate(-50%, 4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.tb-preview:hover .tb-preview-actions,
.tb-preview:focus-within .tb-preview-actions {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tb-preview-action {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--ink-soft, #64748b);
  font-size: 13px;
  line-height: 1;
}

.tb-preview-action:hover {
  background: var(--tb-hover, rgba(0, 0, 0, 0.06));
  color: var(--ink, #111827);
}

.tb-preview-glyph,
.tb-preview-glyph svg {
  display: grid;
  width: 13px;
  height: 13px;
}

.tb-preview.is-minimized .tb-thumb {
  opacity: 0.55;
}

/* --- 22. Clipboard & screenshot shelf -------------------------------------------- */
.tray-shelf-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(30px, calc(36px * var(--shell-scale)), 38px);
  height: clamp(30px, calc(36px * var(--shell-scale)), 38px);
  border-radius: clamp(6px, calc(7px * var(--shell-scale)), 8px);
  color: var(--ink);
}

.tray-shelf-btn:hover { background: var(--tb-hover); }
.tray-shelf-btn .icon { width: 17px; height: 17px; }

.tray-shelf-btn.tb-shelf-new,
.mac-shelf.tb-shelf-new {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent, #2f6bff) 60%, transparent);
}

.tb-shelf {
  position: fixed;
  z-index: 9750;
  width: min(360px, calc(100vw - 24px));
  max-height: min(70vh, 560px);
  overflow: auto;
  padding: 12px;
  border-radius: 14px;
  color: var(--ink, #111827);
  background: var(--menu-bg, rgba(245, 246, 250, 0.96));
  border: 1px solid var(--menu-border, rgba(0, 0, 0, 0.08));
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(min(30px, var(--bs-max-blur, 30px))) saturate(1.4);
  -webkit-backdrop-filter: blur(min(30px, var(--bs-max-blur, 30px))) saturate(1.4);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.tb-shelf.show { opacity: 1; transform: none; }

.tb-shelf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 2px 2px 4px;
  font-size: 13px;
  font-weight: 700;
}

.tb-shelf-sub { font-size: 11px; font-weight: 500; color: var(--ink-soft, #64748b); }

.tb-shelf-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 2px 6px;
}

.tb-shelf-section-head h4 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft, #64748b);
}

.tb-shelf-link {
  padding: 2px 4px;
  border-radius: 5px;
  font-size: 12px;
  color: var(--accent, #2f6bff);
  background: none;
}

.tb-shelf-link:hover { background: var(--tb-hover, rgba(0, 0, 0, 0.06)); }

.tb-shelf-snips {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.tb-shelf-snip {
  aspect-ratio: 4 / 3;
  padding: 0;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--menu-border, rgba(0, 0, 0, 0.1));
  background: rgba(0, 0, 0, 0.06);
  cursor: grab;
}

.tb-shelf-snip img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.tb-shelf-snip:hover { outline: 2px solid color-mix(in srgb, var(--accent, #2f6bff) 60%, transparent); }

.tb-shelf-clips { display: flex; flex-direction: column; gap: 2px; }

.tb-shelf-clip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border-radius: 8px;
  color: inherit;
  background: transparent;
  font-size: 12.5px;
  text-align: left;
  cursor: grab;
}

.tb-shelf-clip:hover { background: var(--tb-hover, rgba(0, 0, 0, 0.06)); }

.tb-shelf-clip-kind {
  flex: none;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10.5px;
  color: var(--ink-soft, #64748b);
  background: color-mix(in srgb, var(--accent, #2f6bff) 14%, transparent);
}

.tb-shelf-clip-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tb-shelf-clip-time { flex: none; font-size: 11px; color: var(--ink-soft, #64748b); }

.tb-shelf-empty {
  grid-column: 1 / -1;
  padding: 6px 2px;
  font-size: 12px;
  color: var(--ink-soft, #64748b);
}

#os.shell-mobile .tray-shelf-btn { display: none; }
