:root {
    --brand: #7a5c3e;
    --brand-dark: #5a4128;
    --bg: #f7f3ec;
    --card-bg: #ffffff;
    --border: #e2dbcd;
    --text: #33291d;
    --muted: #8a7d68;
    --danger: #b3452c;
    --success: #3f7d4f;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
    background: var(--bg);
    color: #33291d;
    line-height: 1.5;
}

a { color: var(--brand-dark); }

.muted { color: #8a7d68; }
.small { font-size: 0.85em; }

/* ---------- 前台 header ---------- */
.site-header {
    background: var(--brand);
    color: #fff;
    padding: 18px 20px;
}
.site-header-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: nowrap;
}
.site-header h1 { margin: 0; font-size: 1.4em; white-space: nowrap; flex-shrink: 0; }
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
    min-width: 0;
}
.site-header .search-form {
    display: flex;
    gap: 8px;
    min-width: 0;
}
.site-header .search-form input[type=text] {
    width: 100%;
    min-width: 60px;
    flex: 1 1 140px;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
}
.admin-link { flex-shrink: 0; }

/* 手機等極窄畫面才改成換行堆疊，避免內容擠壓到看不清楚 */
@media (max-width: 560px) {
    .site-header-inner { flex-wrap: wrap; }
    .header-right { flex-wrap: wrap; }
    .site-header .search-form input[type=text] { flex: 1 1 auto; width: auto; }
}
.btn-header-search {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: rgba(255,255,255,0.9);
    color: var(--brand-dark);
    cursor: pointer;
    font-size: 0.95em;
    white-space: nowrap;
}
.btn-header-search:hover { background: #fff; }
.btn-header-search-clear {
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.6);
    color: #fff;
    text-decoration: none;
    font-size: 0.9em;
    white-space: nowrap;
}
.btn-header-search-clear:hover { background: rgba(255,255,255,0.15); }
.admin-link {
    color: #fff;
    text-decoration: none;
    border: 1px solid rgba(255,255,255,0.6);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.9em;
}
.admin-link:hover { background: rgba(255,255,255,0.15); }

.site-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
}

/* ---------- 分類頁籤 ---------- */
.search-result-info {
    font-size: 0.9em;
    color: #6b5f4a;
    margin: -6px 0 14px;
}
.category-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 28px;
}
.category-tabs a {
    text-decoration: none;
    padding: 7px 16px;
    border-radius: 20px;
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.92em;
}
.category-tabs a.active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

/* ---------- 統計列 ---------- */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 4px;
    margin-bottom: 22px;
}
.stat-box {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stat-label { font-size: 0.8em; color: #8a7d68; }
.stat-value { font-size: 1.4em; font-weight: 700; }
.profit-positive .stat-value { color: var(--success); }
.profit-negative .stat-value { color: var(--danger); }

/* ---------- 物品卡片 ---------- */
.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.item-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    gap: 12px;
}
.item-images {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}
.thumb {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #f0ece2;
    display: block;
}
.thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b2a790;
    font-size: 0.8em;
}
.item-info { flex: 1; min-width: 0; }
.item-cat {
    font-size: 0.75em;
    color: #fff;
    background: var(--brand);
    display: inline-block;
    padding: 2px 9px;
    border-radius: 12px;
    margin-bottom: 6px;
}
.item-name { margin: 0 0 8px; font-size: 1.05em; }
.item-meta { list-style: none; margin: 0; padding: 0; font-size: 0.88em; color: #4d4230; }
.item-meta li { margin-bottom: 2px; }
.item-note {
    margin: 8px 0 0;
    font-size: 0.85em;
    color: #6b5f4a;
    white-space: pre-line;
}

.thumb-clickable {
    cursor: pointer;
    transition: opacity 0.15s;
}
.thumb-clickable:hover {
    opacity: 0.8;
}

/* ---------- 燈箱(點擊放大圖片) ---------- */
.lightbox {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(20, 15, 8, 0.85);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    cursor: zoom-out;
}
.lightbox.open {
    display: flex;
}
.lightbox img {
    max-width: 512px;
    max-height: 512px;
    width: auto;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    cursor: default;
}
.lightbox-caption {
    color: #fff;
    margin-top: 12px;
    font-size: 0.95em;
}
.lightbox-close {
    position: absolute;
    top: 18px;
    right: 28px;
    color: #fff;
    font-size: 2.2em;
    line-height: 1;
    cursor: pointer;
    user-select: none;
}
.lightbox-close:hover { opacity: 0.7; }

.empty-row {
    text-align: center;
    color: #a0947c;
    padding: 40px 0;
    grid-column: 1 / -1;
}

/* ---------- 分頁 ---------- */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin: 24px 0;
}
.pagination a {
    text-decoration: none;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}
.pagination a.disabled {
    pointer-events: none;
    color: #ccc;
}
.page-info { font-size: 0.9em; color: #6b5f4a; }

/* ---------- 後台 ---------- */
.admin-nav {
    background: var(--brand-dark);
    color: #fff;
    padding: 12px 20px;
}
.admin-nav-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.admin-nav nav a {
    color: #fff;
    text-decoration: none;
    margin-left: 16px;
    font-size: 0.92em;
    opacity: 0.9;
}
.admin-nav nav a:hover { opacity: 1; text-decoration: underline; }
.admin-nav nav a.logout-link { opacity: 0.7; }

.admin-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

.admin-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}
.admin-toolbar h2 { margin: 0; margin-right: auto; font-size: 1.2em; }
.bulk-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.bulk-toolbar input[type=text] {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 220px;
}
.toolbar-filter-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.toolbar-filter-form input[type=text] {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 180px;
}

.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--border);
}
.data-table th, .data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 0.9em;
    vertical-align: middle;
}
.data-table th { background: #f0ece2; white-space: nowrap; }
.sort-link {
    color: var(--text);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.sort-link:hover { color: var(--brand-dark); }
.sort-arrow {
    font-size: 0.75em;
    color: #a89b82;
}
.sort-link.sort-active { color: var(--brand-dark); font-weight: 700; }
.sort-link.sort-active .sort-arrow { color: var(--brand-dark); }
.data-table .actions a, .data-table .actions button {
    margin-right: 8px;
}
.truncate-cell {
    max-width: 115px;
    color: #6b5f4a;
    font-size: 0.85em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.date-cell {
    white-space: nowrap;
}

.link-danger {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: inherit;
    padding: 0;
    text-decoration: underline;
}

.inline-form { display: inline-block; margin: 0; }

.reorder-cell { display: flex; gap: 4px; }
.mini-btn {
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
}
.rename-form { display: flex; gap: 6px; align-items: center; }
.rename-form input[type=text] {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.add-category-form {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
}
.add-category-form input {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    min-width: 220px;
}

/* ---------- 表單 ---------- */
.item-form { margin-top: 12px; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.form-grid label, .item-form label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 0.9em;
    color: #4d4230;
}
.item-form > label { margin-bottom: 18px; }
.checkbox-label {
    flex-direction: row !important;
    align-items: center;
    gap: 8px !important;
}
.checkbox-label input[type=checkbox] {
    width: auto;
}
.settings-submit-btn { margin-top: 10px; }
.form-grid .full-width { grid-column: 1 / -1; }
input[type=text], input[type=date], input[type=number], input[type=password], select, textarea {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1em;
    font-family: inherit;
}

.image-fieldset {
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 18px;
}
.current-images {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.current-image-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.remove-label { font-size: 0.8em; color: var(--danger); }
.image-reorder-controls {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 6px;
}
.image-reorder-controls .mini-btn {
    padding: 2px 10px;
    font-size: 0.9em;
}
.image-reorder-controls .mini-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn {
    display: inline-block;
    padding: 9px 18px;
    border-radius: 6px;
    text-decoration: none;
    border: none;
    cursor: pointer;
    font-size: 0.95em;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #ece5d5; color: var(--text); margin-left: 8px; }

/* ---------- 登入/安裝頁 ---------- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.auth-box {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 30px 34px;
    width: 100%;
    max-width: 360px;
}
.auth-box h1 { margin-top: 0; font-size: 1.3em; }
.auth-box form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.auth-box label { display: flex; flex-direction: column; gap: 5px; font-size: 0.9em; }

.alert {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 14px;
    font-size: 0.9em;
}
.alert-error { background: #fbe4dd; color: #8a2d17; border: 1px solid #f0b7a5; }
.alert-success { background: #e2f0e3; color: #235c30; border: 1px solid #b9dcbc; }
.alert-warning { background: #fbf3d9; color: #7a5d0b; border: 1px solid #ecdd9e; }
