/* ==========================================================================
   Admin Dashboard: Apple HIG Liquid Glass & Precision Design System
   ========================================================================== */
:root {
  /* Apple Light Palette (Default Appearance) */
  --system-bg: #f5f5f7;
  --system-canvas: #ffffff;

  --liquid-glass-regular: rgba(255, 255, 255, 0.72);
  --liquid-glass-thin: rgba(255, 255, 255, 0.85);
  --liquid-glass-thick: rgba(255, 255, 255, 0.94);
  --liquid-control-bg: rgba(0, 0, 0, 0.04);
  --liquid-control-hover: rgba(0, 0, 0, 0.07);
  --liquid-control-active: rgba(0, 0, 0, 0.1);

  --liquid-border: rgba(255, 255, 255, 0.85);
  --liquid-border-outer: rgba(0, 0, 0, 0.06);

  --label-primary: #1d1d1f;
  --label-secondary: #6e6e73;
  --label-tertiary: #86868b;
  --separator: rgba(60, 60, 67, 0.12);

  --accent-tint: #0071e3;
  --accent-tint-hover: #0077ed;
  --accent-tint-subtle: rgba(0, 113, 227, 0.08);

  --system-green: #34c759;
  --system-red: #ff3b30;
  --system-orange: #ff9500;

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;

  --shadow-panel: 
    0 16px 36px -10px rgba(0, 0, 0, 0.06),
    0 0 0 1px rgba(0, 0, 0, 0.04),
    inset 0 1px 0.5px rgba(255, 255, 255, 0.95);

  --shadow-float: 
    0 10px 28px rgba(0, 0, 0, 0.07),
    0 0 0 1px rgba(0, 0, 0, 0.04),
    inset 0 1px 0.5px rgba(255, 255, 255, 0.9);

  --shadow-batch: 
    0 20px 48px rgba(0, 0, 0, 0.16),
    0 0 0 1px rgba(0, 0, 0, 0.08),
    inset 0 1px 0.5px rgba(255, 255, 255, 0.95);

  --trans-haptic: 0.15s cubic-bezier(0.2, 0, 0, 1);
  --trans-fluid: 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  --system-bg: #000000;
  --system-canvas: #1c1c1e;

  --liquid-glass-regular: rgba(30, 30, 32, 0.76);
  --liquid-glass-thin: rgba(44, 44, 46, 0.85);
  --liquid-glass-thick: rgba(58, 58, 60, 0.94);
  --liquid-control-bg: rgba(255, 255, 255, 0.06);
  --liquid-control-hover: rgba(255, 255, 255, 0.1);
  --liquid-control-active: rgba(255, 255, 255, 0.14);

  --liquid-border: rgba(255, 255, 255, 0.15);
  --liquid-border-outer: rgba(255, 255, 255, 0.06);

  --label-primary: #f5f5f7;
  --label-secondary: #a1a1a6;
  --label-tertiary: #6e6e73;
  --separator: rgba(255, 255, 255, 0.1);

  --accent-tint: #2997ff;
  --accent-tint-hover: #0077ed;
  --accent-tint-subtle: rgba(41, 151, 255, 0.12);

  --shadow-panel: 
    0 18px 42px -10px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.12),
    inset 0 1px 0.5px rgba(255, 255, 255, 0.2);

  --shadow-float: 
    0 12px 32px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.12),
    inset 0 1px 0.5px rgba(255, 255, 255, 0.2);

  --shadow-batch: 
    0 24px 54px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.18),
    inset 0 1px 0.5px rgba(255, 255, 255, 0.3);
}

/* ==========================================================================
   Base Structure & Atmosphere
   ========================================================================== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--label-primary);
  background-color: var(--system-bg);
  min-height: 100vh;
  line-height: 1.45;
  letter-spacing: -0.015em;
  -webkit-font-smoothing: antialiased;
}

#admin-backdrop {
  position: fixed;
  inset: 0;
  z-index: -3;
  overflow: hidden;
  background-color: var(--system-bg);
}
#admin-backdrop figure {
  position: absolute;
  inset: 0;
  margin: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 0.6s ease;
}
#admin-backdrop figure.active { opacity: 1; }

.admin-ambient-layer {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background: 
    radial-gradient(circle at 10% 10%, rgba(0, 113, 227, 0.035) 0%, transparent 45%),
    radial-gradient(circle at 90% 20%, rgba(52, 199, 89, 0.02) 0%, transparent 45%),
    radial-gradient(circle at 50% 90%, rgba(0, 0, 0, 0.02) 0%, transparent 50%);
}

.admin-frost-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  backdrop-filter: blur(45px) saturate(190%);
  -webkit-backdrop-filter: blur(45px) saturate(190%);
  background: rgba(245, 245, 247, 0.4);
}
[data-theme="dark"] .admin-frost-layer { background: rgba(0, 0, 0, 0.45); }

/* Master App Container */
.admin-viewport {
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 18px 36px;
  padding-bottom: max(36px, env(safe-area-inset-bottom));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Apple Liquid Glass Header
   ========================================================================== */
.admin-navbar {
  position: sticky;
  top: 12px;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  background: var(--liquid-glass-regular);
  backdrop-filter: blur(40px) saturate(190%);
  -webkit-backdrop-filter: blur(40px) saturate(190%);
  border: 1px solid var(--liquid-border);
  box-shadow: var(--shadow-float);
  margin-bottom: 16px;
  gap: 10px;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--label-primary);
  flex-shrink: 0;
}
.admin-brand-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  background: var(--label-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--system-bg);
  font-size: 13px;
}
.admin-brand-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

/* Search Input */
.admin-search-wrapper {
  flex: 1;
  max-width: 320px;
}
.admin-search-box {
  width: 100%;
  padding: 6px 10px 6px 30px;
  border-radius: var(--radius-xs);
  background: var(--liquid-control-bg);
  border: 1px solid var(--separator);
  color: var(--label-primary);
  font-size: 12px;
  outline: none;
  transition: border-color var(--trans-haptic);
}
.admin-search-box:focus { border-color: var(--accent-tint); }

/* Header Controls Cluster */
.admin-nav-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.admin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 10px;
  min-height: 30px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 600;
  color: var(--label-primary);
  background: var(--liquid-control-bg);
  border: 1px solid var(--separator);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--trans-haptic), transform var(--trans-haptic);
  white-space: nowrap;
}
.admin-btn:hover { background: var(--liquid-control-hover); transform: translateY(-0.5px); }
.admin-btn:active { background: var(--liquid-control-active); transform: translateY(0.5px); }
.admin-btn.primary {
  background: var(--accent-tint);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 6px rgba(0, 113, 227, 0.25);
}
.admin-btn.primary:hover { background: var(--accent-tint-hover); }
.admin-btn i { font-size: 12px; }

/* Stats Tag */
.stats-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  font-weight: 600;
  background: var(--liquid-control-bg);
  border: 1px solid var(--separator);
  color: var(--label-secondary);
}

/* ==========================================================================
   Content Grid & Masonry System
   ========================================================================== */
.admin-main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Grid View (Default) */
.media-grid-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  padding: 2px;
}

/* Masonry Waterfall View (100% Pure CSS - Absolutely No Overlap BUG) */
.media-masonry-view {
  column-count: 4;
  column-gap: 14px;
  padding: 2px;
}
.media-masonry-view .media-card {
  break-inside: avoid;
  margin-bottom: 14px;
  height: auto;
}
.media-masonry-view .media-thumb {
  height: auto;
  max-height: 400px;
  object-fit: cover;
}

/* Card Styling (Apple Liquid Regular Material) */
.media-card {
  position: relative;
  border-radius: var(--radius-sm);
  background: var(--liquid-glass-regular);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 1px solid var(--liquid-border);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform var(--trans-fluid), box-shadow var(--trans-fluid);
}
.media-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 36px -10px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--accent-tint);
}
.media-card.selected {
  border-color: var(--accent-tint);
  box-shadow: 0 0 0 2px var(--accent-tint);
}

.card-image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: rgba(0, 0, 0, 0.03);
  overflow: hidden;
  cursor: pointer;
}
.media-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}
.media-card:hover .media-thumb { transform: scale(1.03); }

/* Non-image placeholder */
.media-placeholder-box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--label-secondary);
  font-size: 13px;
  font-weight: 600;
}
.media-placeholder-box i { font-size: 32px; color: var(--accent-tint); }

/* Selection Checkbox Overlay */
.card-select-anchor {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
}
.card-select-anchor input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-tint);
  cursor: pointer;
}

/* Bookmark & Status Badges */
.card-status-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  display: flex;
  gap: 4px;
}
.status-pill-chip {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  backdrop-filter: blur(8px);
}
.status-pill-chip.block { background: var(--system-red); }
.status-pill-chip.white { background: var(--system-green); }

.bookmark-icon-btn {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.bookmark-icon-btn.liked { color: #ff9500; }

/* Card Meta & Action Bar */
.card-meta-bar {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--separator);
  background: var(--liquid-control-bg);
  gap: 6px;
}

.card-file-info {
  flex: 1;
  min-width: 0;
}
.card-filename-text {
  font-size: 11px;
  font-weight: 600;
  color: var(--label-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-filesize-text {
  font-size: 10px;
  color: var(--label-secondary);
}

.card-quick-actions {
  display: flex;
  align-items: center;
  gap: 3px;
}
.micro-action-btn {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--label-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
  transition: all var(--trans-haptic);
}
.micro-action-btn:hover {
  background: var(--liquid-control-hover);
  border-color: var(--separator);
  color: var(--label-primary);
}
.micro-action-btn.danger:hover { color: var(--system-red); }

/* ==========================================================================
   Modern Floating Batch Action Bar (Apple Liquid Float)
   ========================================================================== */
.floating-batch-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  background: var(--liquid-glass-thick);
  backdrop-filter: blur(40px) saturate(190%);
  -webkit-backdrop-filter: blur(40px) saturate(190%);
  border: 1px solid var(--liquid-border);
  box-shadow: var(--shadow-batch);
  transition: transform var(--trans-fluid);
  white-space: nowrap;
}
.floating-batch-bar.visible {
  transform: translateX(-50%) translateY(0);
}

.batch-tally-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--label-primary);
  margin-right: 4px;
}

/* ==========================================================================
   Pagination & Footer
   ========================================================================== */
.pagination-deck {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.admin-footer {
  margin-top: 32px;
  text-align: center;
  font-size: 12px;
  color: var(--label-tertiary);
}

/* ==========================================================================
   Mobile Responsive Rules (Complete Responsive Overhaul)
   ========================================================================== */
@media (max-width: 768px) {
  .admin-viewport {
    padding: 8px 10px 24px;
  }

  .admin-navbar {
    top: 8px;
    padding: 6px 8px;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
  }

  .admin-brand-title {
    font-size: 13px;
  }

  .admin-search-wrapper {
    order: 3;
    max-width: 100%;
    width: 100%;
  }
  .admin-search-box {
    padding: 5px 8px 5px 24px;
    font-size: 12px;
  }

  .admin-nav-actions {
    margin-left: auto;
    gap: 3px;
  }

  .admin-btn {
    padding: 4px 7px;
    font-size: 11px;
    min-height: 28px;
  }
  .admin-btn span {
    font-size: 11px;
  }

  .stats-badge {
    display: none; /* Hide in ultra tight header */
  }

  /* 2-Columns on Mobile */
  .media-grid-view {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
  }

  /* 2-Columns Masonry on Mobile */
  .media-masonry-view {
    column-count: 2;
    column-gap: 8px;
  }
  .media-masonry-view .media-card {
    margin-bottom: 8px;
  }

  .floating-batch-bar {
    bottom: max(16px, env(safe-area-inset-bottom));
    width: 94%;
    justify-content: space-between;
    padding: 6px 10px;
    gap: 4px;
  }
  .floating-batch-bar .admin-btn {
    padding: 4px 6px;
    font-size: 10px;
  }
}
