/* Editable documents and standardized answer sheet */
.storage-auth-dialog [hidden] { display: none !important; }
.storage-auth-dialog > p { color: var(--muted); line-height: 1.8; }
.storage-auth-dialog #google-button { margin-top: 16px; }
.storage-auth-dialog #google-login,
.storage-auth-dialog #microsoft-storage-login { width: 100%; }
.storage-auth-dialog .status-error { color: #ff9aa8; }
.model-qr { display: block; width: 110px; height: 110px; object-fit: contain; image-rendering: pixelated; }
.qr-model-group { display: grid; justify-items: center; gap: 1mm; }
.qr-model-marker { direction: ltr; min-height: 1em; color: #000; font: 700 10px/1 monospace; letter-spacing: 2px; white-space: pre; }
.exam-document-qr-group { position: relative; z-index: 2; float: left; width: 110px; margin: 0 0 12px 14px; }
.exam-document-qr { width: 100%; height: auto; aspect-ratio: 1; }
.answer-sheet-qr-group { position: absolute; z-index: 1; left: 54.3%; top: calc(15% - 10mm); width: 36.2%; }
.answer-sheet-qr { width: 100%; height: auto; aspect-ratio: 1; background: #fff; }
.answer-sheet-head > div:first-child { min-width: 0; }
.document-toolbar { position: sticky; top: 147px; z-index: 12; display: flex; gap: 6px; margin: 10px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-white); padding: 6px; box-shadow: var(--shadow-small); }
.document-toolbar button { min-height: 32px; border: 1px solid var(--line); border-radius: 5px; background: #fff; padding: 5px 10px; font-size: 11px; }
.document-toolbar button:last-child { margin-inline-start: auto; border-color: var(--emerald); background: var(--emerald); color: #fff; }
.content-document.is-editing { min-height: 700px; cursor: text; box-shadow: 0 0 0 3px rgba(63,104,213,.18), 15px 18px 50px rgba(21,33,29,.16); }
.answer-sheet-preview { margin-top: 16px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #dcd7c9; }
.answer-sheet-preview > header { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); background: var(--surface-white); padding: 14px 16px; }
.answer-sheet-preview > header > div { display: grid; }.answer-sheet-preview > header strong { font-size: 16px; }.answer-sheet-preview > header > span { color: var(--muted); font-size: 10px; }
.answer-sheet-document { overflow: auto; padding: 18px; }
.answer-sheet-sheet { position: relative; box-sizing: border-box; width: var(--answer-sheet-width,210mm); height: var(--answer-sheet-height,280mm); direction: ltr; background: #fff; border: 1px solid #aaa899; padding: 0; overflow: hidden; box-shadow: 12px 14px 40px rgba(21,33,29,.14); page-break-after: always; break-after: page; }
.answer-sheet-sheet, .answer-sheet-sheet * { color: #000 !important; }
.answer-sheet-template-image { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: fill; }

@media print {
  .document-toolbar { display: none !important; }
  .creator-preview, .creator-preview * { color: #000 !important; }
  .creator-paper, .creator-paper * { color: #000 !important; }
  .answer-sheet-preview { overflow: visible; border: 0; background: #fff; page-break-before: always; }
  .answer-sheet-preview > header { display: none !important; }
  .answer-sheet-document { overflow: visible; padding: 0; }
  .answer-sheet-sheet { width: var(--answer-sheet-width,210mm); height: var(--answer-sheet-height,280mm); min-height: 0; aspect-ratio: auto; overflow: hidden; margin: 0 auto; border: 0; box-shadow: none; page-break-after: always; break-after: page; }
  .creator-paper { width: var(--paper-width,210mm); min-width: 0; min-height: 0; aspect-ratio: auto; overflow: visible; box-shadow: none; }
}

/* Structured controls and source preview */
.toggle-control { display: grid !important; grid-template-columns: 42px minmax(0,1fr); align-items: center; gap: 10px; min-height: 58px; margin: 4px 0 !important; }
.toggle-control div { display: grid; }
.toggle-control strong { color: var(--ink); font-size: 11px; }
.toggle-control small { color: var(--muted); font-size: 9px; font-weight: 500; }
.toggle-control > span { grid-column: 1; }
.toggle-control div { grid-column: 2; }
.preview-list-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.preview-list-heading > div { display: grid; }
.preview-list-heading strong { margin-top: 3px; font-size: 18px; }
.question-preview-more { display: block; min-height: 40px; margin: 14px auto; }
.status-chip { border: 1px solid #9bd3bd; border-radius: 20px; background: #dcefe6; padding: 5px 9px; color: var(--emerald); font: 500 8px var(--font-mono); }
.source-question { display: grid; grid-template-columns: 42px minmax(0,1fr); gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.source-question:last-child { border-bottom: 0; }
.source-question-index { color: var(--blue); border-left: 1px solid var(--line); padding-left: 8px; font: 500 13px var(--font-mono); }
.source-question h3 { margin: 0 0 9px; font-size: 14px; line-height: 1.8; }
.source-choices { display: flex; flex-wrap: wrap; gap: 6px; }
.source-choice { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #f7f4ea; padding: 5px 8px; color: #59635f; font-size: 10px; }
.source-choice b { font: 500 9px var(--font-mono); }
.source-choice.correct { border-color: var(--emerald); background: #dcefe6; color: var(--emerald); }

/* Live paper and result rendering */
.exam-document-content { direction: inherit; text-align: start; font-size: 12pt; line-height: 1.5; }
.exam-head { position: relative; clear: both; border-bottom: 3px solid #1a1d1b; padding: 0 0 4mm; }
.exam-head h2 { margin: 5px 0; }
.exam-head-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, .9fr) auto; align-items: center; gap: 4mm; direction: rtl; }
.exam-head-identity { display: grid; gap: 2mm; min-width: 0; }
.exam-head-brand { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1mm; min-width: 0; text-align: center; }
.exam-head h1 { margin: 0; font-size: 13pt; line-height: 1.25; }
.exam-institution { margin: 0; font-size: 10pt; font-weight: 700; }
.exam-header-logo { display: block; width: auto; max-width: 18mm; max-height: 11mm; margin: 0; object-fit: contain; }
.exam-meta { display: grid; justify-content: start; gap: 1.5mm; font-size: 9pt; text-align: start; }
.exam-model-name { font-weight: 700; }
.exam-header-fields { display: flex; flex: 1 1 auto; flex-wrap: wrap; justify-content: flex-start; gap: 2mm 5mm; min-width: 0; margin: 0; text-align: start; }
.exam-head > .exam-header-fields { margin-top: 2mm; }
.exam-header-field { display: flex; flex: 1 1 42%; min-width: 34mm; align-items: baseline; gap: 2mm; font-size: 9pt; }
.exam-document-qr-group { float: none; width: 35mm; margin: 0; }
.exam-document-qr-group .model-qr { width: 35mm; height: 35mm; }
.exam-document-qr-group .qr-model-marker { font-size: 8pt; }
.exam-header-field > strong { flex: 0 0 auto; }
.exam-header-field > span { display: flex; flex: 1 1 auto; min-width: 12mm; min-height: 1.35em; align-items: end; }
.exam-header-field i { display: block; flex: 1 1 auto; min-width: 14mm; border-bottom: 1px solid #222; }
.exam-header-studentId > span { direction: ltr; }
.exam-question { margin: 8pt 0; break-inside: avoid; page-break-inside: avoid; }
.exam-question h3 { margin: 0 0 4pt; font-size: 12pt; line-height: 1.5; text-align: start; unicode-bidi: isolate; }
.creator-paper .choices { display: grid; grid-template-columns: repeat(var(--choice-count, 4), minmax(0, 1fr)); gap: 4pt; }
.choice { min-width: 0; border: 1px solid #cbc7ba; border-radius: 5px; padding: 3pt 4pt; font-size: 10pt; line-height: 1.4; overflow-wrap: anywhere; text-align: start; unicode-bidi: isolate; }
.choice.is-correct-answer { border-color: #168052; background: #dcefe6; color: #14583e; }
.correct-answer-label { display: block; margin-top: 2pt; color: #16724f; font-size: 8pt; font-weight: 700; }
.exam-qr { width: 90px; height: 90px; float: left; }
.omr-grid { display: grid; grid-template-columns: 1fr repeat(4, 30px); margin-top: 18px; direction: ltr; border: 1px solid #1a1d1b; }
.omr-grid div { min-height: 24px; display: grid; place-items: center; border-left: 1px solid #1a1d1b; border-bottom: 1px solid #1a1d1b; font-size: 9px; }
.bubble { display: inline-block; width: 9px; height: 9px; border: 1px solid #1a1d1b; border-radius: 50%; margin: 2px; }
.answer-table { width: 100%; border-collapse: collapse; direction: rtl; }
.answer-table th, .answer-table td { border-bottom: 1px solid var(--line); padding: 8px 5px; text-align: right; font-size: 10px; }
.score-card { display: flex; justify-content: space-between; align-items: center; border-right: 4px solid var(--emerald); border-radius: 8px; background: #dcefe6; padding: 16px; font-size: 20px; }

.exam-header-help { margin: 0 0 10px; color: var(--muted); font-size: 10px; line-height: 1.8; }
.exam-header-settings-list { display: grid; gap: 8px; }
.exam-header-setting { display: grid; gap: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-white); padding: 10px; }
.exam-header-setting .toggle-control { min-height: 36px; margin: 0 !important; }
.exam-header-setting label:not(.toggle-control) { margin: 0; }
.exam-header-field-actions { display: flex; gap: 5px; }
.exam-header-field-actions button, .exam-header-add, .exam-header-logo-preview button { min-height: 32px; padding: 5px 9px; font-size: 10px; }
.exam-header-add { width: 100%; margin: 8px 0 12px; }
.exam-header-logo-preview { display: flex; align-items: center; gap: 10px; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-white); padding: 8px; }
.exam-header-logo-preview[hidden] { display: none; }
.exam-header-logo-preview img { width: 72px; height: 48px; object-fit: contain; }

@media (max-width: 620px) {
  .exam-head-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
  .exam-head-brand { grid-column: 1 / -1; grid-row: 1; }
  .exam-head-identity { grid-column: 1; grid-row: 2; }
  .exam-meta { grid-column: 2; grid-row: 2; }
  .exam-document-qr-group { grid-column: 3; grid-row: 1 / span 2; }
  .exam-header-field { flex-basis: 100%; }
}
