:root {
  color-scheme: light dark;
  --bg: #fafafa;
  --fg: #1a1a1a;
  --card: #ffffff;
  --border: #e0e0e0;
  --accent: #2b6cd9;
  --muted: #6b6b6b;
  --danger: #c0392b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --fg: #eaeaea;
    --card: #1e2126;
    --border: #2c2f36;
    --muted: #9a9a9a;
    --danger: #e74c3c;
  }
}

* { box-sizing: border-box; }

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

nav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

nav a {
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
}

nav .spacer { flex: 1; }

nav .brand { font-weight: 700; }

.nav-button,
.nav-link {
  padding: 0.45rem 1rem;
  border-radius: 8px;
  font-size: 0.92rem;
  transition: opacity 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.nav-button {
  background: var(--accent);
  color: #fff;
}

.nav-button:hover { opacity: 0.88; }

.nav-link {
  border: 1px solid var(--border);
  color: var(--fg);
}

.nav-link:hover { border-color: var(--accent); color: var(--accent); }

.admin-menu { position: relative; }

.admin-menu-trigger {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.admin-menu-trigger:hover,
.admin-menu-trigger:focus-visible { border-color: var(--accent); }

.admin-menu-trigger .caret {
  font-size: 0.7em;
  opacity: 0.7;
  transition: transform 0.15s ease;
}

.admin-menu:hover .caret,
.admin-menu:focus-within .caret { transform: rotate(180deg); }

.admin-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  min-width: 170px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  padding: 0.35rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  z-index: 20;
}

.admin-menu:hover .admin-menu-dropdown,
.admin-menu:focus-within .admin-menu-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.admin-menu-dropdown a {
  display: block;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.92rem;
}

.admin-menu-dropdown a:hover { background: var(--bg); color: var(--accent); }

.admin-menu-dropdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.35rem 0.2rem;
}

.menu-badge {
  display: inline-block;
  min-width: 1.35em;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.5rem;
}

main.wide { max-width: 960px; }

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

.messages {
  list-style: none;
  padding: 0.75rem 1rem;
  margin: 0 0 1.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

.card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: var(--fg);
}

.card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}

.card-body { padding: 0.75rem 1rem; }
.card-body h3 { margin: 0 0 0.25rem; font-size: 1rem; }

.no-photo {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.price { font-weight: 600; margin: 0; }
.sold { color: var(--muted); font-weight: 400; }

.detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.gallery {
  display: grid;
  gap: 0.75rem;
}

.gallery img {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.detail-info form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.detail-info label { font-weight: 600; font-size: 0.9rem; }

.detail-info input,
.detail-info textarea {
  font: inherit;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
}

.detail-info button {
  align-self: flex-start;
  margin-top: 0.5rem;
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 640px) {
  .detail { grid-template-columns: 1fr; }
}

.listing-form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
}

.listing-form-card h2 { margin-top: 0; }

.listing-form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  margin-top: 1rem;
}

.listing-form label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.listing-form input[type="text"],
.listing-form input[type="number"],
.listing-form input[type="file"],
.listing-form textarea {
  width: 100%;
  font: inherit;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  transition: border-color 0.15s ease;
}

.listing-form input:focus,
.listing-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.listing-form textarea { resize: vertical; }

.listing-form .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
}

.listing-form .checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  cursor: pointer;
}

.listing-form .checkbox-label input {
  width: auto;
  margin: 0;
}

.listing-form button {
  align-self: flex-start;
  margin-top: 0.25rem;
  padding: 0.65rem 1.4rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.listing-form button:hover { opacity: 0.88; }

@media (max-width: 640px) {
  .listing-form .form-row { grid-template-columns: 1fr; }
}

.dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.5rem 1rem;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--bg);
}

.dropzone-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  pointer-events: none;
}

.dropzone-filelist {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  font-size: 0.85rem;
  color: var(--fg);
  pointer-events: none;
}

.dropzone-filelist li { padding: 0.1rem 0; }

.listing-form .dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  opacity: 0;
  cursor: pointer;
}

.field-hint {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.photo-editor {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.photo-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

.photo-row.dragging { opacity: 0.4; }

.photo-row.to-remove {
  opacity: 0.5;
}

.photo-row.to-remove .caption-input { text-decoration: line-through; }

.photo-row .drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 0 0.15rem;
}

.photo-row img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.photo-row .cover-tag {
  display: none;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #fff;
  background: var(--accent);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.photo-row.is-cover .cover-tag { display: inline-block; }

.photo-row .caption-input {
  flex: 1;
  width: auto;
  min-width: 0;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.photo-row-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.photo-row .move-btn {
  font: inherit;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.photo-row .move-btn:hover { border-color: var(--accent); color: var(--accent); }

.photo-row .remove-toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  font-size: 0.8rem;
  font-weight: 400;
  white-space: nowrap;
  cursor: pointer;
}

.photo-row .remove-toggle input { width: auto; margin: 0; }

.advanced-fields summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.advanced-fields > div { margin-top: 0.75rem; }

.danger-zone {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.danger-zone .field-hint { margin: 0; }

.btn-danger {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-danger:hover { background: var(--danger); color: #fff; }

@media (max-width: 560px) {
  .photo-row { flex-wrap: wrap; }
  .photo-row .caption-input { flex-basis: 100%; order: 3; }
}

.editor-tools {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.25rem 0 0.75rem;
}

.footer-edit {
  margin: 0.6rem 0 0;
}

.footer-edit summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.footer-edit-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.footer-edit-form textarea {
  width: 100%;
  font: inherit;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  resize: vertical;
}

.footer-edit-form button {
  align-self: flex-start;
  padding: 0.4rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin: 1rem 0 1.5rem;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}

.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-label { font-size: 0.8rem; color: var(--muted); }

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.analytics-table th,
.analytics-table td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.analytics-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.analytics-table tr:last-child td { border-bottom: none; }

a.stat-tile {
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease;
}

a.stat-tile:hover { border-color: var(--accent); }

.inquiry-list {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin: 0.6rem 0 2rem;
}

.inquiry {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.15rem;
}

.inquiry.is-handled { opacity: 0.6; }

.inquiry-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.inquiry-item { font-weight: 600; }
.inquiry-item a { color: var(--accent); text-decoration: none; }

.inquiry-date {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.inquiry-from { margin: 0.4rem 0 0; font-size: 0.92rem; }
.inquiry-from a { color: var(--accent); }

.inquiry-message {
  margin: 0.6rem 0 0;
  white-space: pre-wrap;
  font-size: 0.92rem;
}

.inquiry-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.inquiry-actions form { margin: 0; }

.btn-small {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-small:hover { border-color: var(--accent); color: var(--accent); }
.btn-small.danger:hover { border-color: var(--danger); color: var(--danger); }
