:root {
  --cream: #fbf8f3;
  --paper: #ffffff;
  --sand: #f3ece2;
  --line: #e7ded2;
  --ink: #3b2c22;
  --brown: #6b4e36;
  --muted: #8b7465;
  --lavender: #c2b5e2;
  --lavender-soft: #efebf8;
  --plum: #6a5699;
  --plum-dark: #574482;
  --danger: #b3412f;
  --success: #3f7d4f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(59, 44, 34, 0.06), 0 8px 24px rgba(59, 44, 34, 0.06);
  --font-heading: "Playfair Display", Georgia, serif;
  --font-body: "Raleway", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2 {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

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

input, button { font: inherit; color: inherit; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.btn-primary { background: var(--plum); color: #fff; }
.btn-primary:hover { background: var(--plum-dark); }
.btn-ghost { background: transparent; color: var(--brown); border-color: var(--line); }
.btn-ghost:hover { background: var(--sand); }
.btn-block { width: 100%; padding: 0.8rem; }

:focus-visible { outline: 2px solid var(--plum); outline-offset: 2px; }

/* ---------- Login / setup ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 15% 20%, var(--lavender-soft), transparent 45%),
    radial-gradient(circle at 85% 80%, var(--sand), transparent 45%),
    var(--cream);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--paper);
  border-radius: 20px;
  padding: 2.5rem 2rem 2rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
}
.auth-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  pointer-events: none;
}

.auth-brand {
  font-family: var(--font-heading);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  text-align: center;
}
.auth-card h1 { font-size: 1.9rem; text-align: center; }
.auth-intro { color: var(--muted); text-align: center; margin: -0.25rem 0 0.5rem; }

label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 600; font-size: 0.85rem; color: var(--brown); }

input[type="email"],
input[type="url"],
input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  font-weight: 400;
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="email"]:focus,
input[type="url"]:focus,
input[type="password"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--plum);
  box-shadow: 0 0 0 3px var(--lavender-soft);
}

.form-error {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: #fbebe7;
  color: var(--danger);
  font-size: 0.9rem;
}

.form-success {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: #e9f3ea;
  color: var(--success);
  font-size: 0.9rem;
}

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--plum);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

[hidden] { display: none !important; }

/* Loading screen */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--plum);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-back { text-align: center; color: var(--muted); font-size: 0.9rem; text-decoration: none; }
.auth-back:hover { color: var(--plum); }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.topbar-brand {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}
.topbar-brand span {
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--plum);
  background: var(--lavender-soft);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  margin-left: 0.5rem;
  vertical-align: middle;
}
.topbar-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.topbar-actions form { margin: 0; }

/* ---------- Dashboard ---------- */
.dashboard {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panel {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.panel-head h2 { font-size: 1.5rem; }
.tip { font-size: 0.85rem; margin-bottom: 1.25rem; }

/* Upload */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 2.25rem 1rem;
  border: 2px dashed var(--lavender);
  border-radius: var(--radius);
  background: var(--lavender-soft);
  color: var(--plum);
  text-align: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.dropzone strong { font-size: 1.05rem; color: var(--ink); }
.dropzone .link { color: var(--plum); text-decoration: underline; text-underline-offset: 3px; }
.dropzone .hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.dropzone:hover, .dropzone.over { border-color: var(--plum); background: #e6e0f5; }
.dropzone.over { transform: scale(1.01); }
.dropzone:focus-within { outline: 2px solid var(--plum); outline-offset: 2px; }

.check {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
  font-weight: 500;
  color: var(--ink);
  font-size: 0.9rem;
  cursor: pointer;
}
.check input { width: 18px; height: 18px; accent-color: var(--plum); }

.upload-queue { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.upload-queue:not(:empty) { margin-top: 1rem; }
.upload-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.3rem 1rem;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  background: var(--sand);
  font-size: 0.875rem;
}
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-status { color: var(--muted); }
.upload-bar { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.upload-bar span { display: block; height: 100%; width: 0; background: var(--plum); transition: width 0.2s; }
.upload-item.done .upload-status { color: var(--success); font-weight: 600; }
.upload-item.done .upload-bar span { background: var(--success); width: 100%; }
.upload-item.failed { background: #fbebe7; cursor: pointer; }
.upload-item.failed .upload-status { color: var(--danger); font-weight: 600; }
.upload-item.failed .upload-bar { display: none; }

/* Filters */
.filters { display: inline-flex; background: var(--sand); border-radius: 999px; padding: 4px; }
.filter {
  border: 0;
  background: none;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}
.filter.active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* Image cards */
.image-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
}

.image-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, opacity 0.2s, transform 0.2s;
}
.image-card:hover { box-shadow: var(--shadow); }
.image-card.dragging { opacity: 0.4; transform: scale(0.97); }
.image-card.busy { opacity: 0.5; pointer-events: none; }

.card-media {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--sand);
  cursor: grab;
}
.card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }

.drag-handle {
  position: absolute;
  top: 8px;
  left: 8px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.2s;
}
.image-card:hover .drag-handle { opacity: 1; }

.badges {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.badge {
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--plum);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  display: none;
}
.badge-sale { background: #3f7d4f; }
.image-card.featured .badge-home,
.image-card.for-sale .badge-sale { display: block; }

.card-body { padding: 0.75rem; display: flex; flex-direction: column; gap: 0.6rem; }
.card-body .title-input { padding: 0.5rem 0.65rem; font-size: 0.9rem; border-color: transparent; background: var(--cream); }
.card-body .title-input:hover { border-color: var(--line); }
.card-body .title-input:focus { border-color: var(--plum); background: var(--paper); }

.sale-row { display: grid; grid-template-columns: 1fr 5.5rem; gap: 0.4rem; }
.card-body .sale-row input { padding: 0.45rem 0.6rem; font-size: 0.85rem; border-color: transparent; background: var(--cream); min-width: 0; }
.card-body .sale-row input:hover { border-color: var(--line); }
.card-body .sale-row input:focus { border-color: var(--plum); background: var(--paper); }
.image-card.for-sale .etsy-input { color: #3f7d4f; }

.card-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.card-buttons { display: flex; gap: 2px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--sand); color: var(--ink); }
.icon-btn.danger:hover { background: #fbebe7; color: var(--danger); }

/* Toggle switch */
.switch {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--brown);
  cursor: pointer;
  position: relative;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.switch input:checked + .switch-track { background: var(--plum); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--plum); outline-offset: 2px; }

.empty { text-align: center; padding: 2.5rem 1rem; }
.empty p { margin: 0.25rem 0; }

/* Modal */
.modal {
  border: 0;
  border-radius: 18px;
  padding: 0;
  width: min(420px, calc(100% - 2rem));
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  color: var(--ink);
}
.modal::backdrop { background: rgba(59, 44, 34, 0.45); }
.modal form { padding: 1.75rem; display: flex; flex-direction: column; gap: 1rem; }
.modal h2 { font-size: 1.4rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 150%);
  opacity: 0;
  visibility: hidden;
  background: var(--ink);
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  transition: transform 0.3s ease, opacity 0.3s ease, visibility 0.3s;
  z-index: 100;
  max-width: calc(100% - 2rem);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.toast.error { background: var(--danger); }

@media (max-width: 600px) {
  .dashboard { padding: 1rem 1rem 3rem; }
  .panel { padding: 1.1rem; }
  .topbar-inner { padding: 0.75rem 1rem; }
  .topbar-brand span { display: none; }
  .image-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .drag-handle { display: none; }
}
