:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --ink: #2a2a2a;
  --muted: #6b6b6b;
  --line: #e7e3da;
  --primary: #3b6e8f;
  --primary-dark: #2a5570;
  --accent: #c98b56;
  --danger: #b3563f;
  --ok: #4f7a4a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Noto Sans TC', sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 240px;
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
  transition: transform .2s;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px 20px 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.brand a { flex: 1; min-width: 0; }
.sidebar-collapse-btn {
  flex: none;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  width: 30px; height: 30px; line-height: 1;
  color: var(--muted); font-size: 17px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.sidebar-collapse-btn:hover { border-color: var(--primary); color: var(--primary); }
.brand a { display: flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 18px; text-decoration: none; }
.brand-icon { font-size: 22px; }

.sidebar nav { padding: 0 8px; }
.nav-group {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
  padding: 14px 12px 4px;
  text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  text-decoration: none;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg); text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item span { width: 20px; display: inline-block; text-align: center; }

.version { padding: 16px 20px; color: var(--muted); font-size: 11px; }

.menu-toggle {
  display: none;
  position: fixed; top: 12px; left: 12px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 8px;
  width: 40px; height: 40px;
  font-size: 18px; cursor: pointer; z-index: 100;
}

/* ---- Main ---- */
.content {
  margin-left: 240px;
  padding: 24px 32px 80px;
  max-width: 1100px;
  transition: margin-left .2s;
}
.content.full { margin: 8vh auto 0; max-width: 480px; }

/* 桌機收合側欄：整個側欄滑出、內容補滿，浮出清單 icon 可再展開 */
html.app-sidebar-collapsed .sidebar { transform: translateX(-100%); }
html.app-sidebar-collapsed .content:not(.full) { margin-left: 0; }
html.app-sidebar-collapsed .menu-toggle { display: block; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 4px 24px rgba(0,0,0,.15); }
  .menu-toggle { display: block; }
  .content { margin-left: 0; padding: 56px 16px 80px; }
}

/* ---- Flash ---- */
.flashes { margin-bottom: 16px; }
.flash {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 8px;
  background: #fff; border: 1px solid var(--line);
}
.flash.success { border-color: var(--ok); color: var(--ok); }
.flash.error { border-color: var(--danger); color: var(--danger); }

/* ---- Page header ---- */
.page-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.page-title { margin: 0; font-size: 24px; }
.page-title .icon { margin-right: 6px; }
.page-subtitle { color: var(--muted); margin: 4px 0 0; font-size: 14px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink);
  font-size: 14px; cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-link { background: none; border: none; padding: 0; color: var(--primary); cursor: pointer; }

/* ---- Cards / Grid ---- */
.card {
  background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ---- Forms ---- */
.form-row { margin-bottom: 14px; }
.form-row label {
  display: block; margin-bottom: 4px;
  font-size: 13px; color: var(--muted); font-weight: 500;
}
.form-row input[type=text],
.form-row input[type=password],
.form-row input[type=number],
.form-row input[type=date],
.form-row input[type=email],
.form-row input[type=url],
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
.form-row textarea {
  min-height: 260px;
  resize: vertical;
  line-height: 1.7;
  font-size: 15px;
}
/* 主要內文欄位（content / detail / memory / steps / tricky_lyrics 等）給更大空間 */
.form-row textarea[name="content"],
.form-row textarea[name="detail"],
.form-row textarea[name="memory"],
.form-row textarea[name="steps"],
.form-row textarea[name="tricky_lyrics"],
.form-row textarea[name="review"],
.form-row textarea[name="ingredients"],
.form-row textarea[name="note"],
.form-row textarea[name="notes"] {
  min-height: 400px;
}
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }

/* ---- Table ---- */
table.list {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
table.list th, table.list td {
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid var(--line); font-size: 14px;
  vertical-align: middle;
}
table.list th { background: var(--bg); color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
table.list tr:last-child td { border-bottom: none; }
table.list tr:hover td { background: var(--bg); }

/* 表格內欄位寬度：預設整列 nowrap，避免「類別/狀態/日期/按鈕」被擠到變兩行 */
table.list td { white-space: nowrap; }
/* 只有標題、摘要允許換行 */
table.list td.col-title,
table.list td .cell-excerpt {
  white-space: normal;
}
table.list td.col-title {
  min-width: 240px;
  max-width: 420px;
  word-break: break-word;
}
/* 標題欄內部排版：縮圖左 + 標題右，垂直置中 */
.col-title-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}
.col-title-body {
  flex: 1;
  min-width: 0;
}
.col-title-text {
  display: inline;
  line-height: 1.45;
}

.cell-excerpt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 380px;
  min-width: 200px;
  color: var(--muted, #666);
  font-size: 13px;
  line-height: 1.5;
  cursor: help;
  word-break: break-word;
  white-space: normal;
}

/* 列表縮圖（每筆紀錄首張上傳照片做為封面） */
.row-thumb-link {
  display: inline-block;
  position: relative;
  width: 40px; height: 40px;
  vertical-align: middle;
  border-radius: 6px;
  overflow: hidden;
  background: #f3f3f3;
  border: 1px solid var(--line, #e5e5e5);
  flex-shrink: 0;
}
/* 簽章列表縮圖旁的快捷操作（下載 / 複製） */
.row-thumb-wrap {
  display: inline-flex; flex-direction: column; align-items: center; gap: 4px;
  flex-shrink: 0;
}
.row-thumb-actions {
  display: flex; gap: 2px;
}
.row-thumb-actions .btn-sm {
  padding: 1px 5px; font-size: 11px;
  background: var(--bg, #f5f5f5);
  border: 1px solid var(--line, #e0e0e0);
  border-radius: 4px;
  text-decoration: none;
  color: var(--text, #333);
}
.row-thumb-actions .btn-sm:hover {
  background: var(--primary, #3b6e8f); color: #fff; border-color: var(--primary, #3b6e8f);
}

/* 通用棋盤格 mixin（class）— 用來鋪在透明圖背後 */
.checker-bg {
  background-color: #fff !important;
  background-image:
    linear-gradient(45deg, #d8d8d8 25%, transparent 25%),
    linear-gradient(-45deg, #d8d8d8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d8d8d8 75%),
    linear-gradient(-45deg, transparent 75%, #d8d8d8 75%) !important;
  background-size: 12px 12px !important;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0 !important;
}

/* 簽章圖檔常見「黑底掃描」：SVG filter 把暗色當透明，露出底下棋盤格 */
.sig-remove-black { filter: url(#sig-remove-black); }

/* 簽章管理：縮圖加大；棋盤格鋪在容器+img 兩層，object-fit 用 contain */
table.list.slug-signature .row-thumb-link {
  width: 88px !important; height: 64px !important;
  border-radius: 4px;
  background-color: #fff !important;
  background-image:
    linear-gradient(45deg, #d8d8d8 25%, transparent 25%),
    linear-gradient(-45deg, #d8d8d8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d8d8d8 75%),
    linear-gradient(-45deg, transparent 75%, #d8d8d8 75%) !important;
  background-size: 12px 12px !important;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0 !important;
}
/* img 本身：強制 contain + 套 SVG filter 把黑色當透明 */
table.list.slug-signature .row-thumb {
  object-fit: contain !important;
  background: transparent !important;
  filter: url(#sig-remove-black) !important;
}

/* 詳細頁簽章圖也套 filter */
table.list.slug-signature .row-thumb,
body.slug-signature-page .photo img,
.dl-lightbox.sig-mode img {
  filter: url(#sig-remove-black) !important;
}

/* 簽章詳細頁照片縮圖也鋪棋盤格 */
body.slug-signature-page .photo,
body.slug-signature-page .photo img {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e0e0e0 25%, transparent 25%),
    linear-gradient(-45deg, #e0e0e0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e0e0e0 75%),
    linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
}
.row-thumb-link:hover { border-color: var(--primary, #3b6e8f); }
.row-thumb {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.row-thumb-count {
  position: absolute;
  right: 2px; bottom: 2px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 8px;
  line-height: 1.2;
}

/* ── 共用 Lightbox（縮放/拖移） ── */
.dl-lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  overflow: hidden;
  user-select: none;
}
.dl-lightbox-stage {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.dl-lightbox-stage img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  display: block;
  transform-origin: center center;
  transition: transform .08s ease-out;
  cursor: zoom-in;
  -webkit-user-drag: none;
  touch-action: none;
}
.dl-lightbox-toolbar {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.55);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 6px 10px;
  z-index: 10000;
  color: #fff;
}
.dl-lightbox-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.dl-lightbox-btn:hover { background: rgba(255,255,255,.12); }
.dl-lightbox-zoom {
  min-width: 52px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.dl-lightbox-close {
  position: absolute;
  top: 14px; right: 16px;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(0,0,0,.5);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
  transition: background .15s, transform .1s;
}
.dl-lightbox-close:hover {
  background: rgba(220,30,30,.85);
  transform: scale(1.05);
}
@media (max-width: 480px) {
  .dl-lightbox-toolbar { top: 8px; padding: 4px 8px; }
  .dl-lightbox-btn { width: 32px; height: 32px; font-size: 16px; }
  .dl-lightbox-close { top: 8px; right: 8px; width: 38px; height: 38px; font-size: 22px; }
}

/* ---- Stats（舊樣式，向後相容） ---- */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 24px;
}
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; text-decoration: none; color: var(--ink); display: block;
}
.stat:hover { border-color: var(--primary); text-decoration: none; }
.stat-icon { font-size: 22px; }
.stat-name { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat-count { font-size: 22px; font-weight: 700; margin-top: 2px; }

/* ---- Home（編輯式緊湊卡片） ---- */
.home-group { margin-bottom: 12px; }
.home-group-head {
  font-size: 13px; color: var(--muted); letter-spacing: 1px;
  margin: 12px 0 6px; display: flex; align-items: center; gap: 6px;
}
.drag-handle {
  visibility: hidden; cursor: grab; color: var(--muted);
  padding: 0 4px; font-size: 16px; user-select: none;
}
.home-editing .drag-handle { visibility: visible; }
.home-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}
.home-card {
  position: relative;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; text-decoration: none; color: var(--ink);
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; min-height: 56px;
}
.home-card:hover { border-color: var(--primary); text-decoration: none; }
.home-editing .home-card { cursor: grab; }
.home-editing .home-card:active { cursor: grabbing; }
.home-card-icon { font-size: 22px; }
.home-card-name { flex: 1; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-card-count {
  font-size: 12px; color: var(--muted); background: var(--bg);
  padding: 2px 8px; border-radius: 10px; min-width: 24px; text-align: center;
}
.home-card-toggle {
  display: none; position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #c62828; color: #fff; border: none;
  font-size: 12px; cursor: pointer; line-height: 1;
}
.home-editing .home-card-toggle { display: inline-block; }
.home-card-hidden { display: none; }
.home-editing .home-card-hidden { display: flex; opacity: .45; }
.home-card-hidden .home-card-toggle { background: #1e8b3a; }

/* ---- Profile ---- */
.profile-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; padding: 24px; border-radius: 16px; margin-bottom: 16px;
}
.profile-card h2 { margin: 0; font-size: 22px; }
.profile-card .motto { opacity: .85; margin-top: 6px; font-size: 14px; }

/* ---- Tags ---- */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); margin-right: 4px;
}
.tag.fav { background: #fff7e0; border-color: #f1d27a; color: #8d6a14; }
.tag.archived { background: #ecebe6; }
.tag-in { background: #e6f4ec; border-color: #a8d4b6; color: #1e8b3a; }
.tag-out { background: #fbe8ea; border-color: #e9b1b6; color: #c62828; }

/* ---- 密碼管理（passmgr） ---- */
.passmgr-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
@media (max-width: 900px) { .passmgr-layout { grid-template-columns: 1fr; } }
.passmgr-side { position: sticky; top: 8px; align-self: start; }
.ident-row-wrap { position: relative; }
.ident-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; text-decoration: none;
  color: inherit; transition: background .15s;
}
.ident-row:hover { background: var(--bg); }
.ident-row.active { background: rgba(59,110,143,.12); font-weight: 600; }
.ident-icon { font-size: 18px; }
.ident-name { flex: 1; }
.ident-count { font-size: 12px; color: var(--muted); background: var(--bg); padding: 1px 8px; border-radius: 10px; }
.ident-actions {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: none; gap: 2px;
}
.ident-row-wrap:hover .ident-actions { display: flex; }
.cat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 14px; margin: 2px;
  background: var(--bg); border: 1px solid var(--line); font-size: 13px;
  text-decoration: none; color: inherit;
}
.cat-pill.active { background: rgba(59,110,143,.15); border-color: #3b6e8f; color: #3b6e8f; font-weight: 600; }
.cat-pill span { font-size: 11px; opacity: .65; }
/* 帳號條列表 */
.acc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.acc-table th, .acc-table td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.acc-table th {
  background: var(--bg); font-weight: 600; color: var(--muted); font-size: 12px;
}
.acc-tr.insecure { background: #fdf6f6; }
.acc-tr strong { font-weight: 600; }
.acc-toggle {
  background: none; border: none; cursor: pointer; padding: 2px 4px;
  margin-right: 4px; color: var(--muted); font-size: 12px;
}
.acc-toggle:hover { color: var(--text); }
.acc-detail td {
  background: var(--bg); padding: 12px 16px; border-bottom: 2px solid var(--line);
}
.acc-detail-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 4px 16px;
}
.link-badge { font-size: 12px; opacity: .7; margin-left: 4px; }
.acc-row {
  display: flex; align-items: center; gap: 6px; font-size: 13px;
  padding: 2px 0;
}
.acc-row > .muted:first-child { width: 60px; flex-shrink: 0; }
.acc-row .copyable { flex: 1; word-break: break-all; }
.acc-row .pw-mask { flex: 1; font-family: monospace; }
.cat-select { font-size: 12px; padding: 2px 6px; max-width: 120px; }
.pw-mask { font-family: monospace; }

/* dropdown menu (details/summary) */
.dropdown { position: relative; display: inline-block; }
.dropdown > summary { list-style: none; cursor: pointer; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown[open] .dropdown-menu {
  position: absolute; top: 100%; right: 0; min-width: 240px; z-index: 100;
  margin-top: 4px; padding: 12px;
}
.dropdown-menu { display: flex; flex-direction: column; gap: 6px; }

/* dialog modal */
.dlg { border: none; border-radius: 12px; padding: 0; background: transparent; }
.dlg::backdrop { background: rgba(0,0,0,.4); }
.dlg .card { padding: 20px; }

/* ---- Data table（記帳列表通用） ---- */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.data-table th {
  background: var(--bg); font-weight: 600; color: var(--muted); font-size: 12px;
}
.data-table tr:last-child td { border-bottom: none; }

/* ---- Photo grid ---- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.photos .photo { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; }
.photos .photo img { width: 100%; height: 100%; object-fit: cover; }
.photos .photo button {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 50%;
  width: 24px; height: 24px; cursor: pointer; font-size: 14px;
}

/* ---- Detail ---- */
.detail-row { display: flex; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.detail-row:last-child { border-bottom: none; }
.detail-row .key { color: var(--muted); font-size: 13px; min-width: 110px; }
.detail-row .val { flex: 1; word-break: break-word; }
.detail-row .val pre, .val pre, .card pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font: inherit;
  margin: 0;
}

/* ---- Login ---- */
.auth-box {
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 32px; box-shadow: 0 8px 24px rgba(0,0,0,.04);
}
.auth-box h1 { margin: 0 0 4px; }
.auth-box .lead { color: var(--muted); margin-bottom: 24px; }

/* utils */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.empty { text-align: center; padding: 40px; color: var(--muted); }
.password-cell { font-family: monospace; }
.copy-block pre {
  white-space: pre-wrap; word-break: break-word;
  background: var(--bg); padding: 12px 14px; border-radius: 8px;
  border: 1px solid var(--line); margin: 0 0 8px;
  line-height: 1.7;
}
.copy-meta { display: flex; gap: 8px; align-items: center; }
.copy-meta .muted { font-size: 13px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] {
  flex: 1; min-width: 200px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font: inherit;
}
.inline-form { display: inline; }
.hidden { display: none; }
code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.disabled-input,
input:disabled, select:disabled, textarea:disabled {
  background: var(--bg); color: var(--muted); cursor: not-allowed;
}

/* 快速更新 inline form */
.quick-form { display: flex; gap: 2px; align-items: center; }
.quick-form input[type=text] {
  flex: 1; min-width: 60px;
  padding: 3px 6px;
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 13px; background: #fff;
}
.quick-form input[type=number] {
  width: 50px; flex: 0 0 50px;
  padding: 3px 4px; text-align: center;
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 13px; background: #fff;
  -moz-appearance: textfield;
}
.quick-form input[type=number]::-webkit-outer-spin-button,
.quick-form input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.quick-form input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.quick-form .btn-sm { padding: 3px 8px; font-size: 12px; }

/* 今日按鈕、日期顯示 */
.date-display { font-size: 13px; min-width: 76px; display: inline-block; }
.today-form .btn-sm { padding: 3px 8px; font-size: 12px; }

/* 星星 - 編輯 (form) */
.stars-edit { display: inline-flex; gap: 2px; align-items: center; }
.stars-edit .star {
  font-size: 26px; cursor: pointer;
  color: #ddd; user-select: none;
  transition: color .12s, transform .12s;
}
.stars-edit .star.on { color: #f4b400; }
.stars-edit .star:hover { transform: scale(1.15); }
.stars-edit button.star-clear { margin-left: 8px; }

/* 星星 - 列表 inline 點選 */
.stars-inline { display: inline-flex; gap: 0; align-items: center; }
.stars-inline form { display: inline; }
.stars-inline .star-btn {
  background: none; border: none; padding: 0;
  font-size: 16px; line-height: 1;
  color: #ddd; cursor: pointer;
}
.stars-inline .star-btn.on { color: #f4b400; }
.stars-inline .star-btn:hover { transform: scale(1.25); }

/* 星星 - 詳細頁靜態 */
.stars-static { font-size: 18px; color: #ddd; }
.stars-static .on { color: #f4b400; }

/* 行內 AJAX 操作的視覺反饋 */
.toast {
  position: fixed;
  background: #2c3e50; color: #fff;
  padding: 8px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  pointer-events: none;
  opacity: 0; transform: translateY(-6px);
  transition: opacity .2s ease, transform .2s ease;
  z-index: 1000;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #b3563f; }

td.cell-flash, .cell-flash {
  animation: cellFlash 0.9s ease-out;
}
@keyframes cellFlash {
  0% { background-color: #c8e6c9; }
  60% { background-color: #d4edda; }
  100% { background-color: transparent; }
}

form.saving { opacity: 0.55; pointer-events: none; }
form.saving button { cursor: wait; }
.quick-form button[type=submit]:active,
.today-form button[type=submit]:active { transform: scale(0.92); }

/* 類別 tabs */
.cat-tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 12px 0 16px; padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.cat-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 16px;
  background: #fff; border: 1px solid var(--line);
  color: var(--ink); font-size: 13px; text-decoration: none;
}
.cat-tab:hover { background: var(--bg); text-decoration: none; }
.cat-tab.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.cat-tab.active .muted { color: rgba(255,255,255,.8); }

/* ---- 靈感筆記（idea） ---- */
.idea-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.idea-card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; display: flex; flex-direction: column;
  position: relative; transition: box-shadow .15s, transform .1s;
}
.idea-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.idea-card.pinned { border-color: #f1c40f; box-shadow: 0 0 0 2px #fff7e0; }
.idea-pin {
  position: absolute; top: 8px; right: 8px; font-size: 18px; z-index: 2;
  background: rgba(255,255,255,.85); border-radius: 50%; width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
}
.idea-images { position: relative; background: #f5f5f5; }
.idea-images.n1 img { width: 100%; height: auto; max-height: 360px; object-fit: cover; display:block; }
.idea-images.n2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; }
.idea-images.n3 { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; }
.idea-images.n4 { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; }
.idea-images.n2 img, .idea-images.n3 img, .idea-images.n4 img {
  width: 100%; height: 140px; object-fit: cover; display: block;
}
.idea-images.n3 .idea-img:first-child { grid-column: span 2; }
.idea-images.n3 .idea-img:first-child img { height: 200px; }
.idea-img { display: block; cursor: zoom-in; overflow: hidden; }
.idea-img-more {
  position: absolute; right: 6px; bottom: 6px;
  background: rgba(0,0,0,.65); color: #fff; font-size: 12px;
  padding: 2px 8px; border-radius: 10px;
}
.idea-body { padding: 12px 14px 6px; flex: 1; }
.idea-title {
  display: block; font-weight: 600; color: var(--text);
  margin-bottom: 6px; text-decoration: none;
}
.idea-title:hover { color: var(--primary); }
.idea-content {
  white-space: pre-wrap; word-break: break-word; line-height: 1.5;
  font-size: 14px; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical;
  overflow: hidden;
}
.idea-link {
  display: inline-block; margin-top: 8px; font-size: 13px;
  color: var(--primary); text-decoration: none; word-break: break-all;
}
.idea-link:hover { text-decoration: underline; }
.idea-meta {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px 10px; gap: 8px; flex-wrap: wrap;
}
.idea-meta-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.idea-actions { display: flex; gap: 2px; }
.btn-icon {
  background: none; border: none; cursor: pointer; padding: 4px 6px;
  font-size: 16px; border-radius: 6px; line-height: 1;
  text-decoration: none;
}
.btn-icon:hover { background: var(--bg); }
.btn-icon.danger:hover { background: #fbe8ea; }
.idea-group-title { margin: 24px 0 12px; }

/* 卡片 / 條列 切換鈕 */
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--line, #e5e5e5);
  border-radius: 8px;
  overflow: hidden;
  margin-right: 4px;
}
.view-toggle .view-btn {
  border: none;
  border-radius: 0;
  background: #fff;
  color: var(--muted, #666);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.view-toggle .view-btn + .view-btn { border-left: 1px solid var(--line, #e5e5e5); }
.view-toggle .view-btn:hover { background: var(--bg, #fafafa); color: var(--text, #222); }
.view-toggle .view-btn.active {
  background: var(--primary, #3b6e8f);
  color: #fff;
}

/* ── 條列檢視（idea-grid.list-mode） ── */
.idea-grid.list-mode {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.idea-grid.list-mode .idea-card {
  flex-direction: row;
  align-items: stretch;
  padding: 0;
  min-height: 56px;
}
.idea-grid.list-mode .idea-images {
  flex-shrink: 0;
  width: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  position: relative;
}
.idea-grid.list-mode .idea-images.n1 img,
.idea-grid.list-mode .idea-images.n2,
.idea-grid.list-mode .idea-images.n3,
.idea-grid.list-mode .idea-images.n4 {
  display: none;
}
/* 只顯示第一張縮圖 */
.idea-grid.list-mode .idea-images .idea-img:first-child {
  display: block;
  width: 64px; height: 64px;
}
.idea-grid.list-mode .idea-images .idea-img:first-child img {
  width: 64px; height: 64px; object-fit: cover; max-height: none;
}
.idea-grid.list-mode .idea-images .idea-img:not(:first-child) { display: none; }
.idea-grid.list-mode .idea-img-more {
  position: absolute; right: 2px; bottom: 2px;
  font-size: 10px; padding: 1px 5px;
}
.idea-grid.list-mode .idea-pin {
  position: static;
  width: auto; height: auto;
  background: transparent;
  margin: 0 0 0 10px;
  align-self: center;
  font-size: 15px;
  order: -1;
}
.idea-grid.list-mode .idea-body {
  padding: 8px 12px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}
.idea-grid.list-mode .idea-title {
  margin: 0;
  flex-shrink: 0;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.idea-grid.list-mode .idea-content {
  flex: 1;
  min-width: 0;
  -webkit-line-clamp: 1;
  line-height: 1.4;
  font-size: 13px;
  color: var(--muted, #666);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.idea-grid.list-mode .idea-link {
  margin-top: 0;
  flex-shrink: 0;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.idea-grid.list-mode .idea-meta {
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  padding: 6px 10px;
  gap: 6px;
  border-left: 1px solid var(--line, #eee);
}
.idea-grid.list-mode .idea-meta-left { gap: 4px; }
.idea-grid.list-mode .idea-meta-left .muted { font-size: 11px; }
.idea-grid.list-mode .idea-actions { gap: 0; }

@media (max-width: 640px) {
  .idea-grid.list-mode .idea-title { max-width: 110px; font-size: 14px; }
  .idea-grid.list-mode .idea-content { display: none; }
  .idea-grid.list-mode .idea-link { display: none; }
  .idea-grid.list-mode .idea-images { width: 48px; }
  .idea-grid.list-mode .idea-images .idea-img:first-child,
  .idea-grid.list-mode .idea-images .idea-img:first-child img { width: 48px; height: 48px; }
}

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.lightbox.hidden { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-close {
  position: absolute; top: 16px; right: 20px;
  background: none; border: none; color: #fff; font-size: 36px;
  cursor: pointer; line-height: 1;
}
