:root {
  --background: #fdfcfb;
  --foreground: #3d3935;
  --card: #ffffff;
  --border: rgba(196, 19, 0, 0.2);
  --muted-foreground: #6b6560;
  --primary: #c41300;
  --primary-600: #970f00;
  --primary-700: #970f00;
  --radius-panel: 24px;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--foreground);
  background: var(--background);
  line-height: 1.55;
}

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 20px; }
a { color: var(--primary-700); text-decoration: none; }
a:hover { text-decoration: underline; }
.site-main { padding: 40px 0 60px; }

.empty-state { color: var(--muted-foreground); }
.form-error { background: #fdeceb; color: #a12a22; padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }

/* ---------- shared form styling (login + admin) ---------- */

.portal-form { display: flex; flex-direction: column; gap: 16px; max-width: 420px; }
.portal-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9rem; }
.portal-form .hint { font-weight: 400; color: var(--muted-foreground); }
.portal-form input,
.portal-form select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.portal-form button {
  align-self: flex-start;
  padding: 10px 24px;
  background: var(--primary-600);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.portal-form button:hover { opacity: 0.92; }

/* ---------- login ---------- */

.login-wrap { max-width: 480px; padding-top: 20px; }
.login-sub { color: var(--muted-foreground); margin-bottom: 24px; }

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

.admin-wrap { max-width: 720px; }
.admin-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: 24px;
  margin-bottom: 24px;
}
.admin-section h2 { margin-top: 0; }
.admin-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 0.9rem; }
.admin-table th, .admin-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--muted-foreground); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.admin-table-actions { display: flex; align-items: center; gap: 14px; }
.admin-table-actions form { margin: 0; }
.admin-table-actions a,
.admin-table-actions button {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.admin-table-actions button { color: #a12a22; }
.admin-table-actions a:hover,
.admin-table-actions button:hover { text-decoration: underline; }
.upload-result { background: rgba(196, 19, 0, 0.06); border-radius: 12px; padding: 16px 18px; margin-bottom: 20px; }
.upload-result code { background: rgba(0, 0, 0, 0.06); padding: 1px 6px; border-radius: 4px; }
.portal-form-actions { display: flex; align-items: center; gap: 16px; }
.button-link { font-weight: 600; color: var(--muted-foreground); }
.button-link:hover { color: var(--foreground); }

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

.gallery-title { margin: 0 0 32px; }

/* ---------- portal nav: brand + categories + logout, one menu ---------- */

/* Mobile default: a fixed top header bar (logo + burger) that floats over
   the page and never scrolls away; expands downward when opened. */
.portal-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--card);
  border: none;
  border-radius: 0;
  box-shadow: 0 2px 10px rgba(61, 57, 53, 0.1);
  margin-bottom: 0;
  overflow: hidden;
}
.portal-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
}
.portal-nav-brand { display: flex; align-items: center; gap: 8px; color: var(--foreground); }
.portal-nav-brand:hover { text-decoration: none; }
.portal-nav-logo { width: 26px; height: 26px; }
.portal-nav-brand-text { font-weight: 700; letter-spacing: -0.02em; }
.portal-nav-brand-text b { color: var(--primary); font-weight: 700; }

.portal-nav-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}
.portal-nav-toggle span { width: 22px; height: 2px; background: var(--foreground); border-radius: 2px; }

.portal-nav-body { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
.portal-nav-body.open { max-height: calc(100vh - 60px); overflow-y: auto; }

.portal-nav-categories { list-style: none; margin: 0; padding: 0 18px 14px; display: flex; flex-direction: column; gap: 10px; }
.portal-nav-categories a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-foreground);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
}
.portal-nav-categories a svg { flex: none; color: var(--primary); }
.portal-nav-categories a:hover { color: var(--primary-700); text-decoration: none; }
.portal-nav-categories a:hover svg { color: var(--primary-700); }

.portal-nav-logout-form { border-top: 1px solid var(--border); padding: 14px 18px; }
.portal-nav-logout {
  width: 100%;
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  cursor: pointer;
}
.portal-nav-logout:hover { border-color: var(--primary); color: var(--primary-700); }

/* Content clears the fixed mobile header bar; desktop overrides this back
   out since the sidebar there sits beside the content, not above it. */
.gallery-main { margin-top: 68px; }

/* Desktop: a fixed sidebar that never scrolls with the page, always
   expanded, no burger. Pinned to the screen's left edge with a small
   margin. */
@media (min-width: 900px) {
  .portal-nav {
    top: 24px;
    left: 20px;
    right: auto;
    width: 300px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    border-radius: var(--radius-panel);
    box-shadow: none;
    display: flex;
    flex-direction: column;
  }
  .portal-nav-toggle { display: none; }
  .portal-nav-body { max-height: none; overflow: visible; display: flex; flex-direction: column; flex: 1; }
  .portal-nav-logout-form { margin-top: auto; }
  /* The generic .wrap centers itself with margin:auto, which drifts away
     from the screen-fixed sidebar as the viewport widens (and doing this
     via 100vw math instead is unreliable — 100vw includes the scrollbar
     width but the wrap's own centering doesn't, so they'd disagree). So
     .gallery-wrap opts out of centering and instead pads its content over
     by the sidebar's fixed screen position (20px left + 300px width) plus
     an 8px gap — that keeps the gap exactly 8px at any viewport width. */
  .gallery-wrap { max-width: none; margin: 0; padding-left: 328px; }
  .gallery-main { margin-top: 0; margin-left: 0; }
  .gallery-category { scroll-margin-top: 24px; }
}

.gallery-categories { min-width: 0; }
/* Extra scroll-margin on mobile so jumping to a category via the nav
   doesn't leave its H2 hidden behind the fixed header bar. */
.gallery-category { margin-bottom: 40px; scroll-margin-top: 80px; }
.gallery-category > h2 {
  font-size: 1.5rem;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 8px;
  margin-bottom: 20px;
}
.gallery-subcategory { margin-bottom: 24px; }
.gallery-subcategory h3 { font-size: 1.05rem; margin-bottom: 12px; }
.photo-count { color: var(--muted-foreground); font-weight: 400; font-size: 0.85em; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.photo-thumb {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: zoom-in;
  background: none;
  aspect-ratio: 1;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb:hover { border-color: var(--primary); }

/* ---------- lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 13, 0.92);
  z-index: 2000;
  padding: 40px;
  display: none;
}
/* [hidden] and .lightbox are equal-specificity selectors, so without this
   :not() rule, whichever stylesheet loads later wins the display property
   regardless of the hidden attribute — this makes hidden win explicitly. */
.lightbox:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 1;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  transform-origin: center;
  transition: transform 0.15s ease;
  touch-action: none;
}
/* Hides the previous photo's pixels the instant a new one starts loading —
   without this, the browser keeps the old frame on screen until the new
   image finishes decoding, which reads as swiping being stuck. */
.lightbox img.is-loading { opacity: 0; }
.lightbox img.is-zoomed { cursor: grab; }
.lightbox img.is-zoomed.is-dragging { cursor: grabbing; transition: none; }
.lightbox-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lightbox-spin 0.8s linear infinite;
  z-index: 2;
}
.lightbox-spinner[hidden] { display: none; }
@keyframes lightbox-spin {
  to { transform: rotate(360deg); }
}
.lightbox-close, .lightbox-nav, .lightbox-toolbar button {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1.6rem;
  line-height: 1;
}
.lightbox-filename {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 10;
  max-width: calc(100% - 84px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lightbox-close, .lightbox-nav { position: absolute; z-index: 10; }
.lightbox-close { top: 20px; right: 20px; width: 44px; height: 44px; }
.lightbox-nav { top: 50%; transform: translateY(-50%); width: 52px; height: 52px; }
.lightbox-prev { left: 20px; }
.lightbox-next { right: 20px; }
.lightbox-close:hover, .lightbox-nav:hover, .lightbox-toolbar button:hover { background: rgba(255, 255, 255, 0.25); }

.lightbox-toolbar {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 10;
}
.lightbox-toolbar button { width: 44px; height: 44px; font-size: 1.3rem; }

@media (max-width: 640px) {
  .lightbox { padding: 16px; }
  .lightbox-nav { width: 40px; height: 40px; font-size: 1.3rem; }
  .lightbox-toolbar { bottom: 12px; }
  .lightbox-toolbar button { width: 38px; height: 38px; font-size: 1.1rem; }
}
