:root {
  --brown-900: #1f0d06;
  --brown-800: #3c1f0e;
  --brown-700: #5c2e1b;
  --brown-600: #7a4223;
  --cream-100: #faf6f0;
  --cream-200: #f5ede6;
  --cream-300: #e8d8c8;
  --pink-500: #d4555a;
  --pink-600: #b83a42;
  --gold-400: #c9915e;
  --gold-500: #b07848;
  --green-600: #2e7d32;
  --text: #1a0f0a;
  --text-light: rgba(26, 15, 10, 0.62);
  --text-muted: rgba(26, 15, 10, 0.38);
  --white: #ffffff;
  --shadow-sm: 0 2px 8px rgba(26, 15, 10, 0.06);
  --shadow-md: 0 8px 30px rgba(26, 15, 10, 0.1);
  --radius-sm: 8px;
  --radius-md: 14px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: linear-gradient(180deg, var(--cream-100), var(--cream-200));
  color: var(--text);
  min-height: 100vh;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; color: var(--text); margin: 0; }
button { font-family: var(--font-body); cursor: pointer; }
input, select, textarea {
  font-family: var(--font-body);
  font-size: 0.85rem;
  padding: 0.5rem 0.65rem;
  border: 1.5px solid var(--cream-300);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--gold-400);
  box-shadow: 0 0 0 3px rgba(201, 145, 94, 0.18);
}
textarea { resize: vertical; min-height: 44px; }
.hidden { display: none !important; }
.hide { display: none !important; }
.spacer { flex: 1; }
.gold { border-color: var(--gold-400) !important; color: var(--brown-700) !important; }

/* ---------- topbar ---------- */
.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.5rem;
  background: var(--brown-800);
  color: var(--cream-100);
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: 0 2px 12px rgba(26, 15, 10, 0.18);
}
.admin-brand { display: flex; align-items: center; gap: 0.7rem; }
.brand-mark {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--gold-500);
  color: var(--cream-100);
  font-family: var(--font-display);
  font-weight: 900;
  border-radius: 10px;
  font-size: 1rem;
}
.brand-mark.lg { width: 52px; height: 52px; font-size: 1.35rem; margin: 0 auto; border-radius: 14px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }
.brand-sub { font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold-400); }
.admin-actions { display: flex; align-items: center; gap: 0.6rem; }

.dirty-pill {
  background: var(--pink-500);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.3rem 0.7rem;
  border-radius: 50px;
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(212, 85, 90, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(212, 85, 90, 0); }
}

/* ---------- buttons ---------- */
.admin-btn {
  padding: 0.5rem 1.15rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1.5px solid transparent;
  border-radius: 50px;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}
.admin-btn-primary { background: var(--brown-700); color: var(--cream-100); }
.admin-btn-primary:hover:not(:disabled) { background: var(--brown-600); transform: translateY(-1px); }
.admin-btn-ghost { background: transparent; color: var(--cream-200); border-color: rgba(250, 246, 240, 0.35); }
.admin-btn-ghost:hover { border-color: var(--gold-400); color: var(--cream-100); }
.admin-btn-danger { background: transparent; color: var(--pink-500); border-color: rgba(212, 85, 90, 0.5); }
.admin-btn-danger:hover:not(:disabled) { background: rgba(212, 85, 90, 0.1); }
.admin-btn-small { padding: 0.28rem 0.7rem; font-size: 0.7rem; }
.admin-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; padding: 0.7rem; }

/* ---------- login ---------- */
.admin-login {
  max-width: 400px;
  margin: 12vh auto 0;
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 2.2rem;
}
.admin-login .login-brand { text-align: center; margin-bottom: 1.5rem; }
.admin-login .login-brand h1 { font-size: 1.5rem; margin: 0.8rem 0 0.3rem; }
.admin-login .login-brand p { margin: 0; font-size: 0.85rem; color: var(--text-light); }
.admin-login form { display: flex; flex-direction: column; gap: 0.9rem; }
.login-field input { font-size: 0.95rem; padding: 0.7rem 0.9rem; }
.admin-err { color: var(--pink-500); font-size: 0.8rem; margin: 0; min-height: 1.2em; }

/* ---------- layout ---------- */
.admin-main {
  max-width: 1560px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 8rem;
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  position: relative;
}
.admin-main.loading { opacity: 0.6; pointer-events: none; }

.admin-side { width: 268px; flex-shrink: 0; position: sticky; top: 84px; display: flex; flex-direction: column; gap: 1rem; }
.admin-content { flex: 1; min-width: 0; }

/* ---------- loader / empty ---------- */
.loader {
  position: absolute;
  inset: 30% 0 auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  color: var(--text-light);
  font-size: 0.85rem;
  z-index: 5;
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--cream-300);
  border-top-color: var(--gold-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 3.5rem 1rem;
  background: var(--white);
  border: 1.5px dashed var(--cream-300);
  border-radius: var(--radius-md);
  color: var(--text-light);
}
.empty-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.empty-state p { margin: 0 0 1rem; }

/* ---------- sidebar cards ---------- */
.side-card {
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem;
}
.side-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}
.side-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.mini-btn {
  width: 24px; height: 24px;
  border: none;
  border-radius: 8px;
  background: var(--gold-400);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  display: grid; place-items: center;
}
.mini-btn:hover { background: var(--gold-500); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.stat { text-align: center; background: var(--cream-100); border-radius: var(--radius-sm); padding: 0.6rem 0.3rem; }
.stat b { display: block; font-size: 1.35rem; font-family: var(--font-display); color: var(--brown-700); }
.stat span { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  transition: background 0.15s;
}
.side-nav-link:hover { background: var(--cream-100); }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count {
  flex-shrink: 0;
  font-size: 0.68rem;
  color: var(--text-muted);
  background: var(--cream-200);
  border-radius: 20px;
  padding: 0.1rem 0.5rem;
}
.side-muted { font-size: 0.78rem; color: var(--text-muted); margin: 0.4rem 0 0; }
.side-status .status-line { margin: 0; font-size: 0.72rem; color: var(--text-light); word-break: break-all; }
.side-status .status-line.muted { color: var(--text-muted); }
.status-line.ok { color: var(--green-600); font-weight: 600; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.seg {
  display: inline-flex;
  background: var(--white);
  border: 1.5px solid var(--cream-300);
  border-radius: 50px;
  padding: 3px;
  box-shadow: var(--shadow-sm);
}
.seg-btn {
  border: none;
  background: transparent;
  padding: 0.4rem 0.9rem;
  border-radius: 50px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-light);
  transition: all 0.15s;
}
.seg-btn.active { background: var(--brown-700); color: var(--cream-100); }

.search-wrap {
  flex: 1;
  min-width: 220px;
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 0.7rem;
  width: 16px; height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}
#admin-search {
  width: 100%;
  padding: 0.55rem 2.2rem 0.55rem 2.1rem;
  border-radius: 50px;
  background: var(--white);
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
}
#admin-search::placeholder { color: var(--text-muted); }
.search-clear {
  position: absolute;
  right: 0.5rem;
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--cream-200);
  color: var(--text-light);
  font-size: 0.9rem;
  line-height: 1;
  display: grid; place-items: center;
}
.search-clear:hover { background: var(--cream-300); color: var(--text); }
.result-count { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; }

/* ---------- category ---------- */
.admin-category {
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
  overflow: hidden;
  scroll-margin-top: 84px;
  transition: box-shadow 0.2s;
}
.admin-category.flash { box-shadow: 0 0 0 4px var(--gold-400); }
.admin-cat-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1.1rem;
  background: var(--cream-200);
  border-bottom: 1.5px solid var(--cream-300);
  flex-wrap: wrap;
}
.admin-cat-head input.cat-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  border: none;
  background: transparent;
  padding: 0.2rem 0.4rem;
  flex: 1;
  min-width: 120px;
}
.admin-cat-head input.cat-label:hover { background: rgba(255, 255, 255, 0.6); }
.admin-cat-head input.cat-label:focus { background: var(--white); border: 1.5px solid var(--gold-400); }
.admin-cat-head .cat-id { font-size: 0.68rem; color: var(--text-muted); font-family: monospace; }
.admin-cat-count { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

/* ---------- section ---------- */
.admin-section { padding: 0.7rem 1.1rem 0.2rem; }
.admin-section.is-collapsed .admin-sec-body { display: none; }
.admin-sec-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.1rem;
}
.admin-sec-head input.sec-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--brown-700);
  border: none;
  background: transparent;
  flex: 1;
  min-width: 100px;
  padding: 0.25rem 0.4rem;
}
.admin-sec-head input.sec-label:focus { background: var(--white); border: 1.5px solid var(--gold-400); }
.sec-label.unsigned { font-weight: 600; font-size: 0.9rem; color: var(--text-muted); font-style: italic; }

/* ---------- chevrons ---------- */
.chev-btn {
  width: 26px; height: 26px;
  flex-shrink: 0;
  border: 1.5px solid var(--cream-300);
  background: var(--white);
  border-radius: 8px;
  color: var(--brown-600);
  display: grid; place-items: center;
  font-size: 0.6rem;
  padding: 0;
  transition: all 0.15s;
}
.chev-btn:hover { border-color: var(--gold-400); background: var(--cream-100); }
.chev { display: inline-block; transition: transform 0.18s; }
.admin-category.is-collapsed > .admin-cat-head .chev,
.admin-section.is-collapsed > .admin-sec-head .chev,
.admin-item.expanded > .item-head .chev { transform: rotate(90deg); }
.chev-placeholder { width: 26px; flex-shrink: 0; }

/* ---------- item ---------- */
.admin-item {
  background: var(--cream-100);
  border: 1px solid var(--cream-300);
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.admin-item:hover { border-color: var(--gold-400); }
.admin-item.expanded { border-color: var(--gold-400); box-shadow: var(--shadow-sm); }

.item-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
  user-select: none;
}
.admin-item.expanded .item-head { border-bottom: 1px solid var(--cream-300); }

.thumb {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--cream-300);
  flex-shrink: 0;
}
.thumb.no-img { opacity: 0.25; }

.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 600; font-size: 0.92rem; display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.item-desc {
  font-size: 0.78rem;
  color: var(--text-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-price {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--brown-700);
  white-space: nowrap;
  flex-shrink: 0;
}

.badge {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-radius: 20px;
  padding: 0.12rem 0.45rem;
}
.bad-best { background: rgba(201, 145, 94, 0.2); color: var(--gold-500); }
.bad-hid { background: rgba(26, 15, 10, 0.07); color: var(--text-muted); }

/* ---------- item detail (expandable editor) ---------- */
.item-detail {
  display: none;
  padding: 0.8rem 0.9rem;
  background: var(--white);
}
.admin-item.expanded .item-detail { display: block; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem 0.9rem; }
.detail-grid .span2 { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field > span { font-size: 0.66rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); }
.field input, .field select, .field textarea { width: 100%; }

.img-url { display: flex; gap: 0.6rem; align-items: center; }
.img-url input { flex: 1; }
.detail-thumb {
  width: 52px; height: 52px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--cream-300);
  flex-shrink: 0;
}
.detail-thumb.no-img { opacity: 0.25; }

.toggle-row { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: center; }
.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  position: relative;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}
.sw {
  width: 36px; height: 20px;
  border-radius: 20px;
  background: var(--cream-300);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}
.sw::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch input:checked + .sw { background: var(--green-600); }
.switch input:checked + .sw::after { transform: translateX(16px); }
.switch input:focus-visible + .sw { box-shadow: 0 0 0 3px rgba(201, 145, 94, 0.4); }

.detail-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; border-top: 1px solid var(--cream-300); padding-top: 0.7rem; }

/* ---------- section foot ---------- */
.admin-section-foot { padding: 0.6rem 0 0.9rem; }

/* ---------- savebar ---------- */
.admin-savebar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(250, 246, 240, 0.96);
  backdrop-filter: blur(6px);
  border-top: 1.5px solid var(--cream-300);
  padding: 0.8rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  z-index: 25;
  box-shadow: 0 -6px 24px rgba(26, 15, 10, 0.08);
}
.dirty-note { font-size: 0.78rem; color: var(--pink-500); font-weight: 700; }
.admin-save-msg { font-size: 0.8rem; color: var(--green-600); font-weight: 600; }
.admin-save-msg.err { color: var(--pink-500); }

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  right: 1rem;
  bottom: 5.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 50;
}
.toast {
  background: var(--brown-800);
  color: var(--cream-100);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.25s ease-out;
  max-width: 320px;
}
.toast.err { background: var(--pink-600); }
.toast.out { opacity: 0; transform: translateX(12px); transition: all 0.25s; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 13, 6, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 60;
  animation: fade-in 0.18s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 1.4rem 1.5rem;
  width: 100%;
  max-width: 420px;
  animation: pop-in 0.2s ease-out;
}
@keyframes pop-in { from { transform: scale(0.96); opacity: 0; } }
.modal h3 { font-size: 1.15rem; margin-bottom: 0.8rem; }
.modal-body .modal-msg { margin: 0 0 0.4rem; font-size: 0.88rem; color: var(--text-light); line-height: 1.5; }
.modal-field { display: flex; flex-direction: column; gap: 0.35rem; margin: 0.2rem 0 0; }
.modal-field span { font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.modal-field input { font-size: 0.95rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; }

/* ---------- footer ---------- */
.admin-foot { text-align: center; padding: 1.2rem 1rem 6.5rem; color: var(--text-muted); font-size: 0.72rem; }

/* ---------- responsive ---------- */
@media (max-width: 1020px) {
  .admin-main { flex-direction: column; }
  .admin-side {
    width: 100%;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
  }
  .side-card { flex: 1; min-width: 180px; }
  .side-status { flex: 1 1 100%; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid .span2 { grid-column: auto; }
}
@media (max-width: 640px) {
  .admin-topbar { flex-wrap: wrap; padding: 0.7rem 1rem; }
  .brand-sub { display: none; }
  .admin-main { padding: 1rem 0.8rem 8rem; }
  .admin-login { margin-top: 6vh; }
  .admin-item .item-desc { display: none; }
  .detail-actions .admin-btn { flex: 1; justify-content: center; }
}