:root {
  --bg: #ffffff;
  --bg-secondary: #f5f5f5;
  --text: #1a1a1a;
  --text-secondary: #666666;
  --border: #e0e0e0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --bg-secondary: #1a1a1a;
    --text: #e5e5e5;
    --text-secondary: #999999;
    --border: #333333;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Nav */
.nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  margin-right: auto;
}

.nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  transition: color 0.15s;
}

.nav a:hover, .nav a.active {
  color: var(--accent);
}

.nav-user {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-left: 1rem;
}

/* Grid */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 4px;
  padding: 4px;
}

.photo-grid-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  border-radius: 2px;
  background: var(--bg-secondary);
}

.photo-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.photo-grid-item:hover img {
  transform: scale(1.05);
}

.photo-grid-item .video-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.grid-sentinel {
  height: 1px;
}

.grid-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.grid-toolbar select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.filter-date {
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  width: 7.5rem;
}

.filter-coord {
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  width: 5.5rem;
}

.filter-coord-sm {
  width: 3.5rem;
}

/* Selection mode */
.photo-grid-item.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.photo-grid-item.selected::after {
  content: '\2713';
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--accent);
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: bold;
}

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

.sel-count {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Detail */
.detail {
  display: flex;
  min-height: calc(100vh - 53px);
}

.detail-media {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-height: 400px;
}

.detail-media img, .detail-media video {
  max-width: 100%;
  max-height: calc(100vh - 53px);
  object-fit: contain;
}

.detail-sidebar {
  width: 320px;
  padding: 1.5rem;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  max-height: calc(100vh - 53px);
}

.detail-sidebar h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 1.25rem 0 0.5rem;
}

.detail-sidebar h3:first-child {
  margin-top: 0;
}

.detail-meta dt {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.detail-meta dd {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

@media (max-width: 768px) {
  .detail {
    flex-direction: column;
  }
  .detail-sidebar {
    width: 100%;
    max-height: none;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* Tags */
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.6rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
}

.tag-chip button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0;
}

.tag-chip button:hover {
  color: var(--danger);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

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

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

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

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

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

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

/* Upload */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem;
  text-align: center;
  cursor: pointer;
  margin: 1.5rem;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.upload-zone p {
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.upload-list {
  max-width: 600px;
  margin: 1rem auto;
  padding: 0 1.5rem;
}

.upload-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.upload-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-item-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.upload-item-status.done { color: var(--success); }
.upload-item-status.error { color: var(--danger); }
.upload-item-status.dup { color: var(--text-secondary); }

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

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

/* Duplicates */
.dup-group {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.dup-item {
  position: relative;
  width: 160px;
}

.dup-item img {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: var(--radius);
}

.dup-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: 0.35rem;
}

.dup-filename {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.dup-detail {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.dup-actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.35rem;
}

.dup-actions .btn {
  width: 100%;
  justify-content: center;
}

/* Tags page */
.tags-page {
  max-width: 600px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
}

.tags-page .tag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.tags-page .tag-create {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.tags-page input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

/* Login */
.login-card {
  max-width: 360px;
  margin: 15vh auto;
  padding: 2.5rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.login-card p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

/* Share section */
.share-section {
  margin-top: 0.5rem;
}

.share-section .share-url {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.share-section .share-url input {
  flex: 1;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 0.8rem;
}

/* Confirm dialog */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.confirm-dialog {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow);
}

.confirm-dialog p {
  margin-bottom: 1rem;
}

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

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

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-secondary);
}
