:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2b5cff;
  --accent-text: #ffffff;
  --danger: #d92d20;
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1e2127;
    --text: #e8eaed;
    --muted: #9aa0a8;
    --border: #2e323a;
    --accent: #5b82ff;
    --danger: #f04438;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, .button, input {
  font: inherit;
}

button, .button {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:disabled { opacity: 0.6; cursor: wait; }
.primary { background: var(--accent); color: var(--accent-text); }
.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.danger { background: transparent; color: var(--danger); border-color: var(--danger); }

input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

label { display: grid; gap: 0.35rem; font-size: 0.9rem; }

.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }

/* ---------- Kopfzeile ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar form { margin: 0; }
.logo { font-size: 1.2rem; margin: 0; white-space: nowrap; }
#search { flex: 1; max-width: 560px; margin: 0 auto; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 0.75rem 1rem; }
  .logo { flex: 1; }
  #search { order: 10; flex-basis: 100%; max-width: none; }
}

/* ---------- Galerie ---------- */

main { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.card {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  transition: transform 0.12s, box-shadow 0.12s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgb(0 0 0 / 0.12); }
.card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--bg);
  display: block;
}
.caption {
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Dialoge ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.5rem;
  width: min(480px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / 0.55); }
dialog h2 { margin: 0 0 1rem; font-size: 1.2rem; }
dialog form { display: grid; gap: 1rem; }

.actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }

.dropzone {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.dropzone img { max-width: 100%; max-height: 260px; border-radius: 8px; }

dialog.view { width: min(960px, calc(100vw - 32px)); }
.view > img {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  margin: 0 auto 1rem;
  border-radius: 8px;
}
.view .rename { display: flex; gap: 0.5rem; margin-bottom: 1rem; }

/* ---------- Login ---------- */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  display: grid;
  gap: 1rem;
  width: min(360px, 100%);
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card .muted { margin: -0.5rem 0 0; }

[hidden] { display: none !important; }
