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

:root {
  --bg: #1a1a2e;
  --bg-surface: #16213e;
  --bg-elevated: #0f3460;
  --text: #e0e0e0;
  --text-muted: #8a8a9a;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --border: #2a2a4a;
  --success: #4caf50;
  --card-bg: #1e2a45;
  --card-bg-light: #2a3a5a;
  --selection: #00AFAF;
}

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

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

.login-container {
  background: var(--bg-surface);
  padding: 3rem;
  border-radius: 12px;
  text-align: center;
  min-width: 320px;
  border: 1px solid var(--border);
}

.login-container h1 {
  font-size: 1.8rem;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

.login-container input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.login-container input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-container button {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
}

.login-container button:hover {
  background: var(--accent-hover);
}

.error {
  color: var(--accent);
  margin-top: 1rem;
  font-size: 0.85rem;
}

/* Layout */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 1.2rem;
}

.sidebar-item {
  display: block;
  width: 100%;
  padding: 0.65rem 1.25rem;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}

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

.sidebar-item.active {
  background: var(--bg-elevated);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar-item .file-count {
  float: right;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: normal;
}

.sidebar-add {
  display: block;
  width: 100%;
  padding: 0.65rem 1.25rem;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  color: var(--accent);
  text-align: left;
  cursor: pointer;
  font-size: 0.9rem;
  margin-top: auto;
}

.sidebar-add:hover {
  background: var(--bg-elevated);
}

/* Main area */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  background: var(--bg-surface);
}

.toolbar-left {
  flex: 1;
}

.toolbar-left h3 {
  font-size: 1rem;
  font-weight: 600;
}

.toolbar-center {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-shrink: 0;
}

.size-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px;
}

.size-btn {
  padding: 0.35rem 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.8rem;
}

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

.size-btn:hover:not(.active) {
  color: var(--text);
}

.toolbar-right {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-primary {
  padding: 0.4rem 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

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

.btn-secondary {
  padding: 0.4rem 1rem;
  background: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

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

/* Sort controls */
.sort-controls {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px;
}

.sort-btn {
  padding: 0.35rem 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.8rem;
}

.sort-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
}

.sort-btn:hover:not(.active) {
  color: var(--text);
}

.sort-arrow {
  font-size: 0.65rem;
  margin-left: 2px;
}

.group-btn {
  padding: 0.35rem 0.75rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.8rem;
}

.group-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.group-btn.active {
  border-color: var(--selection);
  color: var(--selection);
}

/* Gallery */
.gallery {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: grid;
  gap: 1rem;
  align-content: start;
  position: relative;
}

.gallery.size-normal {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

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

.gallery.size-bigger {
  grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 3rem;
  grid-column: 1 / -1;
}

/* File card */
.file-card {
  background: var(--card-bg);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s;
}

.file-card:hover {
  border-color: var(--accent);
}

.file-card-preview {
  width: 100%;
  aspect-ratio: 16/10;
  object-fit: cover;
  display: block;
  background: var(--bg);
}

.file-card-info {
  padding: 0.5rem 0.75rem;
}

.file-card-name {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-card-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.file-card .video-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  color: rgba(255,255,255,0.8);
  pointer-events: none;
}

.file-card-preview-container {
  position: relative;
}

/* Context menu */
.context-menu {
  position: fixed;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0;
  min-width: 180px;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.context-menu ul {
  list-style: none;
}

.context-menu li {
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
}

.context-menu li:hover {
  background: var(--bg-elevated);
}

.context-menu li.separator {
  border-top: 1px solid var(--border);
  padding: 0;
  margin: 0.25rem 0;
  cursor: default;
}

.context-menu li.separator:hover {
  background: none;
}

.context-menu li.danger {
  color: var(--accent);
}

/* Upload zone */
.upload-zone[hidden] {
  display: none;
}

.upload-zone {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.upload-overlay {
  background: var(--bg-surface);
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 3rem;
  text-align: center;
  min-width: 400px;
}

.upload-overlay.dragover {
  border-color: var(--accent);
  background: var(--bg-elevated);
}

.upload-overlay p {
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.upload-hint {
  font-size: 0.85rem;
}

.upload-hint kbd {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-family: inherit;
  font-size: 0.8rem;
}

.upload-limit {
  font-size: 0.75rem;
  opacity: 0.6;
}

.upload-overlay input[type="file"] {
  margin-bottom: 1rem;
}

#upload-progress {
  margin: 1rem 0;
}

.upload-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.3rem 0;
  font-size: 0.85rem;
}

.upload-item .status {
  color: var(--success);
}

.upload-item .status.error {
  color: var(--accent);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Dialog (for prompts) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  min-width: 320px;
}

.modal h3 {
  margin-bottom: 1rem;
}

.modal input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

.modal input:focus {
  outline: none;
  border-color: var(--accent);
}

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

/* Selection */
.file-card.selected {
  border-color: var(--selection);
  box-shadow: 0 0 0 2px rgba(0, 175, 175, 0.3);
}

.selection-box {
  position: fixed;
  border: 2px solid var(--selection);
  background: rgba(0, 175, 175, 0.1);
  border-radius: 6px;
  pointer-events: none;
  z-index: 100;
}

.selection-box[hidden] {
  display: none;
}

/* Date dividers */
.date-divider {
  grid-column: 1 / -1;
  padding: 0.5rem 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}

/* Referenced files indicator */
.file-card-info-referenced {
  background: repeating-linear-gradient(
    -45deg,
    var(--card-bg),
    var(--card-bg) 4px,
    var(--card-bg-light) 4px,
    var(--card-bg-light) 8px
  );
}
