:root {
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  
  /* Light Theme */
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --warning: #d97706;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
  /* Dark Theme */
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-hover: #334155;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: #1e3a8a;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --danger-light: #450a0a;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

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

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

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

/* Icons */
.icon {
  width: 1.25rem;
  height: 1.25rem;
  display: inline-block;
  vertical-align: middle;
  fill: currentColor;
}
.icon-sm {
  width: 1rem;
  height: 1rem;
}
.icon-lg {
  width: 2rem;
  height: 2rem;
}

.hidden {
  display: none !important;
}

/* Header & Navbar */
.navbar {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 40;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text-main);
  text-decoration: none;
}
.nav-brand:hover {
  text-decoration: none;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  padding: 0.25rem 0.75rem;
  background-color: var(--bg-surface-hover);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
}

.role-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  text-transform: uppercase;
}
.role-admin {
  background-color: #fef3c7;
  color: #92400e;
}
.role-readwrite {
  background-color: #dcfce7;
  color: #166534;
}
.role-readonly, .role-guest {
  background-color: #e0f2fe;
  color: #075985;
}
[data-theme="dark"] .role-admin {
  background-color: #78350f;
  color: #fef3c7;
}
[data-theme="dark"] .role-readwrite {
  background-color: #14532d;
  color: #dcfce7;
}
[data-theme="dark"] .role-readonly, [data-theme="dark"] .role-guest {
  background-color: #0c4a6e;
  color: #e0f2fe;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0.875rem;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  background-color: var(--bg-surface);
  color: var(--text-main);
}
.btn:hover {
  opacity: 0.95;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}

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

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

.btn-icon {
  padding: 0.5rem;
  border-radius: 0.375rem;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  cursor: pointer;
}
.btn-icon:hover {
  background-color: var(--bg-surface-hover);
}

/* Layout */
.container {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1rem;
  flex: 1;
}

/* Toolbar & Breadcrumbs */
.toolbar-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.375rem;
  font-size: 0.9375rem;
}
.crumb-item {
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
}
.crumb-separator {
  color: var(--text-muted);
}
.crumb-current {
  color: var(--text-main);
  font-weight: 600;
}

.actions-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.search-box {
  display: flex;
  align-items: center;
  position: relative;
}
.search-input {
  padding: 0.45rem 0.75rem 0.45rem 2rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  background-color: var(--bg-primary);
  color: var(--text-main);
  outline: none;
  width: 200px;
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}
.search-icon-pos {
  position: absolute;
  left: 0.6rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* File Table */
.table-container {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.file-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.file-table th {
  background-color: var(--bg-surface-hover);
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  user-select: none;
  cursor: pointer;
}
.file-table th:hover {
  color: var(--text-main);
}
.file-table th.no-sort {
  cursor: default;
}
.sort-indicator {
  margin-left: 0.375rem;
  font-size: 0.75rem;
}

.file-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

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

.file-name-cell {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 500;
  cursor: pointer;
}
.file-name-cell:hover {
  color: var(--primary);
}

.file-icon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.file-icon-wrap.folder {
  color: #eab308;
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}
.action-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.375rem;
  border-radius: 0.25rem;
  cursor: pointer;
}
.action-btn:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-main);
  border-color: var(--border-color);
}
.action-btn.delete:hover {
  color: var(--danger);
  border-color: var(--danger);
  background-color: var(--danger-light);
}

/* Empty State / Loading State */
.empty-state {
  padding: 4rem 1rem;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .icon {
  width: 3rem;
  height: 3rem;
  margin-bottom: 0.75rem;
  opacity: 0.4;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-lg {
  max-width: 900px;
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
}
.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  background-color: var(--bg-surface-hover);
}

/* Form inputs */
.form-group {
  margin-bottom: 1rem;
}
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  color: var(--text-main);
}
.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-size: 0.875rem;
  outline: none;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}
textarea.form-control {
  font-family: var(--font-mono);
  resize: vertical;
  min-height: 300px;
  line-height: 1.4;
}

/* Upload Dropzone */
.dropzone {
  border: 2px dashed var(--border-color);
  border-radius: 0.5rem;
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  background-color: var(--bg-primary);
  transition: all 0.2s ease;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background-color: var(--primary-light);
}
[data-theme="dark"] .dropzone.dragover {
  background-color: #1e3a8a33;
}
.upload-progress-container {
  margin-top: 1rem;
}
.progress-bar-bg {
  background-color: var(--bg-surface-hover);
  border-radius: 9999px;
  overflow: hidden;
  height: 8px;
  margin-top: 0.375rem;
}
.progress-bar-fill {
  background-color: var(--primary);
  height: 100%;
  width: 0%;
  transition: width 0.2s ease;
}

/* Preview Area */
.preview-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.preview-img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 0.25rem;
}
.preview-pdf, .preview-frame {
  width: 100%;
  height: 70vh;
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
}
.preview-text {
  width: 100%;
  max-height: 60vh;
  overflow: auto;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background-color: var(--bg-primary);
  padding: 1rem;
  border-radius: 0.25rem;
  border: 1px solid var(--border-color);
  white-space: pre-wrap;
  word-break: break-all;
}

/* Toasts / Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 0.375rem;
  background-color: var(--bg-surface);
  color: var(--text-main);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  font-size: 0.875rem;
  min-width: 280px;
  max-width: 420px;
  animation: slideIn 0.25s ease-out;
}
.toast-success {
  border-left: 4px solid var(--success);
}
.toast-error {
  border-left: 4px solid var(--danger);
}
.toast-warning {
  border-left: 4px solid var(--warning);
}
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .search-input {
    width: 100%;
  }
  .toolbar-card {
    flex-direction: column;
    align-items: stretch;
  }
  .actions-group {
    justify-content: flex-start;
  }
  .file-table th:nth-child(3),
  .file-table td:nth-child(3) {
    display: none; /* Hide modified date on small screens */
  }
}

/* View Toggle Group */
.view-toggle-group {
  display: inline-flex;
  align-items: center;
  background-color: var(--bg-surface-hover);
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  padding: 2px;
  gap: 2px;
}

.view-toggle-btn {
  border: none;
  background: transparent;
  padding: 0.35rem 0.5rem;
  border-radius: 0.25rem;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease-in-out;
}

.view-toggle-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-surface);
}

.view-toggle-btn.active {
  background-color: var(--primary);
  color: #ffffff;
}

#toggleHiddenBtn.active {
  background-color: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* List View Tiny Thumbnail */
.file-thumb-icon {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface-hover);
  display: block;
}

.file-thumb-video-wrap {
  width: 28px;
  height: 28px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background-color: #0f172a;
  flex-shrink: 0;
}

.file-thumb-video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-thumb-video-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  color: #ffffff;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.9));
}

/* Tiles View Grid & Cards */
.tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1.25rem;
  padding: 1.25rem;
}

.tile-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  position: relative;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.tile-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.tile-thumb-box {
  position: relative;
  width: 100%;
  height: 140px;
  background-color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border-color);
}

.tile-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile-thumb-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background-color: #000000;
}

.tile-video-indicator {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  background: rgba(0, 0, 0, 0.75);
  color: #ffffff;
  border-radius: 9999px;
  padding: 0.2rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.tile-icon-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  color: var(--text-muted);
}

.tile-icon-placeholder .icon-xl {
  width: 3.5rem;
  height: 3.5rem;
}

.tile-tag {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  background-color: var(--bg-surface-hover);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  border: 1px solid var(--border-color);
}

.tile-info {
  padding: 0.75rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.tile-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tile-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
  padding: 0.375rem 0.75rem 0.5rem;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-surface);
}
