/* ═══════════════════════════════════════════════════════════
   SỔ NGỮ PHÁP — trang toàn cục, gộp ghi chú (Cặp sách) từ mọi đề
   Dữ liệu: chỉ localStorage, key tts_grammar_{examId} (xem exam-engine.js)
   Layout đồng nhất với vocabulary.css (hero progress bar, filter chips,
   hàng ngang có đánh số + toggle + edit/xoá icon).
   ═══════════════════════════════════════════════════════════ */

body { background: var(--bg); }

/* ─────────────────────────────────────────────
   HERO HEADER — compact progress strip (giống vocab)
   ───────────────────────────────────────────── */
.gn-hero {
  background: #fff;
  padding: calc(var(--nav-h, 60px) + 20px) 20px 20px;
  border-bottom: 1px solid #f1f5f9;
}
.gn-hero-inner { max-width: 640px; margin: 0 auto; }
.gn-progress-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.gpm-count {
  font-size: .82rem;
  font-weight: 700;
  color: #334155;
}
.gpm-count span {
  font-size: 1.15rem;
  font-weight: 800;
  color: #1a2a2e;
}
.gpm-pct {
  font-size: .75rem;
  font-weight: 700;
  color: #16a34a;
}
.gn-progress-bar {
  width: 100%;
  height: 8px;
  background: #e9f0f4;
  border-radius: 999px;
  overflow: hidden;
}
.gn-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4ade80 0%, #16a34a 100%);
  border-radius: 999px;
  width: 0%;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}

.gn-body { max-width: 900px; margin: 0 auto; padding: 20px 16px 80px; }

/* ─────────────────────────────────────────────
   BANNER CẢNH BÁO CHƯA ĐĂNG NHẬP — giống vocab-ls-banner
   ───────────────────────────────────────────── */
.gn-ls-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #92400e;
  line-height: 1.5;
}
.dark .gn-ls-banner {
  background: #2d2107;
  border-color: #854d0e;
  color: #fbbf24;
}
.gn-ls-banner svg { color: #d97706; }
.dark .gn-ls-banner svg { color: #fbbf24; }
.gn-ls-banner span { flex: 1; }
.gn-ls-banner-btn {
  flex-shrink: 0;
  padding: 4px 12px;
  background: #d97706;
  border: none;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: opacity .14s;
  align-self: center;
}
.gn-ls-banner-btn:hover { opacity: .85; }

/* ─────────────────────────────────────────────
   FILTER BAR
   ───────────────────────────────────────────── */
.gn-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}
.gn-search-row { display: flex; align-items: center; gap: 8px; }
.gn-search {
  flex: 1;
  min-width: 0;
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1.5px solid #e2e8f0;
  border-radius: 10px; padding: 9px 12px;
  color: #94a3b8;
}
.gn-search input {
  flex: 1; min-width: 0; border: none; outline: none; background: none;
  font-family: inherit; font-size: 16px; color: #1a2a2e;
}
.gn-search input::placeholder { color: #cbd5e1; }

.gn-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.gn-chip {
  padding: 7px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: #64748b;
  background: #fff;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  white-space: nowrap;
}
.gn-chip:hover { border-color: var(--primary); color: var(--primary); }
.gn-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.gn-chip.chip-known.active  { background: #16a34a; border-color: #16a34a; color: #fff; }
.gn-chip.chip-forgot.active { background: #dc2626; border-color: #dc2626; color: #fff; }
.gn-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1.5px solid var(--primary);
  border-radius: 999px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--primary-light);
  color: var(--primary-dark);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.gn-add-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ─────────────────────────────────────────────
   LIST — giới hạn ~20 hàng, cuộn để xem thêm
   ───────────────────────────────────────────── */
.gn-list {
  display: flex;
  flex-direction: column;
  max-height: min(1120px, 78vh);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

/* Date headers — giống vd-date-header bên từ vựng */
.gn-date-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 26px 0 18px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
}
.gn-date-header:first-child { margin-top: 0; }
.gnd-line { flex: 1; height: 1px; background: #e8ecf0; }
.gnd-label { white-space: nowrap; color: #64748b; }
.gnd-count {
  background: #f1f5f9;
  color: #94a3b8;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: .65rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ─────────────────────────────────────────────
   NOTE ROWS — 1 hàng ngang, căn thẳng dọc
   [# 24] [toggle 40] [text 1fr] [edit 28] [del 28] [info 28]
   ───────────────────────────────────────────── */
@keyframes gnFadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.gn-row {
  display: grid;
  grid-template-columns: 24px 40px 1fr 28px 28px 28px;
  align-items: center;
  column-gap: 10px;
  padding: 9px 14px;
  background: #fff;
  border: 1px solid #e8ecf0;
  border-radius: 12px;
  margin-bottom: 10px;
  transition: box-shadow .18s, border-color .18s, background .22s ease, max-height .26s ease, padding .26s ease, margin-bottom .26s ease, opacity .2s ease;
  animation: gnFadeUp .3s ease both;
  position: relative;
  z-index: 0;
}
.gn-row:hover {
  box-shadow: 0 2px 14px rgba(0,0,0,.06);
  border-color: #d1d9e2;
}
.gn-row.is-known {
  background: #f0fdf4;
  border-color: #bbf7d0;
}
.gn-row.is-known:hover {
  border-color: #86efac;
  box-shadow: 0 2px 14px rgba(22,163,74,.08);
}

.gnr-num {
  font-size: .72rem;
  font-weight: 700;
  color: #b8c2cc;
  text-align: center;
  justify-self: center;
}
.gn-row.is-known .gnr-num { color: #4ade80; }

/* Toggle switch (iOS style) — giống vr-toggle-sw */
.gnr-toggle-sw {
  width: 40px;
  height: 22px;
  border-radius: 11px;
  border: none;
  background: #ef4444;
  cursor: pointer;
  position: relative;
  padding: 0;
  flex-shrink: 0;
  transition: background .22s ease;
  box-shadow: inset 0 1px 4px rgba(0,0,0,.15);
  justify-self: start;
}
.gnr-toggle-sw.known { background: #22c55e; }
.gnr-sw-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform .22s ease;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  pointer-events: none;
}
.gnr-toggle-sw.known .gnr-sw-knob { transform: translateX(18px); }

.gnr-text {
  font-size: .88rem;
  font-weight: 600;
  color: #1a2a2e;
  line-height: 1.45;
  word-break: break-word;
  min-width: 0;
}
.gn-row.is-known .gnr-text { color: #166534; }

/* Icon buttons dùng chung — giống vr-icon-btn */
.gnr-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: #c2cdd6;
  cursor: pointer;
  padding: 0;
  transition: background .15s, color .15s;
  flex-shrink: 0;
  justify-self: center;
}
.gnr-icon-btn:hover     { background: #f1f5f9; color: #64748b; }
.gnr-edit-btn:hover     { background: #ede9fe; color: #6366f1; }
.gnr-del-btn:hover      { background: #fee2e2; color: #ef4444; }
.gnr-info-btn:hover     { background: #f0f9ff; color: #0284c7; }

/* Info popup */
.gnr-info-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
}
.gnr-info-popup {
  display: none;
  position: fixed;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 13px;
  min-width: 175px;
  max-width: 270px;
  box-shadow: 0 6px 24px rgba(0,0,0,.13);
  z-index: 300;
}
.gnr-info-popup.open {
  display: block;
  animation: gniInfoIn .14s ease;
}
@keyframes gniInfoIn {
  from { opacity: 0; transform: translateY(-3px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.gnr-info-popup::before {
  content: '';
  position: absolute;
  top: -6px;
  right: 8px;
  width: 10px;
  height: 10px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  border-left: 1px solid #e2e8f0;
  transform: rotate(45deg);
}
.gni-line {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 0;
  font-size: .75rem;
  font-weight: 500;
  color: #475569;
}
.gni-line svg { color: #94a3b8; flex-shrink: 0; }
.gni-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gni-line + .gni-line {
  border-top: 1px solid #f1f5f9;
  margin-top: 3px;
  padding-top: 7px;
}

/* Inline edit row */
.gn-row-edit {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  background: #fafbff;
  border: 1.5px solid #6366f1;
  border-radius: 12px;
  animation: gnFadeUp .2s ease both;
  box-shadow: 0 0 0 3px rgba(99,102,241,.08);
}
.gnre-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.gnre-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #94a3b8;
}
.gnre-input {
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 11px;
  font-family: inherit;
  font-size: .95rem;
  font-weight: 500;
  color: #1a2a2e;
  outline: none;
  transition: border-color .15s;
  background: #fff;
  resize: vertical;
  min-height: 44px;
}
.gnre-input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.gnre-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.gnre-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
  min-width: 68px;
  justify-content: center;
}
.gnre-save-btn:hover:not(:disabled) { background: var(--primary-dark); }
.gnre-save-btn:disabled { opacity: .6; cursor: not-allowed; }
.gnre-cancel-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: transparent;
  color: #94a3b8;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.gnre-cancel-btn:hover { border-color: #cbd5e1; color: #475569; }

/* ─────────────────────────────────────────────
   EMPTY STATE
   ───────────────────────────────────────────── */
.gn-empty {
  display: none; flex-direction: column; align-items: center; text-align: center;
  gap: 8px; padding: 56px 20px; color: var(--text-3);
}
.gn-empty > svg { color: var(--border-2); margin-bottom: 6px; }
.gn-empty-title { font-size: 1rem; font-weight: 700; color: var(--text-2); }
.gn-empty-sub { font-size: .84rem; line-height: 1.6; max-width: 340px; margin-bottom: 10px; }
.gne-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 24px;
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
  border-radius: 10px;
  font-family: inherit;
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.gne-cta:hover { background: var(--primary); color: #fff; }

@media (max-width: 480px) {
  .gn-hero { padding: calc(var(--nav-h) + 14px) 16px 16px; }
}

.vocab-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid #e2e8f0;
  border-top-color: #1a2a2e;
  border-radius: 50%;
  animation: vSpin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes vSpin { to { transform: rotate(360deg); } }

/* ─────────────────────────────────────────────
   CONFIRM MODAL (thay thế window.confirm xấu) — giống vocabulary.css
   ───────────────────────────────────────────── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: confirm-fade-in .15s ease;
}
@keyframes confirm-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.confirm-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
  padding: 28px 28px 22px;
  max-width: 340px;
  width: 100%;
  animation: confirm-slide-up .18s cubic-bezier(.34,1.2,.64,1);
}
@keyframes confirm-slide-up {
  from { transform: translateY(12px) scale(.97); opacity: 0; }
  to   { transform: translateY(0)    scale(1);   opacity: 1; }
}
.confirm-icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: #fee2e2;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.confirm-icon svg { width: 22px; height: 22px; color: #ef4444; }
.confirm-title {
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 6px;
  line-height: 1.3;
}
.confirm-msg {
  font-size: .875rem;
  color: #64748b;
  line-height: 1.5;
  margin-bottom: 22px;
}
.confirm-msg strong { color: #0f172a; font-weight: 600; }
.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.confirm-btn {
  padding: 9px 20px;
  border-radius: 10px;
  border: none;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.confirm-btn-cancel {
  background: #f1f5f9;
  color: #475569;
}
.confirm-btn-cancel:hover { background: #e2e8f0; }
.confirm-btn-danger {
  background: #ef4444;
  color: #fff;
}
.confirm-btn-danger:hover { background: #dc2626; box-shadow: 0 4px 12px rgba(239,68,68,.35); }
