/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #0f0f0f; --surface: #1a1a1a; --surface2: #222;
  --text: #e8e8e8; --text2: #888; --accent: #7c5cfc;
  --radius: 10px; --gap: 4px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
}

html { scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100dvh; -webkit-tap-highlight-color: transparent; }

/* ── Shared ────────────────────────────────────────────── */
.input {
  width: 100%; padding: 12px 14px; border: 1px solid rgba(255,255,255,0.1); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 15px; outline: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text2); }

.btn {
  padding: 10px 20px; border: none; border-radius: 8px; font-size: 15px; font-weight: 500;
  cursor: pointer; transition: all 0.15s; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { opacity: 0.8; }
.btn.outline { border: 1px solid rgba(255,255,255,0.15); background: transparent; color: var(--text); }
.btn.outline:active { background: var(--surface); }
.btn.ghost { background: transparent; color: var(--text2); border: none; }
.btn.ghost:active { color: var(--text); }

.err { color: #f87171; font-size: 13px; margin-top: 4px; min-height: 1.2em; }
.hint { color: var(--text2); font-size: 13px; }

.spinner {
  width: 32px; height: 32px; border: 3px solid rgba(255,255,255,0.08); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.spinner.sm { width: 20px; height: 20px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Loading ───────────────────────────────────────────── */
.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 80px 20px; gap: 12px; }
.loading p { color: var(--text2); font-size: 14px; }

/* ── Auth ──────────────────────────────────────────────── */
.page { min-height: 100dvh; }
.auth-box {
  max-width: 380px; margin: 0 auto; padding: 80px 20px; text-align: center;
}
.auth-box h1 { font-size: 28px; font-weight: 700; margin-bottom: 6px; }
.auth-box .sub { color: var(--text2); font-size: 14px; margin-bottom: 32px; }
.auth-box .input { margin-bottom: 12px; }
.auth-box .btn { width: 100%; margin-top: 4px; }
.switch-auth { margin-top: 16px; font-size: 14px; color: var(--text2); }
.switch-auth a { color: var(--accent); cursor: pointer; text-decoration: none; }

/* ── Top bar ───────────────────────────────────────────── */
.top-bar {
  position: sticky; top: 0; z-index: 50; display: flex; align-items: center;
  height: 48px; padding: 0 12px; gap: 8px;
  background: rgba(15,15,15,0.88); backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.top-bar h1 { flex: 1; font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Groups list ───────────────────────────────────────── */
.group-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px; padding: 16px;
}
.group-card {
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  background: var(--surface); transition: transform 0.12s;
}
.group-card:active { transform: scale(0.97); }
.group-cover {
  width: 100%; aspect-ratio: 16/10; overflow: hidden;
  background: var(--surface2); display: flex; align-items: center; justify-content: center;
}
.group-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.group-cover .no-cover { color: var(--text2); font-size: 28px; opacity: 0.3; }
.group-body { padding: 12px 14px; display: flex; align-items: center; gap: 8px; }
.group-body .info { flex: 1; min-width: 0; }
.group-body .name { font-size: 15px; font-weight: 600; display: block; }
.group-body .meta { font-size: 12px; color: var(--text2); margin-top: 2px; display: block; }
.role-tag { font-size: 11px; color: var(--text2); background: var(--surface2); padding: 2px 8px; border-radius: 4px; white-space: nowrap; flex-shrink: 0; }
.group-actions { padding: 0 16px 32px; display: flex; gap: 10px; }
.group-actions .btn { flex: 1; }

/* ── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6);
}
.modal {
  background: var(--surface); border-radius: 14px; padding: 24px;
  width: 90%; max-width: 400px; display: flex; flex-direction: column; gap: 12px;
}
.modal h2 { font-size: 18px; text-align: center; }

/* ── Gallery ───────────────────────────────────────────── */
.gallery { padding: 0 var(--gap) 80px; max-width: 1600px; margin: 0 auto; }

.day-group { margin-bottom: 8px; }
.day-header {
  display: flex; align-items: baseline; gap: 8px;
  padding: 16px 6px 8px; font-size: 14px; font-weight: 600; color: var(--text);
  position: sticky; top: 48px; z-index: 5;
  background: rgba(15,15,15,0.92); backdrop-filter: blur(12px);
}
.day-header::after { content: ''; flex: 1; height: 1px; background: linear-gradient(to right, rgba(255,255,255,0.08), transparent); }
.day-count { font-size: 12px; font-weight: 400; color: var(--text2); }

.grid {
  column-count: 2; column-gap: var(--gap);
}
.grid > .card { break-inside: avoid; margin-bottom: var(--gap); }
@media (min-width: 480px) { .grid { column-count: 3; } }
@media (min-width: 700px) { .grid { column-count: 4; } }
@media (min-width: 1000px) { .grid { column-count: 5; } }

.card {
  position: relative; overflow: hidden; cursor: pointer;
  background: var(--surface); line-height: 0; transition: transform 0.12s;
  -webkit-tap-highlight-color: transparent; min-height: 120px;
}
.card:active { transform: scale(0.97); }
.card img { width: 100%; height: auto; display: block; opacity: 0; transition: opacity 0.3s; }
.card img.loaded { opacity: 1; }
.card .badge {
  position: absolute; bottom: 6px; right: 6px; pointer-events: none;
  background: rgba(0,0,0,0.7); border-radius: 4px; padding: 3px 7px;
  display: flex; align-items: center; backdrop-filter: blur(4px);
}

.empty { display: flex; flex-direction: column; align-items: center; padding: 60px 20px; gap: 6px; }
.empty p { color: var(--text2); font-size: 14px; }

.load-more { display: flex; justify-content: center; padding: 20px; }

/* ── Upload ────────────────────────────────────────────── */
.upload-modal { max-width: 500px; }
.drop-zone {
  border: 2px dashed rgba(255,255,255,0.15); border-radius: var(--radius);
  padding: 40px 20px; text-align: center; cursor: pointer; transition: border-color 0.15s;
}
.drop-zone:active, .drop-zone.dragover { border-color: var(--accent); }
.drop-zone p { font-size: 14px; color: var(--text2); }
.upload-list { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.upload-list .file-item { font-size: 13px; color: var(--text2); padding: 4px 0; }
.progress-bar { height: 4px; background: var(--surface2); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.3s; }

.invite-link-box {
  background: var(--surface2); padding: 12px; border-radius: 8px;
  font-size: 13px; word-break: break-all; color: var(--text2);
  user-select: all;
}

/* ── Lightbox ──────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.95);
}
.lightbox-bg { position: absolute; inset: 0; }
.lb-close {
  position: absolute; top: calc(12px + var(--safe-t)); right: 12px; z-index: 12;
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.08); color: #fff; font-size: 24px; cursor: pointer;
}
.lb-nav {
  position: absolute; top: 50%; z-index: 12; transform: translateY(-50%);
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.06); color: #fff; font-size: 28px; cursor: pointer;
}
.lb-prev { left: 8px; } .lb-next { right: 8px; }
.lb-content {
  position: relative; z-index: 1; max-width: 95vw; max-height: 95vh;
  display: flex; flex-direction: column;
}
.lb-media { max-width: 100%; max-height: 85vh; object-fit: contain; }
.lb-info { display: flex; align-items: center; gap: 8px; padding: 8px 4px 0; font-size: 13px; color: var(--text2); }
.lb-date { flex: 1; color: var(--text); }
.lb-btn { background: none; border: 1px solid rgba(255,255,255,0.15); color: var(--text); font-size: 12px; cursor: pointer; padding: 4px 10px; border-radius: 4px; }
.lb-delete { border-color: rgba(248,113,113,0.3); color: #f87171; }

/* ── Select mode ───────────────────────────────────────── */
.card.selectable { cursor: pointer; }
.card.selected { outline: 3px solid var(--accent); outline-offset: -3px; border-radius: 8px; }
.card .sel-check {
  position: absolute; top: 6px; left: 6px; z-index: 2;
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.5);
  background: rgba(0,0,0,0.4); display: none; align-items: center; justify-content: center;
}
.card.selected .sel-check { display: flex; background: var(--accent); border-color: var(--accent); }
.card.selectable .sel-check { display: flex; }

.batch-bar {
  position: sticky; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-b));
  background: rgba(15,15,15,0.95); backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255,255,255,0.06);
}
.batch-bar .count { font-size: 14px; color: var(--text); flex: 1; }
.batch-bar .btn { flex-shrink: 0; }

/* ── Date picker modal ─────────────────────────────────── */
.date-picker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.date-picker-grid select {
  padding: 8px; border: 1px solid rgba(255,255,255,0.1); border-radius: 6px;
  background: var(--surface2); color: var(--text); font-size: 15px;
}

@media (min-width: 768px) {
  .lb-prev { left: 20px; } .lb-next { right: 20px; }
  .lb-content { max-width: 90vw; }
  .lb-media { border-radius: 6px; }
}
