/* ═══════════════════════════════════════════════════
   File Manager — Matches picker-card / login-card design
   Uses ONLY existing design tokens from styles.css
   ═══════════════════════════════════════════════════ */

/* ── Modal overlay ──────────────────────────────── */
.fm-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(8, 8, 20, 0.92);
  backdrop-filter: blur(8px);
  z-index: 300;
  opacity: 0;
  transition: opacity var(--transition);
}

.fm-overlay.fm-visible {
  opacity: 1;
}

/* ── Modal card (matches picker-card / login-card) ── */
.fm-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow:
    0 4px 24px rgb(0, 0, 0, 0.4),
    0 0 40px var(--accent-dim);
  backdrop-filter: blur(24px);
  width: 92%;
  max-width: 940px;
  height: 82vh;
  max-height: 720px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.96);
  transition: transform var(--transition);
  position: relative;
}

.fm-visible .fm-card {
  transform: scale(1);
}

/* ── Toolbar ────────────────────────────────────── */
.fm-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.fm-toolbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  margin-right: 4px;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

.fm-breadcrumb {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  flex: 1 1 auto;
  min-width: 200px;
}

.fm-breadcrumb-sep {
  color: var(--text-muted);
  font-size: 11px;
  padding: 0 2px;
}

.fm-breadcrumb-item {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  white-space: nowrap;
  transition: all var(--transition);
}

.fm-breadcrumb-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.fm-breadcrumb-item.active {
  color: var(--accent);
  font-weight: 600;
}

.fm-toolbar-spacer {
    flex: 1;
}

.fm-auto-rescan-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #cbd5e1;
    margin-right: 12px;
    cursor: pointer;
    user-select: none;
}

.fm-toggle-switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
    flex-shrink: 0;
}

.fm-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.fm-toggle-slider {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 9px;
    transition: background 0.25s ease;
    cursor: pointer;
}

.fm-toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    top: 2px;
    background: #94a3b8;
    border-radius: 50%;
    transition: transform 0.25s ease, background 0.25s ease;
}

.fm-toggle-switch input:checked + .fm-toggle-slider {
    background: var(--accent);
}

.fm-toggle-switch input:checked + .fm-toggle-slider::before {
    transform: translateX(16px);
    background: #fff;
}

/* ── Toolbar buttons (match header-btn pattern) ── */
.fm-toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.fm-toolbar-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

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

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

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

.fm-btn-close {
  padding: 6px 8px;
}

.fm-btn-close:hover {
  color: var(--danger);
  background: rgb(239, 68, 68, 0.08);
  border-color: rgb(239, 68, 68, 0.3);
}

/* ── Body: sidebar + content ────────────────────── */
.fm-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Sidebar (flat favorites) ───────────────────── */
.fm-sidebar {
  width: 210px;
  min-width: 210px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 6px 0;
  flex-shrink: 0;
}

.fm-sidebar::-webkit-scrollbar {
  width: 4px;
}

.fm-sidebar::-webkit-scrollbar-thumb {
  background: var(--accent-dim);
  border-radius: 2px;
}

.fm-tree-item {
  display: block;
  width: 100%;
  padding: 4px 14px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-left: 2px solid transparent;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
  line-height: 1.5;
}

.fm-tree-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.fm-tree-item.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-left-color: var(--accent);
}

/* ── Content (file list) ────────────────────────── */
.fm-content {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
  position: relative;
  min-width: 0;
}

.fm-content::-webkit-scrollbar {
  width: 4px;
}

.fm-content::-webkit-scrollbar-thumb {
  background: var(--accent-dim);
  border-radius: 2px;
}

.fm-loading,
.fm-error,
.fm-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
}

.fm-error {
  color: var(--danger);
}

/* ── File rows (match picker-session-card pattern) ── */
.fm-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  margin: 2px 4px;
  border-radius: var(--radius-sm);
  cursor: default;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.fm-file-dir {
  cursor: pointer;
}

.fm-file-row:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.fm-file-row:hover .fm-file-actions {
  opacity: 1;
}

/* ── File icons (CSS-only, no emoji) ────────────── */
.fm-file-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  position: relative;
}

.fm-icon-dir {
  border: 1.5px solid var(--accent);
  border-radius: 2px;
  width: 16px;
  height: 12px;
  margin-top: 2px;
  position: relative;
}

.fm-icon-dir::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 0;
  width: 7px;
  height: 4px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

.fm-icon-file {
  border: 1.5px solid var(--text-muted);
  border-radius: 2px;
  width: 12px;
  height: 14px;
  margin-left: 2px;
  position: relative;
}

.fm-icon-file::before {
  content: '';
  position: absolute;
  top: -1px;
  right: -1px;
  width: 5px;
  height: 5px;
  border-left: 1.5px solid var(--text-muted);
  border-bottom: 1.5px solid var(--text-muted);
}

.fm-file-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  font-family: var(--font);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.fm-file-dir .fm-file-name {
  font-weight: 500;
}

.fm-file-size {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font);
  width: 70px;
  text-align: right;
  flex-shrink: 0;
}

.fm-file-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
  flex-shrink: 0;
}

.fm-action-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 8px;
  font-family: var(--font);
  transition: all 0.15s ease;
  line-height: 1.4;
}

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

.fm-action-delete:hover {
  color: var(--danger);
  background: rgb(239, 68, 68, 0.08);
  border-color: rgb(239, 68, 68, 0.3);
}

.fm-action-download:hover {
  color: var(--accent);
  border-color: var(--border-accent);
}

.fm-action-extract:hover {
  color: var(--accent);
  border-color: var(--border-accent);
}

.fm-capped-note {
  text-align: center;
  padding: 8px;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font);
}

/* ── Dropzone overlay ───────────────────────────── */
.fm-dropzone-overlay {
  display: none;
  position: absolute;
  inset: 4px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-sm);
  background: rgb(99, 102, 241, 0.06);
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}

.fm-dragover .fm-dropzone-overlay {
  display: flex;
}

.fm-dropzone-text {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
}

/* ── Upload queue ───────────────────────────────── */
.fm-queue {
  border-top: 1px solid var(--border);
  max-height: 200px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: max-height 0.3s ease;
}

.fm-queue.fm-queue-empty {
  max-height: 34px;
}

.fm-queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.fm-queue-header-text {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  font-family: var(--font);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.fm-queue-clear {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  padding: 2px 10px;
  border-radius: var(--radius-xs);
  transition: all 0.15s ease;
}

.fm-queue-clear:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-color: var(--border-accent);
}

.fm-queue-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.fm-queue-list::-webkit-scrollbar {
  width: 4px;
}

.fm-queue-list::-webkit-scrollbar-thumb {
  background: var(--accent-dim);
  border-radius: 2px;
}

.fm-queue-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px;
  font-family: var(--font);
  transition: background 0.15s ease;
}

.fm-queue-row:hover {
  background: var(--bg-hover);
}

.fm-queue-status {
  font-size: 10px;
  font-weight: 600;
  width: 55px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.fm-queue-status-pending {
  color: var(--text-muted);
}

.fm-queue-status-uploading {
  color: var(--accent);
}

.fm-queue-status-done {
  color: var(--success);
}

.fm-queue-status-error {
  color: var(--danger);
}

.fm-queue-status-cancelled {
  color: var(--text-muted);
}

.fm-queue-name {
  font-size: 12px;
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.fm-queue-size {
  font-size: 10px;
  color: var(--text-muted);
  width: 55px;
  text-align: right;
  flex-shrink: 0;
}

.fm-queue-progress {
  width: 80px;
  flex-shrink: 0;
}

.fm-progress-track {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
}

.fm-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.fm-queue-pct {
  font-size: 10px;
  color: var(--text-muted);
  width: 55px;
  text-align: right;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fm-queue-done .fm-queue-pct {
  color: var(--success);
}

.fm-queue-error .fm-queue-pct {
  color: var(--danger);
}

.fm-queue-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ── In-modal prompt (replaces browser prompt()) ── */
.fm-prompt-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 10;
  border-radius: var(--radius);
}

.fm-prompt-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(24px);
  padding: 24px;
  width: 320px;
}

.fm-prompt-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

.fm-prompt-input {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  outline: none;
  transition: all 0.15s ease;
  box-sizing: border-box;
  margin-bottom: 16px;
}

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

.fm-prompt-input::placeholder {
  color: var(--text-muted);
}

.fm-prompt-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.fm-prompt-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
}

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

.fm-prompt-confirm {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.fm-prompt-confirm:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ── Toast notifications ────────────────────────── */
.fm-toast {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  padding: 8px 20px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-family: var(--font);
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 400;
  pointer-events: none;
  white-space: nowrap;
}

.fm-toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.fm-toast-error {
  border-color: rgb(239, 68, 68, 0.3);
  color: var(--danger);
}

.fm-toast-success {
  border-color: rgb(34, 197, 94, 0.3);
  color: var(--success);
}

/* ── Responsive ─────────────────────────────────── */
@media (width <= 640px) {
  .fm-sidebar {
    width: 150px;
    min-width: 150px;
  }

  .fm-card {
    width: 98%;
    height: 90vh;
    max-height: none;
  }

  .fm-toolbar-btn span:not(.fm-toolbar-title) {
    display: none;
  }

  .fm-queue-progress {
    width: 50px;
  }
}
