* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f5f5f5;
  color: #222;
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

/* ========== 上方導覽 ========== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
}

.logo {
  flex-shrink: 0;
  color: #111;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.header-nav {
  display: flex;
  gap: 18px;
  flex: 1;
}

.header-nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #444;
  font-size: 14px;
  text-decoration: none;
}

.header-nav a:hover {
  color: #111;
}

.nav-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e53935;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.header-search {
  width: min(280px, 40%);
}

.header-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  font-size: 14px;
}

.header-search input:focus {
  outline: 1px solid #999;
  outline-offset: 0;
}

.header-auth {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-auth a {
  color: #444;
  font-size: 14px;
  text-decoration: none;
}

.user-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

#current-user {
  display: block;
  width: 34px;
  height: 34px;
  border: 1px solid #e5e5e5;
  border-radius: 50%;
  object-fit: cover;
  background: #f5f5f5;
}

.current-user-name {
  color: #555;
  font-size: 13px;
  line-height: 1.2;
}

#logout-btn {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
}

/* ========== 左右版面 ========== */
.page-layout {
  display: flex;
  gap: 28px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 24px 100px;
}

/* ========== 左側分類（直向兩層選單） ========== */
.sidebar {
  width: 220px;
  flex-shrink: 0;
}

.sidebar-title {
  margin: 0 0 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e0e0e0;
  color: #111;
  font-size: 16px;
  font-weight: 700;
}

/* 手機才用的分類收合按鈕，電腦版隱藏 */
.category-toggle {
  display: none;
}

/* JS 偵測到窄螢幕時加上這個 class：分類清單一定先收起來 */
body.is-compact-category .sidebar {
  position: relative;
  z-index: 40;
  width: 100%;
  max-width: 100%;
}

body.is-compact-category .sidebar-title {
  display: none !important;
}

body.is-compact-category .category-toggle {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

body.is-compact-category .category-toggle-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

body.is-compact-category .category-toggle-label {
  color: #888;
  font-size: 12px;
}

body.is-compact-category .category-current {
  overflow: hidden;
  color: #111;
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.is-compact-category .category-toggle-arrow {
  flex-shrink: 0;
  color: #888;
  font-size: 12px;
  transition: transform 0.2s ease;
}

body.is-compact-category .sidebar.is-expanded .category-toggle-arrow {
  transform: rotate(180deg);
}

body.is-compact-category .category-cascade {
  display: none !important;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 50;
  width: 100%;
  max-height: 60vh;
  margin-top: 8px;
  overflow: auto;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.12);
}

body.is-compact-category .sidebar.is-expanded .category-cascade {
  display: block !important;
}

.category-cascade {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid #e5e5e5;
  background: #fff;
  overflow: hidden;
}

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.category-list li {
  border-bottom: 1px solid #eee;
}

.category-list > .category-item:last-child {
  border-bottom: none;
}

.category-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: #333;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.category-btn:hover {
  background: #f7f7f7;
}

.category-btn.active {
  background: #f0f0f0;
  color: #111;
  font-weight: 600;
}

.category-btn .category-arrow {
  display: inline-block;
  color: #999;
  font-size: 12px;
  line-height: 1;
  transition: transform 0.25s ease, color 0.2s ease;
}

.category-btn.active .category-arrow {
  color: #111;
}

.category-item.is-open .category-arrow {
  transform: rotate(90deg);
}

/* 子分類嵌在主分類項目下方：預設收合，展開時滑出 */
.category-item .subcategory-list {
  display: block;
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  border-top: 0 solid #eee;
  background: #fafafa;
  transition:
    max-height 0.3s ease,
    opacity 0.22s ease,
    border-top-width 0.2s ease;
}

.category-item.is-open .subcategory-list {
  max-height: 800px;
  opacity: 1;
  border-top-width: 1px;
}

.category-item .subcategory-list li {
  border-bottom: 1px solid #eee;
}

.category-item .subcategory-list li:last-child {
  border-bottom: none;
}

.category-item .subcategory-btn {
  display: flex;
  align-items: center;
  width: 100%;
  margin: 0;
  padding: 11px 14px 11px 28px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: #444;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.category-item .subcategory-btn:hover {
  background: #f0f0f0;
}

.category-item .subcategory-btn.active {
  background: #ececec;
  color: #111;
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .category-btn,
  .category-btn .category-arrow,
  .category-item .subcategory-list,
  .category-item .subcategory-btn {
    transition: none;
  }
}

/* ========== 右側內容 ========== */
.main-content {
  flex: 1;
  min-width: 0;
}

.list-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5e5e5;
}

.list-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
}

.list-count {
  margin: 0;
  color: #777;
  font-size: 13px;
}

.sort-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #555;
  font-size: 13px;
}

.sort-label select {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  font-size: 13px;
}

/* ========== 商品網格 ========== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px 16px;
  align-items: stretch;
}

.product-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 12px;
  cursor: pointer;
  transition: box-shadow 0.2s ease;
}

.product-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* 圖片區由外層鎖死高度，不要讓 <img> 自己撐高卡片 */
.product-card-media {
  flex: 0 0 200px;
  height: 200px;
  width: 100%;
  overflow: hidden;
  background: #fafafa;
}

.product-card-media img,
.product-card > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: #fafafa;
}

.product-info {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  padding: 12px 12px 16px;
  min-height: 0;
}

.product-seller {
  margin: 0 0 6px;
  color: #888;
  font-size: 12px;
}

.product-title {
  margin: 0 0 10px;
  color: #222;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  min-height: 2.8em;
}

.product-price {
  margin: 0 0 10px;
  color: #d32f2f;
  font-size: 18px;
  font-weight: 700;
}

.delete-btn,
.favorite-btn {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  color: #555;
  font-size: 13px;
  cursor: pointer;
}

.delete-btn:hover,
.favorite-btn:hover {
  background: #f5f5f5;
  color: #d32f2f;
}

.favorite-btn.active {
  border-color: #d32f2f;
  color: #d32f2f;
  background: #fff5f5;
}

.empty-message {
  margin-top: 48px;
  color: #888;
  text-align: center;
  font-size: 15px;
}

.hidden {
  display: none;
}

.page-search,
.menu-btn,
.drawer,
.drawer-overlay {
  display: none;
}

/* ========== 發布按鈕 ========== */
.publish-btn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 14px 22px;
  border: none;
  border-radius: 999px;
  background: #111;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s ease, background 0.2s ease;
}

.publish-btn:hover {
  transform: scale(1.04);
  background: #333;
}

.publish-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.4);
}

.publish-modal.hidden {
  display: none;
}

.publish-form {
  width: min(420px, 90%);
  padding: 24px;
  border-radius: 4px;
  background: #fff;
}

.publish-form h2 {
  margin: 0 0 16px;
  font-size: 20px;
}

.publish-form label,
.publish-form .form-label-text {
  display: block;
  margin: 10px 0 6px;
  font-size: 14px;
}

.publish-form input,
.publish-form select,
.publish-form textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 16px;
}

.publish-form textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}

.publish-form input[type="file"] {
  padding: 8px 0;
  border: none;
  background: transparent;
}

.publish-form .file-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  cursor: pointer;
}

.file-picker-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.file-picker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 10px 16px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  color: #222;
  font-size: 14px;
}

.file-picker:hover .file-picker-btn {
  background: #f7f7f7;
}

.file-picker-name {
  min-width: 0;
  overflow: hidden;
  color: #666;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.form-hint {
  margin: 6px 0 0;
  color: #777;
  font-size: 13px;
}

.publish-message {
  min-height: 20px;
  margin: 12px 0 0;
  color: #d32f2f;
  font-size: 14px;
}

.publish-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.publish-actions button {
  padding: 10px 16px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.publish-actions button[type="submit"] {
  background: #111;
  border-color: #111;
  color: #fff;
}

/* ========== 手機版 ========== */
@media (max-width: 960px) {
  .product-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 720px) {
  .header-inner {
    gap: 12px;
    padding: 12px 16px;
  }

  .menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    font-size: 20px;
    cursor: pointer;
  }

  .header-nav,
  .header-search {
    display: none;
  }

  .page-search {
    display: block;
    width: 100%;
    margin-bottom: 16px;
  }

  .page-search input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
  }

  .drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 250;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .drawer-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }

  .drawer {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 260;
    width: min(280px, 80%);
    height: 100%;
    background: #fff;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.12);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .drawer.open {
    transform: translateX(0);
  }

  .drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid #eee;
    font-weight: 700;
  }

  .drawer-close {
    border: none;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
  }

  .drawer-nav {
    display: flex;
    flex-direction: column;
  }

  .drawer-nav a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid #f0f0f0;
    color: #222;
    font-size: 16px;
    text-decoration: none;
  }

  .drawer-nav .nav-unread-badge {
    min-width: 20px;
    height: 20px;
    font-size: 12px;
  }

  .page-layout {
    flex-direction: column;
    padding: 16px 16px 100px;
  }

  .sidebar {
    width: 100%;
    max-width: 100%;
  }

  .sidebar-title {
    display: none !important;
  }

  .category-toggle {
    display: flex !important;
  }

  .category-cascade {
    display: none !important;
  }

  .sidebar.is-expanded .category-cascade {
    display: block !important;
  }

  /* 手機也維持直向嵌套展開 */
  .category-list {
    display: block;
  }

  .category-list li {
    border-bottom: 1px solid #eee;
  }

  .category-btn {
    width: 100%;
    max-width: none;
    padding: 12px 14px;
    border: none;
    border-radius: 0;
    background: transparent;
    white-space: normal;
  }

  .category-btn.active {
    background: #f0f0f0;
  }

  .category-item .subcategory-btn {
    width: 100%;
    max-width: none;
    padding: 11px 14px 11px 28px;
    font-size: 14px;
    white-space: normal;
  }

  .publish-form select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .publish-form .file-picker {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .file-picker-btn {
    width: 100%;
    padding: 12px 16px;
  }

  .product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .product-card-media {
    flex-basis: 150px;
    height: 150px;
  }

  .list-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
