:root {
  --bg: #f3f5f8;
  --bg-accent: #e8eef6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #d8dee8;
  --border-strong: #c2cbd8;
  --text: #152033;
  --muted: #5f6f86;
  --accent: #1a6fd4;
  --accent-hover: #155db3;
  --accent-soft: rgba(26, 111, 212, 0.12);
  --danger: #c62828;
  --danger-hover: #a51f1f;
  --success: #1b7a45;
  --shadow: 0 10px 30px rgba(21, 32, 51, 0.08);
  --shadow-sm: 0 2px 8px rgba(21, 32, 51, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --touch: 44px;
  --font: "Outfit", "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 10% -10%, #dce8f8 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #e7eef7 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* —— Login —— */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 2.25rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--muted);
  margin: 0.25rem 0 1.5rem;
}

.login-form label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.login-form input {
  width: 100%;
  min-height: var(--touch);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  margin-bottom: 1rem;
}

.login-form input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
}

/* —— App chrome —— */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid rgba(216, 222, 232, 0.9);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(14px);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 30;
}

.app-header.compact {
  background: rgba(255, 255, 255, 0.92);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.brand-mark,
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.brand-mark:hover {
  text-decoration: none;
  color: var(--accent);
}

.tagline {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.viewer-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.role-badge {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}

.role-admin {
  background: #e8f1fc;
  color: #1557b0;
  border: 1px solid #c5daf5;
}

.role-guest {
  background: #eef1f5;
  color: #4a5a70;
  border: 1px solid #d5dce6;
}

.breadcrumbs {
  padding: 0.85rem 1.25rem 0.35rem;
  font-size: 0.88rem;
  color: var(--muted);
  overflow-x: auto;
  white-space: nowrap;
}

.breadcrumbs .sep {
  margin: 0 0.35rem;
  opacity: 0.55;
}

.breadcrumbs .current {
  color: var(--text);
  font-weight: 600;
}

.toolbar {
  display: flex;
  gap: 0.55rem;
  padding: 0.65rem 1.25rem 1rem;
  flex-wrap: wrap;
}

.select-bar {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.select-count {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 5.5rem;
}

.sticky-bar {
  position: sticky;
  top: 58px;
  z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* —— Buttons —— */
.btn {
  min-height: 40px;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 550;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(26, 111, 212, 0.28);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  box-shadow: none;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.drop-zone {
  margin: 0 1.25rem 1rem;
  padding: 2rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.45);
}

.drop-zone.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* —— Gallery grid —— */
.gallery-wrap {
  position: relative;
  padding: 0 1.25rem 2.5rem;
  user-select: none;
}

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 0.85rem;
}

@media (min-width: 768px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
    gap: 1rem;
  }
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius);
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  min-height: 100%;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  position: relative;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.media-card,
.folder-card {
  position: relative;
}

.card-link {
  display: flex;
  flex-direction: column;
  color: inherit;
  text-decoration: none;
  min-height: 100%;
  flex: 1;
}

.card-link:hover {
  text-decoration: none;
}

.thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: linear-gradient(145deg, #e6ebf2, #f5f7fa);
  display: block;
}

.folder-tile,
.video-tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #edf3fb 0%, #e2eaf4 100%);
  color: #3d6ea8;
}

.folder-svg {
  width: 46%;
  height: auto;
  opacity: 0.92;
}

.video-play {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(21, 32, 51, 0.72);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  padding-left: 3px;
}

.name {
  padding: 0.55rem 0.75rem 0.15rem;
  font-size: 0.82rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta {
  padding: 0 0.75rem 0.65rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.folder-actions {
  padding: 0 0.55rem 0.65rem;
}

.folder-actions .btn {
  width: 100%;
  min-height: 34px;
  font-size: 0.78rem;
  border-radius: 999px;
}

.empty {
  padding: 3rem 1.25rem;
  color: var(--muted);
  text-align: center;
}

/* —— Selection —— */
.pick-hit {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  z-index: 5;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 0;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.card:hover .pick-hit,
.grid-item.is-selected .pick-hit,
body.selection-mode .pick-hit {
  opacity: 1;
}

.pick-hit .media-check {
  position: absolute;
  opacity: 0;
  width: 22px;
  height: 22px;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}

.pick-hit .pick-box {
  position: static;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.95);
  background: rgba(21, 32, 51, 0.35);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.folder-card .pick-box {
  border-color: #fff;
  background: rgba(21, 32, 51, 0.28);
}

.grid-item.is-selected .pick-box,
.card.selected .pick-box {
  background: var(--accent);
  border-color: var(--accent);
}

.grid-item.is-selected .pick-box::after,
.card.selected .pick-box::after {
  content: "";
  display: block;
  width: 5px;
  height: 10px;
  margin: 2px auto 0;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.grid-item.is-selected .card,
.card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow);
}

body.selection-mode .card-link {
  pointer-events: none;
}

.marquee {
  position: absolute;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  pointer-events: none;
  z-index: 5;
  border-radius: 4px;
}

.thumb-fallback {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-accent);
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  padding: 0.5rem;
}

img.thumb {
  -webkit-user-drag: none;
  user-select: none;
}

/* —— Viewer —— */
.viewer {
  padding: 1rem 1.25rem 2rem;
  max-width: 1100px;
  margin: 0 auto;
}

.viewer-stage {
  overflow: auto;
  text-align: center;
  background: #0e1520;
  border-radius: var(--radius);
  padding: 0.5rem;
  box-shadow: var(--shadow);
}

.viewer-media {
  width: 100%;
  max-height: 72dvh;
  object-fit: contain;
  border-radius: calc(var(--radius) - 4px);
  transition: transform 0.15s ease;
  transform-origin: center center;
  background: #0e1520;
}

.viewer-nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  margin: 1rem 0;
}

.meta-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 1.5rem;
  margin-top: 1.25rem;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow-sm);
}

.meta-list dt {
  color: var(--muted);
  font-weight: 500;
}

/* —— Dialogs —— */
dialog {
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  background: var(--surface);
  color: var(--text);
  padding: 1.5rem;
  max-width: 92vw;
  width: 440px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 36, 0.45);
  backdrop-filter: blur(4px);
}

dialog h2 {
  margin-top: 0;
  font-family: var(--font-display);
  font-weight: 600;
}

dialog input[type="text"],
dialog input[type="number"],
dialog input[type="file"] {
  width: 100%;
  margin: 0.45rem 0 0.9rem;
  min-height: 42px;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-family: inherit;
  font-size: 0.95rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1rem;
}

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.upload-dialog-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: min(92vw, 28rem);
}

.upload-summary {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.upload-progress-wrap {
  height: 0.55rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.upload-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent, #2f6fed);
  transition: width 0.2s ease;
}

.upload-current {
  margin: 0;
}

.upload-status {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
  max-height: 220px;
  overflow-y: auto;
}

.upload-status li.ok {
  color: var(--success);
}

.upload-status li.fail {
  color: var(--danger);
}

.upload-status li.pending {
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
}

.share-result {
  background: var(--accent-soft);
  border: 1px solid #c5daf5;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.9rem;
}

.share-error {
  color: #b42318;
  background: #fef3f2;
  border: 1px solid #fecdca;
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
}

.share-folders {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  background: var(--surface-2);
}

.share-folders label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  cursor: pointer;
}

.share-active-block {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
}

.share-history-block {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
}

.share-active-title {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.share-history-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0 0.65rem;
}

.share-history-select-all {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.share-history-row {
  align-items: center;
}

.share-history-row .share-history-check {
  margin-top: 0.15rem;
  flex-shrink: 0;
}

.share-grant-actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex-shrink: 0;
}

.share-edit,
.share-revoke {
  min-height: auto;
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
}

.share-grant-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.65rem;
}

.share-grant-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.share-grant-folders {
  font-weight: 600;
  font-size: 0.9rem;
}

.share-grant-meta {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

.share-success-body h2 {
  margin-top: 0;
}

.share-success-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.85rem;
  margin: 1rem 0;
}

.share-success-meta dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.share-success-meta dd {
  margin: 0;
  font-size: 0.95rem;
}

.share-success-meta code {
  font-size: 1.05rem;
  word-break: break-all;
}

.share-revoke {
  min-height: auto;
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.trash-list {
  list-style: none;
  padding: 0 1.25rem;
  margin: 0;
}

.trash-item {
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--border);
}

.trash-item .meta {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.login-admin-hint {
  margin-top: 1rem;
  text-align: center;
}

.security-page {
  max-width: 42rem;
  margin: 1.5rem auto;
  padding: 0 1rem 3rem;
}

.security-section {
  margin-bottom: 2rem;
}

.passkey-list,
.security-event-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.passkey-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.passkey-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.security-event-list li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.sec-cat {
  display: inline-block;
  font-weight: 600;
  margin-right: 0.5rem;
}

@media (pointer: coarse) {
  .pick-hit {
    opacity: 1;
  }
}
