:root {
  --font-sans: 'Inter', system-ui, sans-serif;
}

/* ===== Loading Screen ===== */
#loadingScreen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

#loadingScreen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-bar {
  width: 200px;
  height: 3px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.loader-bar-inner {
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #1d4ed8);
  border-radius: 3px;
  animation: loading-slide 1.2s ease-in-out infinite;
}

.loader-text {
  color: rgba(0, 0, 0, 0.35);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

@keyframes loading-slide {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(250%); }
  100% { transform: translateX(-100%); }
}

/* Auto dark mode for loading screen */
@media (prefers-color-scheme: dark) {
  #loadingScreen {
    background: #0a0a0a;
  }

  .loader-bar {
    background: rgba(255, 255, 255, 0.1);
  }

  .loader-text {
    color: rgba(255, 255, 255, 0.3);
  }
}

/* Hide app content until loaded */
.app-wrapper {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.app-wrapper.loaded {
  opacity: 1;
}

html {
  scrollbar-gutter: stable;
  scrollbar-width: none; /* Firefox */
}

html::-webkit-scrollbar {
  display: none; /* Chrome, Edge, Safari */
}

/* Material Symbols shorthand */
.ms {
  font-family: 'Material Symbols Rounded';
  font-weight: normal;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
  flex-shrink: 0;
}

.ms.outlined {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.ms.sm { font-size: 18px; }
.ms.lg { font-size: 28px; }
.ms.xl { font-size: 36px; }

/* ===== Dashboard Layout ===== */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  flex-wrap: wrap;
}

.dashboard-header h1 {
  font-size: var(--text-3);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* ===== Stats Cards ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--space-3);
  padding: 0 var(--space-6) var(--space-4);
}

.stat-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-large);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon.blue { background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; }
.stat-icon.green { background: linear-gradient(135deg, #22c55e, #16a34a); color: #fff; }
.stat-icon.purple { background: linear-gradient(135deg, #a855f7, #7c3aed); color: #fff; }
.stat-icon.orange { background: linear-gradient(135deg, #f59e0b, #d97706); color: #fff; }
.stat-icon.red { background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff; }
.stat-icon.cyan { background: linear-gradient(135deg, #06b6d4, #0891b2); color: #fff; }
.stat-icon.gray { background: linear-gradient(135deg, #6b7280, #4b5563); color: #fff; }

.stat-info h3 {
  font-size: var(--text-8);
  font-weight: var(--font-medium);
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}

.stat-value {
  font-size: var(--text-3);
  font-weight: var(--font-bold);
  margin: 0;
  line-height: 1.2;
}

/* ===== Content Sections ===== */
.content-area {
  padding: 0 var(--space-6) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.section-card { padding: 0; overflow: hidden; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  gap: var(--space-3);
  flex-wrap: wrap;
}

.section-header h2 {
  font-size: var(--text-5);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.section-body { padding: var(--space-5); }

/* ===== Drop Zone ===== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-large);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--faint);
  position: relative;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 5%, var(--background));
}

.drop-zone-icon { font-size: 2.5rem; margin-bottom: var(--space-3); opacity: 0.6; }
.drop-zone-text { font-size: var(--text-7); color: var(--muted-foreground); margin: 0; }
.drop-zone-text strong { color: var(--primary); cursor: pointer; }

/* ===== Upload Queue ===== */
.upload-queue {
  margin-top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.upload-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  background: var(--faint);
  border-radius: var(--radius-medium);
  font-size: var(--text-7);
  gap: var(--space-2);
}

.upload-item-name { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.upload-item-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item-size { color: var(--muted-foreground); white-space: nowrap; font-size: var(--text-8); }

.upload-item button {
  background: none; border: none; cursor: pointer;
  color: var(--muted-foreground); padding: var(--space-1);
  font-size: 1rem; line-height: 1;
}

.upload-item button:hover { color: var(--danger); }

.upload-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
  justify-content: flex-end;
}

/* ===== File List / Table ===== */
.file-toolbar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

.file-toolbar .search-wrapper { position: relative; flex: 1; min-width: 180px; max-width: 320px; }
.file-toolbar .search-wrapper input { padding-left: var(--space-8); margin: 0; }

.file-toolbar .search-wrapper .search-icon {
  position: absolute; left: var(--space-3); top: 50%; transform: translateY(-50%);
  color: var(--muted-foreground); font-size: var(--text-7); pointer-events: none;
}

.file-toolbar select { width: auto; min-width: 140px; margin: 0; }

.file-list { list-style: none; padding: 0; margin: 0; }

.file-item {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  transition: background-color var(--transition-fast);
  margin: 0;
}

.file-item:last-child { border-bottom: none; }
.file-item:hover { background-color: var(--faint); }

.file-name { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.file-name-icon { font-size: 1.3rem; flex-shrink: 0; }
.file-name-text { font-weight: var(--font-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: var(--text-8); color: var(--muted-foreground); white-space: nowrap; }

.file-actions { display: flex; gap: var(--space-1); }
.file-actions button { padding: var(--space-1) var(--space-2); font-size: var(--text-8); }

.empty-state { text-align: center; padding: var(--space-10); color: var(--muted-foreground); }
.empty-state-icon { font-size: 3rem; margin-bottom: var(--space-3); opacity: 0.4; }

/* ===== Filter Tabs ===== */
.filter-tabs {
  display: flex; gap: var(--space-1); padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border); overflow-x: auto; -webkit-overflow-scrolling: touch;
}

.filter-tab {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1) var(--space-3); font-size: var(--text-8);
  font-weight: var(--font-medium); color: var(--muted-foreground);
  background: none; border: 1px solid transparent;
  border-radius: var(--radius-full); cursor: pointer;
  white-space: nowrap; transition: all var(--transition-fast);
}

.filter-tab:hover { color: var(--foreground); background-color: var(--faint); }
.filter-tab.active { color: var(--primary-foreground); background-color: var(--primary); border-color: var(--primary); }

.filter-tab .count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.25rem; height: 1.25rem; padding: 0 var(--space-1);
  font-size: 0.65rem; font-weight: var(--font-semibold);
  background: var(--muted); color: var(--muted-foreground);
  border-radius: var(--radius-full); line-height: 1;
}

.filter-tab.active .count { background: rgba(255, 255, 255, 0.25); color: var(--primary-foreground); }

/* ===== Type Group Header ===== */
.type-group-header {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-5); background: var(--faint);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1;
}

.type-group-header-icon { font-size: 1.1rem; }
.type-group-header-label { font-size: var(--text-7); font-weight: var(--font-semibold); color: var(--foreground); }
.type-group-header-count { font-size: var(--text-8); color: var(--muted-foreground); margin-left: auto; }
.type-group-header-size { font-size: var(--text-8); color: var(--muted-foreground); }

/* ===== Sidebar filter count ===== */
.sidebar-filter-count {
  margin-left: auto; display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.25rem; height: 1.25rem; padding: 0 var(--space-1);
  font-size: 0.65rem; font-weight: var(--font-semibold);
  background: var(--muted); color: var(--muted-foreground);
  border-radius: var(--radius-full); line-height: 1;
}

/* ===== File Type Badge ===== */
.file-type-badge {
  display: inline-block; padding: 1px var(--space-2); font-size: 0.65rem;
  font-weight: var(--font-medium); border-radius: var(--radius-full);
  text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
}

.file-type-badge.type-image { background: color-mix(in srgb, #a855f7 12%, transparent); color: #a855f7; }
.file-type-badge.type-document { background: color-mix(in srgb, #f59e0b 12%, transparent); color: #d97706; }
.file-type-badge.type-video { background: color-mix(in srgb, #ef4444 12%, transparent); color: #ef4444; }
.file-type-badge.type-audio { background: color-mix(in srgb, #06b6d4 12%, transparent); color: #0891b2; }
.file-type-badge.type-other { background: var(--muted); color: var(--muted-foreground); }

[data-theme="dark"] .file-type-badge.type-document { color: #fbbf24; }
[data-theme="dark"] .file-type-badge.type-audio { color: #22d3ee; }

/* ===== Connection Badge ===== */
.connection-badge { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-8); }

.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-foreground); animation: none; }
.connection-dot.online { background: var(--success); animation: pulse-dot 2s infinite; }
.connection-dot.offline { background: var(--danger); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== Upload Progress ===== */
.upload-progress-bar { margin-top: var(--space-3); display: none; }
.upload-progress-bar.active { display: block; }
.upload-progress-text { font-size: var(--text-8); color: var(--muted-foreground); margin-bottom: var(--space-1); }

/* ===== Sidebar branding ===== */
.sidebar-brand {
  display: flex; align-items: center; gap: var(--space-3);
  font-weight: var(--font-bold); font-size: var(--text-5);
}

.sidebar-brand-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, #574747, #8b6f6f);
  border-radius: var(--radius-medium);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1rem;
}

.sidebar-section-label {
  font-size: var(--text-8); font-weight: var(--font-semibold);
  color: var(--muted-foreground); text-transform: uppercase;
  letter-spacing: 0.08em; padding: var(--space-3) var(--space-3) var(--space-1);
}

/* ===== Theme Toggle ===== */
.theme-toggle {
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-medium); padding: var(--space-2);
  cursor: pointer; font-size: 1.1rem; color: var(--foreground);
  display: flex; align-items: center; justify-content: center;
  transition: background-color var(--transition-fast);
}

.theme-toggle:hover { background-color: var(--accent); }

/* ===== Rename dialog ===== */
#renameDialog { max-width: 24rem; }

/* ===== Page Views ===== */
.page-view { display: none; }
.page-view.active { display: block; animation: fadeIn 0.2s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Upload page centered layout */
[data-sidebar-layout]>main {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

#page-upload { display: none; }
#page-upload.active { display: flex; flex-direction: column; flex: 1; }

.upload-center {
  flex: 1; display: flex; align-items: center;
  justify-content: center; padding: var(--space-6);
}

.upload-center>.card { width: 100%; max-width: 640px; }
.upload-center .drop-zone { padding: 3rem 2rem; }
.upload-center .drop-zone-icon { margin-bottom: 1rem; }
.upload-center .drop-zone-icon .ms { font-size: 56px; color: var(--muted-foreground); }
.upload-center .drop-zone-text { font-size: 1.1rem; }

.upload-queue-wrapper {
  max-width: 640px; margin: 0 auto;
  padding: 0 var(--space-6) var(--space-6); width: 100%;
}

/* ===== Mobile Menu Button ===== */
.mobile-menu-btn {
  display: none; background: none; border: 1px solid var(--border);
  border-radius: var(--radius-medium); padding: var(--space-2);
  cursor: pointer; color: var(--foreground); line-height: 1;
}

/* ===== Sidebar Overlay ===== */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4); z-index: 9; backdrop-filter: blur(2px);
}

[data-sidebar-open] .sidebar-overlay { display: block; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .mobile-menu-btn { display: flex; align-items: center; }
  .dashboard-header { padding: var(--space-3) var(--space-4); }
  .dashboard-header h1 { font-size: var(--text-4); }
  .stats-grid { padding: 0 var(--space-4) var(--space-4); grid-template-columns: repeat(3, 1fr); }
  .content-area { padding: 0 var(--space-4) var(--space-4); }
  .file-item { grid-template-columns: 1fr auto; gap: var(--space-2); padding: var(--space-3) var(--space-4); }
  .file-meta { display: none; }
  .file-actions button span { display: none; }
  .upload-center { padding: var(--space-4); }
  .upload-queue-wrapper { padding: 0 var(--space-4) var(--space-4); }
  [data-sidebar-layout]>aside[data-sidebar] { z-index: 10; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-header h1 { font-size: var(--text-5); }
}
