/* The problem bank page (/kho-bai): the bank on the left, the test being built beside it. On a phone the test is a
   sheet that slides up from the button at the bottom. Colours and controls come from style.css. */
body.bank-page { display: block; height: auto; min-height: 100%; }
.bank-page main {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start;
  padding: 12px 20px 32px;
}
.bank-head h2 { margin: 0; font-size: 1.25rem; }
.bank-head h2 .hint { font-size: 0.95rem; font-weight: 400; }
.bank-head p { margin: 4px 0 0; max-width: 72ch; }

/* The filters stay in view while the list scrolls. */
.bank-filters {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: end; gap: 8px 12px;
  margin: 10px 0 0; padding: 8px 0 10px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.bank-filters label { margin: 0; font-size: 0.85rem; }
.bank-filters select, .bank-filters input { display: block; margin-top: 3px; font-weight: 400; }
.bank-search { flex: 1 1 180px; }
.bank-page input[type="search"], .bank-page input[type="number"] {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit;
}
.bank-page input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#bank-status { margin: 8px 0 4px; }

.bank-topic h3 { margin: 18px 0 4px; font-size: 1.1rem; }
.bank-topic h4 { margin: 14px 0 6px; font-size: 0.95rem; }
.bank-topic h4 .hint { font-weight: 400; }

/* A problem. */
.bank-item {
  margin-bottom: 10px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  scroll-margin-top: 90px;
}
.bank-item.chosen { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.bank-item.flash { outline: 3px solid var(--changed-border); outline-offset: 2px; }
.item-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.item-id { font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 2px; }
.item-add { margin-left: auto; padding: 4px 12px; font-size: 0.85rem; }
.item-note { margin-left: auto; font-size: 0.85rem; }
.item-note + .item-add { margin-left: 4px; }
.bank-item.chosen .item-add { border-color: var(--accent); color: var(--accent); }
.item-add:disabled { cursor: not-allowed; }
.item-stem { margin: 8px 0 4px; }
.item-figure { margin: 6px 0; }
.item-figure img { display: block; max-width: min(100%, 420px); height: auto; background: #fff; border-radius: 4px; }
.item-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 2px 18px; margin: 4px 0; padding: 0; list-style: none; }
.item-lines { margin: 4px 0; padding: 0; list-style: none; }
.item-lines li { margin: 2px 0; }
.item-answer { margin-top: 6px; font-size: 0.95rem; }
.item-answer summary { cursor: pointer; color: var(--accent); font-size: 0.88rem; width: fit-content; }
.item-answer p { margin: 6px 0; }
.answer-list { margin: 6px 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.formula.bad { color: var(--error); font-family: Consolas, monospace; font-size: 0.9em; }

/* Small labels: form, level (one colour each), flags. */
.tag {
  display: inline-block; padding: 0 8px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); font-size: 0.75rem; line-height: 1.6; white-space: nowrap;
}
.tag.level.biet { color: var(--ok); border-color: currentColor; }
.tag.level.hieu { color: var(--accent); border-color: currentColor; }
.tag.level.van-dung { color: var(--warn); border-color: currentColor; }
/* How hard the whole problem is: filled, so it reads apart from the outlined levels. */
.tag.difficulty { color: var(--bg); border-color: transparent; font-weight: 600; }
.tag.difficulty.de { background: var(--ok); }
.tag.difficulty.trung-binh { background: var(--accent); }
.tag.difficulty.kho { background: var(--error); }

/* The test being built. */
.bank-test {
  position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.test-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.test-head h2 { margin: 0; font-size: 1.1rem; }
#test-close { display: none; }
#test-scope { margin: 6px 0 0; }
#test-level { margin: 10px 0 0; }
#test-level select { padding: 6px 10px; }
#test-actions { margin: 10px 0 4px; }
.test-part h3 { display: flex; justify-content: space-between; gap: 8px; margin: 12px 0 4px; font-size: 0.92rem; }
.test-part .count { color: var(--warn); font-variant-numeric: tabular-nums; white-space: nowrap; }
.test-part .count.full { color: var(--ok); }
.test-part p { margin: 0; }
.test-part ol { margin: 0; padding-left: 24px; }
.test-part li { margin: 2px 0; }
.test-part li > * { margin-right: 6px; vertical-align: baseline; }
.test-part li button.link { padding: 0 2px; font-variant-numeric: tabular-nums; }
.test-type { color: var(--muted); font-size: 0.85rem; }
.test-part .remove { color: var(--error); text-decoration: none; }
table.matrix { width: 100%; margin: 12px 0 0; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
table.matrix caption { text-align: left; font-weight: 600; margin-bottom: 4px; }
table.matrix th, table.matrix td { padding: 3px 6px; border-bottom: 1px solid var(--border); text-align: right; }
table.matrix th:first-child { text-align: left; }
table.matrix th { color: var(--muted); font-weight: 600; }
table.matrix td.off { color: var(--warn); font-weight: 700; }
.test-faults { margin: 10px 0 0; padding-left: 18px; color: var(--warn); font-size: 0.88rem; }
.test-faults:empty { display: none; }
.test-download { margin-top: 12px; padding-top: 4px; border-top: 1px solid var(--border); }
.test-download label { font-size: 0.88rem; }
#test-minutes { max-width: 120px; }
#test-download { margin-top: 12px; width: 100%; }
#test-download:disabled { cursor: not-allowed; }
.test-download .hint { margin: 6px 0 0; }
#test-toggle { display: none; }

@media (max-width: 1000px) {
  .bank-page main { grid-template-columns: minmax(0, 1fr); padding: 8px 12px 88px; }
  .bank-test {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 30;
    max-height: 85vh; border-radius: 12px 12px 0 0; box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.3);
    transform: translateY(105%); visibility: hidden; transition: transform 0.2s, visibility 0.2s;
  }
  .bank-test.open { transform: none; visibility: visible; }
  #test-close { display: inline-block; }
  #test-toggle {
    display: block; position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 20;
    border-radius: 999px; padding: 12px 16px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  #toast { bottom: 76px; left: 12px; right: 12px; }
}
@media (max-width: 600px) {
  .bank-filters { position: static; gap: 6px 8px; }  /* on a phone they would cover a third of the screen */
  .bank-filters label:not(.bank-search) { flex: 1 1 45%; }
  .bank-filters select { width: 100%; }
  .bank-item { padding: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .bank-test { transition: none; }
}
