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

:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #252525;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0a0;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --border: #333;
  --shadow: rgba(0, 0, 0, 0.5);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
}

/* Login Page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.login-box {
  background: var(--bg-secondary);
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 10px 40px var(--shadow);
}

.login-box h1 {
  text-align: center;
  margin-bottom: 30px;
  font-size: 28px;
}

/* App Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  transition: transform 0.3s ease;
  z-index: 1000;
  left: 0;
  top: 0;
}

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

.sidebar-header h2 {
  font-size: 20px;
}

.sidebar-header .menu-toggle {
  display: none;
}

.menu-toggle {
  display: none;
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-primary);
  font-size: 32px;
  cursor: pointer;
  padding: 12px 18px;
  border-radius: 8px;
  transition: all 0.2s;
  line-height: 1;
  min-width: 50px;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.menu-toggle:hover {
  background: var(--accent);
}

.menu-toggle:active {
  transform: scale(0.92);
  background: var(--accent-hover);
}

/* Mobile menu button in header */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 10px 15px;
  z-index: 999;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  height: 60px;
}

.mobile-header h1 {
  font-size: 13px;
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.mobile-header .menu-toggle {
  display: flex;
  flex-shrink: 0;
  padding: 10px 14px;
  font-size: 28px;
  min-width: 46px;
  min-height: 46px;
}

@media (max-width: 380px) {
  .mobile-header h1 {
    font-size: 12px;
  }
  
  .mobile-header .menu-toggle {
    padding: 8px 12px;
    font-size: 26px;
    min-width: 42px;
    min-height: 42px;
  }
  
  .mobile-header {
    padding: 8px 12px;
    gap: 10px;
  }
}

@media (max-width: 320px) {
  .mobile-header h1 {
    font-size: 11px;
  }
}

.nav-menu {
  list-style: none;
  padding: 20px 0;
  flex: 1;
}

.nav-menu li {
  margin: 5px 0;
}

.nav-menu a {
  display: block;
  padding: 12px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s;
}

.nav-menu a:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-menu a.active {
  background: var(--accent);
  color: white;
}

.user-info {
  padding: 20px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-secondary);
}

.main-content {
  flex: 1;
  margin-left: 250px;
  padding: 30px;
  max-width: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.page-header h1 {
  font-size: 32px;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Buttons */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-block;
}

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

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

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

.btn-danger:hover {
  background: #dc2626;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

/* Media Grid */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
}

.files-grid {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.media-card {
  background: var(--bg-secondary);
  border-radius: 12px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

.media-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px var(--shadow);
}

.media-thumbnail {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
}

.media-info {
  padding: 15px;
}

.media-title {
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 16px;
}

.media-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.media-actions {
  display: flex;
  gap: 8px;
}

.file-card {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px;
}

.file-icon {
  font-size: 48px;
  width: 60px;
  text-align: center;
}

.file-details {
  flex: 1;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--bg-secondary);
  padding: 30px;
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.viewer-content {
  max-width: 90vw;
  max-height: 90vh;
}

.close {
  position: absolute;
  right: 20px;
  top: 20px;
  font-size: 28px;
  font-weight: bold;
  color: var(--text-secondary);
  cursor: pointer;
  z-index: 1;
}

.close:hover {
  color: var(--text-primary);
}

#viewerContainer img,
#viewerContainer video {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 8px;
}

#viewerContainer audio {
  width: 100%;
}

/* Upload */
.upload-container {
  max-width: 600px;
  background: var(--bg-secondary);
  padding: 30px;
  border-radius: 12px;
}

.file-info {
  margin-top: 10px;
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 14px;
  display: none;
}

.upload-progress {
  margin-top: 20px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 10px;
}

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

.progress-text {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
}

/* Users List */
.users-list {
  display: grid;
  gap: 15px;
}

.user-card {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-details h3 {
  margin-bottom: 5px;
}

.user-role {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.user-role.admin {
  background: var(--accent);
  color: white;
}

/* Messages */
.message {
  margin-top: 15px;
  padding: 12px;
  border-radius: 6px;
  font-size: 14px;
}

.message.success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
  border: 1px solid var(--success);
}

.message.error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.error-message {
  color: var(--danger);
  font-size: 14px;
  margin-top: 10px;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
  font-size: 18px;
}

/* Responsive */
@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
  }

  .sidebar.active {
    transform: translateX(0);
  }

  .menu-toggle {
    display: block;
  }

  .main-content {
    margin-left: 0;
    margin-top: 60px;
    padding: 20px;
    width: 100%;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
    margin-top: 10px;
  }

  .page-header h1 {
    font-size: 24px;
  }

  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
  }

  .files-grid {
    grid-template-columns: 1fr;
  }

  /* Overlay when sidebar is open */
  .sidebar.active::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
  }
}

@media (max-width: 480px) {
  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
  }

  .login-box {
    padding: 30px 20px;
  }

  .main-content {
    padding: 15px;
  }

  .page-header h1 {
    font-size: 20px;
  }

  .media-thumbnail {
    height: 150px;
  }
}

@media (min-width: 1200px) {
  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

@media (min-width: 1600px) {
  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
}

/* Hide admin-only items for non-admin users */
body:not(.is-admin) .admin-only {
  display: none;
}
