* { box-sizing: border-box; }

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --border: #e2e5ea;
  --radius: 10px;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; align-items: center; }

.container { max-width: 960px; margin: 1.5rem auto; padding: 0 1rem; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.page-head h1 { margin: 0 0 0.25rem; }
.actions { display: flex; gap: 0.5rem; }

.breadcrumb { color: var(--muted); margin: 0 0 0.5rem; }
.muted { color: var(--muted); }
.stat { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 0; }
.small-note { font-size: 0.8rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card.narrow { max-width: 520px; margin: 0 auto; }
.card.empty { text-align: center; color: var(--muted); }
.card h1 { margin-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
}
.grid .card { display: block; color: var(--text); }
.grid .card:hover { border-color: var(--accent); text-decoration: none; }
.grid .card h2 { margin: 0.5rem 0 0.25rem; font-size: 1.05rem; }
.grid .card p { margin: 0.25rem 0; font-size: 0.9rem; }

.item-card img, .item-card .no-photo {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
}
.no-photo {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.85rem;
}

form label { display: block; margin-bottom: 0.9rem; font-weight: 600; font-size: 0.9rem; }
form label .muted { font-weight: 400; }
form label.checkbox { font-weight: 400; }
input:not([type="checkbox"]), textarea, select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
label.checkbox input { display: inline; width: auto; margin-right: 0.4rem; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
}
legend { font-weight: 600; font-size: 0.9rem; padding: 0 0.4rem; }

.field-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.field-row input, .field-row select { margin-top: 0; }
.field-row select { width: auto; }

button, .button {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--accent-dark); text-decoration: none; }
button.secondary, .button.secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover, .button.secondary:hover { background: var(--bg); }
button.danger { background: var(--danger); }
button.small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

.searchbar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.searchbar input { margin-top: 0; flex: 1; }

.tag {
  display: inline-block;
  background: #e8edfb;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.75rem;
  margin: 0 0.25rem 0.25rem 0;
}

.flash { padding: 0.7rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error, .flash-message { background: #fee2e2; color: #991b1b; }

.item-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 720px) { .item-layout { grid-template-columns: 1fr; } }

.details { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0.75rem 0; }
.details dt { font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.details dd { margin: 0; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}
.photo-grid figure { margin: 0; text-align: center; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  margin-bottom: 1rem;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.dragover { border-color: var(--accent); background: #eef2fe; }
.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.dropzone-hint { margin: 0; color: var(--muted); }
.dropzone-hint .link { color: var(--accent); text-decoration: underline; }

.photo-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 0.75rem;
}
.photo-previews:empty { margin-top: 0; }
.photo-previews figure { position: relative; margin: 0; }
.photo-previews img {
  width: 90px;
  height: 90px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}
.remove-photo {
  position: absolute;
  top: -6px;
  right: -6px;
  padding: 0;
  width: 22px;
  height: 22px;
  line-height: 22px;
  font-size: 0.7rem;
  border-radius: 50%;
  background: var(--danger);
}

/* ---------- Dashboard ---------- */

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card { text-align: center; padding: 1rem; }
.stat-number { display: block; font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

.section-head { font-size: 1.15rem; margin: 1.5rem 0 0.6rem; }
.section-head a { color: var(--text); }
.section-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.count-badge {
  background: #e8edfb;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 0.05rem 0.6rem;
  font-size: 0.8rem;
  vertical-align: middle;
}
.small-btn { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.collection-section { margin-bottom: 1rem; }

.mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.6rem;
}
.mini-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem;
  color: var(--text);
  font-size: 0.8rem;
  text-align: center;
}
.mini-card:hover { border-color: var(--accent); text-decoration: none; }
.mini-card img, .mini-card .no-photo {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 5px;
  background: var(--bg);
}
.mini-name {
  display: block;
  margin-top: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Item cards: link area + inline edit ---------- */

.item-card { position: relative; }
.item-card .card-link { display: block; color: var(--text); }
.item-card .card-link:hover { text-decoration: none; }
.item-card .card-link:hover h2 { color: var(--accent); }
.item-card .edit-btn { margin-top: 0.5rem; }
.item-card.editing .edit-btn { display: none; }

.inline-edit { margin-top: 0.6rem; border-top: 1px solid var(--border); padding-top: 0.6rem; }
.inline-edit label { font-size: 0.8rem; margin-bottom: 0.5rem; }
.inline-edit input { padding: 0.35rem 0.5rem; font-size: 0.85rem; }
.inline-edit-actions { display: flex; gap: 0.5rem; }

/* ---------- AI ---------- */

.ai-suggest {
  background: none;
  border: none;
  padding: 0 0.2rem;
  font-size: 0.95rem;
  cursor: pointer;
  vertical-align: middle;
}
.ai-suggest:disabled { opacity: 0.3; cursor: default; }
.ai-suggest:not(:disabled):hover { transform: scale(1.2); background: none; }
.ai-hint { margin-top: -0.5rem; }
.ai-status { color: var(--accent-dark); font-size: 0.9rem; margin-top: 0.5rem; }

.ai-filled {
  outline: 2px solid #16a34a !important;
  outline-offset: -1px;
  transition: outline-color 0.3s;
}

#f-name, #f-description, #f-category, #f-location, #f-tags {
  margin-bottom: 0.9rem;
}
label[for] { margin-bottom: 0.3rem; }

.suggestion-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  margin-bottom: 0.4rem;
}
.suggestion-row input[type="checkbox"] { width: auto; margin: 0; }

/* ---------- Toasts ---------- */

#toast-holder {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  font-size: 0.9rem;
  max-width: 320px;
}

/* ---------- Mobile photo buttons ---------- */

.mobile-photo-buttons { display: flex; gap: 0.6rem; justify-content: center; }
.mobile-only { display: none; }
@media (max-width: 720px) {
  .mobile-only { display: flex; }
  .desktop-only { display: none; }
}

/* ---------- Settings / API ---------- */

.token-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.token-row code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  word-break: break-all;
  flex: 1;
}
.api-doc {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  overflow-x: auto;
}

/* ---------- Theme picker ---------- */

.theme-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}
.theme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  cursor: pointer;
  font-weight: 400;
  text-align: center;
  margin-bottom: 0;
}
.theme-option:has(input:checked) { border-color: var(--accent); background: #f5f8ff; }
.theme-option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.theme-name { font-weight: 600; font-size: 0.85rem; }
.theme-desc { font-size: 0.72rem; }

.theme-preview {
  width: 100%;
  height: 52px;
  border-radius: 4px;
  background: var(--bg);
  padding: 5px;
  display: grid;
  gap: 3px;
}
.theme-preview i, .theme-preview b { background: #c7cede; border-radius: 2px; display: block; }
.preview-standard { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr 1fr; }
.preview-gallery { background: #f4f1ea; grid-template-rows: 1fr 8px; justify-items: center; }
.preview-gallery i { width: 55%; background: #b3a68f; }
.preview-gallery b { width: 35%; height: 4px; background: #8d8371; }
.preview-compact { grid-template-rows: repeat(4, 1fr); }

/* ---------- Gallery theme (museum style) ---------- */

.theme-gallery {
  font-family: Georgia, "Times New Roman", serif;
}
.theme-gallery h1 {
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0.01em;
}
.theme-gallery .stat, .theme-gallery .breadcrumb { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

/* Collection listing: borderless museum browse grid */
.gallery-browse {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 2.5rem 2rem;
  margin-top: 1.5rem;
}
.gallery-tile { margin: 0; text-align: center; }
.gallery-tile img {
  width: 100%;
  height: 220px;
  object-fit: contain;
  background: #f7f4ee;
  transition: transform 0.2s;
}
.gallery-tile a:hover img { transform: scale(1.02); }
.gallery-no-photo {
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ece7dc;
  color: #8d8371;
  font-style: italic;
}
.gallery-tile figcaption { margin-top: 0.75rem; }
.gallery-title {
  font-size: 1.05rem;
  font-style: italic;
  color: var(--text);
}
.gallery-title:hover { color: var(--accent); text-decoration: none; }
.gallery-medium { margin: 0.25rem 0 0; color: #6d675c; font-size: 0.85rem; }

/* Item detail: museum object page */
.gallery-hero {
  text-align: center;
  background: #f7f4ee;
  border-radius: var(--radius);
  padding: 3rem 2rem;
  margin-bottom: 2rem;
}
.gallery-hero img {
  max-width: 100%;
  max-height: 72vh;
  box-shadow: 0 12px 34px rgba(60, 50, 30, 0.2);
}
.gallery-object {
  max-width: 640px;
  margin: 0 auto 2rem;
  text-align: center;
}
.gallery-eyebrow {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 0.72rem;
  color: #8d8371;
  margin: 0 0 0.4rem;
}
.gallery-object-title {
  font-weight: 400;
  font-style: italic;
  font-size: 2rem;
  margin: 0 0 1.25rem;
}
.gallery-labels { margin-bottom: 1.5rem; }
.gallery-labels p { margin: 0.3rem 0; color: #4d4a42; }
.gallery-labels p span {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.65rem;
  color: #8d8371;
  margin-bottom: 0.05rem;
}
.gallery-walltext {
  text-align: left;
  font-size: 1.05rem;
  line-height: 1.75;
  color: #3a382f;
  margin: 0 0 1.5rem;
}
.gallery-tags { margin-bottom: 1.5rem; }
.theme-gallery .photo-grid { margin-top: 0.5rem; }
.theme-gallery .section-head { font-style: italic; font-weight: 400; }

/* ---------- Compact theme ---------- */

.list-card { padding: 0.5rem 1rem; }
.compact-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.compact-table th, .compact-table td {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.compact-table tbody tr:last-child td { border-bottom: none; }
.compact-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }
.thumb-cell { width: 44px; }
.thumb-cell img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}

/* ---------- Admin ---------- */

.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.admin-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.photo-grid img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 0.4rem;
}
