/* ========================================
   GifWall - Theme System
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Dark theme (default) */
  --bg-primary: #050505;
  --bg-secondary: #0e0e0e;
  --bg-card: #141414;
  --bg-card-hover: #1a1a1a;
  --bg-overlay: rgba(0, 0, 0, 0.85);
  --bg-input: #1a1a1a;
  --bg-input-focus: #1e1e1e;

  --border: #1e1e1e;
  --border-subtle: #161616;
  --border-hover: #2a2a2a;
  --border-focus: #6366f1;

  --text-primary: #f0f0f0;
  --text-secondary: #888;
  --text-muted: #555;
  --text-inverse: #0a0a0a;

  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --accent-glow: rgba(99, 102, 241, 0.25);

  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 30px var(--accent-glow);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  --grid-gap: 10px;
  --header-height: 64px;
}

[data-theme="light"] {
  --bg-primary: #f5f5f0;
  --bg-secondary: #eeeee8;
  --bg-card: #ffffff;
  --bg-card-hover: #fafaf8;
  --bg-overlay: rgba(255, 255, 255, 0.9);
  --bg-input: #ffffff;
  --bg-input-focus: #ffffff;

  --border: #e0ddd5;
  --border-subtle: #e8e5dd;
  --border-hover: #ccc8be;
  --border-focus: #6366f1;

  --text-primary: #1a1a18;
  --text-secondary: #6b6860;
  --text-muted: #9e9a90;
  --text-inverse: #ffffff;

  --accent: #5b5ef0;
  --accent-hover: #4f52e8;
  --accent-soft: rgba(91, 94, 240, 0.08);
  --accent-glow: rgba(91, 94, 240, 0.15);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.1);
  --shadow-glow: 0 0 20px var(--accent-glow);
}

/* ========================================
   Reset & Base
   ======================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--transition-base), color var(--transition-base);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ========================================
   Layout
   ======================================== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.app-header .logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  flex-shrink: 0;
}

.app-header .logo span {
  opacity: 0.5;
  font-weight: 400;
  font-size: 0.85rem;
}

.version-badge {
  font-size: 0.65rem !important;
  font-weight: 500 !important;
  opacity: 0.35 !important;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0;
}

/* Search bar */
.search-container {
  flex: 1;
  max-width: 480px;
  position: relative;
}

.search-container input {
  width: 100%;
  height: 40px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0 16px 0 40px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--text-primary);
  transition: all var(--transition-fast);
  outline: none;
}

.search-container input:focus {
  border-color: var(--border-focus);
  background: var(--bg-input-focus);
  box-shadow: var(--shadow-glow);
}

.search-container input::placeholder { color: var(--text-muted); }

.search-container .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  flex-wrap: wrap;
  position: relative;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  pointer-events: auto;
}

.size-slider-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.size-slider-wrap input[type="range"] {
  -webkit-appearance: none;
  width: 100px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.size-slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s;
}

.size-slider-wrap input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.3);
}

.size-slider-wrap input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}

/* Tag filters */
.tag-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.tag-chip:hover,
.tag-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.tag-chip .count {
  font-size: 0.7rem;
  opacity: 0.5;
}

.tag-suggestions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.tag-suggestions-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 100%;
  margin-bottom: 2px;
}

.tag-chip.suggestion {
  font-size: 0.75rem;
  padding: 3px 10px;
  opacity: 0.7;
  border-style: dashed;
}

.tag-chip.suggestion:hover {
  opacity: 1;
}

.tag-chip.suggestion.selected {
  opacity: 0.4;
  border-style: solid;
  background: var(--accent-soft);
}

/* Storage indicator */
.storage-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.storage-bar-track {
  width: 120px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.storage-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width var(--transition-slow);
}

.storage-bar-fill.warning { background: var(--warning); }
.storage-bar-fill.danger { background: var(--danger); }

/* ========================================
   Masonry Grid
   ======================================== */

.gif-grid {
  padding: 0 24px 24px;
  position: relative;
}

.gif-grid-inner {
  position: relative;
  width: 100%;
}

.gif-item {
  position: absolute;
  overflow: hidden;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform var(--transition-slow), box-shadow var(--transition-slow), z-index 0ms;
  will-change: transform;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
}

.gif-item:hover {
  transform: scale(1.05);
  z-index: 10;
  box-shadow: var(--shadow-lg);
  border-color: var(--border-hover);
}

.gif-item img,
.gif-item video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Hover video for video items */
.hover-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.hover-video.active {
  opacity: 1;
}

/* GIF overlay actions */
.gif-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 40px 6px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
  z-index: 10;
}

.gif-item:hover .gif-overlay {
  opacity: 1;
  pointer-events: auto;
}

.gif-overlay-left {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.gif-overlay-right {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.gif-action-btn {
  min-width: 28px;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  backdrop-filter: blur(4px);
  flex-shrink: 0;
}

.gif-action-btn:hover {
  background: rgba(255,255,255,0.3);
}

.gif-action-btn.whatsapp:hover {
  background: #25D366;
}

.gif-action-btn.share:hover {
  background: var(--accent);
}

.gif-action-btn.delete:hover {
  background: var(--danger);
}

.gif-action-btn svg {
  width: 14px;
  height: 14px;
}

/* GIF name tooltip */
.gif-name {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  font-size: 0.7rem;
  color: #fff;
  background: rgba(0,0,0,0.6);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
  backdrop-filter: blur(4px);
  z-index: 3;
}

.gif-item:hover .gif-name {
  opacity: 1;
}

/* Tag editor on gif */
.gif-tags-display {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 3;
}

.gif-item:hover .gif-tags-display {
  opacity: 1;
}

.gif-tag-mini {
  font-size: 0.6rem;
  padding: 1px 6px;
  background: rgba(99, 102, 241, 0.7);
  color: #fff;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(4px);
}

/* ========================================
   Buttons
   ======================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-icon {
  width: 38px;
  padding: 0;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 0.8rem;
}

/* ========================================
   Modals
   ======================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 520px;
  width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(10px) scale(0.98);
  transition: transform var(--transition-base);
}

.modal-backdrop.active .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

.modal.modal-lg {
  max-width: 780px;
}

/* GIF Detail Popup */
.gif-detail-layout {
  display: flex;
  gap: 24px;
}

.gif-detail-preview {
  flex: 1;
  min-width: 0;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gif-detail-preview img {
  max-width: 100%;
  max-height: 55vh;
  object-fit: contain;
  display: block;
}

.gif-detail-info {
  flex: 0 0 240px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gif-detail-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.gif-detail-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.gif-detail-value {
  font-size: 0.9rem;
  color: var(--text-primary);
  word-break: break-word;
}

.gif-detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.gif-item {
  cursor: pointer;
}

@media (max-width: 640px) {
  .gif-detail-layout {
    flex-direction: column;
  }
  .gif-detail-info {
    flex: none;
  }
}

/* Video badge on grid items */
.media-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 4px;
  z-index: 2;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.video-badge {
  background: rgba(239,68,68,0.85);
}

/* Convert section in detail popup */
.convert-section {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.convert-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font-sans);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.convert-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.convert-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.convert-btn.done {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
  cursor: default;
}

.convert-download {
  display: block;
  width: 100%;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  background: rgba(99,102,241,0.08);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.convert-download:hover {
  background: rgba(99,102,241,0.15);
}

.spinner-sm {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

/* Upload progress improvements */
.upload-progress-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.upload-file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.85rem;
}

.upload-file-icon {
  font-size: 1rem;
}

.upload-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}

.upload-file-size {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.upload-progress-item .status {
  display: block;
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
}

/* ========================================
   Forms
   ======================================== */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  outline: none;
  transition: all var(--transition-fast);
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea.form-input {
  height: auto;
  min-height: 80px;
  padding: 10px 12px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

select.form-input {
  appearance: none;
  cursor: pointer;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* ========================================
   Upload zone
   ======================================== */

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--bg-card);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-zone .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.upload-zone p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.upload-zone .hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.upload-progress {
  margin-top: 16px;
}

.upload-progress-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 0.85rem;
}

.upload-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width var(--transition-fast);
}

/* ========================================
   Share modal
   ======================================== */

.share-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.share-option {
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.share-option h4 {
  font-size: 0.85rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.share-link-container {
  display: flex;
  gap: 6px;
}

.share-link-container input {
  flex: 1;
  height: 36px;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
}

.share-wa-option {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.share-wa-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.share-wa-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  background: #25D366;
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.share-wa-btn:hover:not(:disabled) {
  background: #1ebe57;
}

.share-wa-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

.share-wa-btn.done {
  background: var(--success);
}

.share-wa-hint {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.share-wa-hint.success {
  color: var(--success);
  font-weight: 500;
}

.share-wa-hint.error {
  color: var(--danger);
}

.mp4-preview {
  margin-top: 12px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
}

.mp4-preview video {
  width: 100%;
  max-height: 300px;
  display: block;
}

.mp4-loading {
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
}

.mp4-loading .spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ========================================
   Toast notifications
   ======================================== */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 0.85rem;
  color: var(--text-primary);
  animation: toastIn 300ms ease;
  max-width: 360px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

.toast.leaving {
  animation: toastOut 200ms ease forwards;
}

/* ========================================
   Login page
   ======================================== */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
}

.auth-card .logo {
  text-align: center;
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 32px;
  letter-spacing: -0.03em;
}

.auth-card .auth-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}

.auth-card .auth-error.visible { display: block; }

.password-wrapper {
  position: relative;
}

.password-wrapper .form-input {
  padding-right: 42px;
}

.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.password-toggle:hover { color: var(--text-primary); }

.auth-links {
  text-align: center;
  margin-top: 16px;
}

.auth-links a {
  color: var(--accent);
  font-size: 0.85rem;
  text-decoration: none;
}
.auth-links a:hover { text-decoration: underline; }

/* ========================================
   Admin panel
   ======================================== */

.admin-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - var(--header-height));
}

.admin-sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 16px 0;
}

.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
}

.admin-nav-item:hover { color: var(--text-primary); background: var(--bg-card); }
.admin-nav-item.active { color: var(--accent); background: var(--accent-soft); }

.admin-nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.admin-content {
  padding: 24px 32px;
  overflow-y: auto;
}

.admin-section {
  display: none;
}

.admin-section.active {
  display: block;
}

.admin-section h2 {
  font-size: 1.3rem;
  margin-bottom: 20px;
  font-weight: 600;
}

/* Stats cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Data table */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.9rem;
}

.data-table tr:hover td {
  background: var(--bg-card);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-admin { background: var(--accent-soft); color: var(--accent); }
.badge-active { background: rgba(34, 197, 94, 0.1); color: var(--success); }
.badge-expired { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.badge-used { background: rgba(136, 136, 136, 0.1); color: var(--text-muted); }

/* ========================================
   Seafile panel
   ======================================== */

.seafile-source {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}

.seafile-source .url {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seafile-source .status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ========================================
   Scrollbar
   ======================================== */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* ========================================
   Empty state
   ======================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  text-align: center;
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.empty-state p {
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 360px;
}

/* ========================================
   Loading
   ======================================== */

.loading-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--grid-gap);
  padding: 0 24px;
}

.loading-item {
  height: 200px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  animation: pulse 1.5s ease infinite;
}

/* ========================================
   Animations
   ======================================== */

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

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.7; }
}

@keyframes toastIn {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes toastOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(40px); opacity: 0; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ========================================
   Collection Filters & Chips
   ======================================== */

.collection-filters {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-shrink: 0;
  margin-right: 8px;
  padding-right: 8px;
  border-right: 1px solid var(--border);
}

.collection-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.collection-chip:hover { color: var(--text-primary); border-color: var(--border); }

.collection-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.collection-chip.fav-chip { padding: 4px 8px; }
.collection-chip.fav-chip.active { background: #f43f5e; border-color: #f43f5e; }

.collection-chip.new-collection-btn {
  border-style: dashed;
  border-color: var(--border);
  color: var(--text-muted);
  background: transparent;
}
.collection-chip.new-collection-btn:hover { color: var(--accent); border-color: var(--accent); }

.coll-label {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.coll-delete {
  display: none;
  font-size: 0.7rem;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
  margin-left: 2px;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.collection-chip:hover .coll-delete { display: inline-block; }
.collection-chip:hover .coll-edit { display: inline-block; }
.collection-chip:hover .coll-count { display: none; }
.collection-chip:hover .coll-public { display: none; }
.coll-delete:hover { color: var(--danger); background: rgba(244,63,94,0.15); }

.coll-edit {
  display: none;
  font-size: 0.72rem;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}
.coll-edit:hover { color: var(--primary); background: rgba(99,102,241,0.15); }

.coll-public {
  font-size: 0.65rem;
  opacity: 0.7;
}

.discover-chip {
  border: 1px dashed var(--border) !important;
  opacity: 0.8;
  transition: opacity 0.15s !important;
}
.discover-chip:hover { opacity: 1; }

.bmc-btn {
  text-decoration: none !important;
  transition: color 0.15s, background 0.15s;
}
.bmc-btn:hover {
  color: #ffdd00 !important;
  background: rgba(255,221,0,0.12) !important;
}

.bmc-modal {
  border-radius: 12px !important;
}
.bmc-modal iframe {
  background: #fff;
  border-radius: 0 0 12px 12px;
}

.btn-danger {
  background: var(--danger, #f43f5e);
  color: #fff;
  border-color: var(--danger, #f43f5e);
}
.btn-danger:hover { opacity: 0.9; }

.coll-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.coll-count {
  font-size: 0.7rem;
  opacity: 0.6;
  margin-left: 2px;
}

/* Toolbar actions (export/import) */
.toolbar-actions {
  display: flex;
  gap: 2px;
  margin-right: 8px;
}

.btn-sm {
  padding: 4px 6px;
  font-size: 0.78rem;
}

/* ========================================
   Favorite Button
   ======================================== */

.gif-action-btn.fav { color: var(--text-muted); }
.gif-action-btn.fav:hover { color: #f43f5e; }
.gif-action-btn.fav.active { color: #f43f5e; }

.gif-action-btn.remove-coll { color: var(--text-muted); }
.gif-action-btn.remove-coll:hover { color: #f59e0b; }

/* ========================================
   Color Picker
   ======================================== */

.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--text-primary); transform: scale(1.15); }

/* ========================================
   Add to Collection Modal
   ======================================== */

.add-to-coll-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-primary);
  margin-bottom: 6px;
  transition: border-color var(--transition-fast);
}

.add-to-coll-item:hover { border-color: var(--accent); }

.add-to-coll-item .coll-count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ========================================
   Import Results
   ======================================== */

.import-results {
  padding: 8px 0;
}

.import-stat {
  padding: 6px 0;
  font-size: 0.88rem;
}

/* ========================================
   Upload Tabs & URL Import
   ======================================== */

.upload-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 14px;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 3px;
}

.upload-tab {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 500;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.upload-tab:hover { color: var(--text-primary); }

.upload-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.upload-tab-content {
  display: none;
}

.upload-tab-content.active {
  display: block;
}

/* URL input */
.url-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.url-input-row input {
  flex: 1;
  font-size: 0.85rem;
}

.url-source-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 14px;
}

.source-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  color: #fff;
  white-space: nowrap;
}

.source-badge.yt { background: #c00; }
.source-badge.rd { background: #ff4500; }
.source-badge.tt { background: #111; border: 1px solid #444; }
.source-badge.tw { background: #9146ff; }
.source-badge.url { background: var(--accent); }

/* URL preview */
.url-preview {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.url-preview-thumb {
  width: 140px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
}

.url-preview-thumb img,
.url-thumb {
  width: 100%;
  display: block;
}

.url-thumb-placeholder {
  width: 140px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.url-preview-info {
  flex: 1;
  min-width: 0;
}

.url-preview-source {
  margin-bottom: 6px;
}

.url-preview-title {
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.3;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.url-meta {
  display: flex;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.url-meta-item {
  white-space: nowrap;
}

/* Time picker */
.url-time-picker {
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.url-time-picker h4 {
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.time-row {
  display: flex;
  align-items: end;
  gap: 12px;
}

.time-row label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.time-input {
  width: 80px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 4px;
}

.time-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  align-self: center;
}

/* Format picker */
.url-format-picker {
  margin-bottom: 14px;
}

.url-format-picker h4 {
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.format-options {
  display: flex;
  gap: 8px;
}

.format-option {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.format-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

.format-option input { display: none; }

.format-label {
  font-size: 0.85rem;
  font-weight: 500;
}

/* Import actions */
.url-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.url-import-status {
  font-size: 0.82rem;
  min-height: 20px;
}

.url-import-status.loading { color: var(--accent); }
.url-import-status.success { color: var(--success); }
.url-import-status.error { color: var(--danger); }

.url-loading {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.url-error {
  padding: 12px;
  text-align: center;
  color: var(--danger);
  font-size: 0.85rem;
}

/* ========================================
   External Drop Overlay
   ======================================== */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(99, 102, 241, 0.15);
  border: 3px dashed var(--accent);
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  backdrop-filter: blur(2px);
}

.drop-overlay.active {
  display: flex;
  animation: fadeIn 0.15s ease-out;
}

.drop-overlay-content {
  text-align: center;
  background: var(--bg-card);
  padding: 32px 48px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.drop-overlay-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.drop-overlay-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Drop confirm modal */
.drop-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  max-height: 260px;
  margin-bottom: 10px;
}

.drop-preview img {
  max-width: 100%;
  max-height: 260px;
  object-fit: contain;
  display: block;
}

.drop-preview-error {
  padding: 40px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.drop-url-display {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  word-break: break-all;
  padding: 6px 8px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.drop-status {
  font-size: 0.85rem;
  text-align: center;
  min-height: 20px;
  padding: 4px 0;
}

.drop-status.loading { color: var(--accent); }
.drop-status.success { color: var(--success); }
.drop-status.warning { color: #f59e0b; }
.drop-status.error { color: var(--danger); }

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
  .app-header {
    padding: 0 12px;
  }

  .search-container {
    max-width: none;
  }

  .toolbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .toolbar-center {
    position: static;
    transform: none;
    order: 10;
    width: 100%;
    display: flex;
    justify-content: center;
    margin: 0;
  }

  .size-slider-wrap input[type="range"] {
    width: 140px;
  }

  .toolbar-right {
    gap: 6px;
  }

  .toolbar-actions {
    display: flex;
    gap: 4px;
  }

  .storage-bar {
    display: none;
  }

  .gif-grid {
    padding: 0 8px 8px;
  }

  /* Mobile: overlay always visible on touch devices */
  .gif-item {
    -webkit-tap-highlight-color: transparent;
  }

  /* Disable hover scale on mobile — it causes layout jumping */
  .gif-item:hover {
    transform: none;
    z-index: auto;
    box-shadow: none;
    border-color: var(--border);
  }

  /* Touch-activated overlay */
  .gif-item.touch-active .gif-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .gif-item.touch-active .gif-name {
    opacity: 1;
  }

  .gif-item.touch-active .gif-tags-display {
    opacity: 1;
  }

  /* Larger touch targets */
  .gif-action-btn {
    width: 38px;
    height: 38px;
  }

  .gif-action-btn svg {
    width: 18px;
    height: 18px;
  }

  /* Collection chips scroll */
  .collection-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .collection-filters::-webkit-scrollbar {
    display: none;
  }

  /* Modal full-width on mobile */
  .modal {
    max-width: 95vw;
    max-height: 90vh;
    margin: 20px auto;
  }

  .gif-detail-layout {
    flex-direction: column;
  }

  .gif-detail-info {
    max-width: 100%;
    flex: none;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    display: flex;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0;
  }

  .admin-nav-item {
    padding: 12px 16px;
    white-space: nowrap;
  }

  .admin-content {
    padding: 16px;
  }

  .data-table {
    font-size: 0.8rem;
  }

  .data-table th,
  .data-table td {
    padding: 8px 6px;
  }
}

@media (max-width: 480px) {
  .header-actions .btn:not(.btn-icon) span {
    display: none;
  }

  .toolbar-left {
    width: 100%;
  }

  .toolbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .size-slider-wrap input[type="range"] {
    width: 120px;
  }
}

/* Update / Deploy Section */
.update-card {
  max-width: 600px;
}

.update-version {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 1rem;
}

.update-version strong {
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
}

.update-dropzone {
  border: 2px dashed #222;
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all 200ms;
}

.update-dropzone:hover {
  border-color: var(--accent);
  background: rgba(99,102,241,0.03);
}

.update-dropzone p {
  margin-top: 12px;
  color: #888;
}

.progress-bar {
  height: 8px;
  background: #141414;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #222;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 200ms;
  width: 0%;
}
