:root {
  color-scheme: light dark;
  --bg: #fbfbfc;
  --surface: #fff;
  --line: #e3e4e8;
  --text: #16181d;
  --muted: #6b7080;
  --accent: #3b6ef5;
  --ok: #128a52;
  --warn: #b5730a;
  --danger: #c62f3c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 18, 29, .06), 0 6px 18px rgba(16, 18, 29, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --surface: #171a20;
    --line: #272b34;
    --text: #e8eaf0;
    --muted: #969cad;
    --accent: #6b93ff;
    --ok: #3ecf8e;
    --warn: #e0a33a;
    --danger: #ff6b74;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 64px; }
body.centered main { display: grid; place-items: center; min-height: 72vh; }

/* ---------------------------------------------------------------- header */

.top {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 650; color: var(--text); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; color: var(--accent); }
.nav { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 14px; }
.nav .who { color: var(--muted); }
.inline { display: inline; }

button, .pg, .scope {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  width: 100%; padding: 10px; font-weight: 600; margin-top: 6px;
}
button.primary:hover { filter: brightness(1.08); color: #fff; }
button.linkish {
  border: 0; background: none; color: var(--muted); padding: 0;
}
button.ok:hover { border-color: var(--ok); color: var(--ok); }
button.warn:hover { border-color: var(--warn); color: var(--warn); }
button.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ---------------------------------------------------------------- forms */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow);
}
.card.auth { width: min(380px, 100%); }
.card h1 { margin: 0 0 18px; font-size: 20px; letter-spacing: -.01em; }

label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=email], input:not([type]) {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px;
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
input:focus-visible, button:focus-visible, .tile:focus-visible, .drop:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.hint { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.flash {
  margin: 0 0 14px; padding: 9px 12px; border-radius: 8px; font-size: 14px;
  border: 1px solid var(--danger); color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}
.flash.ok { border-color: var(--ok); color: var(--ok);
  background: color-mix(in srgb, var(--ok) 8%, transparent); }
.flash.warn { border-color: var(--warn); color: var(--warn);
  background: color-mix(in srgb, var(--warn) 10%, transparent); }

/* ---------------------------------------------------------------- uploader */

.uploader { margin-bottom: 26px; }
.drop {
  display: grid; place-items: center; gap: 6px; text-align: center;
  padding: 34px 20px; cursor: pointer;
  border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.drop strong { font-size: 16px; font-weight: 600; }

.toggle {
  display: flex; align-items: center; gap: 9px; margin: 14px 0 0;
  font-size: 14px; color: var(--text); cursor: pointer; user-select: none;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track {
  width: 38px; height: 22px; border-radius: 11px; background: var(--line);
  position: relative; transition: background .15s; flex: none;
}
.toggle .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%; background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s;
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(16px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.queue { list-style: none; margin: 12px 0 0; padding: 0; font-size: 13px; }
.queue li {
  display: flex; align-items: center; gap: 8px; padding: 5px 0;
  border-top: 1px solid var(--line); color: var(--muted);
}
.queue li .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue li.done { color: var(--ok); }
.queue li.failed { color: var(--danger); }

/* ---------------------------------------------------------------- gallery */

.gallery-head {
  display: flex; align-items: baseline; gap: 12px; margin: 0 0 12px;
}
.gallery-head h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.scope { margin-left: auto; font-size: 13px; padding: 4px 10px; }

.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
}
.tile {
  position: relative; margin: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); overflow: hidden;
  transition: border-color .15s, transform .12s;
}
.tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.tile img {
  display: block; width: 100%; aspect-ratio: 1; object-fit: cover;
  background: var(--bg);
}
.tile figcaption { padding: 7px 9px; display: grid; gap: 1px; font-size: 12px; }
.tile .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .meta { color: var(--muted); font-size: 11px; }
.tile.copied { border-color: var(--ok); }

.badge {
  position: absolute; top: 6px; left: 6px;
  padding: 1px 6px; border-radius: 5px; font-size: 10px; font-weight: 600;
  background: rgba(0, 0, 0, .62); color: #fff; letter-spacing: .03em;
}
.badge.admin { position: static; background: var(--accent); }

.tile .del {
  position: absolute; top: 5px; right: 5px;
  width: 24px; height: 24px; padding: 0; line-height: 1;
  border: 0; border-radius: 6px; font-size: 16px;
  background: rgba(0, 0, 0, .55); color: #fff;
  opacity: 0; transition: opacity .12s;
}
.tile:hover .del, .tile .del:focus-visible { opacity: 1; }
.tile .del:hover { background: var(--danger); color: #fff; }

.empty { grid-column: 1 / -1; padding: 40px; text-align: center; color: var(--muted); }

.pagination { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  margin-top: 24px; font-size: 14px; }
.pg { padding: 6px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); }
.pg:hover { border-color: var(--accent); text-decoration: none; }
.pg.current { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pg.disabled, .pg.gap { opacity: .4; border-color: transparent; background: none; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 12px);
  padding: 9px 16px; border-radius: 9px; font-size: 14px;
  background: var(--text); color: var(--bg);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- admin */

.table-wrap { overflow-x: auto; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); }
table.users { border-collapse: collapse; width: 100%; font-size: 14px; }
table.users th, table.users td {
  padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.users th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.users tr:last-child td { border-bottom: 0; }
.actions { display: flex; gap: 6px; }
.actions button { padding: 4px 10px; font-size: 13px; }
.status { font-size: 12px; font-weight: 600; }
.status.pending { color: var(--warn); }
.status.active { color: var(--ok); }
.status.blocked { color: var(--danger); }
