/* ============================================
   CSS Variables & Dark Mode
   ============================================ */
:root {
  --bg-primary: #f8f9fa;
  --bg-secondary: white;
  --bg-tertiary: #f9fafb;
  --bg-hover: #f0f7ff;
  --text-primary: #333;
  --text-secondary: #374151;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --border-color: #e5e7eb;
  --border-light: #f3f4f6;
  --brand-primary: #00447c;
  --brand-dark: #003366;
  --brand-light: #f0f7ff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --success: #059669;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.3);
  --input-bg: white;
  --input-border: #d1d5db;
  --overlay-bg: rgba(0,0,0,0.5);
}

body.dark {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #1a1a2e;
  --bg-hover: #1e2a4a;
  --text-primary: #e2e8f0;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --border-color: #334155;
  --border-light: #1e293b;
  --brand-primary: #60a5fa;
  --brand-dark: #93c5fd;
  --brand-light: #1e2a4a;
  --danger: #f87171;
  --danger-bg: #451a1a;
  --danger-border: #7f1d1d;
  --success: #34d399;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.6);
  --input-bg: #1e293b;
  --input-border: #475569;
  --overlay-bg: rgba(0,0,0,0.7);
}

* {
  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;
}

/* ============================================
   Header
   ============================================ */
.header {
  background: var(--bg-secondary);
  color: var(--brand-primary);
  padding: 0.75rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  background: #00447c;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 900;
  font-size: 0.6rem;
  letter-spacing: -0.5px;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--brand-primary);
  letter-spacing: -0.3px;
}

.header-subtitle {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-left: 1rem;
  border-left: 1px solid var(--border-color);
}

.user-email {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
}

/* Dark Mode Toggle */
.dark-mode-toggle {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color 0.2s, border-color 0.2s;
}

.dark-mode-toggle:hover {
  color: var(--brand-primary);
  border-color: var(--brand-primary);
}

.dark-mode-toggle svg {
  width: 18px;
  height: 18px;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.2s, transform 0.1s;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--brand-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--brand-dark);
}

.btn-danger {
  background: transparent;
  color: var(--text-faint);
  padding: 0.4rem;
}

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

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

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-faint);
  padding: 0.3rem;
  cursor: pointer;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}

.btn-icon:hover {
  color: var(--brand-primary);
  background: var(--brand-light);
}

.btn-icon.danger:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.btn-icon svg {
  width: 16px;
  height: 16px;
}

/* ============================================
   Auth Section
   ============================================ */
#auth-section {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #00447c 0%, #003366 50%, #1f2937 100%);
}

.auth-container {
  max-width: 400px;
  width: 100%;
  margin: 0 1rem;
  padding: 2rem;
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}

.auth-container h2 {
  margin-bottom: 1.5rem;
  text-align: center;
  color: #00447c;
  font-size: 1.5rem;
  font-weight: 700;
}

.auth-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-brand-logo {
  display: inline-flex;
  background: #00447c;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 900;
  font-size: 0.7rem;
  letter-spacing: -0.5px;
  margin-bottom: 0.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: #374151;
}

.form-group input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: #00447c;
  box-shadow: 0 0 0 3px rgba(0, 68, 124, 0.1);
}

.auth-btn {
  width: 100%;
  padding: 0.7rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.auth-error {
  color: #dc2626;
  font-size: 0.8rem;
  margin-top: 0.75rem;
  text-align: center;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
}

.auth-error:empty {
  display: none;
}

/* ============================================
   App Container
   ============================================ */
.app-container {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 2rem;
}

/* ============================================
   Toolbar
   ============================================ */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
}

.breadcrumb a {
  color: var(--brand-primary);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb span {
  color: var(--text-faint);
}

.item-count {
  font-size: 0.75rem;
  color: var(--text-faint);
  background: var(--bg-tertiary);
  padding: 0.2rem 0.6rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

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

/* Search Input */
.search-input {
  padding: 0.4rem 0.75rem;
  padding-left: 2rem;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  font-size: 0.8rem;
  background: var(--input-bg);
  color: var(--text-primary);
  width: 200px;
  transition: border-color 0.2s, box-shadow 0.2s, width 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(0, 68, 124, 0.1);
  width: 260px;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-wrapper svg {
  position: absolute;
  left: 0.6rem;
  width: 14px;
  height: 14px;
  color: var(--text-faint);
  pointer-events: none;
}

.search-wrapper .search-shortcut {
  position: absolute;
  right: 0.5rem;
  font-size: 0.65rem;
  color: var(--text-faint);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  pointer-events: none;
}

/* ============================================
   Bulk Action Bar
   ============================================ */
.bulk-action-bar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--brand-light);
  border: 1px solid var(--brand-primary);
  border-radius: 6px;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--brand-primary);
  font-weight: 600;
}

.bulk-action-bar.active {
  display: flex;
}

.bulk-action-bar .bulk-count {
  margin-right: auto;
}

/* ============================================
   File List
   ============================================ */
.file-list {
  background: var(--bg-secondary);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.file-list.drag-over {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(0, 68, 124, 0.15);
}

.file-list-header {
  display: grid;
  grid-template-columns: 36px 1fr 100px 160px 120px;
  padding: 0.7rem 1rem;
  background: var(--bg-tertiary);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
  align-items: center;
}

.file-list-header .sortable {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  user-select: none;
  transition: color 0.2s;
}

.file-list-header .sortable:hover {
  color: var(--brand-primary);
}

.file-list-header .sortable.active {
  color: var(--brand-primary);
}

.sort-arrow {
  font-size: 0.6rem;
  opacity: 0.5;
}

.sortable.active .sort-arrow {
  opacity: 1;
}

.file-item {
  display: grid;
  grid-template-columns: 36px 1fr 100px 160px 120px;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border-light);
  align-items: center;
  transition: background 0.15s;
}

.file-item:first-child {
  border-top: none;
}

.file-item:hover {
  background: var(--bg-hover);
}

.file-item.selected {
  background: var(--brand-light);
}

.file-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--brand-primary);
}

.file-list-header input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--brand-primary);
}

.file-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  min-width: 0;
}

.file-name .file-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-name .file-icon svg {
  width: 20px;
  height: 20px;
}

.file-name a {
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-name a:hover {
  color: var(--brand-primary);
}

.file-size, .file-modified {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.file-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

/* ============================================
   Upload Overlay / Modal
   ============================================ */
.upload-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-bg);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.upload-overlay.active {
  display: flex;
}

.upload-modal {
  background: var(--bg-secondary);
  padding: 2rem;
  border-radius: 8px;
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
}

.upload-modal h3 {
  margin-bottom: 1rem;
  color: var(--brand-primary);
  font-weight: 700;
}

.upload-drop-zone {
  border: 2px dashed var(--input-border);
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.upload-drop-zone.drag-over {
  border-color: var(--brand-primary);
  background: var(--brand-light);
}

.upload-drop-zone p {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.upload-file-list {
  margin-top: 1rem;
  max-height: 250px;
  overflow-y: auto;
}

.upload-file-item {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border-light);
}

.upload-file-item .upload-file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.upload-file-item .upload-file-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  margin-right: 0.5rem;
}

.upload-file-item .upload-progress {
  margin-top: 0.3rem;
}

.upload-file-item .upload-progress-bar {
  width: 100%;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  overflow: hidden;
}

.upload-file-item .upload-progress-bar-fill {
  height: 100%;
  background: var(--brand-primary);
  transition: width 0.3s;
  width: 0%;
}

.upload-file-item .upload-pct {
  font-size: 0.7rem;
  color: var(--text-faint);
  margin-top: 0.15rem;
}

.upload-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

/* ============================================
   New Folder Modal
   ============================================ */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-bg);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

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

.modal {
  background: var(--bg-secondary);
  padding: 1.5rem;
  border-radius: 8px;
  width: 90%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  margin-bottom: 1rem;
  color: var(--brand-primary);
  font-weight: 700;
  font-size: 1rem;
}

.modal input[type="text"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--input-bg);
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.modal input[type="text"]:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(0, 68, 124, 0.1);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

/* ============================================
   Preview Panel
   ============================================ */
.preview-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-bg);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.preview-overlay.active {
  display: flex;
}

.preview-panel {
  background: var(--bg-secondary);
  border-radius: 8px;
  width: 90%;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.preview-header h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 1rem;
}

.preview-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.preview-body {
  flex: 1;
  overflow: auto;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-body img {
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain;
  border-radius: 4px;
}

.preview-body pre {
  width: 100%;
  max-height: 65vh;
  overflow: auto;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1rem;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
}

.preview-body iframe {
  width: 100%;
  height: 65vh;
  border: none;
  border-radius: 4px;
}

.preview-info {
  text-align: center;
  color: var(--text-muted);
}

.preview-info p {
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.preview-info .file-meta {
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-bottom: 1rem;
}

/* ============================================
   Loading / Empty / Progress
   ============================================ */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.spinner {
  display: inline-block;
  width: 30px;
  height: 30px;
  border: 3px solid var(--border-color);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-faint);
}

/* ============================================
   Load More / Pagination
   ============================================ */
.load-more-container {
  text-align: center;
  padding: 1rem;
  border-top: 1px solid var(--border-light);
}

/* ============================================
   Notification
   ============================================ */
.notification {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 0.8rem 1.2rem;
  border-radius: 6px;
  color: white;
  font-size: 0.8rem;
  font-weight: 500;
  z-index: 2000;
  animation: slideIn 0.3s ease;
  max-width: 350px;
}

.notification.success {
  background: var(--success);
}

.notification.error {
  background: var(--danger);
}

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

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  .file-list-header,
  .file-item {
    grid-template-columns: 36px 1fr 80px;
  }

  .file-modified,
  .file-list-header > :nth-child(4) {
    display: none;
  }

  .file-actions,
  .file-list-header > :nth-child(5) {
    display: none;
  }

  .search-input {
    width: 140px;
  }

  .search-input:focus {
    width: 180px;
  }

  .toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .bulk-action-bar {
    flex-wrap: wrap;
  }
}
