/* ===== 提示詞手帳 —— 視覺設計：帳簿紙 + 卡片索引櫃 =====
   色彩：冷調帳簿紙 + 墨藍 + 黃銅 強調色（刻意避開常見嘅暖米色+赭紅AI樣板配色）
   字體：Fraunces（標題，帳簿感襯線）／ Inter（內文）／ JetBrains Mono（提示詞內容，呼應「prompt」嘅指令行出身）
*/

:root {
  --paper: #eceee6;
  --paper-line: #d9d6c8;
  --card: #fbfaf6;
  --ink: #1c2b3a;
  --ink-soft: #5b6b78;
  --brass: #a9762e;
  --brass-dark: #8a5f22;
  --brass-tint: #e8d9b8;
  --clay: #93473a;
  --clay-tint: #f1ded9;
  --sage: #46624f;
  --sage-tint: #dde7df;
  --radius-sm: 6px;
  --radius-md: 10px;
  --shadow-card: 0 1px 0 rgba(28, 43, 58, 0.04), 0 6px 16px -10px rgba(28, 43, 58, 0.25);
  --shadow-pop: 0 12px 32px -8px rgba(28, 43, 58, 0.35);
  font-size: 16px;
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

body {
  margin: 0;
  background: var(--paper);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 27px,
    rgba(28, 43, 58, 0.035) 28px
  );
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  font-family: 'Fraunces', serif;
  font-size: 28px;
  font-weight: 600;
  color: var(--brass);
  border: 1.5px solid var(--brass);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand h1 {
  font-family: 'Fraunces', serif;
  font-size: 26px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #14202c; }

.btn-ghost { background: transparent; color: var(--ink); border-color: var(--paper-line); }
.btn-ghost:hover { background: rgba(28, 43, 58, 0.06); }

.btn-danger { background: var(--clay-tint); color: var(--clay); border-color: var(--clay); }
.btn-danger:hover { background: var(--clay); color: #fff; }

.file-btn { display: inline-flex; align-items: center; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

.search-wrap { position: relative; flex: 1 1 220px; min-width: 180px; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-soft); }

.search-input, .select {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1.5px solid var(--paper-line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
}
.search-input { padding-left: 34px; }
.select { width: auto; cursor: pointer; }
.search-input:focus, .select:focus { outline: 2px solid var(--brass); outline-offset: 1px; }

.favorite-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  user-select: none;
}
.favorite-filter:hover { background: rgba(28, 43, 58, 0.05); }
.favorite-filter input { accent-color: var(--brass); }

/* ---------- Category dropdown (取代舊式tabs，分類多咗時更易用) ---------- */
.category-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.category-dropdown { position: relative; }

.category-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Fraunces', serif;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 14px;
  background: var(--card);
  border: 1.5px solid var(--paper-line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--ink);
}
.category-dropdown-btn:hover { border-color: var(--brass); }
.category-dropdown-btn .chevron { color: var(--ink-soft); font-size: 12px; margin-left: 2px; }

.cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brass);
  flex-shrink: 0;
  display: inline-block;
}

.category-dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 230px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--card);
  border: 1.5px solid var(--paper-line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  padding: 6px;
}

.cat-sort-bar {
  display: flex;
  gap: 4px;
  padding: 2px 4px 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--paper-line);
}
.cat-sort-btn {
  flex: 1;
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 4px;
  border: 1px solid var(--paper-line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.cat-sort-btn:hover { border-color: var(--brass); color: var(--ink); }
.cat-sort-btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.cat-option {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--ink);
}
.cat-option:hover { background: rgba(28, 43, 58, 0.06); }
.cat-option.active { background: var(--brass-tint); font-weight: 600; }
.cat-option .cat-count { margin-left: auto; font-size: 12px; color: var(--ink-soft); }

.btn-small { font-size: 13px; padding: 8px 12px; }

/* ---------- Manage categories modal ---------- */
.categories-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.category-row-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--paper-line);
}
.category-row-item:last-child { border-bottom: none; }

.category-row-item .cat-name { flex: 1; font-size: 14px; }
.category-row-item .cat-count { font-size: 12px; color: var(--ink-soft); }
.category-row-item input[type="color"] {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1.5px solid var(--paper-line);
  border-radius: 50%;
  cursor: pointer;
  background: none;
}

.add-category-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--paper-line);
}
.add-category-row input[type="text"] { flex: 1; }
.add-category-row input[type="color"] {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1.5px solid var(--paper-line);
  border-radius: 50%;
  cursor: pointer;
  background: none;
}

.custom-cat-row { display: flex; gap: 8px; align-items: center; }
.custom-cat-row input[type="text"] { flex: 1; }
.custom-cat-row input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1.5px solid var(--paper-line);
  border-radius: 50%;
  cursor: pointer;
  background: none;
}

/* ---------- Tag filter bar ---------- */
.tag-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  min-height: 0;
}
.tag-chip {
  font-size: 12.5px;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--paper-line);
  background: var(--card);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.12s ease;
}
.tag-chip:hover { border-color: var(--brass); color: var(--ink); }
.tag-chip.active { background: var(--brass); color: #fff; border-color: var(--brass); }

/* ---------- Prompt grid & card ---------- */
.prompt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.prompt-card {
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  border-left: 4px solid var(--cat-color, var(--brass));
  padding: 16px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}

.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }

.card-title-wrap { min-width: 0; }

.card-category {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--cat-color, var(--brass));
  text-transform: uppercase;
}

.card-title {
  font-family: 'Fraunces', serif;
  font-size: 17px;
  font-weight: 600;
  margin: 2px 0 0;
  word-break: break-word;
}

.fav-btn {
  background: none;
  border: none;
  font-size: 19px;
  cursor: pointer;
  color: var(--paper-line);
  line-height: 1;
  padding: 2px;
  flex-shrink: 0;
}
.fav-btn.active { color: var(--brass); }

.card-content {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-soft);
  background: rgba(28, 43, 58, 0.035);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  max-height: 84px;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}
.card-content::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 22px;
  background: linear-gradient(to bottom, transparent, rgba(251,250,246,0.95));
}

.card-tags { display: flex; gap: 5px; flex-wrap: wrap; }
.mini-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--sage-tint);
  color: var(--sage);
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--ink-soft);
  opacity: 0.85;
  margin-top: auto;
}

.card-actions { display: flex; gap: 6px; align-items: center; }

.icon-btn {
  background: none;
  border: 1.5px solid var(--paper-line);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--ink-soft);
  transition: border-color 0.12s ease, color 0.12s ease;
}
.icon-btn:hover { border-color: var(--ink); color: var(--ink); }

/* signature element: 印章式複製按鈕 */
.stamp-btn {
  background: var(--ink);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: transform 0.18s cubic-bezier(.34,1.56,.64,1), background 0.15s ease;
}
.stamp-btn:hover { background: var(--brass-dark); }
.stamp-btn.stamped {
  animation: stamp-press 0.38s ease;
  background: var(--sage);
}
@keyframes stamp-press {
  0% { transform: scale(1) rotate(0); }
  35% { transform: scale(0.82) rotate(-8deg); }
  60% { transform: scale(1.12) rotate(3deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ---------- Empty / loading ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty-title { font-family: 'Fraunces', serif; font-size: 19px; color: var(--ink); margin: 0 0 6px; }
.empty-sub { font-size: 14px; margin: 0; }
.loading-state { text-align: center; padding: 40px; color: var(--ink-soft); font-size: 14px; }
.loading-state[hidden] { display: none; }

/* ---------- Modal ---------- */
.modal {
  border: none;
  border-radius: var(--radius-md);
  padding: 0;
  box-shadow: var(--shadow-pop);
  max-width: 520px;
  width: 92vw;
  background: var(--card);
}
.modal::backdrop { background: rgba(28, 43, 58, 0.45); }
.modal-small { max-width: 380px; }

.modal-form { padding: 26px 26px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-form h2 { font-family: 'Fraunces', serif; font-size: 21px; margin: 0 0 4px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.field-label { font-size: 13px; font-weight: 600; color: var(--ink); }
.hint { font-weight: 400; font-size: 12px; color: var(--ink-soft); display: block; margin-top: 2px; }
.hint code { background: var(--brass-tint); padding: 1px 5px; border-radius: 4px; font-size: 11px; }

input[type="text"], input[type="search"], select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border: 1.5px solid var(--paper-line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
}
textarea {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  resize: vertical;
  line-height: 1.5;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brass); outline-offset: 1px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.checkbox-row input { accent-color: var(--brass); width: 16px; height: 16px; }

.form-error { color: var(--clay); font-size: 13px; margin: 0; }

.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }

.fill-fields { display: flex; flex-direction: column; gap: 12px; }
.fill-fields label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: #fff;
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .app-header { flex-direction: column; }
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; }
  .field-row { flex-direction: column; }
}
