/**
 * IELTS Listening: Notes, Form & Table Completion Design System
 * Enhances fill-in-blank inputs, numbered gap markers, and notes hierarchy across Parts 1 & 4.
 */

:root {
  --lnc-input-bg: #f8fafc;
  --lnc-input-border: #cbd5e1;
  --lnc-input-focus-border: #e11d48;
  --lnc-input-focus-ring: rgba(225, 29, 72, 0.15);
  --lnc-input-color: #0f172a;
  --lnc-badge-bg: #ffe4e6;
  --lnc-badge-color: #9f1239;
  --lnc-correct-bg: #dcfce7;
  --lnc-correct-color: #166534;
  --lnc-correct-border: #22c55e;
  --lnc-incorrect-bg: #fee2e2;
  --lnc-incorrect-color: #991b1b;
  --lnc-incorrect-border: #ef4444;
}

/* Dark mode token overrides */
html.dark,
body.dark-mode,
[data-theme="dark"],
.theme-dark {
  --lnc-input-bg: #1e293b;
  --lnc-input-border: #475569;
  --lnc-input-focus-border: #fb7185;
  --lnc-input-focus-ring: rgba(251, 113, 133, 0.25);
  --lnc-input-color: #f1f5f9;
  --lnc-badge-bg: rgba(244, 63, 94, 0.2);
  --lnc-badge-color: #fda4af;
  --lnc-correct-bg: rgba(34, 197, 94, 0.15);
  --lnc-correct-color: #86efac;
  --lnc-correct-border: #22c55e;
  --lnc-incorrect-bg: rgba(239, 68, 68, 0.15);
  --lnc-incorrect-color: #fca5a5;
  --lnc-incorrect-border: #ef4444;
}

/* Enhanced Fill-in-Blank Input */
.fill-in-blank,
.listening-notes-input {
  display: inline-block;
  vertical-align: middle;
  background-color: var(--lnc-input-bg);
  color: var(--lnc-input-color);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.4;
  padding: 4px 10px;
  min-width: 110px;
  max-width: 220px;
  border: 1.5px solid var(--lnc-input-border);
  border-radius: 6px;
  outline: none;
  text-align: left;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  margin: 0 4px;
}

.fill-in-blank:focus,
.listening-notes-input:focus {
  border-color: var(--lnc-input-focus-border);
  box-shadow: 0 0 0 3px var(--lnc-input-focus-ring);
  background-color: #fff;
}

html.dark .fill-in-blank:focus,
body.dark-mode .fill-in-blank:focus,
[data-theme="dark"] .fill-in-blank:focus,
.theme-dark .fill-in-blank:focus {
  background-color: #0f172a;
}

/* Numbered Question Pill within Fill-in-the-Blank Context */
.listening-q-num-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 9999px;
  background-color: var(--lnc-badge-bg);
  color: var(--lnc-badge-color);
  font-size: 0.75rem;
  font-weight: 800;
  margin-right: 6px;
  vertical-align: middle;
  user-select: none;
  flex-shrink: 0;
}

/* Grading State Highlights */
.fill-in-blank.correct-answer-text,
.listening-notes-input.is-correct {
  border-color: var(--lnc-correct-border) !important;
  background-color: var(--lnc-correct-bg) !important;
  color: var(--lnc-correct-color) !important;
  font-weight: 700 !important;
}

.fill-in-blank.incorrect-answer-text,
.listening-notes-input.is-incorrect {
  border-color: var(--lnc-incorrect-border) !important;
  background-color: var(--lnc-incorrect-bg) !important;
  color: var(--lnc-incorrect-color) !important;
  text-decoration: line-through !important;
}

/* Notes List & Container Polish */
.listening-notes-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  margin-bottom: 1.25rem;
  transition: border-color 0.15s ease;
}

html.dark .listening-notes-card,
[data-theme="dark"] .listening-notes-card {
  background: #0f172a;
  border-color: #334155;
  box-shadow: none;
}

.listening-notes-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

html.dark .listening-notes-title,
[data-theme="dark"] .listening-notes-title {
  color: #f1f5f9;
}

.listening-notes-list {
  list-style: none;
  padding: 0;
  margin: 0;
  space-y: 0.875rem;
}

.listening-notes-item {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  line-height: 1.6;
  font-size: 0.9375rem;
  color: #334155;
}

html.dark .listening-notes-item,
[data-theme="dark"] .listening-notes-item {
  color: #cbd5e1;
}

.listening-notes-bullet {
  color: var(--lnc-input-focus-border);
  font-weight: 800;
  font-size: 1.1rem;
  line-height: 1.3;
  user-select: none;
  flex-shrink: 0;
}

/* ==========================================================================
   Table Completion Design System Harmonization
   Applies to .course-table, .notes-table, .sailing-table, and table:has(.fill-in-blank)
   ========================================================================== */

.course-table,
.notes-table,
.sailing-table,
table:has(.fill-in-blank) {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid #e2e8f0;
  background-color: #ffffff;
  font-family: inherit;
  font-size: 0.9rem;
  box-shadow: 0 1px 4px -1px rgba(15, 23, 42, 0.06);
}

.course-table th,
.notes-table th,
.sailing-table th,
table:has(.fill-in-blank) th {
  background: #f8fafc;
  color: #334155;
  font-size: 0.775rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}

.course-table td,
.notes-table td,
.sailing-table td,
table:has(.fill-in-blank) td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  color: #1e293b;
  line-height: 1.55;
}

/* Multi-bullet or notes cell top alignment */
.course-table td:has(ul),
.course-table td:has(.space-y-2),
.course-table td:has(.space-y-3),
.notes-table td:has(ul),
.notes-table td:has(.space-y-2),
.notes-table td:has(.space-y-3),
.sailing-table td:has(.space-y-3),
.sailing-table td:has(.space-y-4) {
  vertical-align: top;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.course-table tr:last-child td,
.notes-table tr:last-child td,
.sailing-table tr:last-child td,
table:has(.fill-in-blank) tr:last-child td {
  border-bottom: none;
}

.course-table tr:nth-child(even),
.notes-table tr:nth-child(even),
.sailing-table tr:nth-child(even),
table:has(.fill-in-blank) tr:nth-child(even) {
  background-color: #fbfcfe;
}

.course-table tr:hover,
.notes-table tr:hover,
.sailing-table tr:hover,
table:has(.fill-in-blank) tr:hover {
  background-color: #f8fafc;
}

/* Question numbers inside table cells */
.course-table strong.text-amber-600,
.notes-table strong.text-amber-600,
.sailing-table strong.text-sky-600,
table:has(.fill-in-blank) .q-item strong:first-child {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 9999px;
  background-color: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
  font-size: 0.75rem;
  font-weight: 800;
  vertical-align: middle;
  margin-right: 5px;
  margin-left: 2px;
  flex-shrink: 0;
  line-height: 1;
}

/* Currency & preposition prefixes inside table cells */
.course-table td .q-item,
.notes-table td .q-item,
.sailing-table td .q-item,
table:has(.fill-in-blank) td .q-item {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

/* Dynamic input width tuning inside tables */
.course-table input.fill-in-blank,
.notes-table input.fill-in-blank,
.sailing-table input.fill-in-blank,
table:has(.fill-in-blank) input.fill-in-blank {
  min-width: 90px;
  max-width: 150px;
  padding: 4px 8px;
  font-size: 0.875rem;
  vertical-align: middle;
}

/* Compact inputs for numbers/currency */
.course-table input.fill-in-blank[placeholder*="number"],
.notes-table input.fill-in-blank[placeholder*="number"],
.sailing-table input.fill-in-blank[placeholder*="number"] {
  max-width: 85px !important;
  min-width: 70px !important;
}

/* ==========================================================================
   Dark Mode Tokens for Table Completion
   ========================================================================== */
html.dark .course-table,
html.dark .notes-table,
html.dark .sailing-table,
html.dark table:has(.fill-in-blank),
[data-theme="dark"] .course-table,
[data-theme="dark"] .notes-table,
[data-theme="dark"] .sailing-table,
[data-theme="dark"] table:has(.fill-in-blank) {
  background-color: #0f172a;
  border-color: #334155;
  box-shadow: none;
}

html.dark .course-table th,
html.dark .notes-table th,
html.dark .sailing-table th,
html.dark table:has(.fill-in-blank) th,
[data-theme="dark"] .course-table th,
[data-theme="dark"] .notes-table th,
[data-theme="dark"] .sailing-table th,
[data-theme="dark"] table:has(.fill-in-blank) th {
  background: #1e293b;
  color: #94a3b8;
  border-bottom-color: #334155;
}

html.dark .course-table td,
html.dark .notes-table td,
html.dark .sailing-table td,
html.dark table:has(.fill-in-blank) td,
[data-theme="dark"] .course-table td,
[data-theme="dark"] .notes-table td,
[data-theme="dark"] .sailing-table td,
[data-theme="dark"] table:has(.fill-in-blank) td {
  border-bottom-color: #1e293b;
  color: #e2e8f0;
}

html.dark .course-table tr:nth-child(even),
html.dark .notes-table tr:nth-child(even),
html.dark .sailing-table tr:nth-child(even),
html.dark table:has(.fill-in-blank) tr:nth-child(even),
[data-theme="dark"] .course-table tr:nth-child(even),
[data-theme="dark"] .notes-table tr:nth-child(even),
[data-theme="dark"] .sailing-table tr:nth-child(even),
[data-theme="dark"] table:has(.fill-in-blank) tr:nth-child(even) {
  background-color: #131d31;
}

html.dark .course-table tr:hover,
html.dark .notes-table tr:hover,
html.dark .sailing-table tr:hover,
html.dark table:has(.fill-in-blank) tr:hover,
[data-theme="dark"] .course-table tr:hover,
[data-theme="dark"] .notes-table tr:hover,
[data-theme="dark"] .sailing-table tr:hover,
[data-theme="dark"] table:has(.fill-in-blank) tr:hover {
  background-color: #1e293b;
}

html.dark .course-table strong.text-amber-600,
html.dark .notes-table strong.text-amber-600,
html.dark .sailing-table strong.text-sky-600,
html.dark table:has(.fill-in-blank) .q-item strong:first-child,
[data-theme="dark"] .course-table strong.text-amber-600,
[data-theme="dark"] .notes-table strong.text-amber-600,
[data-theme="dark"] .sailing-table strong.text-sky-600,
[data-theme="dark"] table:has(.fill-in-blank) .q-item strong:first-child {
  background-color: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.4);
}

/* =============================================================
   Authentic CD-IELTS Notes & Lecture Hierarchy System
   ============================================================= */
.emh-note-item {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  line-height: 1.7;
}

.emh-note-subitem {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  margin-top: 0.35rem;
  margin-bottom: 0.35rem;
  margin-left: 1.5rem;
  line-height: 1.7;
}

@media (max-width: 640px) {
  .emh-note-subitem {
    margin-left: 1rem;
  }
}

.emh-note-bullet {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background-color: #64748b;
  margin-top: 0.55rem;
  flex-shrink: 0;
  transition: background-color 0.2s ease;
}

.emh-note-dash {
  display: inline-block;
  color: #94a3b8;
  font-weight: 700;
  font-size: 0.875rem;
  line-height: 1.4;
  flex-shrink: 0;
  user-select: none;
}

.emh-note-text {
  flex: 1;
  min-width: 0;
  color: inherit;
  word-break: break-word;
}

/* Guard against question badge + input blank splitting across lines */
span[id^="container-q"]:has(.fill-in-blank),
.inline-flex:has(.fill-in-blank) {
  display: inline-flex !important;
  align-items: center !important;
  vertical-align: middle !important;
  white-space: nowrap !important;
  gap: 0.25rem !important;
}

/* Dark mode note bullets */
html.dark .emh-note-bullet,
[data-theme="dark"] .emh-note-bullet {
  background-color: #94a3b8;
}

html.dark .emh-note-dash,
[data-theme="dark"] .emh-note-dash {
  color: #64748b;
}

