:root {
  --cream:      #f5f0e8;
  --parchment:  #ede5d0;
  --warm-white: #faf7f2;
  --gold:       #b8860b;
  --gold-light: #d4a843;
  --sepia:      #8b6914;
  --dark:       #1c1a17;
  --mid:        #4a4035;
  --muted:      #8c7d6a;
  --border:     rgba(184,134,11,0.2);
  --shadow:     0 4px 24px rgba(28,26,23,0.12);
  --shadow-lg:  0 12px 48px rgba(28,26,23,0.22);
  --radius:     10px;
  --sidebar-w:  240px;
  --topbar-h:   58px;
  --trans:      0.18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--dark);
  background: var(--warm-white);
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100vh;
  background: var(--dark);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.06);
  transition: transform var(--trans);
  z-index: 100;
}

.sidebar-header {
  padding: 1.6rem 1.5rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  text-align: center;
  flex-shrink: 0;
}

.logo-mark { font-size: 1.4rem; color: var(--gold-light); line-height: 1; margin-bottom: .35rem; }

.sidebar-header h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--cream);
  letter-spacing: .04em;
}

.tagline {
  font-size: .65rem;
  color: var(--muted);
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-top: .2rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem .6rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

/* ── Tree ── */
.tree-root { list-style: none; }

.tree-category { position: relative; }

.tree-cat-row {
  display: flex;
  align-items: center;
  border-radius: 5px;
  cursor: pointer;
  transition: background var(--trans);
  user-select: none;
}

.tree-cat-row:hover { background: rgba(255,255,255,0.06); }
.tree-category.active > .tree-cat-row { background: rgba(184,134,11,0.16); }

.tree-arrow {
  flex-shrink: 0;
  width: 20px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .6rem;
  transition: transform var(--trans), color var(--trans);
}

.tree-category.open > .tree-cat-row .tree-arrow {
  transform: rotate(90deg);
  color: var(--gold-light);
}

.tree-cat-icon { flex-shrink: 0; width: 18px; font-size: .78rem; margin-right: 2px; }

.tree-cat-label {
  flex: 1;
  padding: .42rem .4rem .42rem 0;
  font-size: .82rem;
  color: rgba(245,240,232,0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--trans);
}

.tree-cat-row:hover .tree-cat-label { color: var(--cream); }
.tree-category.active > .tree-cat-row .tree-cat-label { color: var(--gold-light); }

.tree-children { list-style: none; display: none; padding-left: 20px; }
.tree-category.open > .tree-children { display: block; }

.tree-leaf {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: .32rem .5rem .32rem .3rem;
  border-radius: 5px;
  cursor: pointer;
  color: rgba(245,240,232,0.55);
  font-size: .78rem;
  transition: background var(--trans), color var(--trans);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-leaf::before {
  content: '';
  flex-shrink: 0;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: rgba(184,134,11,0.4);
  margin-left: 2px;
}

.tree-leaf:hover { background: rgba(255,255,255,0.05); color: var(--cream); }
.tree-leaf.active { background: rgba(184,134,11,0.14); color: var(--gold-light); }
.tree-leaf.active::before { background: var(--gold-light); }

/* ── Main ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ── */
#topbar {
  height: var(--topbar-h);
  background: var(--warm-white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  gap: 1rem;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: .8rem;
  min-width: 0;
  flex: 1;
}

#viewTitle {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.view-count { font-size: .7rem; color: var(--muted); display: block; margin-top: 1px; }

.topbar-right { display: flex; align-items: center; gap: .6rem; flex-shrink: 0; }

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--mid);
  padding: .25rem;
}

.search-wrap input {
  background: var(--parchment);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: .38rem .9rem;
  font-size: .8rem;
  font-family: inherit;
  color: var(--dark);
  width: 175px;
  outline: none;
  transition: border-color var(--trans), width var(--trans);
}

.search-wrap input:focus { border-color: var(--gold); width: 215px; }

.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--parchment);
  border-radius: 5px;
  padding: 2px;
}

.view-toggle button {
  background: none;
  border: none;
  padding: .28rem .45rem;
  border-radius: 3px;
  cursor: pointer;
  color: var(--muted);
  font-size: .9rem;
  transition: background var(--trans), color var(--trans);
}

.view-toggle button.active { background: var(--dark); color: var(--cream); }

/* ── Photo Grid ── */
.photo-grid {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1.1rem;
  align-content: start;
  scrollbar-width: thin;
  scrollbar-color: var(--parchment) transparent;
}

.photo-grid.list-view {
  grid-template-columns: 1fr;
  gap: .4rem;
  padding: 1rem 1.25rem;
}

.grid-section { grid-column: 1 / -1; }

.grid-section-header {
  font-family: 'Playfair Display', serif;
  font-size: .92rem;
  font-weight: 600;
  color: var(--mid);
  padding: .4rem 0 .6rem;
  margin-top: .3rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .45rem;
}

.grid-section-header::before {
  content: '';
  display: inline-block;
  width: 3px; height: 1em;
  background: var(--gold);
  border-radius: 2px;
}

.grid-section-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1.1rem;
  padding-top: .7rem;
  padding-bottom: .4rem;
}

/* ── Card ── */
.photo-card {
  background: var(--cream);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform var(--trans), box-shadow var(--trans), border-color var(--trans);
}

.photo-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: rgba(184,134,11,0.38);
}

.card-img-wrap { aspect-ratio: 4/3; overflow: hidden; background: var(--parchment); }
.card-img-wrap img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.photo-card:hover .card-img-wrap img { transform: scale(1.04); }

.card-info { padding: .55rem .65rem; }

.card-name {
  font-family: 'Playfair Display', serif;
  font-size: .8rem;
  font-weight: 600;
  color: var(--dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: .25rem;
}

.card-price { font-size: .76rem; font-weight: 500; color: var(--sepia); }

.list-view .photo-card { display: flex; align-items: center; gap: .8rem; padding: .45rem; }
.list-view .card-img-wrap { width: 52px; height: 52px; aspect-ratio: unset; flex-shrink: 0; border-radius: 5px; }
.list-view .card-info { flex: 1; padding: 0; display: flex; align-items: center; justify-content: space-between; min-width: 0; gap: .8rem; }
.list-view .card-name { flex: 1; margin-bottom: 0; }

/* ── Empty ── */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--muted); gap: .6rem; padding: 4rem;
}
.empty-state.hidden { display: none; }
.empty-icon { font-size: 2.5rem; opacity: .25; }
.empty-state p { font-family: 'Playfair Display', serif; font-style: italic; }

/* ── Lightbox ── */
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.lightbox.hidden { display: none; }

.lightbox-backdrop {
  position: absolute; inset: 0;
  background: rgba(28,26,23,0.88);
  backdrop-filter: blur(4px);
}

.lightbox-container {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: .75rem;
  max-width: 96vw; max-height: 94vh;
}

.lightbox-content {
  background: var(--warm-white);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  border: 1px solid var(--border);
}

.lightbox-image-wrap {
  width: clamp(280px, 48vw, 680px);
  background: #111;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}

.lightbox-image-wrap img {
  max-width: 100%; max-height: 90vh;
  object-fit: contain; display: block;
}

.lightbox-panel {
  width: 270px;
  flex-shrink: 0;
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: .9rem;
  overflow-y: auto;
  background: var(--warm-white);
}

.lb-name {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--dark);
  line-height: 1.35;
}

.lb-notes {
  font-size: .82rem;
  color: var(--mid);
  line-height: 1.55;
  flex: 1;
}

.lb-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  padding-top: .8rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.lb-price {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--sepia);
}

.btn-add-cart {
  background: var(--dark);
  color: var(--cream);
  border: none;
  border-radius: 6px;
  padding: .5rem .9rem;
  font-size: .78rem;
  font-family: 'Playfair Display', serif;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--trans);
  white-space: nowrap;
}

.btn-add-cart:hover { background: var(--mid); }
.btn-add-cart.in-cart { background: var(--gold); color: var(--dark); }
.btn-add-cart.in-cart:hover { background: #e0b050; }

.lightbox-close {
  position: absolute;
  top: -2.2rem; right: 0;
  background: rgba(255,255,255,0.12);
  border: none; color: var(--cream);
  font-size: .9rem; width: 28px; height: 28px;
  border-radius: 50%; cursor: pointer;
  transition: background var(--trans);
  display: flex; align-items: center; justify-content: center;
}
.lightbox-close:hover { background: rgba(255,255,255,0.22); }

.lightbox-nav {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.14);
  color: var(--cream);
  font-size: 1.8rem; width: 38px; height: 38px;
  border-radius: 50%; cursor: pointer;
  transition: background var(--trans);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; line-height: 1;
}
.lightbox-nav:hover { background: rgba(255,255,255,0.2); }

/* ── Cart button ── */
.cart-btn {
  position: fixed;
  bottom: 1.8rem; right: 1.8rem;
  background: var(--dark);
  color: var(--cream);
  border: none;
  border-radius: 28px;
  padding: .65rem 1.2rem;
  font-size: .9rem;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: background var(--trans), transform var(--trans);
  z-index: 150;
  display: flex; align-items: center; gap: .4rem;
}
.cart-btn:hover { background: var(--mid); transform: translateY(-2px); }

.cart-badge {
  background: var(--gold);
  color: var(--dark);
  font-size: .68rem;
  font-weight: 700;
  border-radius: 10px;
  padding: .08rem .42rem;
  min-width: 18px;
  text-align: center;
}
.cart-badge.hidden { display: none; }

/* ── Cart panel ── */
.cart-backdrop {
  position: fixed; inset: 0;
  background: rgba(28,26,23,0.4);
  z-index: 200;
}
.cart-backdrop.hidden { display: none; }

.cart-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 96vw);
  background: var(--warm-white);
  box-shadow: var(--shadow-lg);
  z-index: 210;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  transform: translateX(0);
}
.cart-panel.hidden { display: none; }

.cart-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.2rem 1.4rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cart-header h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  color: var(--dark);
}

.cart-close {
  background: none; border: none;
  font-size: 1rem; cursor: pointer;
  color: var(--muted);
  padding: .2rem .35rem;
  border-radius: 4px;
  transition: color var(--trans);
}
.cart-close:hover { color: var(--dark); }

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: .8rem 1.2rem;
  scrollbar-width: thin;
}

.cart-empty {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  font-size: .85rem;
  padding: 2rem 0;
}

.cart-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 0;
  border-bottom: 1px solid rgba(184,134,11,0.1);
}

.cart-item-thumb {
  width: 48px; height: 48px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.cart-item-thumb-placeholder {
  width: 48px; height: 48px;
  background: var(--parchment);
  border-radius: 5px;
  flex-shrink: 0;
}

.cart-item-info { flex: 1; min-width: 0; }

.cart-item-name {
  font-size: .82rem;
  font-weight: 500;
  color: var(--dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: .2rem;
}

.cart-item-price { font-size: .78rem; color: var(--sepia); font-weight: 500; }

.cart-item-controls {
  display: flex;
  align-items: center;
  gap: .3rem;
  flex-shrink: 0;
}

.qty-btn {
  background: var(--parchment);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 24px; height: 24px;
  cursor: pointer;
  font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--mid);
  transition: background var(--trans);
}
.qty-btn:hover { background: var(--cream); }

.qty-val {
  font-size: .82rem;
  min-width: 18px;
  text-align: center;
  color: var(--dark);
}

.cart-item-del {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  font-size: .85rem;
  padding: .2rem;
  margin-left: .2rem;
  border-radius: 3px;
  transition: color var(--trans);
}
.cart-item-del:hover { color: #c83c3c; }

.cart-footer {
  padding: 1.1rem 1.4rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .9rem;
}

.cart-total-row span { color: var(--muted); }

.cart-total-row strong {
  font-family: 'Playfair Display', serif;
  font-size: 1.15rem;
  color: var(--dark);
}

.btn-print-cart {
  background: var(--dark);
  color: var(--cream);
  border: none;
  border-radius: 7px;
  padding: .65rem;
  font-size: .82rem;
  font-family: 'Playfair Display', serif;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--trans);
  letter-spacing: .03em;
}
.btn-print-cart:hover { background: var(--mid); }

/* ── Sidebar backdrop (mobile) ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 99;
}
.sidebar-backdrop.active { display: block; }

/* ── Responsive ── */
@media (max-width: 820px) {
  #sidebar { position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .hamburger { display: flex; }
  .lightbox-content { flex-direction: column; }
  .lightbox-image-wrap { width: 100%; min-height: 180px; max-height: 50vh; }
  .lightbox-panel { width: 100%; max-height: 40vh; }
  .search-wrap input { width: 120px; }
}

/* ── Print ── */
@media print {
  body { display: block; overflow: visible; background: white; }
  #sidebar, #main, .lightbox, .cart-btn, .cart-backdrop, .cart-close,
  .cart-header h3 ~ button, .cart-item-controls, .cart-item-del { display: none !important; }

  .cart-panel {
    position: static !important;
    width: 100% !important;
    box-shadow: none !important;
    border: none !important;
    display: flex !important;
  }

  .cart-header { border-bottom: 2px solid var(--dark); }
  .cart-header h3 { font-size: 1.3rem; }
  .btn-print-cart { display: none; }

  .cart-item { break-inside: avoid; }
}

/* ── Texture ── */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 9999; opacity: .35;
}

/* ── Sidebar credits ── */
.sidebar-credits {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: 1rem 1.1rem;
  border-top: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

.lc-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  flex-shrink: 0;
  opacity: .9;
}

.lc-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lc-name {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .1em;
  color: rgba(245,240,232,0.65);
}

.lc-ver {
  font-size: .65rem;
  color: rgba(245,240,232,0.35);
  letter-spacing: .06em;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--parchment); border-radius: 3px; }
