/* ═══════════════════════════════════════════════════════════════════
   FileVault — Modern File Storage UI
   ═══════════════════════════════════════════════════════════════════ */

/* ── CSS Variables ──────────────────────────────────────────────── */
:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #161625;
  --bg-card: #1c1c30;
  --bg-card-hover: #22223a;
  --bg-sidebar: #12121f;
  --bg-input: #1a1a2e;
  --bg-overlay: rgba(0, 0, 0, 0.6);
  --border: #2a2a45;
  --border-light: #333355;
  --text-primary: #e8e8f0;
  --text-secondary: #9999bb;
  --text-muted: #666688;
  --accent: #6c63ff;
  --accent-hover: #7b73ff;
  --accent-glow: rgba(108, 99, 255, 0.2);
  --danger: #ff4757;
  --danger-hover: #ff6b81;
  --success: #2ed573;
  --warning: #ffa502;
  --info: #1e90ff;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 4px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
}

/* ── Reset & Base ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input { font-family: inherit; outline: none; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
  width: 260px;
  min-width: 260px;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: transform var(--transition), width var(--transition), min-width var(--transition);
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon { color: var(--accent); }
.logo-text { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.5px; }

.sidebar-toggle {
  background: none;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-xs);
  transition: var(--transition);
  display: none;
}

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

.sidebar-nav {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: none;
  font-size: 0.93rem;
  transition: var(--transition);
  width: 100%;
  text-align: left;
}

.nav-item:hover { color: var(--text-primary); background: var(--bg-card); }
.nav-item.active { color: var(--accent); background: var(--accent-glow); }
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }
.nav-divider { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

.disk-usage {
  padding: 12px;
  margin-top: auto;
}

.disk-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.disk-bar {
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.disk-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--info));
  border-radius: 3px;
  transition: width 1s ease;
}

.disk-text { font-size: 0.78rem; color: var(--text-muted); }

/* ── Main Content ───────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}

/* ── Topbar ─────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.crumb-link {
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  transition: var(--transition);
}

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

.crumb-sep {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.crumb-current {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 2px 6px;
}

/* Search */
.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  transition: var(--transition);
  gap: 6px;
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon { color: var(--text-muted); flex-shrink: 0; }

.search-input {
  background: none;
  border: none;
  color: var(--text-primary);
  padding: 8px 0;
  font-size: 0.9rem;
  width: 200px;
  transition: width var(--transition);
}

.search-input:focus { width: 280px; }
.search-input::placeholder { color: var(--text-muted); }

.search-clear {
  background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 2px 4px;
  border-radius: 50%;
  line-height: 1;
}

.search-clear:hover { color: var(--text-primary); }

/* ── Toolbar ────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.item-count, .total-size {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.selection-info { font-size: 0.82rem; color: var(--text-secondary); }

/* ── File Area ──────────────────────────────────────────────────── */
.file-area {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
  position: relative;
}

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

/* File Card */
.file-card {
  background: var(--bg-card);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  position: relative;
  user-select: none;
}

.file-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.file-card:active { transform: scale(0.98); }
.file-card.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.file-check {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
}

.file-check.visible { display: block !important; }

.checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.file-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-icon svg { width: 48px; height: 48px; }

.img-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  background-size: cover;
  background-position: center;
  background-color: var(--bg-input);
}

.file-info {
  text-align: center;
  width: 100%;
  min-width: 0;
}

.file-name {
  font-size: 0.85rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
  margin: 0 auto;
}

.file-meta {
  display: flex;
  gap: 8px;
  justify-content: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.file-action {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-xs);
  opacity: 0;
  transition: var(--transition);
}

.file-card:hover .file-action { opacity: 1; }
.file-action:hover { color: var(--text-primary); background: var(--bg-card); }

/* List View */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.file-list-item:hover { background: var(--bg-card); }
.file-list-item .file-icon { width: 32px; height: 32px; }
.file-list-item .file-icon svg { width: 28px; height: 28px; }
.file-list-item .file-name-cell { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
.file-list-item .file-size-cell { width: 80px; text-align: right; font-size: 0.82rem; color: var(--text-secondary); }
.file-list-item .file-date-cell { width: 140px; text-align: right; font-size: 0.82rem; color: var(--text-muted); }

/* Drop Zone */
.drop-zone {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.drop-zone-inner {
  text-align: center;
  color: var(--accent);
  padding: 40px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.drop-zone-inner h2 { margin: 12px 0 4px; font-size: 1.3rem; }
.drop-zone-inner p { color: var(--text-secondary); }

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state h3 { margin: 16px 0 8px; color: var(--text-secondary); font-size: 1.2rem; }
.empty-state p { margin-bottom: 20px; }
.empty-state svg { opacity: 0.4; }

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
  gap: 12px;
}

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

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

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-sm, .btn-danger, .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 10px 20px;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  padding: 10px 20px;
  border: 1px solid var(--border);
}

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  padding: 10px 20px;
  border: 1px solid var(--danger);
}

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

.btn-sm {
  background: var(--bg-card);
  color: var(--text-secondary);
  padding: 5px 12px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
}

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

.btn-icon {
  background: none;
  color: var(--text-secondary);
  padding: 8px;
  border-radius: var(--radius-sm);
}

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

.btn-link {
  background: none;
  color: var(--accent);
  font-size: 0.82rem;
  padding: 0 4px;
}

.btn-link:hover { text-decoration: underline; }

/* ── Modal ───────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.25s ease;
}

.modal-sm { max-width: 400px; }
.modal-lg { max-width: 800px; }

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

.modal-header h3 { font-size: 1.05rem; font-weight: 600; }

.modal-header-actions { display: flex; align-items: center; gap: 8px; }

.modal-close {
  background: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  line-height: 1;
}

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

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

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

/* Upload Dropzone */
.upload-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  color: var(--text-secondary);
  transition: var(--transition);
  cursor: pointer;
}

.upload-dropzone:hover, .upload-dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.upload-dropzone svg { color: var(--text-muted); margin-bottom: 12px; }

.upload-list {
  margin-top: 16px;
  max-height: 200px;
  overflow-y: auto;
}

.upload-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-card);
  border-radius: var(--radius-xs);
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.upload-item .remove-file {
  background: none;
  color: var(--danger);
  font-size: 1.1rem;
  padding: 2px 6px;
}

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

.progress-bar {
  height: 8px;
  background: var(--bg-card);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-text {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* Input */
.input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: var(--transition);
}

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

/* ── Context Menu ───────────────────────────────────────────────── */
.context-menu {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  min-width: 180px;
  z-index: 250;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: scaleIn 0.15s ease;
}

.context-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  background: none;
  width: 100%;
  text-align: left;
  font-size: 0.85rem;
  transition: var(--transition);
}

.context-item:hover { background: var(--accent-glow); color: var(--text-primary); }
.context-item.danger { color: var(--danger); }
.context-item.danger:hover { background: rgba(255, 71, 87, 0.1); }
.context-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.context-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* ── Toast ───────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  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-sm);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  animation: slideInRight 0.3s ease;
  min-width: 280px;
  max-width: 400px;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.info { border-color: var(--info); }

.toast-message { flex: 1; }

.toast-close {
  background: none;
  color: var(--text-muted);
  padding: 2px 4px;
  font-size: 1.1rem;
}

/* ── Animations ──────────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideInRight { from { transform: translateX(100px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes scaleIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Utilities ───────────────────────────────────────────────────── */
.hidden { display: none !important; }
.mobile-only { display: none; }

/* ── Responsive: Tablet ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-toggle { display: block; }
  .mobile-only { display: flex; }

  .search-input { width: 140px; }
  .search-input:focus { width: 180px; }

  .file-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .file-card { padding: 12px; }
  .file-icon { width: 48px; height: 48px; }
  .file-icon svg { width: 40px; height: 40px; }
  .file-name { font-size: 0.78rem; max-width: 120px; }

  .topbar { padding: 10px 16px; }
  .file-area { padding: 12px 16px; }
  .toolbar { padding: 6px 16px; }
}

/* ── Responsive: Mobile ──────────────────────────────────────────── */
@media (max-width: 600px) {
  .sidebar { width: 280px; min-width: 280px; }

  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar-right { gap: 6px; }

  .breadcrumbs { font-size: 0.8rem; }

  .search-input { width: 100px; }
  .search-input:focus { width: 130px; }

  .file-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
  .file-card { padding: 10px; }
  .file-icon { width: 40px; height: 40px; }
  .file-icon svg { width: 34px; height: 34px; }
  .file-name { font-size: 0.75rem; max-width: 100px; }

  .file-area { padding: 8px; }
  .toolbar { padding: 4px 8px; gap: 6px; }

  .modal-content { width: 95%; max-width: none; }
  .modal-body { padding: 12px; }
  .modal-header { padding: 12px; }

  .upload-dropzone { padding: 24px 16px; }

  .toast-container { left: 8px; right: 8px; bottom: 8px; }
  .toast { max-width: none; min-width: 0; }
}

/* ── Dark scrollbar for pre/code in preview ──────────────────────── */
.preview-content {
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow: auto;
  max-height: 60vh;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.preview-image {
  max-width: 100%;
  max-height: 65vh;
  border-radius: var(--radius-sm);
  display: block;
  margin: 0 auto;
}

.preview-video, .preview-audio {
  max-width: 100%;
  border-radius: var(--radius-sm);
  outline: none;
}
