:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  --bg-hover: #f1f3f5;
  --bg-selected: #e7f5ff;
  --text-primary: #212529;
  --text-secondary: #495057;
  --text-muted: #868e96;
  --border-color: #dee2e6;
  --accent: #228be6;
  --accent-hover: #1c7ed6;
  --accent-light: #d0ebff;
  --danger: #fa5252;
  --danger-hover: #e03131;
  --success: #40c057;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-sm: 4px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg-primary: #1a1b1e;
  --bg-secondary: #25262b;
  --bg-tertiary: #2c2e33;
  --bg-hover: #373a40;
  --bg-selected: #1b3a5c;
  --text-primary: #c1c2c5;
  --text-secondary: #909296;
  --text-muted: #5c5f66;
  --border-color: #373a40;
  --accent: #4dabf7;
  --accent-hover: #74c0fc;
  --accent-light: #1b3a5c;
  --danger: #ff6b6b;
  --danger-hover: #ff8787;
  --success: #51cf66;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
  color-scheme: dark;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-brand svg { width: 24px; height: 24px; }

.search-bar {
  flex: 1;
  max-width: 600px;
  position: relative;
}

.search-bar input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border-color);
  border-radius: 24px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.search-bar input:focus { border-color: var(--accent); }

.search-bar svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* Layout */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 256px;
  min-width: 256px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius);
  background: none;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s;
}

.sidebar-btn:hover { background: var(--bg-hover); }
.sidebar-btn.active { background: var(--bg-selected); color: var(--accent); font-weight: 600; }
.sidebar-btn svg { width: 20px; height: 20px; flex-shrink: 0; }

.sidebar-btn.new-btn {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  margin-bottom: 8px;
  justify-content: center;
}

.sidebar-btn.new-btn:hover { background: var(--accent-hover); }

.sidebar-divider {
  height: 1px;
  background: var(--border-color);
  margin: 8px 0;
}

.quota-bar {
  margin-top: auto;
  padding: 12px;
}

.quota-bar-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.quota-bar-track {
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

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

/* Main content */
.main-content {
  flex: 1;
  padding: 16px 24px;
  overflow-y: auto;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb-sep { color: var(--text-muted); }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

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

.file-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  position: relative;
  user-select: none;
}

.file-card:hover {
  background: var(--bg-hover);
  box-shadow: var(--shadow);
}

.file-card.selected {
  background: var(--bg-selected);
  border-color: var(--accent);
}

.file-card-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.file-card-name {
  font-size: 13px;
  text-align: center;
  word-break: break-word;
  max-width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.file-card-info {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* File list view */
.file-list { width: 100%; }

.file-list-header, .file-list-row {
  display: grid;
  grid-template-columns: 1fr 120px 140px 80px;
  gap: 8px;
  padding: 8px 12px;
  align-items: center;
  font-size: 13px;
}

.file-list-header {
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.file-list-row {
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.file-list-row:hover { background: var(--bg-hover); }
.file-list-row.selected { background: var(--bg-selected); }

.file-list-name {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.file-list-name svg { width: 20px; height: 20px; flex-shrink: 0; }
.file-list-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn:hover { background: var(--bg-hover); }
.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-icon { padding: 6px; border: none; background: none; border-radius: var(--radius-sm); }
.btn-icon:hover { background: var(--bg-hover); }

/* Context menu */
.context-menu {
  position: fixed;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px 0;
  min-width: 180px;
  z-index: 1000;
  display: none;
}

.context-menu.show { display: block; }

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.15s;
}

.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item.danger { color: var(--danger); }
.context-menu-item svg { width: 16px; height: 16px; }
.context-menu-divider { height: 1px; background: var(--border-color); margin: 4px 0; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--bg-primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 480px;
  padding: 24px;
}

.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; }

.modal input[type="text"], .modal input[type="password"], .modal select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
}

.modal input:focus, .modal select:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: slideIn 0.3s ease;
}

.toast.error { border-left: 4px solid var(--danger); }
.toast.success { border-left: 4px solid var(--success); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Upload zone */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(34,139,230,0.1);
  border: 3px dashed var(--accent);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  font-size: 24px;
  font-weight: 600;
  color: var(--accent);
}

.drop-overlay.show { display: flex; }

/* Upload progress */
.upload-progress {
  position: fixed;
  bottom: 24px;
  left: 24px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  min-width: 300px;
  z-index: 500;
  display: none;
}

.upload-progress.show { display: block; }

.upload-progress-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }

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

.upload-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state svg { width: 80px; height: 80px; margin-bottom: 16px; opacity: 0.5; }
.empty-state p { font-size: 16px; margin-bottom: 8px; }

/* Login page */
.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 24px;
}

.login-page h1 { font-size: 32px; color: var(--accent); }
.login-page p { color: var(--text-secondary); }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .file-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .file-list-header, .file-list-row { grid-template-columns: 1fr 80px; }
  .file-list-header > :nth-child(3),
  .file-list-header > :nth-child(4),
  .file-list-row > :nth-child(3),
  .file-list-row > :nth-child(4) { display: none; }
}
