/* ════════════════════════════════════════
   LIBRARY — Sổ từ vựng (redesign)
════════════════════════════════════════ */

/* ── Page shell ────────────────────────── */
.lib-page {
  padding: 0 !important;
  /* Thoát khỏi padding ngang của #main để controls header full-width */
  margin-left: calc(-1 * var(--main-px, 16px));
  margin-right: calc(-1 * var(--main-px, 16px));
  width: calc(100% + 2 * var(--main-px, 16px));
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.page.active.lib-page { display: flex !important; }

/* ── Controls (sticky header compact) ────── */
.lib-controls {
  flex-shrink: 0;
  padding: 12px 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.lib-header-row {
  display: flex; align-items: center;
  justify-content: space-between; gap: 8px;
}
/* Stat text inline: "📚 3 bộ · 📝 60 từ" */
.lib-stat-inline {
  font-size: 0.82rem; color: var(--text-muted); font-weight: 500;
  flex: 1; min-width: 0;
}
.lib-stat-inline b { color: var(--text); font-weight: 700; }
.lib-stat-due { color: #DC2626; font-weight: 600; }

/* Filter icon button */
.lib-btn-filter-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  background: none; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: 0.9rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.lib-btn-filter-icon:hover  { border-color: var(--purple); color: var(--purple); }
.lib-btn-filter-icon.active { background: var(--purple-light); border-color: var(--purple); color: var(--purple); }

/* Filter | Sort | View (collapsible) */
.lib-row-controls { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.lib-row-controls.hidden { display: none; }
.lib-filter-select { flex: 1; min-width: 0; border: 1.5px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); padding: 7px 9px; font-size: 0.78rem; font-weight: 600; color: var(--text); cursor: pointer; font-family: inherit; outline: none; }
.lib-filter-select:focus { border-color: var(--purple); }

/* ── FAB: Tạo bộ từ ─────────────────────── */
.lib-fab {
  /* !important: chống mọi inline style đè (ripple ở main.js cũ từng gán
     position:relative khi nhấn → FAB nhảy sang góc trái) */
  position: fixed !important;
  right: 20px;
  bottom: calc(var(--nav-h) + 14px);
  width: 52px; height: 52px;
  background: var(--purple); color: #fff;
  border: none; border-radius: 50%;
  font-size: 1.6rem; font-weight: 300; line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(14,165,233,0.45);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 90;
}
.lib-fab:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(14,165,233,0.55); }

/* ── View toggle ────────────────────────── */
.lib-view-toggle { display: flex; gap: 2px; margin-left: 4px; }
.lib-view-btn {
  background: none; border: 1.5px solid var(--border); color: var(--text-muted);
  border-radius: var(--radius-sm); width: 32px; height: 32px;
  font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.lib-view-btn:hover { border-color: var(--purple); color: var(--purple); }
.lib-view-btn.active { background: var(--purple); border-color: var(--purple); color: #fff; }
@media (max-width: 767px) { .lib-view-toggle { display: none; } }

/* ── Section labels ─────────────────────── */
.lib-section-label { font-size: 0.72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; padding: 0 2px; margin-bottom: 8px; }
.lib-all-label { margin-top: 18px; }

/* ── "Học tiếp" continue card ───────────── */
.lib-continue-wrap { margin-bottom: 4px; }
.lib-continue-card {
  background: linear-gradient(135deg, var(--purple-light) 0%, var(--surface) 80%);
  border: 1.5px solid rgba(14,165,233,0.25);
  border-radius: var(--radius);
  display: flex; align-items: center; gap: 12px;
  padding: 14px 12px 14px 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.lib-continue-card:hover { border-color: var(--purple); box-shadow: 0 2px 14px rgba(14,165,233,0.12); }
.lcc-icon {
  width: 42px; height: 42px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem; flex-shrink: 0;
}
.lcc-body { flex: 1; min-width: 0; }
.lcc-name { font-size: 0.95rem; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lcc-sub  { font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; }
.lcc-btn  {
  background: var(--purple); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: 8px 14px;
  font-size: 0.82rem; font-weight: 700; cursor: pointer;
  font-family: inherit; white-space: nowrap; flex-shrink: 0;
  transition: background 0.15s;
}
.lcc-btn:hover { background: var(--purple-d); }

/* ── Deck list wrap ─────────────────────── */
.lib-deck-list-wrap { flex: 1; overflow-y: auto; padding: 16px 16px calc(var(--nav-h) + 28px); }
.lib-section        { margin-bottom: 20px; }
.lib-section.hidden { display: none; }

/* List mode */
.lib-deck-list { display: flex; flex-direction: column; gap: 12px; }

/* Grid mode — multi column, bắt đầu từ tablet 640px */
@media (min-width: 640px) {
  .lib-deck-list--grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
  }
  .lib-deck-list--grid .ldc-icon-wrap { width: 42px; height: 42px; font-size: 1.25rem; }
  .lib-deck-list--grid .ldc-name      { font-size: 0.95rem; -webkit-line-clamp: 2; }
  .lib-deck-list--grid .ldc-meta      { font-size: 0.76rem; margin-bottom: 6px; }
  .lib-deck-list--grid .ldc-bar-row   { display: flex; }
  .lib-deck-list--grid .ldc-study-btn { width: 36px; height: 36px; font-size: 0.88rem; }
}

.lib-deck-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  display: flex; align-items: center;
  transition: border-color 0.15s, box-shadow 0.15s;
  overflow: hidden;
}
.lib-deck-card:hover { border-color: rgba(14,165,233,0.4); box-shadow: 0 2px 12px rgba(14,165,233,0.08); }

.ldc-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 11px;
  padding: 11px 8px 11px 12px;
  cursor: pointer;
}
.ldc-icon-wrap {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: var(--purple-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
}
.ldc-body { flex: 1; min-width: 0; }
.ldc-name { font-size: 0.9rem; font-weight: 700; color: var(--text); margin-bottom: 3px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.ldc-meta { font-size: 0.74rem; color: var(--text-muted); }
.ldc-due  { color: #DC2626; font-weight: 600; }

/* Meta row */
.ldc-meta-row { display: flex; align-items: center; gap: 5px; margin-bottom: 4px; }

/* Status pills — softer than before */
.ldc-sp {
  font-size: 0.63rem; font-weight: 600; padding: 1px 6px;
  border-radius: 50px; white-space: nowrap; flex-shrink: 0; line-height: 1.7;
}
.ldc-sp-due      { background: #FEF2F2; color: #DC2626; }
.ldc-sp-new      { background: #F0F9FF; color: #0284C7; opacity: 0.85; }
.ldc-sp-done     { background: #ECFDF5; color: #059669; }
.ldc-sp-mastered { background: #FEFCE8; color: #A16207; }

.ldc-bar-row  { display: flex; align-items: center; gap: 6px; }
.ldc-bar-wrap { flex: 1; height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.ldc-bar-fill { height: 100%; background: linear-gradient(90deg, var(--purple), #7DD3FC); border-radius: 3px; transition: width 0.3s; }
.ldc-pct      { font-size: 0.68rem; font-weight: 600; color: var(--text-muted); flex-shrink: 0; text-align: right; white-space: nowrap; }

/* Container fixed-width để ldc-main luôn có width đồng đều giữa các card */
.ldc-actions {
  display: grid; grid-template-columns: 40px 36px;
  align-items: center; flex-shrink: 0;
}

/* Play button on each card */
.ldc-study-btn {
  width: 32px; height: 32px; flex-shrink: 0; justify-self: center;
  background: var(--purple-light); color: var(--purple);
  border: none; border-radius: 50%;
  font-size: 0.8rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.ldc-study-btn:hover { background: var(--purple); color: #fff; }

.ldc-menu-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 1rem; cursor: pointer; padding: 11px 10px;
  border-radius: var(--radius-sm); flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.ldc-menu-btn:hover { background: var(--bg); color: var(--text); }

@media (min-width: 1024px) {
  .lib-deck-list-wrap { padding: 18px 28px 40px; }
  .lib-fab { right: 32px; bottom: 32px; }
  .lib-deck-list--grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
}

/* Search + sort row */
.lib-search-sort-row { display: flex; gap: 8px; margin-bottom: 8px; }

/* Deck search + filter toggle in one row */
.deck-search-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.deck-search-row .lib-search-wrap { flex: 1; }
.deck-filter-toggle {
  flex-shrink: 0; width: 36px; height: 36px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-muted);
  font-size: 0.95rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.deck-filter-toggle:hover { border-color: var(--purple); color: var(--purple); }
.deck-filter-toggle.active { background: var(--purple-light); border-color: var(--purple); color: var(--purple); }
.btn-add-more { background: var(--purple-light); border-color: var(--purple); color: var(--purple); font-size: 1.15rem; font-weight: 700; }
.btn-add-more:hover { background: var(--purple); color: #fff !important; }

/* Deck filter dropdowns row (collapsible) */
.deck-filter-row { display: flex; gap: 6px; align-items: center; }
.deck-filter-row.hidden { display: none; }
.deck-filter-row .lib-filter-select { flex: 1; min-width: 0; }
.deck-filter-row select.hidden { display: none; }
.lib-search-wrap     { flex: 1; position: relative; }
.lib-search-icon     { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 0.82rem; pointer-events: none; color: var(--text-muted); }
.lib-search-input    { width: 100%; padding: 8px 30px 8px 32px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 0.86rem; font-family: inherit; outline: none; background: var(--bg); color: var(--text); transition: border-color 0.2s, box-shadow 0.2s; }
.lib-search-input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(14,165,233,0.1); background: var(--surface); }
.lib-search-clear    { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); background: var(--border); border: none; border-radius: 50%; width: 18px; height: 18px; font-size: 0.62rem; cursor: pointer; color: var(--text-muted); display: flex; align-items: center; justify-content: center; }
.lib-sort-select     { border: 1.5px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); padding: 8px 9px; font-size: 0.78rem; font-weight: 600; color: var(--text); cursor: pointer; font-family: inherit; outline: none; flex-shrink: 0; }

/* Filter chips row */
.lib-chips-row { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 8px; }
.lib-chips-row::-webkit-scrollbar { display: none; }

/* CTA bar */
.lib-cta-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0 10px; border-top: 1px solid var(--border); }
.lib-cta-info { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.lib-cta-btn  {
  background: var(--purple); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: 8px 18px;
  font-size: 0.85rem; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: opacity 0.15s; white-space: nowrap; flex-shrink: 0;
}
.lib-cta-btn:hover { opacity: 0.88; }

/* Bulk bar */
.lib-bulk-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin-bottom: 10px;
  background: var(--purple-light); border-radius: var(--radius-sm);
  border: 1.5px solid rgba(14,165,233,0.2);
}
.lib-bulk-count   { font-size: 0.8rem; font-weight: 700; color: var(--purple); flex: 1; }
.lib-bulk-actions { display: flex; gap: 6px; }
.lib-bulk-btn {
  border: 1.5px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); padding: 5px 10px;
  font-size: 0.74rem; font-weight: 600; cursor: pointer;
  font-family: inherit; color: var(--text); transition: all 0.15s;
}
.lib-bulk-btn:hover    { border-color: var(--purple); color: var(--purple); }
.lib-bulk-del:hover    { border-color: var(--red) !important; color: var(--red) !important; }
.lib-bulk-close {
  background: none; border: none; font-size: 1rem; cursor: pointer;
  color: var(--text-muted); padding: 2px 4px; transition: color 0.15s;
}
.lib-bulk-close:hover { color: var(--text); }

/* ── Body: list + drawer ────────────────── */
.lib-body     { display: flex; flex: 1; overflow: hidden; }
.lib-list-col { flex: 1; overflow-y: auto; min-width: 0; }

/* ── Word list ──────────────────────────── */
.lib-word-list { padding: 10px 18px 24px; display: flex; flex-direction: column; gap: 5px; }

/* ── Word item ──────────────────────────── */
.lib-word-item {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  user-select: none;
}
.lib-word-item:hover      { border-color: rgba(14,165,233,0.4); box-shadow: 0 2px 10px rgba(14,165,233,0.06); }
.lib-word-item.drawer-open { border-color: var(--purple); background: var(--purple-light); }
.lib-word-item.selected    { border-color: var(--purple); background: #E0F2FE; }

/* Checkbox */
.lib-wi-sel {
  width: 20px; height: 20px; border-radius: 50%;
  border: 1.5px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 800;
  flex-shrink: 0; cursor: pointer; color: transparent;
  transition: all 0.15s;
}
.lib-word-item:hover .lib-wi-sel { border-color: var(--purple); }
.lib-wi-sel.checked { background: var(--purple); border-color: var(--purple); color: #fff; }

/* Emoji */
.lib-wi-emoji { font-size: 1.25rem; flex-shrink: 0; width: 26px; text-align: center; }

/* Word info */
.lib-wi-main { flex: 1; min-width: 0; }
.lib-wi-en {
  font-weight: 700; font-size: 0.88rem; color: var(--text);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-wi-vi   { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-wi-pos  { font-size: 0.7rem; font-weight: 700; font-style: italic; color: var(--purple); opacity: 0.85; }
.lib-wi-deck { font-size: 0.67rem; color: var(--text-muted); background: var(--border); border-radius: 4px; padding: 1px 5px; font-weight: 600; flex-shrink: 0; }

/* Right: status + fav */
.lib-wi-right  { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.lib-wi-status { font-size: 0.67rem; font-weight: 700; padding: 3px 7px; border-radius: 50px; white-space: nowrap; }
.lib-ws-new      { background: #E0F2FE; color: var(--purple); }
.lib-ws-learning { background: #FFFBEB; color: #D97706; }
.lib-ws-due      { background: #FEF2F2; color: #DC2626; }
.lib-ws-known    { background: #ECFDF5; color: #059669; }
.lib-ws-weak     { background: #FFF7ED; color: #B45309; }

.lib-wi-fav        { background: none; border: none; font-size: 0.95rem; cursor: pointer; padding: 2px; opacity: 0.35; transition: opacity 0.15s; }
.lib-wi-fav:hover  { opacity: 0.85; }
.lib-wi-fav.active { opacity: 1; }

/* ── Empty state ────────────────────────── */
.lib-empty      { text-align: center; padding: 56px 24px; color: var(--text-muted); }
.lib-empty-icon { font-size: 2.4rem; margin-bottom: 10px; }
.lib-empty p    { font-size: 0.86rem; line-height: 1.65; }

/* ── Detail drawer ──────────────────────── */
.lib-drawer {
  width: clamp(280px, 40vw, 360px); flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}
.lib-drawer-close {
  position: sticky; top: 10px; float: right;
  margin: 10px 12px 0;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 50%; width: 28px; height: 28px;
  font-size: 0.8rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: all 0.15s; z-index: 2;
}
.lib-drawer-close:hover { background: var(--border); color: var(--text); }
.lib-drawer-body { padding: 12px 20px 32px; clear: both; }

/* Drawer content */
.lwd-word { font-size: 1.45rem; font-weight: 900; color: var(--text); margin-bottom: 3px; }
.lwd-ipa  { font-size: 0.86rem; color: var(--purple); margin-bottom: 4px; }
.lwd-pos  {
  font-size: 0.74rem; font-weight: 600; color: var(--text-muted);
  background: var(--border); display: inline-block;
  padding: 2px 7px; border-radius: 4px; margin-bottom: 10px;
}
.lwd-vi  { font-size: 1.05rem; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.lwd-def {
  font-size: 0.8rem; color: var(--text-muted); font-style: italic;
  margin-bottom: 10px; border-left: 2px solid var(--border); padding-left: 9px;
}
.lwd-ex-block { background: var(--bg); border-radius: var(--radius-sm); padding: 9px 11px; margin-bottom: 12px; }
.lwd-ex       { font-size: 0.82rem; color: var(--text); font-style: italic; margin-bottom: 4px; display: flex; align-items: flex-start; gap: 6px; }
.lwd-ex-vi { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; display: none; }
.lwd-ex-speak {
  background: none; border: none; cursor: pointer;
  font-size: 0.85rem; padding: 0; line-height: 1;
  flex-shrink: 0; opacity: 0.6; transition: opacity 0.15s;
  margin-top: 1px;
}
.lwd-ex-speak:hover { opacity: 1; }
.lwd-status-row { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 7px; }
.lwd-deck-tag   { font-size: 0.74rem; color: var(--text-muted); margin-bottom: 14px; }
.lwd-actions    { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.lwd-btn {
  border: 1.5px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); padding: 6px 10px;
  font-size: 0.76rem; font-weight: 600; cursor: pointer;
  font-family: inherit; color: var(--text); transition: all 0.15s;
}
.lwd-btn:hover        { border-color: var(--purple); color: var(--purple); }
.lwd-btn-active       { border-color: #D97706; color: #D97706; }
.lwd-btn-del:hover    { border-color: var(--red) !important; color: var(--red) !important; }
.lwd-study-btn {
  width: 100%; padding: 11px; background: var(--purple); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-size: 0.88rem; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: opacity 0.15s;
}
.lwd-study-btn:hover { opacity: 0.88; }

/* ── AI / header buttons ────────────────── */
.lib-header-btns { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.lib-btn-notebook {
  padding: 8px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: 0.82rem; font-weight: 700;
  cursor: pointer; font-family: inherit; white-space: nowrap; transition: all 0.15s;
  flex-shrink: 0;
}
.lib-btn-notebook:hover { border-color: var(--purple); color: var(--purple); background: var(--purple-light); }

.lib-btn-study-all {
  padding: 8px 14px; border: none; border-radius: var(--radius-sm);
  background: var(--green, #059669); color: #fff; font-size: 0.82rem; font-weight: 700;
  cursor: pointer; font-family: inherit; white-space: nowrap; transition: opacity 0.15s;
  flex-shrink: 0;
}
.lib-btn-study-all:hover { opacity: 0.88; }

.lib-btn-ai {
  padding: 8px 14px; border: none; border-radius: var(--radius-sm);
  background: var(--purple); color: #fff; font-size: 0.82rem; font-weight: 700;
  cursor: pointer; font-family: inherit; white-space: nowrap; transition: opacity 0.15s;
  flex-shrink: 0;
}
.lib-btn-ai:hover { opacity: 0.88; }

/* ── Context menu (shared with page-deck) ── */
/* Deck word filter popup */
.deck-filter-menu {
  position: fixed; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); z-index: 500;
  min-width: 210px; padding: 4px 0;
}
.dfm-row {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px 9px 16px;
  font-size: 0.86rem; font-weight: 500; color: var(--text);
  cursor: pointer; transition: background 0.15s;
}
.dfm-row:hover { background: var(--bg); }
.dfm-row-label { flex-shrink: 0; }
.dfm-row-value {
  margin-left: auto; color: var(--purple); font-weight: 600;
  font-size: 0.82rem; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 110px;
}
.dfm-row-arrow { color: var(--text-muted); font-size: 1.1rem; line-height: 1; }

.dfm-submenu {
  position: absolute; right: 100%; top: -5px; margin-right: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  min-width: 170px; padding: 4px 0;
  display: none; z-index: 501;
}
.dfm-row:hover > .dfm-submenu,
.dfm-row.dfm-open > .dfm-submenu { display: block; }

.dfm-item {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 8px 16px; border: none; background: none;
  font-size: 0.86rem; font-weight: 500; color: var(--text);
  cursor: pointer; font-family: inherit; text-align: left; transition: background 0.15s;
}
.dfm-item:hover { background: var(--bg); }
.dfm-item.active { color: var(--purple); font-weight: 700; }
.dfm-item.active::after { content: '✓'; font-size: 0.82rem; color: var(--purple); margin-left: 8px; }
.dfm-item.hidden { display: none; }

.lib-deck-menu {
  position: fixed; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); z-index: 500; min-width: 170px; overflow: hidden;
}
.lib-deck-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 16px; border: none; background: none;
  font-size: 0.86rem; font-weight: 600; color: var(--text);
  cursor: pointer; font-family: inherit; text-align: left; transition: background 0.15s;
}
.lib-deck-menu button:hover { background: var(--bg); }
.lib-deck-menu-danger { color: var(--red) !important; }
.ldm-icon { font-size: 0.95rem; width: 20px; flex-shrink: 0; }

/* ── Word item (page-deck) ──────────────── */
.word-list   { display: flex; flex-direction: column; gap: 5px; }
.word-item   { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 10px 12px; display: flex; align-items: center; gap: 10px; transition: border-color 0.15s; }
.word-item:hover { border-color: rgba(14,165,233,0.35); }
.word-icon-badge { font-size: 1.3rem; flex-shrink: 0; width: 28px; text-align: center; }
.word-status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.word-status-dot.status-new      { background: var(--purple); }
.word-status-dot.status-learning { background: #F59E0B; }
.word-status-dot.status-known    { background: #059669; }
.word-info   { flex: 1; min-width: 0; }
.word-en     { font-weight: 700; font-size: 0.88rem; color: var(--text); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.word-vi     { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.word-ph     { font-size: 0.72rem; color: var(--purple); margin-top: 1px; }
.word-deck-tag { background: var(--border); color: var(--text-muted); border-radius: 4px; padding: 1px 5px; font-size: 0.67rem; font-weight: 600; }
.word-dupe-badge { background: #FFF7ED; color: #B45309; border-radius: 4px; padding: 1px 5px; font-size: 0.67rem; font-weight: 600; }
.word-actions { display: flex; gap: 4px; flex-shrink: 0; }
.btn-fav      { background: none; border: none; font-size: 0.95rem; cursor: pointer; padding: 3px; opacity: 0.35; transition: opacity 0.15s; }
.btn-fav:hover, .btn-fav.active { opacity: 1; }
.btn-icon-sm  { background: none; border: none; font-size: 0.9rem; cursor: pointer; padding: 3px 4px; color: var(--text-muted); transition: color 0.15s; }
.btn-icon-sm:hover { color: var(--purple); }

/* Review time tags */
.wrt { font-size: 0.67rem; font-weight: 700; padding: 2px 6px; border-radius: 50px; }
.wrt-due   { background: #FEF2F2; color: #DC2626; }
.wrt-today { background: #FFFBEB; color: #D97706; }
.wrt-soon  { background: #EFF6FF; color: #2563EB; }
.wrt-ok    { background: #ECFDF5; color: #059669; }

/* ── Favorites page ─────────────────────── */
.fav-hint { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 14px; }

/* ── Study button (page-deck) ───────────── */
.lib-panel-study-btn {
  background: var(--purple); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 10px 18px; font-size: 0.9rem; font-weight: 700;
  cursor: pointer; font-family: inherit; transition: opacity 0.2s;
}
.lib-panel-study-btn:hover { opacity: 0.88; }

.deck-study-btn {
  background: var(--purple); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: 9px 20px;
  font-size: 0.88rem; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: opacity 0.15s; white-space: nowrap;
}
.deck-study-btn:hover { opacity: 0.88; }
.deck-study-btn--due { background: #DC2626; }
.deck-study-btn--new { background: #059669; }
.deck-export-btn {
  background: var(--surface); color: var(--text-muted);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 14px; font-size: 1rem; cursor: pointer;
  font-family: inherit; transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.deck-export-btn:hover { border-color: var(--purple); color: var(--purple); }

/* ── Desktop ≥ 1024px ────────────────────── */
@media (min-width: 1024px) {
  .lib-controls  { padding: 18px 28px 16px; }
  .lib-word-list { padding: 12px 28px 28px; }
  .lib-drawer    { width: clamp(320px, 35vw, 400px); }
}

/* ── Hover actions (page-deck word list) ─── */
/* Trên thiết bị có hover: ẩn ✏️🗑️, chỉ hiện khi hover */
@media (hover: hover) {
  .word-item .btn-word-edit,
  .word-item .btn-word-del {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
  }
  .word-item:hover .btn-word-edit,
  .word-item:hover .btn-word-del {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ── Deck word filter chips ──────────────── */
.deck-chips-bar {
  display: flex; align-items: center;
  flex-wrap: wrap; gap: 6px;
  margin-top: 8px;
}
.deck-chips-bar.hidden { display: none; }
.deck-cefr-bar  { margin-top: 6px; }
.dchip-label    { font-size: 0.68rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; flex-shrink: 0; }
.deck-word-count {
  font-size: 0.74rem; font-weight: 700; color: var(--purple);
  background: var(--purple-light); border-radius: 50px;
  padding: 3px 10px; white-space: nowrap; flex-shrink: 0;
}

/* CEFR dot inside filter chips */
.cefr-dot { border-radius: 3px; padding: 1px 5px; font-size: 0.72rem; font-weight: 700; }

/* ── Deck pagination ─────────────────────── */
.deck-pagination {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
  padding: 14px 0 4px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.dp-info { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.dp-btns { display: flex; align-items: center; gap: 4px; }
.dp-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  border: 1.5px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 600;
  color: var(--text-muted); cursor: pointer; font-family: inherit;
  transition: all 0.15s;
}
.dp-btn:hover:not(:disabled) { border-color: var(--purple); color: var(--purple); }
.dp-btn.active { background: var(--purple); border-color: var(--purple); color: #fff; }
.dp-btn:disabled { opacity: 0.35; cursor: default; }

/* ── Select mode (chuyển từ giữa deck) ─────────────────── */
#deck-select-btn.active { background: var(--purple); color: #fff; border-color: var(--purple); }

.word-item--selected { background: rgba(99,102,241,0.07); border-left: 3px solid var(--purple); }
.wi-check-wrap { display: flex; align-items: center; justify-content: center; width: 28px; flex-shrink: 0; }
.wi-check {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--surface);
  display: inline-block; transition: all 0.15s;
}
.wi-check.checked { background: var(--purple); border-color: var(--purple); position: relative; }
.wi-check.checked::after { content: '✓'; color: #fff; font-size: 0.72rem; font-weight: 800; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); }

.deck-select-bar {
  position: sticky; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-top: 1.5px solid var(--border);
  padding: 12px 16px; box-shadow: 0 -2px 16px rgba(0,0,0,0.08);
  z-index: 20;
}
.dsb-count { flex: 1; font-size: 0.88rem; font-weight: 600; color: var(--text); }
.dsb-move-btn {
  background: var(--purple); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 8px 14px; font-size: 0.85rem; font-weight: 700;
  cursor: pointer; font-family: inherit; transition: opacity 0.15s;
}
.dsb-move-btn:hover { opacity: 0.88; }
.dsb-cancel {
  background: none; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 0.82rem; color: var(--text-muted);
  cursor: pointer; font-family: inherit;
}

/* ── Deck study mode sheet ─────────────── */
.dss-hint {
  font-size: 0.82rem; color: var(--text-muted);
  text-align: center; margin: -8px 0 14px; line-height: 1.4;
}
.dss-options { display: flex; flex-direction: column; gap: 8px; }
.dss-opt {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 13px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-family: inherit;
  color: var(--text); cursor: pointer; transition: all 0.15s; text-align: left;
}
.dss-opt:hover:not(:disabled) { border-color: var(--purple); background: var(--purple-light); }
.dss-opt--disabled { opacity: 0.45; cursor: not-allowed; }
.dss-emoji { font-size: 1.3rem; flex-shrink: 0; line-height: 1; }
.dss-body  { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.dss-label { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.dss-desc  { font-size: 0.78rem; color: var(--text-muted); }
.dss-arrow { font-size: 1.3rem; color: var(--text-muted); flex-shrink: 0; line-height: 1; }

/* ── Mobile: drawer as bottom sheet ─────── */
@media (max-width: 767px) {
  .lib-body { position: relative; }
  .lib-drawer {
    position: absolute; bottom: 0; left: 0; right: 0;
    width: 100%; height: 72%;
    border-left: none; border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0; z-index: 50;
    box-shadow: 0 -4px 28px rgba(0,0,0,0.12);
  }
}
