:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e2e5eb;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 10px;
  --header-h: 60px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

html.scroll-locked {
  overflow: hidden;
  overscroll-behavior: none;
}

html.scroll-locked body {
  overflow: hidden;
  position: fixed;
  width: 100%;
  left: 0;
  right: 0;
}

.hidden { display: none !important; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.login-subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-card label {
  display: block;
  margin-bottom: 1rem;
}

.login-card label span {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.login-card input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0 0 1rem;
}

/* App layout */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-main,
.header-selection {
  width: 100%;
}

.header-main {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  grid-template-areas: "left search cta icons";
  align-items: center;
  gap: 0.5rem 0.75rem;
  min-height: var(--header-h);
  padding: 1rem;
}

.header-top { display: contents; }

.header-left {
  grid-area: left;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.header-icons {
  grid-area: icons;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  flex-shrink: 0;
}

.header-search {
  grid-area: search;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.header-search .search-box {
  flex: 1;
  min-width: 0;
}

#search-scope {
  flex-shrink: 0;
  max-width: 11rem;
}

.header-cta {
  grid-area: cta;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.header-cta .btn-mobile-icon {
  display: none;
}

.header-selection {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--header-h);
  padding: 1rem;
  background: rgba(37, 99, 235, 0.06);
}

#app.selection-active .header-main {
  display: none;
}

#app.selection-active .header-selection {
  display: flex;
}

.header-selection-left {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  flex: 0 1 auto;
}

.header-selection-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.15rem;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
}

.header-selection-actions .btn-icon {
  flex-shrink: 0;
  border-color: transparent;
  background: transparent;
}

.header-selection-actions .btn-icon:hover {
  background: rgba(37, 99, 235, 0.1);
}

.btn-danger-icon {
  color: var(--danger);
}

.btn-danger-icon:hover {
  background: rgba(220, 38, 38, 0.1) !important;
}

.selection-count {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.touch-drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  padding: 0.45rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--primary);
  transform: translate(-50%, -120%);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-title {
  font-size: 1.1rem;
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: none;
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  min-width: 0;
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 0.9rem;
  width: 100%;
}

.breadcrumb {
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
  font-size: 0.9rem;
}

.breadcrumb button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0.15rem 0.25rem;
  border-radius: 4px;
}

.breadcrumb button:hover {
  background: var(--bg);
}

.breadcrumb button.drop-target {
  background: rgba(37, 99, 235, 0.12);
  outline: 2px solid rgba(37, 99, 235, 0.35);
}

.breadcrumb .sep {
  color: var(--text-muted);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  gap: 0.75rem;
  flex-wrap: wrap;
}

.sort-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.main {
  flex: 1;
  padding: 0 1rem 2rem;
  position: relative;
}

.main.drag-over {
  outline: 2px dashed var(--primary);
  outline-offset: -4px;
  background: rgba(37, 99, 235, 0.04);
}

.loading, .empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.loading::before {
  content: '';
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: sod-spin 0.7s linear infinite;
  flex-shrink: 0;
}

.global-activity {
  position: relative;
  height: 3px;
  flex-shrink: 0;
  background: var(--border);
  overflow: visible;
}

.global-activity-fill {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: rgba(37, 99, 235, 0.12);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.global-activity.is-active .global-activity-fill {
  opacity: 1;
}

.global-activity-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 40%;
  height: 100%;
  background: var(--primary);
  animation: sod-activity-slide 1.2s ease-in-out infinite;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.global-activity.is-active .global-activity-fill::after {
  opacity: 1;
}

.global-activity-label {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

.global-activity.is-active .global-activity-label {
  opacity: 1;
  visibility: visible;
}

.global-activity.is-active .global-activity-label:not(:empty)::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 0.35rem;
  border: 2px solid rgba(37, 99, 235, 0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: sod-spin 0.7s linear infinite;
  vertical-align: -2px;
}

.upload-in-progress .global-activity.is-active .global-activity-fill {
  background: rgba(37, 99, 235, 0.18);
}

@keyframes sod-spin {
  to { transform: rotate(360deg); }
}

@keyframes sod-activity-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.search-header.loading-inline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.search-header.loading-inline::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: sod-spin 0.7s linear infinite;
  flex-shrink: 0;
}

.app-busy .breadcrumb {
  opacity: 0.85;
}

.muted { opacity: 0.8; }

.file-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "icon main actions";
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.selection-mode .file-row {
  grid-template-columns: auto auto 1fr auto;
  grid-template-areas: "check icon main actions";
}

.file-checkbox {
  display: none;
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--primary);
  grid-area: check;
  align-self: center;
}

.selection-mode .file-checkbox {
  display: block;
}

.file-icon {
  grid-area: icon;
  align-self: center;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.file-icon.folder { background: #fef3c7; }
.file-icon.image { background: #dbeafe; }

.file-row:hover {
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.file-row.selected {
  background: rgba(37, 99, 235, 0.06);
  border-color: rgba(37, 99, 235, 0.2);
}

.file-row.dragging {
  opacity: 0.45;
}

.file-row.drop-target {
  background: rgba(37, 99, 235, 0.12);
  border-color: var(--primary);
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.file-row[draggable="true"] {
  cursor: grab;
}

.file-row[draggable="true"]:active {
  cursor: grabbing;
}

.file-icon.pdf { background: #fee2e2; }
.file-icon.video { background: #ede9fe; }
.file-icon.text { background: #d1fae5; }
.file-icon.archive { background: #f3e8ff; }
.file-icon.audio { background: #fce7f3; }
.file-icon.file { background: #f3f4f6; }

.file-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
}

.file-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.file-cell-main {
  grid-area: main;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.file-meta-line {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.file-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.file-meta.path {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 12rem;
}

.file-actions {
  grid-area: actions;
  justify-self: end;
  align-self: center;
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-header {
  padding: 0.5rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  font-size: 0.875rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.btn:hover { background: var(--bg); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-icon {
  padding: 0.4rem;
  min-width: 36px;
  min-height: 36px;
}

.btn-block { width: 100%; }

.btn-sm {
  padding: 0.3rem 0.55rem;
  font-size: 0.8rem;
}

.select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  background: var(--surface);
}

/* Upload panel */
.upload-overlay {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  z-index: 1200;
  width: min(400px, calc(100vw - 2rem));
  max-width: 100%;
}

.upload-overlay.hidden {
  pointer-events: none;
}

.upload-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: min(520px, 65dvh);
  touch-action: manipulation;
}

.upload-panel.upload-panel-minimized {
  max-height: none;
}

.upload-panel.upload-panel-minimized .upload-panel-body {
  display: none;
}

.upload-panel.upload-panel-minimized #upload-panel-minimize svg {
  transform: rotate(180deg);
}

.upload-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.upload-panel-heading {
  min-width: 0;
  flex: 1;
}

.upload-panel-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
}

.upload-panel-summary {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-panel-destination {
  display: block;
  font-size: 0.75rem;
  color: var(--primary);
  margin-top: 0.1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.upload-panel-summary.has-errors {
  color: var(--danger);
  font-weight: 500;
}

.upload-panel-summary.has-skipped {
  color: var(--muted);
}

.upload-panel-controls {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.upload-panel-controls .btn-icon {
  min-width: 36px;
  min-height: 36px;
  padding: 0.35rem;
  border-color: transparent;
  background: transparent;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.upload-panel-body {
  overflow-y: auto;
  padding: 0.5rem 0.75rem 0.75rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.upload-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.upload-panel-skipped,
.upload-panel-errors {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.upload-skipped-line {
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
}

.upload-skipped-line strong {
  display: block;
  font-weight: 600;
  color: var(--text);
}

.upload-error-line {
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--danger);
}

.upload-error-line strong {
  display: block;
  font-weight: 600;
  color: var(--text);
}

.upload-item-waiting .upload-item-name {
  padding: 0.35rem 0;
}

.upload-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.upload-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.upload-item-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.upload-item-status {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  color: var(--text-muted);
}

.upload-item-done .upload-item-status {
  color: var(--success, #16a34a);
}

.upload-item-skipped .upload-item-status {
  color: var(--text-muted);
}

.upload-item-failed .upload-item-status {
  color: var(--danger);
}

.upload-item-processing .upload-item-status {
  color: var(--primary);
}

.upload-item-processing .upload-item-name::after {
  content: ' — finalisation serveur';
  color: var(--text-muted);
  font-weight: normal;
}

.upload-item-pending .upload-item-status {
  color: var(--text-muted);
  opacity: 0.65;
}

.upload-bar-pending {
  background: var(--border);
  opacity: 0.45;
}

.upload-bar-pending .upload-bar-fill {
  width: 0;
}

.upload-item-checking {
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}

.upload-item.uploading .upload-item-status { color: var(--primary); }
.upload-item.done .upload-item-status { color: #16a34a; }
.upload-item.error .upload-item-status { color: var(--danger); }

.upload-item-info {
  flex: 1;
  min-width: 0;
}

.upload-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.upload-item-error {
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--danger);
  line-height: 1.35;
  word-break: break-word;
  white-space: normal;
}

.upload-item-pct {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 2.25rem;
  text-align: right;
}

.upload-item.done .upload-item-pct { color: #16a34a; }
.upload-item.error .upload-item-pct { color: var(--danger); }

.upload-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.upload-bar-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.2s;
  width: 0;
}

.upload-bar-indeterminate {
  overflow: hidden;
}

.upload-bar-indeterminate .upload-bar-fill {
  width: 40% !important;
  animation: upload-bar-indeterminate 1.2s ease-in-out infinite;
}

@keyframes upload-bar-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.upload-item-preparing .upload-item-status {
  color: var(--primary);
}

.upload-item.done .upload-bar-fill { background: #16a34a; }

.upload-item.error .upload-bar-fill {
  background: var(--danger);
  width: 100% !important;
}

@media (max-width: 1024px) {
  .upload-overlay {
    left: max(0.65rem, env(safe-area-inset-left, 0px));
    right: max(0.65rem, env(safe-area-inset-right, 0px));
    width: auto;
  }

  .upload-panel {
    max-height: min(50vh, 320px);
  }
}

/* Modal */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: 90vw;
  width: 560px;
  max-height: 90vh;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
}

.modal-preview {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(96vw, 1400px);
  max-width: 96vw;
  height: min(96vh, 96dvh);
  max-height: min(96vh, 96dvh);
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  margin: auto;
}

.modal-preview::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal-preview[open] {
  display: flex;
}

.modal-preview-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.modal-preview .modal-header {
  background: var(--surface);
  position: relative;
  z-index: 2;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 1rem;
  position: relative;
  z-index: 2;
}

.modal-close,
.preview-header-actions .btn-icon {
  min-width: 40px;
  min-height: 40px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.preview-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.modal-body {
  padding: 1.25rem;
  max-height: 70vh;
  overflow: auto;
}

.modal-body-preview {
  flex: 1;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  position: relative;
  background: #525659;
}

.preview-frame {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.preview-pdf {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: #525659;
}

.preview-pdf-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: #fff;
  padding: 2rem;
  text-align: center;
}

.modal-footer {
  padding: 0.75rem 1.25rem 1.25rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-shrink: 0;
}

.batch-progress {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.batch-progress-label {
  margin: 0;
  font-weight: 500;
}

.batch-progress-count {
  margin: 0;
  font-size: 0.875rem;
}

.modal-body .upload-bar {
  margin-top: 0.25rem;
}

.modal-body input[type="text"],
.modal-body input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.modal-body label span {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.preview-image, .preview-video {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  background: #111;
}

.preview-text {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg);
  padding: 1.25rem;
  margin: 0;
  flex: 1;
  overflow: auto;
}

.preview-info {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.preview-info .file-icon-large {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* Users management */
.users-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.users-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.users-toolbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sessions-section {
  margin-bottom: 0.25rem;
}

.sessions-heading {
  margin: 0 0 0.35rem;
  font-weight: 600;
}

.sessions-hint {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
}

.sessions-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.sessions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.sessions-table th,
.sessions-table td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.sessions-table th {
  font-weight: 600;
  background: var(--bg-elevated, var(--surface));
}

.sessions-table tr:last-child td {
  border-bottom: none;
}

.sessions-table .actions {
  white-space: nowrap;
}

.session-upload-dest {
  display: block;
  font-size: 0.75rem;
  margin-top: 0.15rem;
}

.badge-current {
  background: color-mix(in srgb, var(--primary) 15%, transparent);
  color: var(--primary);
}

.badge-upload {
  background: color-mix(in srgb, var(--warning, #e6a700) 18%, transparent);
  color: var(--warning, #b8860b);
}

.users-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.users-table th,
.users-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.users-table th {
  background: var(--bg);
  font-weight: 600;
}

.users-table tr:last-child td {
  border-bottom: none;
}

.users-table .actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-admin {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-user {
  background: var(--bg);
  color: var(--text-muted);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.permissions-list .checkbox-label {
  margin-bottom: 0;
}

/* Context menu */
.context-menu {
  position: fixed;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 0.35rem;
  min-width: 180px;
  list-style: none;
  margin: 0;
}

.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
}

.context-menu button:hover {
  background: var(--bg);
}

.context-menu button.danger {
  color: var(--danger);
}

.context-menu-sep {
  height: 1px;
  background: var(--border);
  margin: 0.35rem 0;
}

.context-menu button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: #1a1d23;
  color: #fff;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}

.toast.error { background: var(--danger); }
.toast.success { background: #16a34a; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (min-width: 1025px) {
  .user-label { display: inline; }
}

@media (max-width: 1024px) {
  .modal {
    width: calc(100vw - 1.25rem);
    max-width: calc(100vw - 1.25rem);
    max-height: min(92dvh, 92vh);
  }

  .modal-preview {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    padding:
      env(safe-area-inset-top, 0px)
      env(safe-area-inset-right, 0px)
      env(safe-area-inset-bottom, 0px)
      env(safe-area-inset-left, 0px);
  }

  .modal-preview[open] {
    display: flex;
  }

  .modal-preview .modal-header {
    padding: 0.65rem 0.75rem;
  }

  .preview-header-actions .btn-secondary {
    padding: 0.35rem 0.55rem;
    font-size: 0.8rem;
  }

  .header-main {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
    min-height: 0;
    padding: 0.5rem 0.65rem;
  }

  .header-selection {
    padding: 0.5rem 0.65rem;
    gap: 0.5rem;
  }

  .header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    width: 100%;
  }

  .header-left {
    flex: 1;
    min-width: 0;
  }

  .header-title {
    font-size: 1rem;
  }

  .header-icons {
    flex-shrink: 0;
  }

  .header-search {
    width: 100%;
  }

  #search-scope {
    display: none;
  }

  .header-cta {
    width: 100%;
    justify-content: flex-end;
    gap: 0.35rem;
  }

  .header-cta .btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0.4rem;
  }

  .header-cta .btn-text {
    display: none;
  }

  .header-cta .btn-mobile-icon {
    display: block;
  }

  #app.selection-active .header-selection {
    gap: 0.25rem;
    min-height: var(--header-h);
    padding: 0.5rem 0.65rem;
  }

  #app.selection-active .header-selection-actions .btn-icon {
    min-width: 40px;
    min-height: 40px;
    padding: 0.35rem;
  }

  .file-row {
    align-items: flex-start;
    gap: 0.5rem 0.65rem;
  }

  .file-cell-main {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }

  .file-name {
    flex: none;
    width: 100%;
  }

  .file-meta-line {
    gap: 0.5rem;
    font-size: 0.75rem;
    flex-wrap: wrap;
  }

  .file-meta.path {
    max-width: none;
    white-space: normal;
    word-break: break-all;
  }

  .file-actions {
    align-self: start;
    justify-self: end;
  }

  .file-checkbox,
  .file-icon {
    align-self: center;
  }
}

@media (max-width: 480px) {
  .sort-group label { display: none; }
}
