/* Simple, balanced layout — not cluttered */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f0f2f5;
  --card: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-h: #1d4ed8;
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --pick: #eff6ff;
  --pick-b: #93c5fd;
  --chip-active: #0f172a;
  --opt-letter: #334155;
  --progress-track: #e2e8f0;
  --map-count-bg: #f1f5f9;
  --map-count-fg: #334155;
  --map-dot-border: #cbd5e1;
  --cell-ok-bg: #ecfdf5;
  --cell-ok-fg: #047857;
  --cell-bad-bg: #fef2f2;
  --cell-bad-fg: #b91c1c;
  --explain-fg: #334155;
  --explain-wrong-bg: #fff7ed;
  --explain-wrong-bd: #fed7aa;
  --explain-wrong-fg: #9a3412;
  --note-bg: #fffbeb;
  --note-bd: #fde68a;
  --note-fg: #92400e;
  --alt-fg: #475569;
  --star-bg: #fffbeb;
  --star-bd: #fcd34d;
  --star-fg: #f59e0b;
  --sync-busy-bg: #eff6ff;
  --sync-busy-fg: #1d4ed8;
  --sync-on-bg: #e0f2fe;
  --sync-on-bd: #7dd3fc;
  --sync-on-fg: #0369a1;
  --modal-scrim: rgba(15, 23, 42, 0.45);
  --hover-bd: #94a3b8;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

html.dark {
  --bg: #0b1220;
  --card: #111827;
  --surface: #1a2332;
  --surface-2: #1e293b;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --line: #2d3748;
  --primary: #3b82f6;
  --primary-h: #60a5fa;
  --ok: #34d399;
  --ok-bg: #064e3b;
  --bad: #f87171;
  --bad-bg: #450a0a;
  --pick: #1e3a5f;
  --pick-b: #3b82f6;
  --chip-active: #e2e8f0;
  --opt-letter: #cbd5e1;
  --progress-track: #1e293b;
  --map-count-bg: #1e293b;
  --map-count-fg: #cbd5e1;
  --map-dot-border: #475569;
  --cell-ok-bg: #064e3b;
  --cell-ok-fg: #6ee7b7;
  --cell-bad-bg: #450a0a;
  --cell-bad-fg: #fca5a5;
  --explain-fg: #cbd5e1;
  --explain-wrong-bg: #431407;
  --explain-wrong-bd: #9a3412;
  --explain-wrong-fg: #fdba74;
  --note-bg: #422006;
  --note-bd: #a16207;
  --note-fg: #fde68a;
  --alt-fg: #94a3b8;
  --star-bg: #422006;
  --star-bd: #d97706;
  --star-fg: #fbbf24;
  --sync-busy-bg: #1e3a5f;
  --sync-busy-fg: #93c5fd;
  --sync-on-bg: #0c4a6e;
  --sync-on-bd: #38bdf8;
  --sync-on-fg: #7dd3fc;
  --modal-scrim: rgba(0, 0, 0, 0.65);
  --hover-bd: #64748b;
  color-scheme: dark;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

button,
input {
  font: inherit;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

/* Top */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.brand-code {
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--muted);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Owner-only visitor strip (hidden for everyone else) */
.visit-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: -4px 0 12px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.35;
}

.visit-bar[hidden] {
  display: none !important;
}

.visit-bar.is-error {
  border-color: var(--bad);
  color: var(--bad);
}

.visit-label {
  font-weight: 700;
  color: var(--text);
  margin-right: 2px;
}

.visit-bar b {
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.visit-sep {
  opacity: 0.55;
}

.visit-item {
  white-space: nowrap;
}

.visit-hide {
  margin-left: auto;
}

.subjects {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sub-tab {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

.sub-tab:hover {
  border-color: var(--hover-bd);
  color: var(--text);
}

.sub-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.sub-tab[data-subject="prm393"].active {
  background: #7c3aed;
  border-color: #7c3aed;
}

.sub-tab[data-subject="jfe301"].active {
  background: #059669;
  border-color: #059669;
}

.sub-tab[data-subject="jit401"].active {
  background: #dc2626;
  border-color: #dc2626;
}

.sub-tab.is-locked {
  opacity: 0.72;
  border-style: dashed;
}

.sub-tab.is-locked.active {
  opacity: 1;
  border-style: solid;
}

.access-error {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bad-bg);
  color: var(--bad);
  font-size: 0.82rem;
}

.access-error[hidden] {
  display: none !important;
}

.modal-access {
  max-width: 360px;
}

.modal-access .sync-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  letter-spacing: 0.04em;
}

.top-actions {
  display: flex;
  gap: 4px;
}

/* Workspace: content + map */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px;
  gap: 12px;
  align-items: start;
}

.main-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Compact toolbar */
.toolbar-simple {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stats-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  font-size: 0.8rem;
  color: var(--muted);
}

.stats-inline b {
  color: var(--text);
  font-weight: 700;
}

.stats-inline .ok b {
  color: var(--ok);
}

.stats-inline .bad b {
  color: var(--bad);
}

.progress-wrap {
  width: 80px;
  height: 5px;
  background: var(--progress-track);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #22c55e);
  transition: width 0.2s ease;
}

.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.jump {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.jump input {
  width: 56px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--muted);
}

.chip:hover {
  border-color: var(--hover-bd);
}

.chip.active {
  background: var(--chip-active);
  border-color: var(--chip-active);
  color: var(--card);
}

html.dark .chip.active {
  color: #0f172a;
}

/* Full-width source row under toolbar — always easy to see */
.source-bar,
.source-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  margin: 0 0 10px;
}

.source-filters .source-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  padding: 0 4px 0 2px;
  white-space: nowrap;
}

.source-filters .chip {
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 600;
}

.source-filters .chip.active {
  background: #7c3aed;
  border-color: #7c3aed;
  color: #fff;
}

html.dark .source-filters .chip.active {
  color: #fff;
}

/* Quiz PT column — teal so it stands apart */
.source-filters .chip-pt {
  border-color: #14b8a6;
  color: #0f766e;
  font-weight: 700;
}

html.dark .source-filters .chip-pt {
  border-color: #2dd4bf;
  color: #5eead4;
}

.source-filters .chip-pt:not(.active):hover {
  background: rgba(13, 148, 136, 0.12);
}

.source-filters .chip-pt.active {
  background: #0d9488;
  border-color: #0d9488;
  color: #fff;
}

/* Zip 240 column — amber */
.source-filters .chip-zip {
  border-color: #f59e0b;
  color: #b45309;
  font-weight: 700;
}

html.dark .source-filters .chip-zip {
  border-color: #fbbf24;
  color: #fcd34d;
}

.source-filters .chip-zip:not(.active):hover {
  background: rgba(245, 158, 11, 0.12);
}

.source-filters .chip-zip.active {
  background: #d97706;
  border-color: #d97706;
  color: #fff;
}

/* Buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover {
  background: var(--primary-h);
}

.btn.ghost {
  background: transparent;
  padding: 7px 9px;
}

.btn.small {
  padding: 5px 9px;
  font-size: 0.85rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Exam card — focus */
.exam-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px 24px;
  min-height: 280px;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.card-sep {
  opacity: 0.4;
}

.card-pos {
  margin-left: auto;
  font-size: 0.75rem;
}

.card-choose {
  margin: 0 0 12px;
  font-size: 0.84rem;
  color: var(--muted);
  font-style: italic;
}

.card-question {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.5;
}

.card-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.opt {
  display: flex;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1.5px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: inherit;
}

.opt:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--line);
}

.opt.selected {
  background: var(--pick);
  border-color: var(--pick-b);
}

.opt.correct {
  background: var(--ok-bg);
  border-color: #6ee7b7;
}

.opt.wrong {
  background: var(--bad-bg);
  border-color: #fca5a5;
}

.opt.missed {
  background: var(--ok-bg);
  border-color: #6ee7b7;
}

.opt:disabled {
  cursor: default;
}

/* Điền khuyết tự điền */
.fill-wrap {
  display: flex;
  gap: 8px;
  width: 100%;
  flex-wrap: wrap;
}

.fill-input {
  flex: 1 1 220px;
  min-width: 0;
  font: inherit;
  color: inherit;
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.fill-input:focus {
  outline: none;
  border-color: var(--pick-b);
}

.fill-input.correct {
  background: var(--ok-bg);
  border-color: #6ee7b7;
}

.fill-input.wrong {
  background: var(--bad-bg);
  border-color: #fca5a5;
}

.opt-letter {
  font-weight: 700;
  min-width: 1.2em;
  color: var(--opt-letter);
}

.opt-text {
  flex: 1;
  line-height: 1.45;
  font-size: 0.95rem;
}

.card-feedback {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 0.92rem;
  font-weight: 600;
}

.card-feedback.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.card-feedback.bad {
  background: var(--bad-bg);
  color: var(--bad);
}

.card-explain {
  margin-top: 10px;
  padding: 12px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.86rem;
  color: var(--explain-fg);
  line-height: 1.5;
  max-height: 220px;
  overflow: auto;
}

.card-explain strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.card-explain .explain-body {
  display: block;
  white-space: pre-wrap;
}

.card-explain.explain-wrong {
  background: var(--explain-wrong-bg);
  border-color: var(--explain-wrong-bd);
  color: var(--explain-wrong-fg);
}

.card-note {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--note-bg);
  border: 1px solid var(--note-bd);
  font-size: 0.84rem;
  color: var(--note-fg);
}

.card-alt {
  margin-top: 8px;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  font-size: 0.85rem;
  color: var(--alt-fg);
}

.card-alt strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.72rem;
  color: var(--muted);
}

/* Nav ngay sau đáp án — feedback/giải thích nằm dưới, không che nút Tiếp */
.card-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 8px;
  z-index: 15;
  background: var(--card);
  /* soft edge when sticky over content */
  box-shadow: 0 -10px 16px -8px rgba(15, 23, 42, 0.08);
  border-radius: 0 0 8px 8px;
}

html.dark .card-nav {
  box-shadow: 0 -10px 16px -8px rgba(0, 0, 0, 0.4);
}

.card-nav #btnNext {
  min-width: 7.5rem;
  font-weight: 700;
}

#btnStar.starred {
  color: var(--star-fg);
  border-color: var(--star-bd);
  background: var(--star-bg);
}

/* Side map — fixed height for iPad Safari (flex:1 often collapses to 0) */
.side-map {
  position: sticky;
  top: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  /* Prefer dvh; fallback vh. Explicit height avoids iOS flex bug */
  height: calc(100vh - 88px);
  height: calc(100dvh - 88px);
  min-height: 280px;
  max-height: calc(100vh - 88px);
  max-height: calc(100dvh - 88px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  flex: 0 0 auto;
}

.map-count {
  font-size: 0.75rem;
  background: var(--map-count-bg);
  border-radius: 999px;
  padding: 1px 7px;
  color: var(--map-count-fg);
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-bottom: 8px;
  font-size: 0.68rem;
  color: var(--muted);
  flex: 0 0 auto;
}

.map-legend .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 3px;
  border: 1px solid var(--map-dot-border);
  vertical-align: middle;
  /* empty <i> can collapse on some WebKit builds */
  min-width: 8px;
  min-height: 8px;
}

.map-legend .dot.current {
  background: var(--primary);
  border-color: var(--primary);
}

.map-legend .dot.ok {
  background: #6ee7b7;
  border-color: #34d399;
}

.map-legend .dot.bad {
  background: #fca5a5;
  border-color: #f87171;
}

.map-legend .dot.unseen {
  background: var(--surface);
}

.q-map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
  gap: 5px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Critical: do NOT rely on flex:1 alone on iPad */
  flex: 1 1 auto;
  min-height: 180px;
  height: 100%;
  align-content: start;
}

.q-map-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 16px 8px;
}

.q-cell {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  height: 30px;
  min-height: 30px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}

.q-cell:hover {
  border-color: var(--hover-bd);
}

.q-cell.is-current {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.q-cell.is-ok {
  background: var(--cell-ok-bg);
  border-color: #6ee7b7;
  color: var(--cell-ok-fg);
}

.q-cell.is-bad {
  background: var(--cell-bad-bg);
  border-color: #fca5a5;
  color: var(--cell-bad-fg);
}

.q-cell.is-star:not(.is-current) {
  box-shadow: inset 0 0 0 1px #fbbf24;
}

.q-cell.is-ok.is-current,
.q-cell.is-bad.is-current {
  color: #fff;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--modal-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  max-height: 90vh;
  overflow: auto;
  color: var(--text);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-lead {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.sync-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: 10px;
}

.sync-row {
  display: flex;
  gap: 6px;
}

.sync-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.sync-field textarea {
  width: 100%;
  min-height: 4.5rem;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.35;
  resize: vertical;
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.sync-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  margin-bottom: 8px;
}

.sync-status {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.82rem;
}

.sync-status.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.sync-status.err {
  background: var(--bad-bg);
  color: var(--bad);
}

.sync-status.busy {
  background: var(--sync-busy-bg);
  color: var(--sync-busy-fg);
}

.sync-link-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.78rem;
  word-break: break-all;
  margin-bottom: 8px;
}

.sync-link-box a {
  color: var(--primary);
}

.modal-hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 10px 0;
}

#btnSync.sync-on {
  color: var(--sync-on-fg);
  border-color: var(--sync-on-bd);
  background: var(--sync-on-bg);
}

#btnTheme {
  min-width: 40px;
  font-size: 1.05rem;
  line-height: 1;
}

/* iPad / tablet: same 2-col layout as laptop */
@media (max-width: 900px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 170px;
    gap: 10px;
  }

  .side-map {
    top: 8px;
    height: calc(100vh - 96px);
    height: calc(100dvh - 96px);
    min-height: 300px;
  }

  .q-map {
    min-height: 200px;
  }

  .q-cell {
    height: 28px;
    min-height: 28px;
    font-size: 0.65rem;
  }
}

/* Phone only: stack */
@media (max-width: 640px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-map {
    position: static;
    height: auto;
    min-height: 0;
    max-height: none;
    order: 2;
  }

  .q-map {
    min-height: 160px;
    max-height: 200px;
    height: 200px;
  }

  .app {
    padding: 10px;
  }

  .toolbar-simple {
    flex-direction: column;
    align-items: stretch;
  }

  .card-nav .btn {
    flex: 1 1 auto;
  }
}

/* Question Image Styling */
.card-q-img-wrap {
  margin: 12px 0 16px;
  text-align: center;
}

.card-q-img {
  max-width: 100%;
  max-height: 480px;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  object-fit: contain;
  cursor: zoom-in;
  transition: transform 0.15s ease;
}

.card-q-img:hover {
  transform: scale(1.01);
}

/* Search Modal Styling */
.modal-search {
  max-width: 680px;
  width: 92%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px;
  max-height: 85vh;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.25);
}

.search-trigger-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 12px;
  font-size: 0.95rem;
  color: var(--muted);
  pointer-events: none;
}

.search-input-wrap input {
  width: 100%;
  padding: 10px 36px 10px 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.search-input-wrap input:focus {
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

html.dark .search-input-wrap input:focus {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.search-clear-btn {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.search-clear-btn:hover {
  color: var(--text);
  background: var(--line);
}

.search-meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0 2px;
}

.search-count {
  font-weight: 600;
}

.search-shortcut-hint {
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 3px;
}

.search-shortcut-hint kbd {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 0.7rem;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 460px;
  padding-right: 4px;
  margin-top: 4px;
}

.search-item {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.search-item:hover,
.search-item.is-selected {
  background: var(--surface-2);
  border-color: var(--primary);
}

.search-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
}

.search-item-id {
  font-weight: 700;
  color: var(--primary);
}

.search-item-badge {
  background: var(--map-count-bg);
  color: var(--map-count-fg);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.7rem;
  font-weight: 600;
}

.search-item-status {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
}

.search-item-status.ok {
  color: var(--ok);
}

.search-item-status.bad {
  color: var(--bad);
}

.search-item-status.star {
  color: var(--star-fg);
}

.search-item-question {
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.45;
  color: var(--text);
}

.search-item-matched-option,
.search-item-matched-explain {
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface-2);
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1.4;
  border-left: 3px solid var(--primary);
}

.search-hl {
  background: #fef08a;
  color: #854d0e;
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 600;
}

html.dark .search-hl {
  background: #854d0e;
  color: #fef08a;
}

.search-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}
