:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #1f2328;
  --muted: #646b73;
  --line: #e4ded4;
  --accent: #b4532a;
  --accent-ink: #ffffff;
  --accent-soft: #f7e6dc;
  --ok: #2f7a4b;
  --ok-soft: #e1f1e7;
  --bad: #b42335;
  --bad-soft: #f8e1e4;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1f2226;
    --ink: #eceff1;
    --muted: #a0a7ae;
    --line: #2f343a;
    --accent: #e0814f;
    --accent-ink: #1a1a1a;
    --accent-soft: #3a2a21;
    --ok: #6cc28c;
    --ok-soft: #1f3327;
    --bad: #f08391;
    --bad-soft: #3a2226;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

/* Classes like .btn and .row set display, which would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
  text-decoration: none;
  margin-right: auto;
  white-space: nowrap;
}

.brand::before { content: "▣ "; color: var(--accent); }

nav { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

nav a, nav button {
  font: inherit;
  font-size: 0.95rem;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 999px;
  border: 0;
  background: none;
  cursor: pointer;
}

nav a[aria-current="page"] { color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }

main { max-width: 960px; margin: 0 auto; padding: 20px 16px 80px; }

main.narrow { max-width: 440px; }

h1 { font-size: 1.6rem; line-height: 1.2; margin: 8px 0 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

p.lead { color: var(--muted); margin-top: -8px; }

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

label { display: block; font-weight: 600; margin: 12px 0 6px; }
label.inline { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.hint { color: var(--muted); font-size: 0.9rem; font-weight: 400; }

input[type="text"], input[type="password"], input[type="number"], input[type="time"], select {
  width: 100%;
  font: inherit;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}

input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

input:focus, select:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
}

.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 0.9rem; }
.btn.block { width: 100%; margin-top: 18px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.msg { padding: 10px 14px; border-radius: 10px; margin: 12px 0; }
.msg.error { background: var(--bad-soft); color: var(--bad); }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg:empty { display: none; }

/* Upload */
.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 36px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .big { font-size: 2.4rem; line-height: 1; }
.drop input { display: none; }

.queue { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 10px; }
.item {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}
.item img, .item .ph { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--bg); }
.item .name { font-size: 0.85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item input { padding: 8px 10px; font-size: 0.95rem; }
.item .status { font-size: 0.9rem; margin-top: 4px; }
.item .status.ok { color: var(--ok); }
.item .status.error { color: var(--bad); }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }

/* Gallery */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { position: relative; padding: 0; border: 0; background: var(--surface); border-radius: 12px; overflow: hidden; cursor: pointer; aspect-ratio: 1; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .who {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 18px 8px 6px; font-size: 0.8rem; color: #fff; text-align: left;
  background: linear-gradient(transparent, rgb(0 0 0 / 65%));
}
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

dialog.viewer { border: 0; padding: 0; background: transparent; max-width: 100vw; max-height: 100vh; width: 100%; height: 100%; }
dialog.viewer::backdrop { background: rgb(0 0 0 / 88%); }
.viewer-inner { display: flex; flex-direction: column; height: 100%; color: #fff; }
.viewer-img { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; }
.viewer-img img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.viewer-bar { padding: 12px 16px 20px; display: grid; gap: 8px; max-width: 760px; width: 100%; margin: 0 auto; }
.viewer-bar .meta { color: #d0d4d8; font-size: 0.9rem; }
.viewer-bar input { background: rgb(255 255 255 / 10%); color: #fff; border-color: rgb(255 255 255 / 20%); }
.viewer-close { position: absolute; top: 10px; right: 12px; font-size: 1.6rem; background: rgb(0 0 0 / 40%); color: #fff; border: 0; border-radius: 999px; width: 44px; height: 44px; cursor: pointer; }

/* Admin */
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 10px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.tag { display: inline-block; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.tag.admin { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag.off { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.linkbox { display: flex; gap: 8px; margin-top: 10px; }
.linkbox input { font-family: ui-monospace, monospace; font-size: 0.85rem; }
.code { font: 700 2.6rem/1 ui-monospace, monospace; letter-spacing: 0.2em; text-align: center; padding: 14px; background: var(--bg); border-radius: 12px; margin: 10px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.scroll-x { overflow-x: auto; }

@media (max-width: 560px) {
  .hide-sm { display: none; }
  .grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .tile { border-radius: 6px; }
  .tile .who { display: none; }
}
