/* CloudDrive Preview v2 – Full-format preview with Apple/Huawei glass design */
/* v0.2.8 */

:root {
  --pv-bg: rgba(0,0,0,.94);
  --pv-glass: rgba(28,28,30,.78);
  --pv-glass-strong: rgba(44,44,46,.88);
  --pv-text: #f5f5f7;
  --pv-muted: #98989d;
  --pv-line: rgba(255,255,255,.1);
  --pv-line-strong: rgba(255,255,255,.18);
  --pv-accent: #0a84ff;
  --pv-accent-soft: rgba(10,132,255,.15);
  --pv-red: #ff453a;
  --pv-green: #30d158;
  --pv-radius: 14px;
  --pv-radius-sm: 10px;
  --pv-transition: .36s cubic-bezier(.22,1,.36,1);
  --pv-spring: .4s cubic-bezier(.34,1.56,.64,1);
}

[data-theme="light"] {
  --pv-bg: rgba(242,242,247,.96);
  --pv-glass: rgba(255,255,255,.72);
  --pv-glass-strong: rgba(255,255,255,.88);
  --pv-text: #1d1d1f;
  --pv-muted: #86868b;
  --pv-line: rgba(0,0,0,.1);
  --pv-line-strong: rgba(0,0,0,.16);
  --pv-accent: #007aff;
  --pv-accent-soft: rgba(0,122,255,.12);
  --pv-red: #ff3b30;
  --pv-green: #34c759;
}

/* === Preview Overlay Base === */
.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 140;
  background: var(--pv-bg);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity .28s ease, visibility 0s .28s;
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  backdrop-filter: saturate(180%) blur(30px);
}

.preview-overlay.show {
  opacity: 1;
  visibility: visible;
  transition: opacity .28s ease, visibility 0s 0s;
}

/* === Top Bar (glass) === */
.preview-top {
  height: 56px;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--pv-glass);
  border-bottom: 1px solid var(--pv-line);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  z-index: 2;
  flex-shrink: 0;
}

.preview-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--pv-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -.01em;
}

.preview-top .icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--pv-radius-sm);
  background: var(--pv-accent-soft);
  color: var(--pv-accent);
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .18s, transform .18s;
}

.preview-top .icon-btn:hover {
  background: rgba(10,132,255,.22);
  transform: scale(1.05);
}

.preview-top .icon-btn .icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

/* === Body === */
.preview-body {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  padding: 16px;
}

/* === Navigation Arrows === */
.preview-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--pv-glass-strong);
  border: 1px solid var(--pv-line);
  color: var(--pv-text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .18s, transform .18s, opacity .18s;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.preview-nav:hover {
  background: var(--pv-glass);
  transform: translateY(-50%) scale(1.08);
}

.preview-nav.left { left: 12px; }
.preview-nav.right { right: 12px; }

.preview-nav .icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
}

/* === Bottom Bar (glass) === */
.preview-bottom {
  height: 56px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--pv-glass);
  border-top: 1px solid var(--pv-line);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  z-index: 2;
  flex-shrink: 0;
}

.preview-bottom button {
  height: 36px;
  border-radius: var(--pv-radius-sm);
  padding: 0 16px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid var(--pv-line);
  cursor: pointer;
  transition: background .18s, transform .18s, border-color .18s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--pv-text);
  background: transparent;
}

.preview-bottom button:hover {
  background: var(--pv-accent-soft);
  border-color: var(--pv-accent);
  color: var(--pv-accent);
  transform: translateY(-1px);
}

.preview-bottom .danger-btn {
  color: var(--pv-red);
  border-color: rgba(255,69,58,.2);
}

.preview-bottom .danger-btn:hover {
  background: rgba(255,69,58,.12);
  border-color: var(--pv-red);
  color: var(--pv-red);
}

/* === Content Container === */
#previewContent {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  min-height: 0;
}

#previewContent img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,.2);
  user-select: none;
  -webkit-user-drag: none;
}

#previewContent video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,.35);
  outline: none;
}

#previewContent iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 12px;
  background: #fff;
}

/* === Audio Player === */
.pv-audio-card {
  width: min(420px, 90vw);
  padding: 28px 24px;
  border-radius: 20px;
  background: var(--pv-glass-strong);
  border: 1px solid var(--pv-line-strong);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  text-align: center;
  display: grid;
  gap: 16px;
}

.pv-audio-card .tile-icon {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  margin: 0 auto;
}

.pv-audio-card audio {
  width: 100%;
  height: 40px;
  border-radius: 10px;
}

.pv-audio-meta {
  font-size: 13px;
  color: var(--pv-muted);
  font-weight: 600;
}

/* === Audio Wave Animation === */
.pv-wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 40px;
}

.pv-wave span {
  width: 3px;
  border-radius: 2px;
  background: var(--pv-accent);
  animation: pv-wave 1.2s ease-in-out infinite;
}

.pv-wave span:nth-child(1) { animation-delay: 0s; height: 12px; }
.pv-wave span:nth-child(2) { animation-delay: .1s; height: 24px; }
.pv-wave span:nth-child(3) { animation-delay: .2s; height: 36px; }
.pv-wave span:nth-child(4) { animation-delay: .3s; height: 28px; }
.pv-wave span:nth-child(5) { animation-delay: .4s; height: 18px; }
.pv-wave span:nth-child(6) { animation-delay: .5s; height: 30px; }
.pv-wave span:nth-child(7) { animation-delay: .6s; height: 22px; }
.pv-wave span:nth-child(8) { animation-delay: .7s; height: 14px; }
.pv-wave span:nth-child(9) { animation-delay: .8s; height: 26px; }
.pv-wave span:nth-child(10) { animation-delay: .9s; height: 20px; }
.pv-wave span:nth-child(11) { animation-delay: 1s; height: 34px; }
.pv-wave span:nth-child(12) { animation-delay: 1.1s; height: 16px; }

@keyframes pv-wave {
  0%, 100% { transform: scaleY(.4); opacity: .5; }
  50% { transform: scaleY(1); opacity: 1; }
}

/* === Text / Code Viewer === */
.pv-text-viewer {
  width: 100%;
  height: 100%;
  max-width: 960px;
  background: var(--pv-glass-strong);
  border: 1px solid var(--pv-line);
  border-radius: var(--pv-radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.pv-text-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--pv-line);
  background: var(--pv-glass);
  font-size: 12px;
  color: var(--pv-muted);
  font-weight: 700;
  flex-shrink: 0;
}

.pv-text-header .copy-btn {
  height: 28px;
  border-radius: 6px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--pv-line);
  background: transparent;
  color: var(--pv-accent);
  cursor: pointer;
  transition: background .18s;
}

.pv-text-header .copy-btn:hover {
  background: var(--pv-accent-soft);
}

.pv-text-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
  font-family: 'SF Mono','Fira Code','Cascadia Code','JetBrains Mono',ui-monospace,Menlo,Consolas,monospace;
  font-size: 13px;
  line-height: 1.65;
  color: var(--pv-text);
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 4;
}

/* === Office / PDF Loader === */
.pv-iframe-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--pv-glass);
  border-radius: var(--pv-radius);
  z-index: 1;
  transition: opacity .3s;
}

.pv-iframe-loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.pv-iframe-loader .spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--pv-line-strong);
  border-top-color: var(--pv-accent);
  border-radius: 50%;
  animation: pv-spin .7s linear infinite;
}

@keyframes pv-spin {
  to { transform: rotate(360deg); }
}

/* === Fallback / Unsupported === */
.pv-fallback {
  text-align: center;
  display: grid;
  gap: 16px;
  justify-items: center;
  padding: 32px;
  color: var(--pv-text);
}

.pv-fallback .tile-icon {
  width: 80px;
  height: 80px;
  border-radius: 22px;
}

.pv-fallback h3 {
  font-size: 18px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -.01em;
}

.pv-fallback p {
  font-size: 13px;
  color: var(--pv-muted);
  margin: 0;
  line-height: 1.5;
}

.pv-fallback .btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.pv-fallback .primary-btn {
  height: 40px;
  border-radius: 10px;
  padding: 0 20px;
  font-size: 14px;
  font-weight: 800;
  background: var(--pv-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: transform .18s, box-shadow .18s;
  box-shadow: 0 4px 14px rgba(10,132,255,.35);
}

.pv-fallback .primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(10,132,255,.4);
}

.pv-fallback .ghost-btn {
  height: 40px;
  border-radius: 10px;
  padding: 0 20px;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid var(--pv-line-strong);
  background: transparent;
  color: var(--pv-text);
  cursor: pointer;
  transition: background .18s;
}

.pv-fallback .ghost-btn:hover {
  background: var(--pv-accent-soft);
  border-color: var(--pv-accent);
}

/* === Image Zoom States === */
#previewContent.zoomed img {
  max-width: none;
  max-height: none;
  cursor: grab;
}

#previewContent.zoomed img:active {
  cursor: grabbing;
}

/* === Swipe Transition === */
#previewContent.swipe-left {
  animation: pv-swipe-out-left .25s ease forwards;
}

#previewContent.swipe-right {
  animation: pv-swipe-out-right .25s ease forwards;
}

#previewContent.swipe-in {
  animation: pv-swipe-in .3s var(--pv-spring) forwards;
}

@keyframes pv-swipe-out-left {
  to { transform: translateX(-40px); opacity: 0; }
}

@keyframes pv-swipe-out-right {
  to { transform: translateX(40px); opacity: 0; }
}

@keyframes pv-swipe-in {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* === Editing Mode (photo editor) === */
.preview-overlay.editing .preview-top,
.preview-overlay.editing .preview-bottom {
  background: var(--pv-glass);
  opacity: .9;
}

.preview-overlay.editing .preview-nav {
  opacity: .36;
}

.preview-overlay.editing .preview-nav:hover {
  opacity: 1;
}

/* === Responsive === */
@media (max-width: 820px) {
  .preview-top {
    height: 52px;
    min-height: 52px;
    padding: 0 12px;
  }

  .preview-bottom {
    height: 52px;
    min-height: 52px;
    padding: 0 12px;
  }

  .preview-nav {
    width: 38px;
    height: 38px;
  }

  .preview-nav.left { left: 8px; }
  .preview-nav.right { right: 8px; }

  .preview-body {
    padding: 10px;
  }

  #previewContent video {
    border-radius: 8px;
  }

  .pv-audio-card {
    width: calc(100vw - 32px);
    padding: 20px 16px;
    border-radius: 16px;
  }

  .pv-text-viewer {
    border-radius: 12px;
  }
}

@media (max-width: 420px) {
  .preview-top {
    height: 48px;
    min-height: 48px;
  }

  .preview-name {
    font-size: 14px;
  }

  .preview-bottom {
    height: 48px;
    min-height: 48px;
    gap: 8px;
  }

  .preview-bottom button {
    font-size: 12px;
    padding: 0 12px;
    height: 32px;
  }

  .preview-nav {
    width: 34px;
    height: 34px;
  }
}

/* === Keyboard shortcut hint === */
.pv-shortcut-hint {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--pv-glass-strong);
  border: 1px solid var(--pv-line);
  font-size: 11px;
  color: var(--pv-muted);
  font-weight: 700;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.pv-shortcut-hint.show {
  opacity: 1;
}

.pv-shortcut-hint kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255,255,255,.12);
  font-family: inherit;
  font-size: 11px;
  margin: 0 2px;
}
