// ── Host ──────────────────────────────────────────────────────────
:host {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 97px);
  overflow: hidden;
}

// ── Root ──────────────────────────────────────────────────────────
.ab-root {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--bg-page);
  overflow: hidden;
  font-family: var(--app-font-family);
}

.ab-loading {
  text-align: center;
  padding: 20px;
  color: var(--text-tertiary);
  font-size: 13px;
}

// ── Body layout ───────────────────────────────────────────────────
.ab-body {
  display: flex;
  gap: 16px;
  padding: 16px;
  flex: 1;
  min-height: 0;
  align-items: flex-start;
  overflow-y: auto;
}
.ab-left  { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.ab-right { width: 260px; flex-shrink: 0; display: flex; flex-direction: column; gap: 14px; }

// ── Card ──────────────────────────────────────────────────────────
.ab-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

// ── Config Card header ────────────────────────────────────────────
.ab-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.ab-card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }

.ab-mode-toggle {
  display: flex;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  overflow: hidden;

  button {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;

    &.active {
      background: var(--action-primary-default);
      color: #fff;
    }
    &:not(.active):hover { background: var(--bg-hover); }
  }
}

// ── Questions Section ─────────────────────────────────────────────
.ab-questions-wrap { display: flex; flex-direction: column; gap: 12px; }

.ab-q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  padding: 10px 16px;
}
.ab-q-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.5px;
}

.ab-empty-sections {
  background: var(--bg-surface);
  border: 1px dashed var(--border-default);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

// ── Question Card ─────────────────────────────────────────────────
.ab-q-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  padding: 14px 16px;
}

.ab-q-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.ab-q-meta  { display: flex; align-items: flex-start; gap: 8px; flex: 1; min-width: 0; }
.ab-q-num   { font-size: 12px; font-weight: 600; color: var(--text-tertiary); flex-shrink: 0; padding-top: 1px; }
.ab-q-text  { font-size: 13px; color: var(--text-primary); font-weight: 500; line-height: 1.4; }
.ab-q-badges { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.ab-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;

  &.badge-qt-0 { background: var(--category-bg-alpha);  color: var(--category-text-alpha); }
  &.badge-qt-1 { background: var(--category-bg-beta);   color: var(--category-text-beta);  }
  &.badge-qt-2 { background: var(--status-error-bg);    color: var(--status-error-text);   }
  &.badge-qt-3 { background: var(--category-bg-gamma);  color: var(--category-text-gamma); }
  &.badge-qt-4 { background: var(--category-bg-delta);  color: var(--category-text-delta); }
  &.badge-qt-5 { background: var(--bg-muted);           color: var(--text-secondary);      }
}

.ab-marks { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; }

.ab-q-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-tertiary);
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;

  &:hover { background: var(--bg-hover); color: var(--text-primary); }
  &.ab-q-del:hover { color: var(--status-error-text); background: var(--status-error-bg); }
}

// ── Options list ──────────────────────────────────────────────────
.ab-opts { display: flex; flex-direction: column; gap: 6px; }

.ab-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--text-primary);

  &--correct {
    background: var(--status-success-bg, #f1f8f1);
    color: var(--status-success-text);
    font-weight: 500;
  }
}

.ab-opt-icon { display: flex; align-items: center; }

.ab-radio {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border-default);
  flex-shrink: 0;

  &.filled {
    border-color: var(--action-primary-default);
    background: var(--action-primary-default);
    box-shadow: inset 0 0 0 3px var(--bg-surface);
  }
}

.ab-checkbox {
  width: 14px; height: 14px; border-radius: 3px;
  border: 2px solid var(--border-default);
  flex-shrink: 0;
  position: relative;

  &.checked {
    border-color: var(--action-primary-default);
    background: var(--action-primary-default);

    &::after {
      content: '✓';
      position: absolute;
      top: -2px;
      left: 1px;
      font-size: 10px;
      color: #fff;
    }
  }
}

.ab-opt-text    { flex: 1; line-height: 1.4; }
.ab-correct-tag { font-size: 11px; font-weight: 600; color: var(--status-success-text); margin-left: auto; white-space: nowrap; }

// ── Buttons ───────────────────────────────────────────────────────
.btn-save {
  padding: 7px 18px;
  border: none;
  border-radius: 6px;
  background: var(--action-primary-default);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;

  &:hover { filter: brightness(90%); }
}

.btn-add-q {
  padding: 6px 14px;
  border: 1px solid var(--action-primary-default);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--action-primary-default);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;

  &:hover { background: var(--bg-selected); }
}

.btn-cancel {
  padding: 6px 16px;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;

  &:hover { background: var(--bg-hover); }
}

// ── Dialog ────────────────────────────────────────────────────────
.ab-dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 900;
}

.ab-dialog {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border-radius: 8px;
  z-index: 901;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;

  &--wide { width: min(680px, 96vw); }
}

.ab-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-default);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-surface);
}

.ab-dialog-close {
  background: none; border: none; font-size: 18px;
  color: var(--text-tertiary); cursor: pointer; padding: 2px 6px;
  &:hover { color: var(--status-error-text); }
}

.ab-dialog-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.ab-dialog-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border-default);
  flex-shrink: 0;
}

.ab-dlg-row {
  display: flex;
  gap: 12px;

  .ab-field { flex: 1; }
}

// ── Dialog form controls ──────────────────────────────────────────
.ab-field { display: flex; flex-direction: column; gap: 4px; }

.ab-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);

  .req { color: var(--status-error-text); }
}

.ab-input {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--field-border-default);
  border-radius: 5px;
  font-size: 13px;
  color: var(--field-text-default);
  background: var(--field-bg-default);
  outline: none;
  width: 100%;
  box-sizing: border-box;

  &:focus { border-color: var(--field-border-focus); }
}

.ab-select { @extend .ab-input; padding: 0 8px; cursor: pointer; }

.ab-textarea {
  padding: 8px 10px;
  border: 1px solid var(--field-border-default);
  border-radius: 5px;
  font-size: 13px;
  color: var(--field-text-default);
  background: var(--field-bg-default);
  outline: none;
  width: 100%;
  resize: vertical;
  box-sizing: border-box;
  font-family: inherit;

  &:focus { border-color: var(--field-border-focus); }
}

// ── Paper Config Card ─────────────────────────────────────────────
.ab-paper-config-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ab-section-lbl {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.ab-pc-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.ab-field--sm { min-width: 120px; max-width: 160px; }

.ab-pc-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
}

.ab-toggle-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ab-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);

  .ab-toggle-track {
    width: 34px;
    height: 18px;
    border-radius: 9px;
    background: var(--border-default);
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
  }

  .ab-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  }

  &.ab-toggle-on {
    color: var(--action-primary-default);

    .ab-toggle-track { background: var(--action-primary-default); }
    .ab-toggle-knob  { transform: translateX(16px); }
  }
}

// ── Paper Sections Card ───────────────────────────────────────────
.ab-paper-sections-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ab-sec-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ab-sec-list-title-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ab-sec-total-hint {
  font-size: 11px;
  color: var(--text-tertiary);
}

// ── Section Card (display mode) ───────────────────────────────────
.ab-sec-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  overflow: hidden;
}

.ab-sec-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-muted);
  border-bottom: 1px solid var(--border-default);
}

.ab-sec-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.ab-sec-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--action-primary-default);
  background: var(--bg-selected, #ede9fe);
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.ab-sec-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ab-sec-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ab-sec-summary {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.ab-sel-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 10px;
  background: var(--category-bg-alpha);
  color: var(--category-text-alpha);
  white-space: nowrap;

  &.badge-fixed {
    background: var(--category-bg-gamma);
    color: var(--category-text-gamma);
  }
}

// ── Pool Questions (within section card) ─────────────────────────
.ab-pool-q-section {
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ab-pool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 6px;
}

.ab-pool-q-lbl {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-tertiary);
  text-transform: uppercase;
}

.ab-empty-pool {
  font-size: 12px;
  color: var(--text-disabled);
  padding: 8px 0 4px;
  font-style: italic;
}

// ── Pool Question Row (compact display) ───────────────────────────
.ab-pq-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-page);
  border: 1px solid var(--border-default);
  border-radius: 6px;
}

.ab-pq-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--action-primary-default);
  background: var(--bg-selected, #ede9fe);
  padding: 2px 7px;
  border-radius: 4px;
  flex-shrink: 0;
}

.ab-pq-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ab-pq-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ab-pq-qtext {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ab-pq-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

[dir='rtl'] {
  .ab-q-meta  { flex-direction: row-reverse; }
  .ab-opt-text { text-align: right; }
}

// ── Options Editor (dialog) ───────────────────────────────────────
.ab-opts-editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-page, #f8f9fa);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  padding: 12px 14px;
}

.ab-opts-lbl {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.ab-opt-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ab-opt-sel-btn {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border-default);
  background: var(--bg-surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
  transition: border-color 0.15s;

  &.ab-opt-check-btn { border-radius: 4px; }

  &.is-correct {
    border-color: var(--action-primary-default);
    background: var(--action-primary-default);

    &::after {
      content: '';
      display: block;
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: #fff;
    }

    &.ab-opt-check-btn::after {
      content: '✓';
      width: auto;
      height: auto;
      border-radius: 0;
      font-size: 12px;
      font-weight: 700;
      line-height: 1;
    }
  }

  &:not(.is-correct):hover { border-color: var(--action-primary-default); }
}

.ab-opt-inp {
  flex: 1;
  height: 36px;
  border: 1px solid var(--field-border-default, #e0e0e0);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 13px;
  color: var(--field-text-default);
  background: var(--bg-surface);
  outline: none;
  transition: border-color 0.15s;

  &:focus { border-color: var(--field-border-focus, #2196f3); }
  &:read-only { background: var(--bg-muted); color: var(--text-secondary); cursor: default; }
}

.ab-opt-rm {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-tertiary);
  padding: 4px 5px;
  border-radius: 4px;
  line-height: 1;
  display: flex;
  align-items: center;

  &:hover { color: var(--status-error-text); background: var(--status-error-bg); }
}

.ab-opt-add-btn {
  margin-top: 2px;
  align-self: flex-start;
  border: 1px dashed var(--border-default);
  background: transparent;
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  transition: border-color 0.15s, color 0.15s;

  &:hover {
    border-color: var(--action-primary-default);
    color: var(--action-primary-default);
  }
}

// ── Matching (type 4) — review list & preview ─────────────────────
.ab-match-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font-size: 13px;
  color: var(--text-primary);
}

.ab-match-side  { flex: 1; }
.ab-match-arrow { color: var(--text-tertiary); flex-shrink: 0; }

// ── Matching (type 4) — editor rows ────────────────────────────────
.ab-match-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;

  .ab-opt-inp { flex: 1; }
}

// ── Ordering (type 5) — review list & preview ─────────────────────
.ab-order-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font-size: 13px;
  color: var(--text-primary);
}

.ab-order-num { flex-shrink: 0; font-weight: 600; color: var(--text-secondary); }

// ── Ordering (type 5) — editor rows (drag to reorder) ──────────────
.ab-order-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;

  .ab-opt-inp { flex: 1; }
}

.ab-drag-handle {
  flex-shrink: 0;
  cursor: grab;
  color: var(--text-tertiary);
  font-size: 14px;
  line-height: 1;
}

.cdk-drag-preview {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  background: var(--bg-surface);
}

.cdk-drag-placeholder {
  opacity: 0.3;
}

// ── Short Answer field ────────────────────────────────────────────
.ab-sa-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ab-sa-input {
  padding: 8px 10px;
  border: 1px solid var(--field-border-default, #e0e0e0);
  border-radius: 6px;
  font-size: 13px;
  color: var(--field-text-default);
  background: var(--bg-surface);
  outline: none;
  width: 100%;
  resize: vertical;
  min-height: 60px;
  box-sizing: border-box;
  font-family: inherit;

  &:focus { border-color: var(--field-border-focus, #2196f3); }
}

// ── Preview: Question Paper ────────────────────────────────────────
.paper-sheet {
  background: var(--bg-surface);
  font-family: 'Times New Roman', serif;
}

.paper-title {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.paper-meta {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-default);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.paper-empty {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
  font-style: italic;
  padding: 16px 0;
}

.paper-section {
  margin-bottom: 16px;
}

.paper-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-default);
  padding-bottom: 4px;
  margin-bottom: 10px;
}

.paper-section-hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-tertiary);
}

.paper-question {
  margin-bottom: 14px;
}

.paper-q-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 14px;
  color: var(--text-primary);
}

.paper-q-no   { font-weight: 700; flex-shrink: 0; }
.paper-q-text { flex: 1; line-height: 1.5; }
.paper-q-marks { font-size: 12px; color: var(--text-tertiary); flex-shrink: 0; white-space: nowrap; }

.paper-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0 0 22px;
}

.paper-option {
  font-size: 13px;
  color: var(--text-secondary);
}

.paper-answer-line {
  margin: 10px 22px 0;
  border-bottom: 1px dashed var(--border-default);
  height: 20px;
}
