:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #e2e5eb;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-contrast: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { overflow-x: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}
button:hover { background: #e4e7ed; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.link-btn { background: transparent; border-color: transparent; }
.link-btn:hover { background: var(--surface-2); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 1.2rem; margin: 0; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

main { padding: 1rem 1.2rem 3rem; max-width: 1400px; margin: 0 auto; }

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

.category-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.category-card:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(16, 24, 40, 0.1); }
.category-thumb {
  height: 140px;
  background-size: cover;
  background-position: center;
  background-color: var(--surface-2);
}
.category-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  gap: 0.4rem;
}
.category-label { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-count { color: var(--muted); font-size: 0.8rem; }
.edit-label { padding: 0.2rem 0.4rem; background: transparent; border-color: transparent; }

.photo-tile {
  margin: 0;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.photo-tile img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
.photo-tile figcaption {
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.photo-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-date { color: var(--muted); }
.photo-dl {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(17, 20, 28, 0.55);
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 1rem;
}

.empty { color: var(--muted); text-align: center; margin-top: 3rem; }
.muted { color: var(--muted); }

/* Lightbox zostaje celowo ciemny - standard dla podgladu zdjec, nie mesza swiatlem i nie rozprasza od fotografii */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 14, 0.96);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.lightbox:not([hidden]) {
  display: flex;
}
.lightbox img { max-width: 92vw; max-height: 78vh; object-fit: contain; }
.lb-close {
  position: absolute; top: 1rem; right: 1.2rem;
  font-size: 1.8rem; background: transparent; color: #fff; border-color: transparent;
}
.lb-close:hover { background: rgba(255, 255, 255, 0.12); }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 2.5rem; background: transparent; color: #fff; border-color: transparent; padding: 0 1rem;
}
.lb-nav:hover { background: rgba(255, 255, 255, 0.1); }
.lb-prev { left: 0.5rem; }
.lb-next { right: 0.5rem; }
.lb-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(92vw, 700px);
  margin-top: 0.8rem;
  color: #f0f1f4;
}
.lb-caption .muted { color: #a7abb8; }
.lb-caption a {
  color: var(--accent-contrast);
  background: var(--accent);
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  text-decoration: none;
}
.lb-caption a:hover { background: var(--accent-hover); }

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.18);
}
dialog::backdrop { background: rgba(31, 36, 48, 0.35); }
dialog label { display: flex; flex-direction: column; gap: 0.3rem; margin: 0.6rem 0; }
dialog input {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}
dialog input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
.dialog-actions button[type="submit"] { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.dialog-actions button[type="submit"]:hover { background: var(--accent-hover); }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 0.5rem !important; }

#upload-dialog { width: min(90vw, 440px); }
#upload-new-category { margin-bottom: 0.8rem; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.dropzone.dragover {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(79, 70, 229, 0.06);
}
.dropzone button { margin-left: 0.3rem; }

.upload-file-list {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  font-size: 0.85rem;
}
.upload-file-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}
.upload-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
  flex-shrink: 0;
}
.upload-thumb.broken { display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.upload-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-file-list button {
  background: transparent;
  border-color: transparent;
  padding: 0 0.4rem;
  color: var(--muted);
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2rem;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: min(90vw, 320px);
  box-shadow: var(--shadow);
}
.login-box h1 { margin: 0 0 0.5rem; font-size: 1.3rem; text-align: center; }
.login-box input {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
}
.login-box input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-box button { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.login-box button:hover { background: var(--accent-hover); }
.error { color: #dc2626; margin: 0; font-size: 0.85rem; }

/* --- Mobile --- */
@media (max-width: 640px) {
  .topbar { padding: 0.6rem 0.8rem; }
  .topbar h1 { font-size: 1.05rem; width: 100%; }
  .actions { width: 100%; }
  .actions button { flex: 1 1 auto; font-size: 0.8rem; padding: 0.5rem 0.5rem; white-space: nowrap; }

  main { padding: 0.8rem 0.8rem 2rem; }

  .category-grid, .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
    gap: 0.6rem;
  }
  .category-thumb { height: 100px; }
  .photo-tile img { height: 110px; }
  .photo-tile figcaption { font-size: 0.7rem; }

  .lightbox img { max-width: 96vw; max-height: 68vh; }
  .lb-nav { font-size: 2rem; padding: 0 0.4rem; }
  .lb-close { font-size: 1.6rem; top: 0.6rem; right: 0.8rem; }
  .lb-caption {
    flex-direction: column;
    align-items: stretch;
    width: 94vw;
    gap: 0.6rem;
  }
  .lb-caption a { text-align: center; }

  dialog, #upload-dialog { width: 92vw; max-height: 85vh; overflow-y: auto; }
}
