:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #65758b;
  --line: #dbe2ea;
  --accent: #0f766e;
  --accent-strong: #0b5e58;
  --gold: #b7791f;
  --danger: #b42318;
  --topbar-bg: #102026;
  --topbar-text: #ffffff;
  --eyebrow: #9bd7ce;
  --soft-accent: #e7f4f2;
  --soft-accent-line: #b9ded8;
  --field-bg: #ffffff;
  --shadow: 0 12px 30px rgba(15, 32, 38, 0.06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-template="gallery"] {
  --bg: #f7f7f4;
  --panel: #ffffff;
  --text: #1f2428;
  --muted: #687073;
  --line: #d8ddd9;
  --topbar-bg: #27342f;
  --topbar-text: #fbfffc;
  --eyebrow: #b8d8ca;
  --soft-accent: #eef6f1;
  --soft-accent-line: #c7ded2;
  --field-bg: #ffffff;
  --shadow: 0 10px 24px rgba(39, 52, 47, 0.08);
}

:root[data-template="darkroom"] {
  --bg: #181716;
  --panel: #24211f;
  --text: #f1ede6;
  --muted: #b8b0a4;
  --line: #3b3834;
  --topbar-bg: #0f0e0d;
  --topbar-text: #f8f4ec;
  --eyebrow: #d6b46d;
  --soft-accent: #2e2b27;
  --soft-accent-line: #5a4b2f;
  --field-bg: #1e1c1a;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

:root[data-font="serif"] {
  font-family: Georgia, "Times New Roman", serif;
}

:root[data-font="mono"] {
  font-family: "Cascadia Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px);
  background: var(--topbar-bg);
  color: var(--topbar-text);
}

.topbar-search {
  display: flex;
  align-items: end;
  gap: 12px;
  width: min(620px, 52vw);
}

.topbar-search label {
  color: var(--topbar-text);
}

.topbar-search .search {
  flex: 1 1 280px;
}

.topbar-search label:not(.search) {
  flex: 0 1 180px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--eyebrow);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.6rem);
}

.layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) 1fr;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px) 48px;
}

.login-screen {
  display: grid;
  place-items: start center;
  padding: 48px clamp(18px, 4vw, 48px);
}

.login-form {
  width: min(440px, 100%);
}

.sidebar,
.content {
  min-width: 0;
}

@media (min-width: 821px) {
  body[data-admin="true"] {
    display: grid;
    grid-template-rows: auto 1fr;
    height: 100vh;
    overflow: hidden;
  }

  body[data-admin="true"] .topbar {
    position: relative;
    z-index: 10;
  }

  body[data-admin="true"] .layout {
    min-height: 0;
    overflow: hidden;
    padding-bottom: 24px;
  }

  body[data-admin="true"] .sidebar,
  body[data-admin="true"] .content {
    min-height: 0;
    overflow: auto;
  }
}

.sidebar-toggle {
  flex: 0 0 auto;
  color: var(--topbar-text);
  background: rgba(255, 255, 255, 0.14);
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.22);
}

body.sidebar-collapsed .layout {
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}

body.sidebar-collapsed .sidebar {
  display: none;
}

.panel,
.toolbar,
.image-card,
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 16px;
  margin-bottom: 18px;
}

.stats strong {
  display: block;
  font-size: 1.6rem;
}

.stats span {
  color: var(--muted);
  font-size: 0.78rem;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.section-title h2 {
  margin: 0;
  font-size: 1rem;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.album-list {
  display: grid;
  padding: 12px;
}

.album-row {
  display: grid;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.album-row:last-child {
  border-bottom: 0;
}

.album {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  width: 100%;
  padding: 10px 12px 10px calc(12px + (var(--album-depth, 0) * 18px));
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  text-align: left;
}

.album-list > .album:first-child {
  grid-template-columns: 1fr;
}

.album.active,
.album:hover {
  background: var(--soft-accent);
  border-color: var(--soft-accent-line);
}

.album.is-hidden {
  color: var(--muted);
  background: var(--field-bg);
}

.album small {
  color: var(--muted);
}

.album-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-left: calc(12px + (var(--album-depth, 0) * 18px));
}

.album-row-actions button {
  min-height: 0;
  padding: 5px 8px;
  color: var(--accent-strong);
  background: var(--soft-accent);
  border: 0;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
}

.album-row-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.album-row-actions .danger-action {
  color: var(--danger);
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
  margin-bottom: 18px;
}

.toolbar label:not(.search):not(.toggle) {
  min-width: 140px;
}

.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: -6px 0 18px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.bulk-bar strong {
  margin-right: 6px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--field-bg);
}

.drop-zone {
  position: relative;
  display: grid;
  gap: 8px;
  place-items: center;
  min-height: 132px;
  padding: 20px;
  color: var(--muted);
  background: var(--field-bg);
  border: 2px dashed #b9c8d6;
  border-radius: 8px;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.drop-zone strong {
  color: var(--text);
}

.drop-zone.dragging {
  background: var(--soft-accent);
  border-color: var(--accent);
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.search {
  flex: 1;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.toggle input {
  width: auto;
}

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

:root[data-density="compact"] .gallery {
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}

:root[data-density="roomy"] .gallery {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

:root[data-layout="masonry"] .gallery {
  align-items: start;
}

.image-card {
  position: relative;
  overflow: hidden;
}

.image-card.is-hidden-photo {
  opacity: 0.58;
}

.select-photo {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  padding: 6px 8px;
  color: var(--text);
  background: var(--panel);
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(16, 32, 38, 0.15);
}

.select-photo input {
  width: auto;
}

.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: var(--line);
  transition: transform 0.18s ease;
}

.image-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.image-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.image-title h3 {
  margin: 0;
  font-size: 1.05rem;
}

.image-body p {
  margin: 0;
  color: var(--text);
  line-height: 1.45;
}

.meta,
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tags span {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--soft-accent);
  color: var(--text);
  font-size: 0.78rem;
}

.metadata,
.viewer-metadata {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.metadata dt,
.viewer-metadata dt {
  font-weight: 700;
}

.metadata dd,
.viewer-metadata dd {
  margin: 0;
}

.card-actions {
  justify-content: space-between;
  align-items: center;
}

.card-actions a,
.card-actions button {
  color: var(--accent-strong);
  background: transparent;
  border: 0;
  padding: 0;
  text-decoration: none;
}

.card-actions button {
  color: var(--accent-strong);
}

.card-actions button[data-template="delete"] {
  color: var(--danger);
}

.rating-control {
  display: inline-flex;
  gap: 3px;
}

.rating-control button {
  min-width: 22px;
  padding: 2px 4px;
  border-radius: 4px;
}

.rating-control button.active {
  color: #fff;
  background: var(--gold);
}

.danger-action {
  color: var(--danger);
}

.primary,
.secondary,
.icon-button,
.favorite {
  border: 0;
  border-radius: 6px;
  min-height: 40px;
}

.primary {
  padding: 10px 16px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.primary:hover {
  background: var(--accent-strong);
}

.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  color: var(--text);
  background: var(--soft-accent);
  font-weight: 700;
}

.secondary.compact {
  min-height: 36px;
  padding: 8px 10px;
  font-size: 0.86rem;
}

.secondary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary:hover {
  background: var(--soft-accent-line);
}

.admin-link {
  margin-left: auto;
  color: var(--topbar-text);
  font-weight: 700;
  text-decoration: none;
}

.admin-link:hover {
  color: var(--eyebrow);
}

.icon-button,
.favorite {
  display: inline-grid;
  place-items: center;
  width: 40px;
  color: var(--text);
  background: var(--soft-accent);
  font-size: 1.2rem;
}

.favorite {
  flex: 0 0 36px;
  width: 36px;
  min-height: 36px;
  color: #7b8794;
}

.favorite.on {
  color: #fff;
  background: var(--gold);
}

dialog {
  width: min(640px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(16, 32, 38, 0.55);
}

.image-viewer {
  position: relative;
  display: grid;
  place-items: center;
  padding: 18px;
}

.image-viewer .icon-button {
  position: absolute;
  top: 28px;
  right: 28px;
  z-index: 1;
}

.image-viewer .viewer-prev,
.image-viewer .viewer-next {
  top: 50%;
  right: auto;
  transform: translateY(-50%);
}

.image-viewer .viewer-prev {
  left: 28px;
}

.image-viewer .viewer-next {
  right: 28px;
}

.viewer-slideshow {
  position: absolute;
  right: 78px;
  top: 28px;
  z-index: 1;
}

.viewer-fullscreen {
  position: absolute;
  right: 190px;
  top: 28px;
  z-index: 1;
}

.viewer-metadata {
  position: absolute;
  left: 28px;
  bottom: 28px;
  max-width: min(420px, calc(100vw - 56px));
  padding: 12px;
  color: #fff;
  background: rgba(16, 32, 38, 0.82);
  border-radius: 8px;
}

.image-viewer img {
  display: block;
  max-width: min(1100px, calc(100vw - 72px));
  max-height: calc(100vh - 72px);
  background: #fff;
  border: 8px solid #fff;
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(16, 32, 38, 0.35), 0 24px 70px rgba(0, 0, 0, 0.45);
}

.modal {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h2 {
  margin: 0;
}

.display-settings {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.dialog-intro {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.display-settings legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.display-option {
  grid-template-columns: auto 1fr 68px 32px 32px;
  align-items: center;
  gap: 10px;
}

.display-option input[type="checkbox"] {
  width: auto;
}

.display-option input[type="number"] {
  padding: 6px 8px;
}

.display-option button {
  width: 32px;
  min-height: 32px;
  padding: 0;
  color: var(--accent-strong);
  background: var(--soft-accent);
  border: 0;
  border-radius: 6px;
  font-weight: 700;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.inline-actions button,
.inline-actions .secondary {
  min-height: 36px;
  padding: 8px 10px;
  color: var(--accent-strong);
  background: var(--soft-accent);
  border: 0;
  border-radius: 6px;
  font-weight: 700;
}

.theme-upload {
  width: auto;
  cursor: pointer;
}

.activity-list {
  display: grid;
  gap: 8px;
  max-height: 60vh;
  overflow: auto;
}

.activity-item {
  padding: 10px 12px;
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.empty,
.error,
.form-status {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.form-status {
  margin: 0;
  padding: 10px 12px;
  color: var(--muted);
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.form-status.error {
  color: var(--danger);
  background: #fff5f5;
  border-color: #f3b3ac;
}

.setup-error {
  display: block;
  max-width: 760px;
  margin: 12vh auto;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

body[data-admin="true"] .layout.setup-error {
  overflow: auto;
}

.setup-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 18px 0;
  color: var(--muted);
}

.setup-details dt {
  font-weight: 700;
  color: var(--text);
}

.setup-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 820px) {
  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-search {
    width: 100%;
    flex-wrap: wrap;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .split {
    grid-template-columns: 1fr;
  }
}
