:root {
  --bg: #0b0b0d;
  --bg-2: #131318;
  --line: #1f1f23;
  --text: #ececee;
  --muted: #8a8a93;
  --accent: #f5a524;
  --accent-ink: #1a1206;
  --danger: #ef4444;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ===== Login ===== */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(1000px 600px at 50% -10%, #1a1a22, var(--bg) 60%);
}
.login-card {
  width: min(380px, 92vw);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px;
}
.login-title { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.login-sub   { margin: 0 0 24px; color: var(--muted); }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  background: #0a0a0e; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.btn-primary {
  margin-top: 4px;
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 8px; padding: 11px 14px;
  font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-primary:hover { filter: brightness(1.05); }
.alert {
  background: rgba(239,68,68,0.1); color: #fda4a4;
  border: 1px solid rgba(239,68,68,0.3); padding: 10px 12px;
  border-radius: 8px; font-size: 13px; margin-bottom: 14px;
}

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(11,11,13,0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1400px; margin: 0 auto;
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { font-weight: 600; letter-spacing: -0.01em; }
.topbar-nav { display: flex; align-items: center; gap: 12px; }
.user-chip {
  font-size: 12px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px;
}
.ghost-btn {
  border: 1px solid var(--line);
  background: transparent; color: var(--text);
  padding: 6px 12px; border-radius: 6px;
  font-size: 13px; cursor: pointer;
}
.ghost-btn:hover { border-color: #2a2a30; }

/* ===== Layout ===== */
.container { max-width: 1400px; margin: 0 auto; padding: 28px 24px 80px; }
.page-title { margin: 4px 0 6px; font-size: 26px; letter-spacing: -0.02em; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { margin: 0 6px; }

.empty {
  border: 1px dashed var(--line);
  padding: 40px; border-radius: 10px;
  color: var(--muted); text-align: center;
}

/* ===== Album grid ===== */
.album-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  margin-top: 18px;
}
.album-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.album-card:hover { border-color: #2a2a30; transform: translateY(-2px); }
/* Don't lift the card while one of its forms is open — it shifts under the cursor. */
.album-card:has(.album-form:not(.hidden)):hover { transform: none; }
.album-link { display: block; }
.album-card { position: relative; }
.album-rename-icon {
  position: absolute; top: 8px; right: 8px; z-index: 1;
  width: 28px; height: 28px; padding: 0;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.6); color: #fff;
  border: 1px solid rgba(255,255,255,0.22); border-radius: 6px;
  cursor: pointer; opacity: 0;
  backdrop-filter: blur(4px);
  transition: opacity .12s, background-color .12s, border-color .12s;
}
.album-card:hover .album-rename-icon,
.album-rename-icon:focus-visible { opacity: 1; }
.album-rename-icon:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
@media (hover: none) { .album-rename-icon { opacity: 1; } }

.album-admin { border-top: 1px solid var(--line); padding: 10px 14px; }
.album-admin-row { display: flex; flex-wrap: wrap; gap: 6px; }
.album-admin-row .ghost-btn { font-family: inherit; font-size: 12px; padding: 6px 10px; }
.album-form-go { margin-top: 0; padding: 7px 14px; font-size: 13px; }
.album-move-label {
  display: block; margin-bottom: 6px;
  font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.album-move-row { display: flex; flex-wrap: wrap; gap: 6px; }
.album-move-input {
  flex: 1 1 120px; min-width: 0;
  background: #0a0a0e; color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px; font-size: 13px; font-family: inherit;
}
.album-move-input:focus { outline: none; border-color: var(--accent); }
.album-move-status:empty { display: none; }
.album-move-status {
  margin: 8px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5;
}
.album-form { margin-top: 2px; }
.album-cover { aspect-ratio: 4/3; background: #0a0a0e; }
.album-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album-cover-empty {
  width:100%; height:100%; display:grid; place-items:center;
  color: var(--muted); font-size: 12px;
}
.album-meta { padding: 12px 14px; }
.album-name { font-weight: 500; }
.album-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 18px; align-items: center;
  padding: 14px 0 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}
.toolbar-group { display: flex; align-items: center; gap: 8px; }
.toolbar-group.right { margin-left: auto; }
.toolbar-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.seg {
  display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
}
.seg button {
  background: transparent; color: var(--text); border: 0;
  padding: 6px 12px; cursor: pointer; font-size: 13px;
  border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: rgba(255,255,255,0.04); }
.seg button.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4ade80; box-shadow: 0 0 0 0 rgba(74,222,128,0.7);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(74,222,128,0.6); }
  70% { box-shadow: 0 0 0 8px rgba(74,222,128,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}
.live-text { font-size: 12px; color: var(--muted); }

/* ===== Photo grid ===== */
.photo-grid {
  display: grid; gap: 6px;
  grid-template-columns: repeat(5, 1fr);
}
.photo-grid[data-cols="3"] { grid-template-columns: repeat(3, 1fr); gap: 12px; }
.photo-grid[data-cols="5"] { grid-template-columns: repeat(5, 1fr); gap: 8px; }
.photo-grid[data-cols="7"] { grid-template-columns: repeat(7, 1fr); gap: 6px; }
.photo-grid[data-cols="9"] { grid-template-columns: repeat(9, 1fr); gap: 4px; }
.photo-tile {
  aspect-ratio: 1/1; overflow: hidden; background: #0a0a0e;
  position: relative; display: block;
}
.photo-tile img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform .25s;
}
.photo-tile:hover img { transform: scale(1.04); }
.photo-tile.new { animation: fadeIn .4s ease; }
.nef-badge {
  /* Bottom-right, because the download button now owns the top-right corner. */
  position: absolute; bottom: 6px; right: 6px;
  background: rgba(0,0,0,0.65); color: var(--accent);
  font-size: 9px; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 5px; border-radius: 4px;
  pointer-events: none; line-height: 1.4;
  backdrop-filter: blur(4px);
}
@keyframes fadeIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

/* Per-tile actions: delete (admins) top-left, download original top-right. */
.photo-cell { position: relative; }
.tile-del,
.tile-download {
  position: absolute; top: 4px;
  width: 22px; height: 22px; padding: 0;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.65); color: #fff;
  border: 1px solid rgba(255,255,255,0.25); border-radius: 5px;
  font-size: 15px; line-height: 1; font-family: inherit;
  cursor: pointer; opacity: 0;
  backdrop-filter: blur(4px);
  transition: opacity .12s, background-color .12s, border-color .12s;
}
.tile-del { left: 4px; }
.tile-download { right: 4px; }
.photo-cell:hover .tile-del,
.photo-cell:hover .tile-download,
.tile-del:focus-visible,
.tile-download:focus-visible { opacity: 1; }
.tile-del:hover { background: var(--danger); border-color: var(--danger); }
.tile-del:disabled { opacity: .5; cursor: default; }
.tile-download:hover {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink);
}
@media (hover: none) {
  /* touch devices have no hover to reveal these */
  .tile-del, .tile-download { opacity: 1; }
}

/* Hover loupe: a large preview beside the tile the pointer is resting on. */
.hover-preview {
  position: fixed;
  z-index: 40;
  top: 0; left: 0;
  padding: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.65);
  /* Never intercept the pointer: the loupe opens next to the cursor, and a
     hit-testable panel there would swallow the click meant for the tile. */
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.98);
  transition: opacity .13s ease, transform .13s ease, visibility .13s;
}
.hover-preview.visible {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}
.hover-preview img {
  display: block;
  max-width: min(52vw, 860px);
  max-height: 76vh;
  width: auto; height: auto;
  border-radius: 4px;
  background: #0a0a0e;
}
.hover-preview-name {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  word-break: break-all;
}
@media (prefers-reduced-motion: reduce) {
  .hover-preview { transition: none; transform: none; }
  .hover-preview.visible { transform: none; }
}

@media (max-width: 800px) {
  .photo-grid[data-cols="7"], .photo-grid[data-cols="9"] { grid-template-columns: repeat(4, 1fr); }
  .photo-grid[data-cols="5"] { grid-template-columns: repeat(3, 1fr); }
  .photo-grid[data-cols="3"] { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Detail page ===== */
.detail-grid {
  display: grid; grid-template-columns: 1fr 320px; gap: 28px;
  margin-top: 8px;
}
.detail-image {
  background: #050507; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; display: grid; place-items: center;
  min-height: 60vh;
}
.detail-image img {
  max-width: 100%; max-height: 86vh; display: block;
  object-fit: contain;
}
.detail-image-crop {
  display: flex; flex-direction: column;
  align-items: stretch; justify-content: flex-start;
  padding: 0;
  overflow: hidden;
  min-height: 80vh;
}
.detail-side { display: flex; flex-direction: column; gap: 18px; }
.download-btn {
  display: flex; align-items: center; gap: 14px;
  background: var(--accent); color: var(--accent-ink);
  padding: 18px 20px; border-radius: 14px;
  font-weight: 600; font-size: 16px;
  transition: filter .15s;
}
.download-btn:hover { filter: brightness(1.05); }
.download-btn svg { flex: 0 0 40px; }
.filename {
  word-break: break-all; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--line); padding-bottom: 12px;
}
.exif { width: 100%; border-collapse: collapse; font-size: 13px; }
.exif th, .exif td { text-align: left; padding: 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.exif th { font-weight: 500; color: var(--muted); width: 110px; }
.exif a { color: var(--accent); }
.detail-actions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding-top: 4px;
}
.detail-actions .ghost-btn { font-family: inherit; }
.danger-btn { color: #fda4a4; border-color: rgba(239,68,68,0.35); }
.danger-btn:hover { border-color: var(--danger); background: rgba(239,68,68,0.1); }
.detail-action-status {
  flex: 1 0 100%; margin: 0;
  font-size: 12px; color: var(--muted); line-height: 1.5;
}
.back-btn { align-self: flex-start; }

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
}

/* ===== Filmstrip (other photos in the album) ===== */
.filmstrip {
  margin-top: 18px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.filmstrip-track {
  display: flex; gap: 8px;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: #2a2a30 transparent;
}
.filmstrip-track::-webkit-scrollbar { height: 8px; }
.filmstrip-track::-webkit-scrollbar-track { background: transparent; }
.filmstrip-track::-webkit-scrollbar-thumb { background: #2a2a30; border-radius: 4px; }
.filmstrip-item {
  flex: 0 0 auto;
  width: 108px; height: 72px;          /* 3:2 — the shape the frames actually are */
  background: #0a0a0e;
  border: 2px solid transparent; border-radius: 4px;
  overflow: hidden; display: block;
  transition: border-color .12s, opacity .12s;
  opacity: 0.55;
}
.filmstrip-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.filmstrip-item:hover { opacity: 1; border-color: #2a2a30; }
.filmstrip-item.current {
  opacity: 1;
  border-color: var(--accent);
}
.filmstrip-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 600px) {
  .filmstrip-item { width: 84px; height: 56px; }
}

/* ===== Crop editor ===== */
.crop-topbar {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px;
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--line);
}
.crop-ratios {
  display: inline-flex; align-items: center; gap: 8px;
}
.crop-ratio-group {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-2);
}
.crop-ratio-btn {
  background: transparent; color: var(--text);
  border: 0;
  border-right: 1px solid var(--line);
  padding: 8px 18px;
  font-size: 13px; font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background-color .12s, color .12s;
}
.crop-ratio-btn:last-child { border-right: 0; }
.crop-ratio-btn:hover { background: rgba(255,255,255,0.04); }
.crop-ratio-btn.active {
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600;
}
.crop-ratio-custom {
  width: 76px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px; font-weight: 500;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color .12s, background-color .12s, color .12s;
}
.crop-ratio-custom::placeholder { color: var(--muted); font-weight: 400; }
.crop-ratio-custom:focus { border-color: #2a2a30; }
.crop-ratio-custom.active {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 600;
}
.crop-ratio-custom.active::placeholder { color: var(--accent-ink); opacity: 0.6; }
.crop-ratio-custom.invalid { border-color: #7a3b3b; }
.crop-rotate-btns { display: inline-flex; gap: 8px; }
.crop-rotate-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px; font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background-color .12s, border-color .12s;
}
.crop-rotate-btn:hover {
  background: rgba(255,255,255,0.04);
  border-color: #2a2a30;
}
.crop-rotate-btn svg { flex: 0 0 16px; opacity: 0.85; }
.crop-tilt {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 5px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 8px;
}
.crop-tilt-label {
  font-size: 13px; font-weight: 500; color: var(--muted);
}
.crop-tilt-range {
  width: 120px; height: 4px; cursor: pointer;
  -webkit-appearance: none; appearance: none;
  background: var(--line); border-radius: 2px; outline: none;
}
.crop-tilt-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 0;
}
.crop-tilt-range::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 0;
}
.crop-tilt-val {
  min-width: 44px; text-align: right;
  font-size: 13px; font-weight: 500; color: var(--text);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.crop-canvas-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex; align-items: stretch; justify-content: stretch;
}
#crop-canvas { display: block; width: 100%; height: 100%; }
.crop-bottombar {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px;
  background: rgba(255,255,255,0.02);
  border-top: 1px solid var(--line);
}
.crop-info {
  font-size: 13px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.crop-sizes {
  display: inline-flex; align-items: center; gap: 8px;
}
.crop-size-group {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-2);
}
.crop-size-btn {
  background: transparent; color: var(--text);
  border: 0;
  border-right: 1px solid var(--line);
  padding: 8px 18px;
  font-size: 13px; font-weight: 500;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color .12s, color .12s;
}
.crop-size-btn:last-child { border-right: 0; }
.crop-size-btn:hover { background: rgba(255,255,255,0.04); }
.crop-size-btn.active {
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600;
}
.crop-size-custom {
  width: 88px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px; font-weight: 500;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color .12s, background-color .12s, color .12s;
}
.crop-size-custom::placeholder { color: var(--muted); font-weight: 400; }
.crop-size-custom:focus { border-color: #2a2a30; }
.crop-size-custom.active {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 600;
}
.crop-size-custom.active::placeholder { color: var(--accent-ink); opacity: 0.6; }
.crop-size-custom::-webkit-outer-spin-button,
.crop-size-custom::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.crop-size-custom { -moz-appearance: textfield; }
.crop-bottombar .btn-primary {
  margin: 0;
  font-family: inherit;
  padding: 9px 18px;
}
