/* css/storage.css */

/* Header Styles are now in app.css (.cal-header) */

/* Masonry Layout */

/* Masonry Layout */
#storage-grid {
  column-gap: 1.5rem;
  row-gap: 2rem;
}

/* =========================================
   LIST VIEW REWRITE - STRICT ROW
   ========================================= */
#storage-files-grid.view-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

#storage-files-grid.view-list > div {
    width: 100%;
}

/* 1. THE ROW CONTAINER */
#storage-files-grid.view-list .file-card {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: nowrap !important; /* CRITICAL */
    gap: 1rem;
    padding: 0 1rem;
    height: 3.5rem; /* Fixed Height */
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--color-highlight);
    background: transparent;
    border-radius: 0;
    margin: 0;
    box-shadow: none;
}

#storage-files-grid.view-list .file-card:hover {
    background-color: var(--color-hover-bg) !important;
}

/* Fix: Ensure preview background is transparent so row hover shows through */
#storage-files-grid.view-list .file-card:hover .file-card-preview {
    background-color: transparent !important;
}

/* 2. ICON (Left) */
#storage-files-grid.view-list .file-card-preview {
    order: 1;
    width: 2.5rem;
    height: 2.5rem;
    min-width: 2.5rem;
    flex-shrink: 0;
    margin: 0;
    background: transparent !important;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
/* Hide grid-specific elements (Default: Hide IMG too) */
#storage-files-grid.view-list .file-card-preview img,
#storage-files-grid.view-list .file-card-preview > div:not(.list-icon),
#storage-files-grid.view-list .file-card-preview svg:not(.list-icon svg) { 
    display: none !important; 
}

/* Allow Images to show ONLY for actual Image files */
#storage-files-grid.view-list .type-image .file-card-preview img {
    display: block !important;
    width: 100%;
    height: 100%;
    object-fit: contain !important; /* Contain to prevent stretch */
    border-radius: 4px;
}

/* If Image exists (in Image Type), Hide List Icon */
#storage-files-grid.view-list .type-image .file-card-preview img ~ .list-icon {
    display: none !important;
}

/* Show List Icon defaults */
#storage-files-grid.view-list .list-icon {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

/* 3. INFO CONTAINER (Middle) -> MUST BE ROW */
#storage-files-grid.view-list .file-card-info {
    order: 2;
    flex: 1 1 auto; /* Grow to fill space */
    display: flex !important;
    flex-direction: row !important; /* Force Row */
    align-items: center !important;
    justify-content: space-between !important;
    min-width: 0; /* Enable text truncation inside */
    padding: 0;
    background: transparent !important; /* Explicitly Transparent */
    gap: 1rem;
    height: 100%; /* Match parent height */
}

/* 3a. TITLE SECTION (Left side of Info) */
#storage-files-grid.view-list .file-card-main {
    flex: 1 1 auto; /* Grow */
    display: flex !important;
    align-items: center;
    min-width: 0; /* Critical for truncation */
}

#storage-files-grid.view-list .file-card-title {
    font-size: 0.9rem;
    font-weight: 500;
    margin: 0;
    text-align: left !important; /* Force Left */
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
    width: auto;
}

#storage-files-grid.view-list .file-card-meta {
    display: none !important;
}

/* 3b. METADATA SECTION (Right side of Info) */
#storage-files-grid.view-list .file-list-meta {
    flex: 0 0 auto; /* Do not grow */
    display: flex !important;
    flex-direction: row !important; /* Force Row */
    align-items: center;
    gap: 2rem;
    margin-left: auto; /* Push to right just in case */
}

#storage-files-grid.view-list .fav-icon {
    display: flex !important;
}

#storage-files-grid.view-list .file-size {
    display: block !important;
    width: 80px;
    text-align: right;
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--color-secondary-text);
}

#storage-files-grid.view-list .file-date-list {
    display: block !important;
    width: 120px;
    text-align: right;
    font-size: 0.85rem;
    color: var(--color-secondary-text);
}

/* 4. DELETE BUTTON (Far Right) */
#storage-files-grid.view-list .delete-btn-hover {
    order: 3;
    position: static !important;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 0.5rem;
    opacity: 0;
}

#storage-files-grid.view-list .file-card:hover .delete-btn-hover {
    opacity: 1;
}

/* View Toggle Buttons */
.view-btn.active {
    background-color: var(--color-hover-bg);
  color: var(--color-primary-text);
}

.view-list-show {
  display: none;
}
#storage-grid.view-list .view-list-show {
  display: inline;
}

#storage-grid > div {
  break-inside: avoid;
}

/* Base Card Styles */
.storage-card {
  background-color: var(--color-panel-bg);
  border: 1px solid var(--color-highlight);
  border-radius: 1rem;
  overflow: hidden;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.storage-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
  border-color: var(--color-primary);
}

.dark .storage-card:hover {
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Image Card */
.storage-card.type-image img {
  width: 100%;
  height: auto;
  display: block;
}

/* Note Card */
.storage-card.type-note .card-content {
  padding: 1.25rem;
  font-size: 0.95rem;
  color: var(--color-primary-text);
  line-height: 1.6;
  max-height: 300px;
  overflow: hidden;
  position: relative;
  white-space: pre-wrap;
}

.storage-card.type-note .card-content::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 40px;
  background: linear-gradient(to bottom, transparent, var(--color-panel-bg));
  pointer-events: none;
}

/* Link Card */
.storage-card.type-link .card-content {
  /* Padding handled by utility class */
}

.storage-card.type-link .link-domain {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--color-accent);
  margin-top: 0.5rem;
}

/* List view adjustments for Link Card */
#storage-grid.view-list .link-preview {
  width: 48px !important;
  height: 48px !important;
  border-radius: 6px;
  margin-left: -0.5rem; /* align with padding */
}

/* Context Menu (Standardized) */
#storage-context-menu {
  width: 12rem; /* w-48 (192px) */
  min-width: 12rem;
  background: var(--color-panel-bg);
  border: 1px solid var(--color-highlight);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04); /* shadow-xl */
  border-radius: 0.75rem; /* rounded-xl */
  padding: 0.375rem; /* p-1.5 (6px) */
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 2px; /* mb-0.5 equivalent space between items */
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px; /* px-3 py-2 */
  font-size: 0.875rem; /* text-sm */
  font-weight: 400; /* font-normal */
  color: var(--color-primary-text);
  border-radius: 0.5rem; /* rounded-lg */
  cursor: pointer;
  transition: background-color 0.15s;
  text-align: left;
}

.ctx-item:hover {
  background: var(--color-highlight); /* hover:bg-highlight */
}

.ctx-item.delete {
  color: #ef4444; /* text-red-500 */
}

.ctx-item.delete:hover {
  background: rgba(239, 68, 68, 0.1); /* hover:bg-red-50 variant */
}

.ctx-separator {
  height: 1px;
  background: var(--color-highlight);
  margin: 4px 0; /* my-1 */
}

.color-row {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.color-row::-webkit-scrollbar {
  display: none;
}

.color-option {
  width: 20px; /* Standardize size */
  height: 20px;
  flex-shrink: 0;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.2s, border-color 0.2s;
}
.color-option:hover {
  transform: scale(1.15);
}
.color-option.active {
  border-color: var(--color-primary-text);
  transform: scale(1.1);
}

/* Footer Metadata */
.card-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--color-highlight);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--color-secondary-text);
  background-color: rgba(127, 127, 127, 0.05);
}

/* Filter Buttons */
.filter-btn.active {
  background-color: var(--color-primary);
  color: #fff;
  border-color: transparent;
}

.dark .filter-btn.active {
  background-color: #fff;
  color: #000;
}

/* Delete Button */
.delete-btn-hover {
  opacity: 0;
  transition: opacity 0.2s ease;
}
.storage-card:hover .delete-btn-hover {
  opacity: 1;
}

/* Progress Bar Animation */
@keyframes progress-pop {
  0% {
    transform: scaleY(1);
  }
  50% {
    transform: scaleY(1.3);
  }
  100% {
    transform: scaleY(1);
  }
}
.progress-updating {
  animation: progress-pop 0.3s ease;
}

/* Revealing Folder UI */
.folder-card {
  position: relative;
  width: 150px; /* Smaller fixed width */
  height: 120px; /* Fixed height */
  cursor: pointer;
  perspective: 1000px;
  margin: 0; /* Margins handled by updated flex container gap */
  flex-shrink: 0; /* Prevent shrinking in flex row */
}

/* Back Plate with Tab */
.folder-back-plate {
  position: absolute;
  inset: 10px 0 0 0;
  background-color: var(--folder-bg-back, #e0f2fe);
  border-top-left-radius: 0px;
  border-top-right-radius: 12px;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  transition: background-color 0.3s;
}
.folder-tab {
  position: absolute;
  top: -10px;
  left: 0;
  width: 60px; /* Smaller tab */
  height: 10px;
  background-color: var(--folder-bg-back, #e0f2fe);
  border-radius: 8px 8px 0 0;
  transition: background-color 0.3s;
}

/* Contents Container */
.folder-contents {
  position: absolute;
  inset: 10px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  overflow: visible;
  z-index: 5;
}

.file-preview {
  position: absolute;
  width: 65px; /* Smaller card */
  height: 85px;
  bottom: 15px;
  background: white;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);

  /* Fan Logic */
  --center: calc((var(--total) - 1) / 2);
  --offset: calc(var(--idx) - var(--center));

  transform: translateX(calc(var(--offset) * 14px)) /* Tighter spread */
    rotate(calc(var(--offset) * 8deg));
  transform-origin: bottom center;
  z-index: var(--idx);

  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* Ensure content stays in */
}

/* Hover Effect: Pop Up */
.folder-card:hover .file-preview {
  transform: translateX(calc(var(--offset) * 22px)) translateY(-35px)
    /* Smaller pop */ rotate(calc(var(--offset) * 12deg));
  box-shadow: 0 8px 12px -3px rgba(0, 0, 0, 0.15);
  z-index: calc(30 + var(--idx)); /* Pop above front plate */
}

.file-preview-icon {
  width: 100%;
  height: 60%;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #cbd5e1;
}
.file-preview-lines {
  width: 100%;
  height: 40%;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: white;
}
.line-1 {
  height: 3px;
  width: 70%;
  background: #e2e8f0;
  border-radius: 2px;
  margin: 0 auto;
}
.line-2 {
  height: 3px;
  width: 40%;
  background: #e2e8f0;
  border-radius: 2px;
  margin: 0 auto;
  opacity: 0.6;
}

/* Front Plate */
.folder-front-plate {
  position: absolute;
  inset: 40px 0 0 0; /* Cover bottom ~70% */
  background-color: var(--folder-bg-front, rgba(186, 230, 253, 0.3));
  border-radius: 12px;
  z-index: 20;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
  transition: all 0.3s;
  overflow: hidden;
}

.folder-card:hover .folder-front-plate {
  box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

/* Shine */
.folder-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.5),
    rgba(255, 255, 255, 0.1) 60%,
    transparent
  );
  pointer-events: none;
}

/* Folder Name on Front Plate */
.folder-name-label {
  position: absolute;
  bottom: 12px;
  left: 8px;
  right: 8px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.folder-name-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary-text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(4px);
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.dark .folder-name-text {
  background: rgba(30, 41, 59, 0.6);
  color: var(--color-primary-text);
}

/* Highlight Bar */
.folder-highlight-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background-color: var(--folder-highlight, #60a5fa);
  opacity: 0.5;
}

/* Label below folder */
.folder-label-container {
  position: absolute;
  bottom: -25px;
  left: -10px;
  right: -10px;
  text-align: center;
}
.folder-card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-primary-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.folder-card-meta {
  display: inline-block;
  font-size: 10px;
  font-weight: 500;
  color: var(--color-secondary-text);
  background: var(--color-highlight);
  padding: 3px 8px;
  border-radius: 8px;
  opacity: 0.8;
}

/* Unified File Card Design */
.file-card {
  position: relative;
  width: 100%;
  /* Removed max-width to utilization grid column space */
  background: var(--color-panel-bg);
  border: 1px solid var(--color-highlight);
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  break-inside: avoid;
  margin-bottom: 2rem; /* Consistent spacing */
}

/* Wide variant for landscape images (16:9, etc.) */
.file-card.wide {
  /* No specific width limit, fills column but maintains wide aspect logic */
}

.file-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.file-card-preview {
  width: 100%;
  min-height: 120px;
  max-height: 200px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-panel-bg);
}

/* Square cards - taller preview */
.file-card:not(.wide) .file-card-preview {
  max-height: 200px;
}

/* Wide cards - shorter preview for landscape */
.file-card.wide .file-card-preview {
  max-height: 140px;
}

.file-card-preview img {
  width: 100%;
  height: auto;
  max-height: 200px;
  object-fit: contain;
  object-position: center;
  display: block;
}

.file-card-info {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--color-panel-bg);
}

.file-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}

.file-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.file-type-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.file-date {
  font-size: 10px;
  color: var(--color-secondary-text);
  white-space: nowrap;
}

/* Staggered Entry Animation */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-card {
  animation: fadeInUp 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  opacity: 0; /* Start hidden */
}

/* Context Menu */
#storage-context-menu {
  flex-direction: column;
  min-width: 180px;
  padding: 6px;
  border: 1px solid var(--color-highlight);
  background-color: var(--color-panel-bg);
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-primary-text);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s;
}

.ctx-item:hover {
  background-color: var(--color-hover-bg, rgba(0, 0, 0, 0.05));
  color: var(--color-primary-text);
}
.dark .ctx-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.ctx-item svg {
  color: var(--color-secondary-text);
}

.ctx-item:hover svg {
  color: var(--color-primary-text);
}

.ctx-item.delete {
  color: #ef4444;
}
.ctx-item.delete svg {
  color: #ef4444;
}
.ctx-item.delete:hover {
  background-color: rgba(239, 68, 68, 0.1);
}

.ctx-separator {
  height: 1px;
  background-color: var(--color-highlight);
  margin: 4px 0;
}
