:root {
  --bg: #fbf7f2;
  --surface: #ffffff;
  --surface-2: #f4eee6;
  --text: #1f1a17;
  --muted: #6b625b;
  --line: #e8dfd4;
  --brand: #e11d48;
  --brand-2: #f59e0b;
  --brand-ink: #ffffff;
  --danger: #b91c1c;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgba(31, 26, 23, .06), 0 8px 24px rgba(31, 26, 23, .06);
  --radius: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120f;
    --surface: #1f1b17;
    --surface-2: #2a241f;
    --text: #f3ece4;
    --muted: #b3a89c;
    --line: #3a322b;
    --brand: #fb7185;
    --brand-ink: #1f1a17;
    --danger: #f87171;
    --focus: #60a5fa;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); min-height: 100dvh; line-height: 1.5; }
body.no-scroll { overflow: hidden; }
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); min-height: 1.2em; margin: .25rem 0; font-size: .9rem; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

label { display: grid; gap: .3rem; font-size: .9rem; font-weight: 600; }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: .55rem .75rem; min-width: 0;
}
input:focus, select:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }

.btn {
  font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .5rem .9rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: .3rem .6rem; font-size: .82rem; }
.btn:disabled { opacity: .6; cursor: wait; }

.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.1rem; color: var(--text); background: none; border: 0; cursor: pointer; padding: 0; font-family: inherit; }
.brand img { width: 32px; height: 32px; }
.brand.big { font-size: 1.6rem; }
.brand.big img { width: 44px; height: 44px; }

/* Sign in */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--brand-2) 18%, transparent), transparent 50%), radial-gradient(circle at 90% 90%, color-mix(in srgb, var(--brand) 14%, transparent), transparent 50%); }
.login-card { width: min(380px, 100%); padding: 2rem; display: grid; gap: 1rem; }
.login-card p { margin: 0; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem clamp(16px, 4vw, 32px); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-actions { display: flex; align-items: center; gap: .25rem; }
.who { color: var(--muted); font-size: .9rem; padding: 0 .5rem; }
.view { padding: 1.25rem clamp(16px, 4vw, 32px) 3rem; max-width: 1400px; margin: 0 auto; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.title-row { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.title-row h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.tools input[type=search] { width: 220px; }
.badge { font-size: .75rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }

/* Loading */
.splash { position: fixed; inset: 0; display: grid; place-items: center; align-content: center; gap: 1rem; background: var(--bg); z-index: 60; }
.splash img { width: 56px; height: 56px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--brand) 25%, transparent); border-top-color: var(--brand); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--surface-2) 60%, var(--surface)) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border: 0; box-shadow: none; }
.album.skeleton { height: 112px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.btn.back { padding: .45rem .75rem; }

/* Folders */
.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.album { text-decoration: none; display: grid; gap: .25rem; justify-items: start; text-align: left; padding: 1.1rem; cursor: pointer; font: inherit; color: inherit; transition: transform .12s, box-shadow .12s; }
.album:hover { transform: translateY(-2px); }
.album-icon { font-size: 2rem; line-height: 1; }
.album-name { font-weight: 700; word-break: break-word; }

/* Photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .6rem; }
.photo { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 10px; overflow: hidden; background: var(--surface-2); cursor: pointer; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.photo.is-video::after { content: '▶'; position: absolute; left: 8px; bottom: 6px; color: #fff; font-size: .9rem; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.photo:hover img { transform: scale(1.03); }
.video-tile { width: 100%; height: 100%; display: grid; place-items: center; align-content: center; gap: .25rem; color: var(--muted); padding: .5rem; }
.video-tile span { font-size: 2rem; }
.video-tile small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.photo .check { position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%; display: none; place-items: center; background: rgba(255, 255, 255, .85); color: transparent; border: 2px solid #fff; font-weight: 800; }
.photos.selecting .photo .check { display: grid; }
.photo.selected { outline: 3px solid var(--brand); outline-offset: -3px; }
.photo.selected .check { background: var(--brand); color: #fff; }
.selection-bar { position: sticky; top: 64px; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem .8rem; margin-bottom: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.selection-bar span { font-weight: 700; margin-right: auto; }

.uploads { margin-bottom: 1rem; padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: .5rem; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand-2), var(--brand)); transition: width .2s; }
.drop-hint { position: fixed; inset: 12px; z-index: 30; display: grid; place-items: center; border: 3px dashed var(--brand); border-radius: 20px; background: color-mix(in srgb, var(--bg) 85%, transparent); font-size: 1.4rem; font-weight: 700; pointer-events: none; }

/* Upload panel */
.upload-panel { position: fixed; right: 16px; bottom: 16px; z-index: 35; width: min(360px, calc(100% - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0, 0, 0, .18); padding: .7rem .8rem; }
.up-head { display: flex; align-items: center; gap: .5rem; }
.up-toggle { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: .5rem; background: none; border: 0; padding: .2rem 0; font: inherit; font-weight: 700; color: var(--text); cursor: pointer; text-align: left; }
.up-toggle span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-chevron { transition: transform .15s; color: var(--muted); }
.upload-panel:not(.open) .up-chevron { transform: rotate(180deg); }
.up-actions { display: flex; gap: .3rem; }
.up-list { list-style: none; margin: .6rem 0 0; padding: 0; max-height: 40vh; overflow: auto; display: none; }
.upload-panel.open .up-list { display: block; }
.up-list li { display: flex; justify-content: space-between; gap: .75rem; padding: .35rem 0; border-top: 1px solid var(--line); font-size: .85rem; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-state { color: var(--muted); white-space: nowrap; }
.up-done .up-state { color: #15803d; font-weight: 700; }
.up-failed .up-state { color: var(--danger); max-width: 50%; overflow: hidden; text-overflow: ellipsis; }
.picker-hint { position: fixed; left: 50%; top: 80px; transform: translateX(-50%); z-index: 45; display: flex; align-items: center; gap: .6rem; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: .6rem 1rem; box-shadow: var(--shadow); font-weight: 600; }

/* Credentials box */
.creds { margin: 0; padding: .8rem; border-radius: 10px; background: var(--surface-2); white-space: pre-wrap; word-break: break-all; font: .9rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; user-select: all; }
.creds-actions { display: flex; gap: .5rem; }
.badge.off { margin-left: .5rem; background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.people tr.is-disabled td:first-child b { color: var(--muted); text-decoration: line-through; }

/* People */
.add-user { padding: 1.2rem; margin-bottom: 1rem; }
.add-user .row { display: grid; grid-template-columns: 1fr 1fr 180px auto; gap: .75rem; align-items: end; }
.people { width: 100%; border-collapse: collapse; }
.people th, .people td { text-align: left; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.people tr:last-child td { border-bottom: 0; }
.people th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }

/* Dialog */
dialog { width: min(440px, calc(100% - 32px)); padding: 1.4rem; color: var(--text); }
dialog::backdrop { background: rgba(20, 15, 10, .45); backdrop-filter: blur(2px); }
#dialog-body { display: grid; gap: .8rem; margin-bottom: .5rem; }
#dialog-body p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.share-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .35rem 0; border-bottom: 1px solid var(--line); font-weight: 600; }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 40; background: rgba(10, 8, 6, .96); display: grid; grid-template-rows: auto 1fr; color: #fff; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .6rem 1rem; font-size: .9rem; }
.viewer-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
.viewer-bar div { display: flex; gap: .5rem; }
.viewer-bar .btn { background: rgba(255, 255, 255, .1); color: #fff; border-color: rgba(255, 255, 255, .15); }
.viewer-stage { display: grid; place-items: center; padding: 0 56px 16px; min-height: 0; }
.viewer-stage img.loading { filter: blur(2px); }
.viewer-stage img, .viewer-stage video { transition: filter .2s;  max-width: 100%; max-height: calc(100dvh - 80px); object-fit: contain; border-radius: 6px; }
.viewer .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .12); color: #fff; font-size: 2rem; cursor: pointer; }
.viewer .nav:hover { background: rgba(255, 255, 255, .22); }
.viewer .prev { left: 8px; }
.viewer .next { right: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; background: var(--text); color: var(--bg); padding: .65rem 1rem; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100% - 32px); font-size: .92rem; }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 720px) {
  .who, #password-btn { display: none; }
  .tools { width: 100%; }
  .tools input[type=search] { flex: 1 1 140px; width: auto; }
  .photos { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: .35rem; }
  .add-user .row { grid-template-columns: 1fr; }
  .viewer-stage { padding: 0 8px 16px; }
  .viewer .nav { width: 36px; height: 52px; font-size: 1.6rem; }
  .people th:nth-child(2), .people td:nth-child(2) { display: none; }
  .upload-panel { right: 8px; left: 8px; bottom: 8px; width: auto; }
  .row-actions { justify-content: flex-start; }
}
