:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #2b2a27;
  --muted: #7a766d;
  --line: #e4e0d6;
  --accent: #2f5d50;
  --accent-soft: #e3eee9;
  --warn: #b5482f;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
}
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .85rem; }

/* 頂部 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 1.5rem; background: var(--accent); color: #fff;
}
.brand { color: #fff; font-weight: 700; font-size: 1.15rem; text-decoration: none; }
#nav { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
#nav a, #nav button {
  color: #fff; text-decoration: none; background: transparent; border: 1px solid transparent;
  padding: .3rem .7rem; border-radius: 6px; font-size: .95rem; cursor: pointer; font-family: inherit;
}
#nav a:hover, #nav button:hover, #nav a.active { border-color: rgba(255,255,255,.5); }
#nav .who { opacity: .85; font-size: .9rem; margin-right: .3rem; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* 按鈕與表單 */
.btn {
  display: inline-block; border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: .45rem 1rem; border-radius: 6px; cursor: pointer; font-size: .95rem; font-family: inherit;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; color: var(--warn); border-color: var(--warn); }
.btn.sm { padding: .2rem .6rem; font-size: .85rem; }
input, textarea, select {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 6px;
  font-size: 1rem; font-family: inherit; background: #fff;
}
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: .9rem; margin: .7rem 0 .25rem; color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.form-actions { margin-top: 1.2rem; display: flex; gap: .6rem; justify-content: flex-end; }
.error { color: var(--warn); font-size: .9rem; margin-top: .6rem; min-height: 1.2em; }

/* 館藏頁 */
.catalog { display: grid; grid-template-columns: 240px 1fr; gap: 1.5rem; align-items: start; }
.sidebar {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto;
}
.sidebar h3 { margin: 0 0 .5rem; font-size: 1rem; }
.cat-item { display: flex; align-items: center; gap: .5rem; padding: .2rem 0; cursor: pointer; font-size: .95rem; }
.cat-item input { width: auto; }
.cat-item .count { margin-left: auto; color: var(--muted); font-size: .8rem; }
.cat-all { border-bottom: 1px solid var(--line); padding-bottom: .5rem; margin-bottom: .4rem; font-weight: 600; }
.toolbar { display: flex; gap: .7rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.toolbar input { flex: 1; min-width: 200px; }
.toolbar select { width: auto; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem; }
.book {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column; transition: box-shadow .15s;
}
.book:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.cover {
  aspect-ratio: 3 / 4; background: var(--accent-soft); display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 2.5rem; overflow: hidden;
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.book-info { padding: .7rem .8rem .9rem; display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.book-title { font-weight: 600; line-height: 1.35; }
.book-meta { font-size: .85rem; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }
.tag { font-size: .75rem; background: var(--accent-soft); color: var(--accent); padding: .05rem .5rem; border-radius: 999px; }
.status { font-size: .75rem; padding: .05rem .5rem; border-radius: 999px; background: #eee; color: #555; align-self: flex-start; }
.status.ok { background: #e2f1e5; color: #2e7a3f; }
.status.out { background: #fbe9e4; color: var(--warn); }

/* 詳細資料 */
.detail { display: grid; grid-template-columns: 180px 1fr; gap: 1.2rem; }
.detail .cover { border-radius: 8px; }
.detail h2 { margin: 0 0 .4rem; }
.detail dl { display: grid; grid-template-columns: 80px 1fr; gap: .3rem .6rem; margin: .8rem 0; font-size: .95rem; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; word-break: break-word; }

/* 卡片與表格 */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem; margin-bottom: 1.3rem; }
.panel h2 { margin-top: 0; font-size: 1.2rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.panel-head h2 { margin: 0; }
.auth-box { max-width: 420px; margin: 2rem auto; }
.stats { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.3rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1.2rem; min-width: 140px; }
.stat b { display: block; font-size: 1.6rem; color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .85rem; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #faf9f5; }
.type { font-size: .75rem; padding: .05rem .5rem; border-radius: 999px; white-space: nowrap; }
.type.lib { background: var(--accent-soft); color: var(--accent); }
.type.ext { background: #f1e9fb; color: #6a3fa0; }
.actions { white-space: nowrap; display: flex; gap: .3rem; }
.table-wrap { overflow-x: auto; }

/* 視窗 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal-box { background: #fff; border-radius: 12px; padding: 1.5rem; width: 100%; max-width: 640px; max-height: 90vh; overflow: auto; position: relative; }
.modal-box.wide { max-width: 900px; }
.modal-close { position: absolute; top: .5rem; right: .8rem; border: none; background: none; font-size: 1.6rem; cursor: pointer; color: var(--muted); }
.modal-box h2 { margin-top: 0; }
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .6rem 1.2rem; border-radius: 8px; z-index: 60; }

@media (max-width: 760px) {
  .catalog { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .detail { grid-template-columns: 1fr; }
  .detail .cover { max-width: 200px; }
  .form-row { grid-template-columns: 1fr; }
  .topbar { padding: .6rem 1rem; }
  main { padding: 1rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
