/* Shared dark-mode overrides for Bootstrap's fixed light utilities. Screen-only; print stays light. */
@media screen {
  html[data-bs-theme="dark"] :is(.bg-light, .bg-white, .text-bg-light, .bg-body-tertiary, .bg-light-subtle) {
    background-color: var(--app-surface-muted) !important;
    color: var(--app-text) !important;
    border-color: var(--app-border) !important;
  }
  html[data-bs-theme="dark"] .text-dark:not(.bg-warning):not(.bg-info):not(.bg-success):not(.bg-primary):not(.btn):not(.alert-warning):not(.alert-info) {
    color: var(--app-text) !important;
  }
  html[data-bs-theme="dark"] .text-muted { color: var(--app-text-muted) !important; }
  html[data-bs-theme="dark"] .card-header.bg-info {
    background-color: var(--app-surface-muted) !important;
    color: var(--app-text) !important;
  }
  html[data-bs-theme="dark"] .btn-light {
    --bs-btn-color: var(--app-text);
    --bs-btn-bg: var(--app-surface-muted);
    --bs-btn-border-color: var(--app-border);
    --bs-btn-hover-color: var(--app-text);
    --bs-btn-hover-bg: var(--app-surface);
    --bs-btn-hover-border-color: var(--app-accent);
  }
  html[data-bs-theme="dark"] .card,
  html[data-bs-theme="dark"] .modal-content,
  html[data-bs-theme="dark"] .list-group-item,
  html[data-bs-theme="dark"] .dropdown-menu {
    --bs-card-bg: var(--app-surface);
    --bs-card-border-color: var(--app-border);
    --bs-modal-bg: var(--app-surface);
    --bs-list-group-bg: var(--app-surface);
    --bs-list-group-border-color: var(--app-border);
    --bs-dropdown-bg: var(--app-surface);
    --bs-dropdown-border-color: var(--app-border);
  }
  html[data-bs-theme="dark"] .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--app-text);
    --bs-table-border-color: var(--app-border);
    --bs-table-striped-bg: var(--app-surface-muted);
    --bs-table-hover-bg: var(--app-surface-muted);
  }
  html[data-bs-theme="dark"] :is(.form-control, .form-select) {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
  }
  /* Native multi-select listboxes (unit/lesson pickers) paint hovered and
     selected rows with the OS's own light highlight color unless overridden. */
  html[data-bs-theme="dark"] .form-select option:hover,
  html[data-bs-theme="dark"] .form-select option:checked {
    background: #1c3350 !important;
    color: var(--app-text) !important;
  }

  /* ---- Page-specific surfaces that hard-code white/near-white ---- */
  html[data-bs-theme="dark"] :is(
    .editor-card, .sticky-actions,
    .filter-shell, .question-pagination, .pdf-frame-container, .pdf-card,
    .section-block, .selection-type-wrapper, .preference-tile, .lesson-wrapper,
    .exam-card, .stats-table-shell, .header-style-strip, .open-ended-option,
    .question-selection-table, .selection-summary-bar,
    #question-table .pdf-select-checkbox, #editQuestionModal .modal-footer,
    #editQuestionModal .modal-header-status, #math-answer) {
    background: var(--app-surface) !important;
    border-color: var(--app-border) !important;
    color: var(--app-text);
  }
  html[data-bs-theme="dark"] :is(
    .source-block, .answer-panel, .difficulty-band, .page-jump__control,
    .filter-panel, .filter-footer, .filter-bar, .exam-card-header, .total-row,
    .pdf-preview, .sidebar, .setting-section, #settingsTab, .toggle-header,
    .previous-toggle label, .previous-exam-panel, .toggle-pill, .achievement-band,
    .publication-band, .question-type-segment, .question-type-segment-btn.is-coming-soon,
    #editQuestionModal .modal-header, .modern-search) {
    background: var(--app-surface-muted) !important;
    border-color: var(--app-border) !important;
    color: var(--app-text);
  }
  /* question_list.html: .filter-panel artık .filter-shell'den daha acik
     (surface-muted) bir zeminde; iceride kalan select/input'lar da ayni
     acik zemine uysun diye tek tek acik renk zorlaniyor. */
  html[data-bs-theme="dark"] .filter-panel :is(.form-select, .form-control) {
    background-color: var(--app-surface-muted) !important;
  }
  html[data-bs-theme="dark"] :is(
    .difficulty-pill, .achievement-pill, .publication-pill, .author-badge,
    .image-file-name, .eco-reminder, .mock-exam-question-switch, .previous-question-switch):not(.active) {
    background: var(--app-surface-muted) !important;
    border-color: var(--app-border) !important;
    color: var(--app-text) !important;
  }
  html[data-bs-theme="dark"] .toggle-content { background: var(--app-surface) !important; border-color: var(--app-border) !important; }
  html[data-bs-theme="dark"] .question-pagination .page-jump__button {
    background: color-mix(in srgb, var(--app-accent) 16%, var(--app-surface));
    color: var(--app-accent);
  }
  html[data-bs-theme="dark"] .question-pagination .page-jump__button:hover {
    background: var(--app-accent);
    color: var(--app-bg);
  }
  html[data-bs-theme="dark"] .question-pagination .page-item:not(.disabled):not(.active) .page-link {
    color: var(--app-text-muted);
  }
  html[data-bs-theme="dark"] .question-pagination .page-item:not(.disabled):not(.active) .page-link:hover {
    background: var(--app-surface-muted);
    color: var(--app-accent);
  }
  html[data-bs-theme="dark"] :is(.stats-table-shell, .exam-card) :is(td, th) { border-color: var(--app-border); }
  html[data-bs-theme="dark"] .stats-table-shell :is(tr, td):not(.total-row) { background-color: transparent; }
  /* MathLive varsayilan renkleri acik tema icin: kesir/kok gibi yapinin icindeyken acik zemin + acik yazi,
     \komut yazarken koyu mavi yazi okunmuyordu. Satir ici (beyaz) alanlar haric. */
  html[data-bs-theme="dark"] math-field:not(.inline-math-field) {
    --contains-highlight-background-color: rgba(147, 197, 253, 0.18);
    --latex-color: #93c5fd;
    --caret-color: var(--app-accent);
  }
  html[data-bs-theme="dark"] .stats-table-shell thead th { background: var(--app-surface-muted) !important; color: var(--app-text) !important; }
  html[data-bs-theme="dark"] .question-row-inactive > td { background-color: #3a1f24 !important; }
  html[data-bs-theme="dark"] #question-table tr.is-selected > td { background-color: #1c3350 !important; }
  html[data-bs-theme="dark"] .filter-loading-skeleton {
    background: linear-gradient(90deg, var(--app-surface-muted) 25%, var(--app-surface) 37%, var(--app-surface-muted) 63%);
    background-size: 400% 100%;
  }

  /* scanning_test */
  html[data-bs-theme="dark"] #scanning-test :is(.preset-card, .content-card) .card-body { background: var(--app-surface); }
  html[data-bs-theme="dark"] #formset-table thead th { background-color: var(--app-surface-muted); color: var(--app-text); }
  html[data-bs-theme="dark"] #formset-table :is(th, td) { border-color: var(--app-border); }
  html[data-bs-theme="dark"] #formset-table :is(select, input[type="number"]) {
    background-color: var(--app-surface); border-color: var(--app-border); color: var(--app-text);
  }
  html[data-bs-theme="dark"] #formset-table tbody tr:hover, html[data-bs-theme="dark"] #summary-table tbody tr:nth-child(even) { background-color: var(--app-surface-muted); }
  html[data-bs-theme="dark"] .previous-exam-panel .form-select { background-color: var(--app-surface); }

  html[data-bs-theme="dark"] .math-insert, html[data-bs-theme="dark"] .open-answer-shortcuts .math-shortcut-btn {
    background: var(--app-surface-muted) !important; border-color: var(--app-border) !important; color: var(--app-text) !important;
  }
  html[data-bs-theme="dark"] .math-insert--primary { background: #253c60 !important; border-color: #4d6e9e !important; color: var(--app-accent) !important; }
  html[data-bs-theme="dark"] .math-insert:hover { border-color: var(--app-accent) !important; }
  html[data-bs-theme="dark"] .table-striped.stats-table tbody tr:nth-of-type(odd) { background-color: var(--app-surface-muted) !important; }
  html[data-bs-theme="dark"] .stats-table tbody tr, html[data-bs-theme="dark"] .stats-table tbody td { --bs-table-bg: transparent; --bs-table-accent-bg: transparent; }
  html[data-bs-theme="dark"] .total-row > *, html[data-bs-theme="dark"] .stats-table tbody .total-row td:nth-child(1),
  html[data-bs-theme="dark"] .stats-table tbody .total-row td:nth-child(2) { background-color: #1c3350 !important; color: var(--app-text) !important; }

  /* combined_test.html: .modern-card sabit acik gri kenarlik kullaniyor */
  html[data-bs-theme="dark"] .modern-card { border-color: var(--app-border) !important; }

  /* combined_test.html: Ders/Ünite/Kazanım/Yayın başlık şeritlerinin acik
     "surface-muted" rengi yerine, Zorluk Seviyesi kartıyla aynı .section-block
     yuzey rengini (var(--app-surface)) kullansın (.toggle-header eklenerek
     yukarida baska dallardan sismis olan :is() ozgunlugune esitleniyor). */
  html[data-bs-theme="dark"] #lessonContainer .toggle-header,
  html[data-bs-theme="dark"] #unitsContainer .toggle-header,
  html[data-bs-theme="dark"] #achievementsContainer .toggle-header,
  html[data-bs-theme="dark"] #publicationsContainer .toggle-header {
    background: var(--app-surface) !important;
  }

  /* question_list achievement picker */
  html[data-bs-theme="dark"] .achievement-list { background: var(--app-surface) !important; border-color: var(--app-border) !important; }
  html[data-bs-theme="dark"] .achievement-item { background: var(--app-surface-muted); border-color: var(--app-border); color: var(--app-text); }
  html[data-bs-theme="dark"] .achievement-item.is-selected { background: #1c3350; border-color: var(--app-accent); }
  html[data-bs-theme="dark"] .achievement-list:empty { color: var(--app-text-muted); }
  html[data-bs-theme="dark"] .achievement-description { background: #1c3350; border-color: #3b5c8a; color: var(--app-text); }
  html[data-bs-theme="dark"] .achievement-description-line + .achievement-description-line { border-top-color: #3b5c8a; }
  /* combined_test.html/question_list.html: kazanım kartlarındaki konu metni
     sabit koyu lacivert (#0f172a) renk kullanıyor, koyu temada okunmuyordu. */
  html[data-bs-theme="dark"] .achievement-pill:not(.active) .achievement-topic,
  html[data-bs-theme="dark"] .achievement-item:not(.is-selected) .achievement-topic {
    color: var(--app-text) !important;
  }
  /* Kazanım kartları çevresindeki yüzeyle karışıyordu; biraz daha belirgin
     bir zemin ve kenarlık verildi. Zorluk Seviyesi ve Yayın kartlarındaki
     nötr gri kenarlık (var(--app-border)) da aynı şekilde düzeltildi. */
  html[data-bs-theme="dark"] .achievement-pill:not(.active),
  html[data-bs-theme="dark"] .achievement-item:not(.is-selected),
  html[data-bs-theme="dark"] .difficulty-pill:not(.active),
  html[data-bs-theme="dark"] .publication-pill:not(.active) {
    background: #2d4058 !important;
    border-color: #4c6a8c !important;
    box-shadow: 0 2px 6px rgb(0 0 0 / 25%) !important;
  }

  /* Yayın ve Zorluk Seviyesi kartlarının hover'ı, dark moddaki genel
     :not(.active) renk kilidi yüzünden hiç görünmüyordu. */
  html[data-bs-theme="dark"] :is(.difficulty-pill, .publication-pill):not(.active):hover,
  html[data-bs-theme="dark"] :is(.difficulty-pill, .publication-pill):not(.active):focus-visible {
    border-color: var(--app-accent) !important;
    color: var(--app-accent) !important;
  }

  /* question_form.html: Ders Seçimi (#lessonList) ve Kazanım Seçimi
     (#achievementList) kartları, diğer kazanım kartlarıyla aynı !important
     kuralla çakışıp seçili/seçili olmayan arasında fark göstermiyordu.
     ID'ye bağlanarak kesin kazanan, daha belirgin bir görünüm verildi. */
  html[data-bs-theme="dark"] #lessonList .achievement-item,
  html[data-bs-theme="dark"] #achievementList .achievement-item {
    background: #2d4058 !important;
    border-color: #4c6a8c !important;
    box-shadow: 0 2px 6px rgb(0 0 0 / 25%) !important;
  }
  html[data-bs-theme="dark"] #lessonList .achievement-item.is-selected,
  html[data-bs-theme="dark"] #achievementList .achievement-item.is-selected {
    background: #2a4d7a !important;
    border-color: var(--app-accent) !important;
    box-shadow: 0 0 0 2px rgba(164, 200, 255, 0.35), 0 2px 8px rgb(0 0 0 / 30%) !important;
  }

  /* question_list.html: soru listesindeki ünite/kazanım rozetleri açık
     temaya göre sabit renklerle (açık mavi/indigo zemin, koyu yazı)
     tasarlanmıştı, koyu temada okunmuyordu. */
  html[data-bs-theme="dark"] .unit-chip {
    background: linear-gradient(135deg, #0c3648 0%, #0d4550 100%) !important;
    border-color: #1f7aa8 !important;
    color: #93e0fb !important;
  }
  html[data-bs-theme="dark"] .achievement-chip {
    background: linear-gradient(135deg, #0a2e2e 0%, #0f3d3a 100%) !important;
    border-color: #157a6e !important;
    color: #5eead4 !important;
  }

  /* question_list.html: Çıkmış Soruları Göster / Deneme Soruları anahtarları,
     .toggle-pill kartıyla aynı renge sahip olduğu için görünmüyordu. */
  html[data-bs-theme="dark"] #showPreviousQuestions + label .toggle-pill,
  html[data-bs-theme="dark"] #showMockQuestions + label .toggle-pill {
    background: var(--app-border) !important;
  }
  html[data-bs-theme="dark"] #showPreviousQuestions:checked + label {
    background: linear-gradient(120deg, rgba(59, 130, 246, 0.18), rgba(45, 212, 191, 0.14)) !important;
    border-color: var(--app-accent) !important;
  }
  html[data-bs-theme="dark"] #showMockQuestions:checked + label {
    background: linear-gradient(120deg, rgba(245, 158, 11, 0.18), rgba(251, 191, 36, 0.14)) !important;
    border-color: #f59e0b !important;
  }
  html[data-bs-theme="dark"] #showPreviousQuestions:checked + label .toggle-pill {
    background: linear-gradient(120deg, #3b82f6, #2dd4bf) !important;
  }
  html[data-bs-theme="dark"] #showMockQuestions:checked + label .toggle-pill {
    background: linear-gradient(120deg, #f59e0b, #facc15) !important;
  }
  /* Anahtarların soldaki ikon rozetleri açık temaya göre çok düşük
     opaklıkta (%12-18) mavi/amber tondaydı; koyu zeminde neredeyse
     gri/renksiz görünüyordu. */
  html[data-bs-theme="dark"] .previous-toggle-icon {
    background: linear-gradient(120deg, rgba(59, 130, 246, 0.3), rgba(45, 212, 191, 0.24)) !important;
    color: #93c5fd !important;
  }
  html[data-bs-theme="dark"] .mock-toggle .previous-toggle-icon {
    background: linear-gradient(120deg, rgba(245, 158, 11, 0.32), rgba(251, 191, 36, 0.26)) !important;
    color: #fbbf24 !important;
  }
  /* Anahtar kutularının kenarlığı nötr gri (var(--app-border)) geliyordu;
     ikonlarla uyumlu hafif mavi/amber tonlu kenarlık verildi. */
  html[data-bs-theme="dark"] #showPreviousQuestions[type="checkbox"] + label {
    border-color: rgba(59, 130, 246, 0.4) !important;
  }
  html[data-bs-theme="dark"] #showMockQuestions[type="checkbox"] + label {
    border-color: rgba(245, 158, 11, 0.4) !important;
  }
  /* Kapalıyken kutu zemini de kenarlık renginin %10 opaklıklı tonu olsun
     (açıkken yukarıdaki :checked gradyanı geçerli). */
  html[data-bs-theme="dark"] #showPreviousQuestions[type="checkbox"]:not(:checked) + label {
    background: rgba(59, 130, 246, 0.1) !important;
  }
  html[data-bs-theme="dark"] #showMockQuestions[type="checkbox"]:not(:checked) + label {
    background: rgba(245, 158, 11, 0.1) !important;
  }
  /* Seçiliyken kutu belirgin olsun: daha dolgun zemin, parlak kenarlık, dış halka ve ikon rozeti.
     (Yukarıdaki genel kenarlık kuralı :checked kenarlığını eziyordu.) */
  html[data-bs-theme="dark"] #showPreviousQuestions[type="checkbox"]:checked + label {
    background: linear-gradient(120deg, rgba(59, 130, 246, 0.4), rgba(45, 212, 191, 0.28)) !important;
    border-color: #60a5fa !important;
    box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.6), 0 6px 18px rgba(59, 130, 246, 0.3) !important;
  }
  html[data-bs-theme="dark"] #showMockQuestions[type="checkbox"]:checked + label {
    background: linear-gradient(120deg, rgba(245, 158, 11, 0.38), rgba(251, 191, 36, 0.26)) !important;
    border-color: #fbbf24 !important;
    box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.6), 0 6px 18px rgba(245, 158, 11, 0.3) !important;
  }
  html[data-bs-theme="dark"] #showPreviousQuestions:checked + label .previous-toggle-icon {
    background: linear-gradient(120deg, rgba(59, 130, 246, 0.7), rgba(45, 212, 191, 0.55)) !important;
    color: #fff !important;
  }
  html[data-bs-theme="dark"] #showMockQuestions:checked + label .previous-toggle-icon {
    background: linear-gradient(120deg, rgba(245, 158, 11, 0.7), rgba(251, 191, 36, 0.55)) !important;
    color: #fff !important;
  }
  html[data-bs-theme="dark"] :is(#showPreviousQuestions, #showMockQuestions):checked + label .previous-toggle-label {
    color: #fff !important;
  }
  html[data-bs-theme="dark"] :is(#showPreviousQuestions, #showMockQuestions):checked + label .previous-toggle-label small {
    color: #cbd5e1 !important;
  }
  /* .previous-toggle label'daki açık temaya özel "inset 0 1px 0 rgba(255,255,255,.8)"
     parlaklık efekti, üst kenarda beyazımsı/gri bir çizgi gibi görünüyordu. */
  html[data-bs-theme="dark"] .previous-toggle label {
    box-shadow: none !important;
  }
  html[data-bs-theme="dark"] .previous-toggle label:hover {
    box-shadow: 0 6px 18px rgba(59, 130, 246, 0.25) !important;
  }
  html[data-bs-theme="dark"] .mock-toggle label:hover {
    box-shadow: 0 6px 18px rgba(245, 158, 11, 0.25) !important;
  }

  /* question_form.html: Soru tipi segment kontrolü (Şıklı/Açık Uçlu/...)
     nötr gri kenarlık ve açık temaya özel beyazımsı inset parlaklık
     kullanıyordu; #questionTypeGroup ID'sine bağlanarak diğer kartlarla
     aynı belirgin kenarlığa kavuşturuldu. */
  html[data-bs-theme="dark"] #questionTypeGroup[role="group"] {
    border-color: #4c6a8c !important;
    box-shadow: none !important;
  }
  html[data-bs-theme="dark"] #questionTypeGroup .question-type-segment-btn + .question-type-segment-btn {
    border-left-color: var(--app-border) !important;
  }

  /* question_form.html: OCR tarafından üretilen etiket önerileri
     (#ocr-suggestion-chips .btn) nötr gri btn-outline-secondary
     kullanıyordu; koyu zeminde kenarlık/yazı neredeyse görünmüyordu. */
  html[data-bs-theme="dark"] #ocr-suggestion-chips .btn {
    color: var(--app-accent) !important;
    border-color: var(--app-accent) !important;
    background: rgba(164, 200, 255, 0.1) !important;
  }
  html[data-bs-theme="dark"] #ocr-suggestion-chips .btn:hover {
    background: var(--app-accent) !important;
    color: #0b1220 !important;
  }

  /* analiz/student_profile.html */
  html[data-bs-theme="dark"] .lesson-item:hover { background-color: var(--app-surface-muted); }
  html[data-bs-theme="dark"] .student-lesson-date { background: var(--app-surface-muted); color: var(--app-text-muted); }
  html[data-bs-theme="dark"] .student-lesson-month { border-color: var(--app-border) !important; }
  html[data-bs-theme="dark"] .student-lesson-month .accordion-button:not(.collapsed) { background: var(--app-surface-muted); color: var(--app-text); }
  html[data-bs-theme="dark"] .achievement-filters .input-group-text { background-color: var(--app-surface-muted); border-color: var(--app-border); color: var(--app-text); }
  html[data-bs-theme="dark"] #achievementSuccessFilter option { background-color: var(--app-surface); color: var(--app-text); }

  /* Bootstrap semantic text/button colours are tuned for light backgrounds */
  html[data-bs-theme="dark"] .text-primary { color: #6ea8fe !important; }
  html[data-bs-theme="dark"] .text-success { color: #75b798 !important; }
  html[data-bs-theme="dark"] .text-danger { color: #ea868f !important; }
  html[data-bs-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: var(--app-text-muted); --bs-btn-border-color: var(--app-border);
    --bs-btn-hover-color: var(--app-text); --bs-btn-hover-bg: var(--app-surface-muted); --bs-btn-hover-border-color: var(--app-accent);
    --bs-btn-active-color: var(--app-text); --bs-btn-active-bg: var(--app-surface-muted);
  }
  html[data-bs-theme="dark"] .btn-outline-success {
    --bs-btn-color: #75b798; --bs-btn-border-color: #3f8a68;
    --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #198754; --bs-btn-hover-border-color: #198754;
  }
  html[data-bs-theme="dark"] .btn-outline-primary {
    --bs-btn-color: var(--app-accent); --bs-btn-border-color: #4d6e9e;
    --bs-btn-hover-color: #0b1220; --bs-btn-hover-bg: var(--app-accent); --bs-btn-hover-border-color: var(--app-accent);
  }
  html[data-bs-theme="dark"] :is(#autoFields, .setting-section, .pdf-card) .form-label { color: var(--app-accent); }
  html[data-bs-theme="dark"] .editor-card__header, html[data-bs-theme="dark"] .editor-card__header * { color: var(--app-text) !important; }
  html[data-bs-theme="dark"] h1:not([class]) { color: var(--app-text); }
  html[data-bs-theme="dark"] :is(.previous-question-switch, .mock-exam-question-switch) :is(label, span, small) { color: inherit !important; }
  html[data-bs-theme="dark"] .question-type-segment-btn:not(.is-active) { color: var(--app-text-muted); }
  /* Açık temaya özel :hover kuralı (background:#edf2ff, color:#314b9b)
     koyu temada da geçerliydi; üstüne basit renk kuralımızla karışıp
     hover'da görünür bir değişiklik olmuyordu. */
  html[data-bs-theme="dark"] .question-type-segment-btn:not(.is-active):hover {
    background: #2c435f !important;
    color: var(--app-accent) !important;
  }
  html[data-bs-theme="dark"] .open-ended-option .form-check-label { color: var(--app-text) !important; }
  html[data-bs-theme="dark"] #save-question-btn:disabled { background-color: #4b5563; border-color: #4b5563; color: #e5e7eb; }

  /* headings/labels that hard-code dark ink */
  html[data-bs-theme="dark"] :is(.filter-field label, .filter-footer .form-check-label, .previous-toggle-label,
    .settings-title, .exam-card-header h1, .exam-card-header h2, .exam-card-header h3, .exam-card-header h4,
    .editor-card h1, .editor-card h2, .editor-card h3, .editor-card h4, .editor-card label, .pdf-card label) {
    color: var(--app-text) !important;
  }
  html[data-bs-theme="dark"] :is(.filter-footer small, .previous-toggle-label small) { color: var(--app-text-muted) !important; }
}
