/* =========================================================
   🌸 全域設定（Index + Add 共用）
========================================================= */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Microsoft JhengHei", sans-serif;
  margin: 0;
  background: #f4f5f7;
  color: #222;
}

.main-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* =========================================================
   🌸 Header（Index）
========================================================= */
.header-row {
  padding: 16px;
  background: #ffffffcc;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #eee;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-container {
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.title-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
}

/* =========================================================
   🔍 搜尋框（Index）
========================================================= */
.search-box {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  position: relative;
  padding: 0 16px;
  box-sizing: border-box;
}

#search {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border: 1px solid #ddd;
  border-radius: 14px;
  font-size: 1rem;
  background: #fff;
  transition: 0.25s;
  box-sizing: border-box;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

#search:focus {
  outline: none;
  border-color: #7ab7f9;
  box-shadow: 0 0 0 3px rgba(122,183,249,0.25);
}

.search-box::before {
  content: "🔍";
  position: absolute;
  top: 13px;
  left: 28px;
  font-size: 1.2rem;
  opacity: 0.6;
}

/* 手機微調 */
@media (max-width: 480px) {
  .search-box {
    padding: 0 10px;
  }
  .search-box::before {
    left: 22px;
  }
}

/* =========================================================
   ➕ 新增按鈕（Index）
========================================================= */
.add-btn {
  display: inline-block;
  padding: 8px 14px;
  background: linear-gradient(135deg, #6cb0ff, #4f88ff);
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
  transition: 0.18s;
}

.add-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(0,0,0,0.25);
}

.secondary-btn {
  background: #eef4ff;
  color: #2b477a;
  box-shadow: none;
  border: 1px solid #d2e3ff;
}

.menu-wrapper {
  position: relative;
}

.menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: #eef4ff;
  color: #4f88ff;
  border: 1px solid #d2e3ff;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.menu-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(79,136,255,0.12);
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: none;
  flex-direction: column;
  min-width: 160px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.12);
  overflow: hidden;
  z-index: 30;
}

.menu-dropdown.open {
  display: flex;
}

.menu-dropdown a {
  padding: 12px 14px;
  text-decoration: none;
  color: #1f2a44;
  font-weight: 600;
  border-bottom: 1px solid #f1f1f1;
}

.menu-dropdown a:last-child {
  border-bottom: none;
}

.menu-dropdown a:hover,
.menu-dropdown a.active {
  background: #eef4ff;
  color: #2b477a;
}

/* =========================================================
   🌼 花卡片 Grid（Index）
========================================================= */
.grid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 18px;
}

.flower-card {
  background: white;
  padding: 18px 16px;
  border-radius: 18px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}

.flower-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 18px rgba(0,0,0,0.12);
}

.flower-name {
  font-weight: 700;
  font-size: 1.15rem;
  margin-bottom: 10px;
  letter-spacing: 0.3px;
}

/* 稀有度圓標 */
.rarity {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: white;
  font-weight: bold;
  font-size: 1rem;
  margin-bottom: 10px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.12);
  border: 2px solid rgba(255,255,255,0.9);
  backdrop-filter: blur(6px);
}

/* 稀有度顏色 */
.rarity-凡 { background: radial-gradient(circle, #e3f8d6 0%, #9ddc87 90%); }
.rarity-普 { background: radial-gradient(circle, #d9ecff 0%, #78b4f0 90%); }
.rarity-珍 { background: radial-gradient(circle, #eedcff 0%, #a285dd 90%); }
.rarity-華 { background: radial-gradient(circle, #ffe7c4 0%, #d39d3c 90%); }
.rarity-仙 { background: radial-gradient(circle, #ffd0d0 0%, #d86464 90%); }

/* 展開 */
.toggle {
  margin-top: 12px;
  color: #0d6efd;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.toggle:hover { text-decoration: underline; }

.owners {
  margin-top: 10px;
  font-size: 0.92rem;
  background: #f7f8fa;
  padding: 10px;
  border-radius: 10px;
  line-height: 1.5;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.08);
}

/* =========================================================
   🔥 Loading Overlay（Index）
========================================================= */
#loading-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  font-size: 18px;
  color: #444;
}

.loader {
  width: 40px;
  height: 40px;
  border: 5px solid #ddd;
  border-top-color: #ff69b4;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   ⭐ 稀有度篩選列（Index）
========================================================= */
.rarity-filter {
  margin: 12px auto 8px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  max-width: 880px;
  -webkit-overflow-scrolling: touch;
}

.rarity-filter button {
  padding: 6px 14px;
  border-radius: 999px;
  border: 2px solid transparent;
  background: #f3f4f6;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  transition: 0.2s;
}

/* 與稀有度一致色 */
/* ⭐ 全部按鈕（亮一點，帶邊框） */
.rarity-filter button[data-r="全部"] {background: #ffffff; color: #4f88ff;}
.rarity-filter button[data-r="凡"] { background:#e3f8d6; color:#266b1f;}
.rarity-filter button[data-r="普"] { background:#d9ecff; color:#2a72c8;}
.rarity-filter button[data-r="珍"] { background:#eedcff; color:#714bb1;}
.rarity-filter button[data-r="華"] { background:#ffe7c4; color:#b4751f;}
.rarity-filter button[data-r="仙"] { background:#ffd0d0; color:#b84345;}

.rarity-filter button.active {
  border-color: #4f88ff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

/* 搜尋結果數 */
#result-count {
  text-align: right;
  margin: 2px auto 12px;
  max-width: 880px;
  font-size: 0.9rem;
  color: #666;
  padding: 0 16px;
}

/* 搜尋高亮 */
.highlight {
  background: yellow;
  border-radius: 4px;
  padding: 0 2px;
}

/* 排序列 */
.sort-row {
  max-width: 880px;
  margin: 0 auto 12px;
  padding: 0 16px;
  display: flex;
  gap: 10px;
}

.sort-row select {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid #ccc;
  font-size: 0.9rem;
}

/* =========================================================
   📄 Add.html 專用樣式（已整合）
========================================================= */
.add-header {
  padding: 14px 20px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.add-header .menu-wrapper {
  margin-left: auto;
}

.back-btn {
  padding: 6px 14px;
  background: #eef4ff;
  color: #4f88ff;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  border: 1px solid #d2e3ff;
  font-size: 0.9rem;
}

.add-header h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  flex: 1;
  text-align: center;
}

main {
  max-width: 480px;
  margin: 24px auto;
  padding: 20px;
  padding-top: 40px;
  padding-bottom: 120px;
  flex: 1;
}

.tab-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}

.add-tabs {
  background: #eef4ff;
  border: 1px solid #d2e3ff;
  padding: 4px;
  border-radius: 14px;
  display: inline-flex;
  gap: 6px;
}

.tab-btn {
  margin: 0;
  width: auto;
  padding: 10px 14px;
  background: transparent;
  color: #4f5b7a;
  border-radius: 10px;
  box-shadow: none;
}

.tab-btn.active {
  background: #4f88ff;
  color: #fff;
}

.tab-hint {
  font-size: 0.85rem;
  color: #6b7280;
  margin-bottom: 14px;
}

.card {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
  position: relative;
  overflow: visible;
  margin-bottom: 18px;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.pill {
  padding: 6px 10px;
  background: #f2f6ff;
  color: #4f88ff;
  border-radius: 999px;
  border: 1px solid #d2e3ff;
  font-size: 0.85rem;
  font-weight: 700;
}

.pill-link {
  padding: 6px 12px;
  background: #f2f6ff;
  color: #2b477a;
  border-radius: 999px;
  border: 1px solid #d2e3ff;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
}

.pill-link:hover {
  background: #e6efff;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #ddd;
  font-size: 1rem;
  margin-bottom: 14px;
  box-sizing: border-box;
  display: block;
  max-width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #6cb0ff;
  box-shadow: 0 0 6px rgba(108,176,255,0.5);
}

button {
  width: 100%;
  padding: 12px 0;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #6cb0ff, #4f88ff);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
  margin-top: 10px;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.2);
}

.batch-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.batch-tools button {
  width: auto;
  padding: 10px 16px;
  margin-top: 0;
}

.batch-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 12px;
  margin-bottom: 6px;
}

.batch-form button {
  grid-column: 1 / -1;
}

.batch-preview {
  background: #f7f9ff;
  border: 1px solid #dce6ff;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  max-height: 260px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  padding: 8px 6px;
  border-bottom: 1px solid #e6ecff;
}

.preview-row:last-child { border-bottom: none; }

.preview-row .index { color: #6b7280; width: 42px; }
.preview-row .status.ok { color: #0f9d58; font-weight: 700; }
.preview-row .status.err { color: #d93025; font-weight: 700; }
.preview-row .text { color: #111827; flex: 1; }
.preview-row .note { color: #6b7280; font-size: 0.85rem; }
.preview-row .strong { font-weight: 700; }

.text-btn {
  background: transparent;
  color: #d93025;
  border: none;
  padding: 6px 10px;
  width: auto;
  margin: 0;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.text-btn:hover {
  background: #ffecec;
}

/* =========================================================
   🏆 任務指派頁
========================================================= */
.assign-header {
  justify-content: space-between;
}

.assign-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  white-space: nowrap;
}

.assign-title .title-short {
  display: none;
}

.assign-main {
  max-width: 780px;
  margin: 24px auto;
  padding: 0 20px 120px;
  box-sizing: border-box;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.assign-main .card { margin-bottom: 0; }

.card-desc {
  margin-top: 6px;
  color: #6b7280;
  line-height: 1.5;
}

.assignment-form {
  margin-top: 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 12px;
  margin-top: 8px;
}

.assignment-form button {
  width: 100%;
  margin-top: 4px;
}

.form-message {
  margin-top: 10px;
  font-weight: 700;
  color: #4f88ff;
}

.form-message.error {
  color: #d93025;
}

.assignment-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (max-width: 560px) {
  .assign-header {
    gap: 8px;
  }

  .assign-title {
    font-size: 1.05rem;
  }

  .assign-title .title-full {
    display: none;
  }

  .assign-title .title-short {
    display: inline;
  }

  .assign-main .card-title-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .assignment-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .complete-btn {
    width: 100%;
  }

  .assignment-meta {
    grid-template-columns: 1fr;
  }

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

.assignment-item {
  border: 1px solid #dce6ff;
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 10px 26px rgba(63, 81, 181, 0.06);
  box-sizing: border-box;
}

.assignment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.assignment-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.assignment-status {
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef9ff;
  color: #0f6bc6;
  border: 1px solid #cfe6ff;
  font-weight: 700;
  font-size: 0.9rem;
}

.assignment-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  align-items: stretch;
  font-weight: 700;
}

.assignment-meta .badge {
  background: #4f88ff;
  color: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.95rem;
}

.assignment-meta .tag {
  background: #f5f7ff;
  color: #2b477a;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.95rem;
  border: 1px solid #e0e7ff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.assignment-meta .tag .label {
  color: #6b7280;
  font-weight: 600;
  margin-right: 6px;
  font-size: 0.88rem;
}

.assignment-meta .tag .value {
  font-weight: 800;
  color: #111827;
  word-break: break-word;
  text-align: right;
}

.assignment-body {
  background: #f8fbff;
  border-radius: 10px;
  padding: 10px;
  border: 1px dashed #d6e4ff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.assignment-note {
  margin: 0;
  line-height: 1.5;
}

.assignment-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.complete-btn {
  width: auto;
  margin: 0;
  padding: 10px 14px;
  background: #10b981;
}

.complete-btn:hover {
  box-shadow: 0 6px 12px rgba(16, 185, 129, 0.3);
}

.muted {
  color: #6b7280;
  margin: 0;
}

.badge {
  background: #eef3ff;
  color: #3f51b5;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
}

.hidden { display: none !important; }

.inline-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #4b5563;
  padding: 6px 0;
}

.loader-sm {
  width: 26px;
  height: 26px;
  border-width: 4px;
}

.msg { margin-top: 12px; font-size: 0.9rem; }
.msg.ok { color: #198754; }
.msg.err { color: #dc3545; }

.small { font-size: 0.8rem; color:#666; }

/* 小型 Loading（Add） */
#submit-loading,
#update-loading {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

#submit-loading { display: none; }

/* Add 下拉 */
.dropdown { position: relative; }

.input-with-action {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.input-with-action .dropdown {
  flex: 1 1 auto;
  min-width: 0;
}

.input-with-action input {
  margin-bottom: 0;
}

.ghost-btn {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1.5px solid #d1d5db;
  background: #f9fafb;
  color: #374151;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s ease;
  white-space: nowrap;
  width: auto;
  margin: 0;
  align-self: stretch;
}

.ghost-btn:hover { background: #f3f4f6; }
.ghost-btn:active { transform: translateY(1px); }

.dropdown-list {
  position: absolute;
  top: 48px;
  width: 100%;
  background: white;
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
  max-height: 220px;
  overflow-y: auto;
  display: none;
  z-index: 3000;
  overscroll-behavior: contain;
}

.dropdown-item {
  padding: 10px 14px;
  font-size: 0.95rem;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
}

.dropdown-item:hover {
  background: #f7faff;
}

.dropdown-item:last-child { border-bottom:none; }

/* =========================================================
   Footer（Index、Add 共用）
========================================================= */
.footer {
  position: sticky;
  bottom: 0;
  width: 100%;
  text-align: center;
  padding: 10px 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-top: 1px solid #e0e0e0;
  font-size: 0.8rem;
  color: #555;
  margin-top: 20px;
}

.footer .version {
  font-size: 0.75rem;
  color: #777;
  margin-top: 2px;
}

/* 🔽 進階篩選按鈕（已修正：不超出畫面、置中、固定寬度） */
.advanced-btn {
  padding: 10px 16px;
  background: #eef3ff;
  border-radius: 999px;
  border: 1px solid #c8d5ff;
  color: #3f51b5;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;

  /* ⭐ 置中 & 限制寬度 */
  max-width: 380px;
  width: 100%;
  display: block;
  margin: 10px auto;

  text-align: center;
}

.advanced-btn:hover {
  background: #dde7ff;
}

/* 🔽 可折疊的進階區塊 */
.advanced-box {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
  padding: 0 16px;
}

.advanced-box.open {
  max-height: 200px;
  padding-top: 10px;
}