/* writing-review.css
   Writing Review teacher dashboard styles for LingoLugo (Switchboard).
   All selectors are prefixed with .wr- to avoid collisions with global.css.
   Uses CSS variables with fallbacks matching the LingoLugo purple theme (#6564b6).
*/

/* ── CSS Variables ─────────────────────────────────────────────────────────── */

:root {
  --wr-accent:       var(--theme-accent-2, #6564b6);
  --wr-accent-dark:  #534f9a;
  --wr-accent-light: var(--theme-color-1, #b0c2ff);
  --wr-success:      #22c55e;
  --wr-success-dark: #16a34a;
  --wr-warning:      #f59e0b;
  --wr-error:        #ef4444;
  --wr-blue:         #3b82f6;
  --wr-blue-dark:    #2563eb;

  --wr-bg:           #fafbff;
  --wr-surface:      #ffffff;
  --wr-border:       #d8d9eb;
  --wr-border-light: #e5e7eb;
  --wr-text:         #1a1a2e;
  --wr-text-muted:   #6b7280;
  --wr-text-light:   #9ca3af;

  --wr-radius-sm:    6px;
  --wr-radius-md:    10px;
  --wr-radius-lg:    16px;

  --wr-shadow-sm:    0 1px 3px rgba(0,0,0,0.08);
  --wr-shadow-md:    0 4px 12px rgba(0,0,0,0.12);
  --wr-shadow-lg:    0 8px 24px rgba(0,0,0,0.16);

  --wr-transition:   0.18s ease;
}

/* ── Page baseline ─────────────────────────────────────────────────────────── */

.wr-main {
  min-height: 80vh;
  padding: 1.5rem 1.25rem 3rem;
  background: var(--wr-bg);
  font-family: 'Lexend Deca', system-ui, sans-serif;
  color: var(--wr-text);
  max-width: 1400px;
  margin: 0 auto;
}

.wr-main [hidden] {
  display: none !important;
}

/* ── Loading spinner ───────────────────────────────────────────────────────── */

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--wr-border);
  border-top-color: var(--wr-accent);
  border-radius: 50%;
  animation: wr-spin 0.8s linear infinite;
  margin: 4rem auto;
}

@keyframes wr-spin {
  to { transform: rotate(360deg); }
}

/* ── Auth message boxes ────────────────────────────────────────────────────── */

.wr-msg {
  max-width: 32rem;
  margin: 4rem auto;
  padding: 2rem 1.5rem;
  background: var(--wr-surface);
  border: 1px solid var(--wr-border);
  border-radius: var(--wr-radius-lg);
  text-align: center;
  box-shadow: var(--wr-shadow-sm);
}

.wr-msg h2 {
  margin-top: 0;
  color: var(--wr-accent);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */

.wr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--wr-radius-md);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--wr-transition);
  text-decoration: none;
}

.wr-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.wr-btn-primary {
  background: var(--wr-accent);
  color: #fff;
}
.wr-btn-primary:hover:not(:disabled) {
  background: var(--wr-accent-dark);
  transform: translateY(-1px);
  box-shadow: var(--wr-shadow-md);
}

.wr-btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.wr-btn-warning {
  background: var(--wr-warning);
  color: #fff;
}
.wr-btn-warning:hover:not(:disabled) {
  background: #d97706;
  transform: translateY(-1px);
}

/* ── Review lock banner ────────────────────────────────────────────────────── */

.wr-lock-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #fef3c7;
  border: 1px solid #fbbf24;
  border-radius: var(--wr-radius-md);
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  color: #92400e;
  margin-bottom: 0.75rem;
}

.wr-lock-banner span {
  flex: 1;
}

/* ── Header controls (filters row) ────────────────────────────────────────── */

.wr-header-controls {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--wr-border);
}

.wr-header-top h1 {
  margin: 0 0 0.75rem;
  font-size: 1.5rem;
  color: var(--wr-accent);
}

.wr-filters-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.wr-filter-group {
  display: flex;
  align-items: center;
  min-width: 0;
}

.wr-filter-group-question { flex: 0 0 22%; }
.wr-filter-group-status   { flex: 0 0 16%; }
.wr-filter-group-student  { flex: 1 1 0; }

.wr-filter-group select {
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--wr-border);
  border-radius: var(--wr-radius-md);
  background: var(--wr-surface);
  color: var(--wr-text);
  font-family: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  outline: none;
  height: 38px;
  transition: border-color var(--wr-transition);
}

.wr-filter-group select:hover,
.wr-filter-group select:focus {
  border-color: var(--wr-accent);
  box-shadow: 0 0 0 2px rgba(101, 100, 182, 0.12);
}

/* ── "Still being corrected" live indicator ───────────────────────────────── */
.wr-inflight {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.88rem;
  color: var(--wr-accent);
}

.wr-inflight[hidden] {
  display: none;
}

.wr-inflight-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--wr-accent);
  animation: wr-inflight-pulse 1.2s ease-in-out infinite;
}

@keyframes wr-inflight-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.35; transform: scale(0.7); }
}

@media (prefers-reduced-motion: reduce) {
  .wr-inflight-dot { animation: none; }
}

/* ── Charts accordion (admin only) ────────────────────────────────────────── */

.wr-charts-accordion {
  margin-top: 0.75rem;
  background: var(--wr-surface);
  border-radius: var(--wr-radius-lg);
  border: 2px solid var(--wr-accent-light);
  box-shadow: var(--wr-shadow-sm);
}

.wr-charts-accordion .wr-accordion-item {
  border: none;
  background: transparent;
}

.wr-charts-accordion .accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  cursor: pointer;
  background: transparent;
  font-weight: 600;
  color: var(--wr-accent);
  transition: background var(--wr-transition);
}

.wr-charts-accordion .accordion-header:hover {
  background: rgba(101,100,182,0.06);
}

.wr-charts-accordion .accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.wr-charts-accordion .wr-accordion-item.active .accordion-content {
  max-height: 900px;
}

.wr-charts-container {
  padding: 1rem;
  max-height: 700px;
  overflow-y: auto;
}

.wr-charts-loading {
  text-align: center;
  color: var(--wr-text-muted);
  padding: 1rem;
}

/* Chart bar rows */
.wr-exam-groups-wrapper {
  display: flex;
  gap: 1.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.wr-exam-group {
  min-width: 280px;
  flex-shrink: 0;
}

.wr-exam-group-label {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--wr-text);
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--wr-accent-light);
}

.wr-chart-bar-row {
  display: flex;
  align-items: center;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
}

.wr-chart-bar-label {
  width: 80px;
  font-size: 0.78rem;
  color: var(--wr-text-muted);
  text-align: right;
  flex-shrink: 0;
}

.wr-chart-bar-container {
  flex: 1;
  height: 26px;
  background: #f3f4f6;
  border-radius: var(--wr-radius-sm);
  display: flex;
  overflow: hidden;
  min-width: 160px;
}

.wr-chart-segment {
  height: 100%;
  cursor: pointer;
  transition: opacity 0.18s, filter 0.18s;
  position: relative;
  border-right: 1px solid rgba(255,255,255,0.3);
}

.wr-chart-segment:last-child { border-right: none; }

.wr-chart-segment:hover {
  opacity: 0.85;
  filter: brightness(1.1);
}

.wr-chart-segment.wr-uncorrected {
  background-color: #d1d5db !important;
  cursor: default;
}

/* Chart popover */
.wr-chart-popover {
  position: fixed;
  background: var(--wr-surface);
  border: 1px solid var(--wr-border);
  border-radius: var(--wr-radius-md);
  padding: 0.75rem;
  box-shadow: var(--wr-shadow-lg);
  z-index: 1200;
  min-width: 200px;
  font-size: 0.84rem;
}

.wr-popover-title {
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--wr-text);
  border-bottom: 1px solid var(--wr-border);
  padding-bottom: 0.4rem;
}

.wr-popover-link {
  color: var(--wr-blue);
  text-decoration: none;
  cursor: pointer;
}
.wr-popover-link:hover { text-decoration: underline; }

.wr-popover-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.2rem;
  color: var(--wr-text-muted);
}
.wr-popover-row span:last-child {
  font-weight: 500;
  color: var(--wr-text);
}

/* ── Feedback container ────────────────────────────────────────────────────── */

.wr-feedback-container {
  background: var(--wr-surface);
  border-radius: var(--wr-radius-lg);
  box-shadow: var(--wr-shadow-sm);
  padding: 1.5rem;
  position: relative;
}

/* ── Navigation bar ────────────────────────────────────────────────────────── */

.wr-navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--wr-border);
  position: sticky;
  top: 0;
  background: var(--wr-surface);
  z-index: 100;
  border-radius: var(--wr-radius-lg);
  box-shadow: var(--wr-shadow-sm);
}

.wr-navigation.stuck {
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

.wr-sections-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  overflow-x: auto;
  padding: 0.15rem 0;
  scrollbar-width: thin;
}

.wr-section-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.4rem 0.6rem;
  background: transparent;
  border: none;
  border-radius: var(--wr-radius-md);
  cursor: pointer;
  transition: all var(--wr-transition);
  white-space: nowrap;
  min-width: fit-content;
  font-family: inherit;
}

.wr-section-btn:hover {
  background: rgba(101,100,182,0.1);
}

.wr-section-btn.active {
  background: rgba(101,100,182,0.14);
}

.wr-section-name {
  font-size: 0.73rem;
  color: var(--wr-text-muted);
  font-weight: 500;
  transition: all var(--wr-transition);
  text-align: center;
  max-width: 110px;
  white-space: normal;
  line-height: 1.2;
}

.wr-section-btn.active .wr-section-name {
  color: var(--wr-accent);
  font-weight: 700;
}

.wr-section-score-container {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.wr-section-score,
.wr-section-total-score {
  font-size: 0.84rem;
  color: var(--wr-text-muted);
  font-weight: 600;
  min-width: 1.4rem;
  text-align: center;
  transition: all var(--wr-transition);
}

.wr-section-btn.active .wr-section-score,
.wr-section-btn.active .wr-section-total-score {
  color: var(--wr-accent);
  font-weight: 700;
}

/* Score adjust ± buttons */
.wr-score-adjust-btn {
  width: 17px;
  height: 17px;
  padding: 0;
  border: 1px solid var(--wr-border);
  background: var(--wr-bg);
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: bold;
  line-height: 1;
  color: var(--wr-text-muted);
  transition: all var(--wr-transition);
  display: none;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.wr-section-btn:hover .wr-score-adjust-btn,
.wr-section-btn.active .wr-score-adjust-btn {
  display: flex;
}

.wr-score-adjust-btn:hover {
  background: var(--wr-accent);
  color: #fff;
  border-color: var(--wr-accent);
}

/* Student/exam info centre */
.wr-student-exam-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 0.75rem;
  min-width: 120px;
}

.wr-student-name {
  font-size: 0.82rem;
  color: var(--wr-text-muted);
  font-weight: 500;
}

.wr-exam-name {
  font-size: 0.78rem;
  color: var(--wr-text-light);
}

/* Prev/Next buttons */
.wr-nav-buttons-group {
  display: flex;
  gap: 0.4rem;
}

.wr-nav-button {
  background: var(--wr-accent);
  color: #fff;
  border: none;
  border-radius: var(--wr-radius-md);
  padding: 0.45rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  font-size: 0.88rem;
  transition: all var(--wr-transition);
}

.wr-nav-button:hover:not(:disabled) {
  background: var(--wr-accent-dark);
  transform: translateY(-2px);
  box-shadow: var(--wr-shadow-md);
}

.wr-nav-button:active:not(:disabled) { transform: translateY(0); }

.wr-nav-button:disabled {
  background: #d1d5db;
  cursor: not-allowed;
  opacity: 0.65;
}

/* ── Essay accordions ──────────────────────────────────────────────────────── */

.wr-essay-accordion {
  margin-bottom: 1rem;
  background: var(--wr-surface);
  border-radius: var(--wr-radius-lg);
  border: 2px solid var(--wr-accent-light);
  padding: 0.4rem;
  box-shadow: var(--wr-shadow-sm);
  transition: box-shadow var(--wr-transition);
}

.wr-essay-accordion:hover { box-shadow: var(--wr-shadow-md); }

.accordion-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

/* Accordion items use a wr-prefixed class so global.css generic `.accordion-item`
   selectors (which leak padding + grey backgrounds into every nested div) don't
   match. Anything that previously relied on the unprefixed class lives here. */
.wr-accordion-item {
  border: 1px solid var(--wr-border-light);
  border-radius: var(--wr-radius-sm);
  overflow: hidden;
  margin: 0;
}

.accordion-header {
  background: #f0f4ff;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--wr-accent);
  transition: background var(--wr-transition);
  user-select: none;
}

.accordion-header:hover { background: #e0e8ff; }

.accordion-icon {
  font-size: 1.1rem;
  font-weight: bold;
  transition: transform var(--wr-transition);
}

.wr-accordion-item .accordion-content {
  padding: 0;
  max-height: 0;
  overflow: hidden;
  box-sizing: border-box;
  transition: none;
}

.wr-accordion-item.active .accordion-content {
  padding: 0.75rem;
  max-height: 1500px;
}

.wr-accordion-text {
  background: #f9fafb;
  padding: 0.75rem;
  border-radius: var(--wr-radius-sm);
  border: 1px solid var(--wr-border-light);
  white-space: pre-wrap;
  line-height: 1.65;
  max-height: 320px;
  overflow-y: auto;
  font-size: 0.92rem;
}

.wr-formatted-html { white-space: normal; }
.wr-formatted-html b,
.wr-formatted-html strong {
  font-weight: bold;
  color: #1d4ed8;
}

/* Cambridge handbook iframe */
.wr-handbook-container { position: relative; width: 100%; min-height: 100px; }

.wr-handbook-iframe {
  width: 100%;
  height: 820px;
  border: none;
  display: block;
}

.wr-pdf-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--wr-text-muted);
}

.wr-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--wr-border);
  border-top-color: var(--wr-accent);
  border-radius: 50%;
  animation: wr-spin 0.9s linear infinite;
  margin-bottom: 0.5rem;
}

.wr-handbook-na {
  padding: 2rem;
  text-align: center;
  color: var(--wr-text-muted);
  font-style: italic;
}

/* ── Examples ──────────────────────────────────────────────────────────────── */

.wr-examples-container { width: 100%; }

.wr-examples-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--wr-border);
}

.wr-example-nav-btn {
  padding: 0.35rem 0.9rem;
  background: var(--wr-accent);
  color: #fff;
  border: none;
  border-radius: var(--wr-radius-md);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
  transition: all var(--wr-transition);
}

.wr-example-nav-btn:hover:not(:disabled) {
  background: var(--wr-accent-dark);
}

.wr-example-nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--wr-text-muted);
}

.wr-example-counter {
  font-weight: 600;
  color: var(--wr-text);
  min-width: 56px;
  text-align: center;
  font-size: 0.88rem;
}

.wr-example-loading,
.wr-example-na {
  padding: 1.5rem;
  text-align: center;
  color: var(--wr-text-muted);
  font-size: 0.88rem;
}

.wr-example-layout {
  display: flex;
  gap: 1.25rem;
  width: 100%;
}

.wr-example-left {
  flex: 1;
  min-width: 0;
}

.wr-example-right {
  flex: 0 0 320px;
  min-width: 0;
}

.wr-example-section,
.wr-example-score,
.wr-example-comments {
  margin-bottom: 1.25rem;
}

.wr-example-section h4,
.wr-example-score h4,
.wr-example-comments h4 {
  color: var(--wr-text);
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.wr-example-text {
  padding: 0.9rem 1rem;
  background: #fff;
  border-radius: var(--wr-radius-md);
  border: 1px solid var(--wr-border);
  box-shadow: var(--wr-shadow-sm);
  line-height: 1.65;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

#example-score-value {
  color: var(--wr-accent);
  font-weight: 700;
  font-size: 1.1rem;
}

.wr-example-source-text {
  font-size: 0.82rem;
  color: var(--wr-text-muted);
  margin: 0;
  font-style: italic;
}

/* ── Main content display ──────────────────────────────────────────────────── */

.wr-content-display {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Advice + Script container ─────────────────────────────────────────────── */

.wr-advice-script-container {
  width: 100%;
  margin-top: 0.75rem;
}

.wr-student-sees-label {
  font-size: 0.84rem;
  color: var(--wr-text-light);
  margin: 0 0 0.4rem;
}

.wr-advice-script-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 0.75rem;
  align-items: stretch;
}

.wr-advice-wrapper,
.wr-script-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.wr-script-label {
  font-size: 0.84rem;
  color: var(--wr-text-light);
  margin: 0 0 0.4rem;
}

/* Advice area */
.wr-advice-area {
  background: var(--wr-surface);
  border-radius: var(--wr-radius-lg);
  border: 2px solid var(--wr-success);
  padding: 0.75rem;
  line-height: 1.75;
  box-sizing: border-box;
  min-height: 120px;
  flex: 1;
  transition: box-shadow var(--wr-transition);
  box-shadow: var(--wr-shadow-sm);
  outline: none;
}

.wr-advice-area:hover,
.wr-advice-area:focus { box-shadow: var(--wr-shadow-md); }

/* Script area */
.wr-script-area {
  background: var(--wr-surface);
  border-radius: var(--wr-radius-lg);
  border: 2px solid var(--wr-accent);
  padding: 0.75rem;
  line-height: 1.75;
  box-sizing: border-box;
  transition: box-shadow var(--wr-transition);
  box-shadow: var(--wr-shadow-sm);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.wr-script-area:hover { box-shadow: var(--wr-shadow-md); }

.wr-editable-content {
  position: relative;
  outline: none;
  min-height: 50px;
  flex: 1;
  transition: background-color var(--wr-transition);
}

.wr-editable-content:hover { background: rgba(255,255,255,0.9); }
.wr-editable-content:focus { background: #fff; box-shadow: inset 0 0 0 2px rgba(101,100,182,0.3); }

/* ── Audio recorder ────────────────────────────────────────────────────────── */

.wr-audio-recorder {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(101,100,182,0.15);
}

.wr-audio-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.wr-audio-media-slot {
  flex: 1 1 0%;
  min-width: 100px;
  min-height: 32px;
  display: flex;
  align-items: center;
}

.wr-audio-button {
  border: none;
  border-radius: 999px;
  background: var(--wr-accent);
  color: #fff;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  box-shadow: 0 4px 12px rgba(101,100,182,0.22);
}

.wr-audio-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(101,100,182,0.28);
}

.wr-audio-button:active:not(:disabled),
.wr-audio-button.recording {
  transform: translateY(0);
  background: #dc2626;
  box-shadow: 0 8px 20px rgba(220,38,38,0.24);
}

.wr-audio-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.wr-audio-status {
  margin: 0;
  font-size: 0.77rem;
  line-height: 1.4;
  color: var(--wr-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.wr-audio-meter {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: rgba(101,100,182,0.12);
  overflow: hidden;
  border: 1px solid rgba(101,100,182,0.14);
}

.wr-audio-meter[hidden] { display: none; }

.wr-audio-meter-fill {
  height: 100%;
  width: 6%;
  min-width: 8px;
  border-radius: inherit;
  background: linear-gradient(90deg, #a855f7, #ec4899);
  transition: width 0.08s linear;
}

.wr-audio-recorder.recording .wr-audio-meter-fill {
  background: linear-gradient(90deg, #ef4444, #f97316);
}

.wr-audio-playback {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}

.wr-audio-playback[hidden] { display: none; }

.wr-audio-playback audio {
  flex: 1;
  min-width: 0;
  height: 30px;
}

.wr-audio-delete {
  border: none;
  border-radius: 5px;
  background: transparent;
  color: #dc2626;
  padding: 0.3rem;
  cursor: pointer;
  transition: background var(--wr-transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.wr-audio-delete:hover:not(:disabled) { background: rgba(220,38,38,0.1); }
.wr-audio-delete:disabled { cursor: wait; opacity: 0.6; }

/* ── Highlights area ───────────────────────────────────────────────────────── */

.wr-highlights-area {
  background: var(--wr-surface);
  border-radius: var(--wr-radius-lg);
  border: 2px solid var(--wr-accent-light);
  padding: 1.25rem;
  width: 100%;
  min-height: 200px;
  box-sizing: border-box;
  line-height: 1.8;
  white-space: pre-wrap;
  transition: box-shadow var(--wr-transition);
  box-shadow: var(--wr-shadow-sm);
  outline: none;
}

.wr-highlights-area:hover { box-shadow: var(--wr-shadow-md); }

/* Highlight spans created by feedback-editor.js. The .wr-hl-active class is
   applied by the JS co-hover handler to ALL spans sharing an id (so two
   `mistake2` spans light up together), and is the same visual state used for
   hover on a single span. */
span[id^="tip"] {
  background: rgba(34,197,94,0.28);
  border-radius: 3px;
  cursor: pointer;
  transition: background var(--wr-transition);
}

span[id^="tip"]:hover,
span[id^="tip"].wr-hl-active { background: rgba(34,197,94,0.55); }

span[id^="mistake"] {
  background: rgba(239,68,68,0.22);
  border-radius: 3px;
  cursor: pointer;
  transition: background var(--wr-transition);
}

span[id^="mistake"]:hover,
span[id^="mistake"].wr-hl-active { background: rgba(239,68,68,0.5); }

/* (Drag-handle styling lives further down with the wr- prefixed
   selectors that match the JS — see "Highlight resize handles" block.) */

/* Editable content (highlights is contenteditable) */
.wr-highlights-area [contenteditable]:hover { background: rgba(255,255,255,0.9); }
.wr-highlights-area [contenteditable]:focus { box-shadow: inset 0 0 0 2px rgba(101,100,182,0.35); }

/* Tippy custom theme for editable highlights */
.tippy-box[data-theme~='edit'] {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

.tippy-box[data-theme~='edit'] .tippy-content { padding: 0; }
.tippy-box[data-theme~='edit'] .tippy-arrow { display: none; }

.tippy-edit-input,
.wr-tippy-input {
  min-width: 340px;
  max-width: 480px;
  padding: 9px 13px;
  border: 2px solid #d1d5db;
  border-radius: var(--wr-radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  box-sizing: border-box;
  background: #fff;
  color: #111827;
  transition: all 0.15s ease;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  resize: vertical;
  overflow-y: hidden;
}

.tippy-edit-input,
.wr-tippy-input:hover { border-color: #9ca3af; }
.tippy-edit-input,
.wr-tippy-input:focus {
  border-color: var(--wr-accent);
  box-shadow: 0 0 0 3px rgba(101,100,182,0.14), 0 4px 6px -1px rgba(0,0,0,0.1);
}
.tippy-edit-input,
.wr-tippy-input::placeholder { color: #9ca3af; }

/* Subtle span highlight on input hover */
.input-span-highlight {
  outline: 2px solid var(--wr-warning);
  outline-offset: 1px;
  box-shadow: 0 2px 6px rgba(245,158,11,0.35);
  transition: outline 0.12s, box-shadow 0.12s;
}

/* ── Tags editor (tag-picker.js) ────────────────────────────────────────────── */

.wr-tags-editor {
  background: var(--wr-surface);
  border: 1px solid var(--wr-border);
  border-radius: var(--wr-radius-md);
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.wr-tags-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.wr-tags-header h3 {
  margin: 0;
  font-size: 0.92rem;
  color: var(--wr-text);
}

.wr-tags-retag-btn {
  font-size: 0.78rem;
  font-family: inherit;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--wr-accent);
  border-radius: var(--wr-radius-sm);
  background: transparent;
  color: var(--wr-accent);
  cursor: pointer;
  transition: all var(--wr-transition);
  font-weight: 600;
}

.wr-tags-retag-btn:hover:not(:disabled) {
  background: var(--wr-accent);
  color: #fff;
}
.wr-tags-retag-btn:disabled { opacity: 0.6; cursor: wait; }

.wr-tags-row {
  display: flex;
  gap: 1rem;
}

.wr-tags-group {
  flex: 1;
  min-width: 0;
}

.wr-tags-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.wr-tags-label--negative { color: #b91c1c; }
.wr-tags-label--positive { color: #15803d; }

.wr-tags-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
  min-height: 22px;
}

.wr-tags-empty {
  font-size: 0.8rem;
  color: var(--wr-text-light);
  font-style: italic;
}

.wr-tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
}

.wr-tag-pill--negative { background: rgba(239,68,68,0.1); color: #b91c1c; }
.wr-tag-pill--positive { background: rgba(34,197,94,0.1); color: #15803d; }

.wr-tag-remove {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.88rem;
  line-height: 1;
  padding: 0;
  color: inherit;
  opacity: 0.65;
  transition: opacity var(--wr-transition);
}
.wr-tag-remove:hover { opacity: 1; }

.wr-tags-add-wrapper { position: relative; }

.wr-tags-search {
  width: 100%;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--wr-border);
  border-radius: var(--wr-radius-sm);
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--wr-transition);
  box-sizing: border-box;
}

.wr-tags-search:focus { border-color: var(--wr-accent); }

.wr-tags-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--wr-surface);
  border: 1px solid var(--wr-border);
  border-radius: var(--wr-radius-sm);
  box-shadow: var(--wr-shadow-md);
  max-height: 200px;
  overflow-y: auto;
  z-index: 300;
  display: none;
}

.wr-tags-dropdown-item {
  padding: 0.4rem 0.65rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background var(--wr-transition);
}

.wr-tags-dropdown-item:hover,
.wr-tags-dropdown-item--active { background: rgba(101,100,182,0.1); }

.wr-tags-dropdown-empty {
  color: var(--wr-text-muted);
  font-style: italic;
  cursor: default;
}

/* ── Summary section ───────────────────────────────────────────────────────── */

.wr-summary-area {
  background: var(--wr-surface);
  border-radius: var(--wr-radius-lg);
  border: 2px solid var(--wr-accent);
  padding: 1.5rem;
  width: 100%;
  box-sizing: border-box;
  line-height: 1.75;
  transition: box-shadow var(--wr-transition);
  box-shadow: var(--wr-shadow-sm);
}

.wr-summary-area:hover { box-shadow: var(--wr-shadow-md); }

.wr-summary-area h2 {
  color: var(--wr-text);
  margin-top: 0;
  margin-bottom: 1.25rem;
  font-size: 1.5rem;
  text-align: center;
  border-bottom: 2px solid var(--wr-border);
  padding-bottom: 0.6rem;
}

.wr-summary-area h3 {
  color: var(--wr-text);
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--wr-border-light);
  padding-bottom: 0.4rem;
}

/* Action buttons row */
.wr-summary-actions {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.wr-reprocess-button {
  flex: 1;
  background: #d1d5db;
  color: #6b7280;
  border: none;
  border-radius: var(--wr-radius-md);
  padding: 0.85rem 1.25rem;
  font-size: 1.1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: not-allowed;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.wr-reviewed-button {
  flex: 1;
  background: var(--wr-success);
  color: #fff;
  border: none;
  border-radius: var(--wr-radius-md);
  padding: 0.85rem 1.25rem;
  font-size: 1.1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--wr-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  box-shadow: var(--wr-shadow-md);
}

.wr-reviewed-button:hover:not(:disabled) {
  background: var(--wr-success-dark);
  transform: translateY(-2px);
  box-shadow: var(--wr-shadow-lg);
}

.wr-reviewed-button:active:not(:disabled) { transform: translateY(0); }

.wr-reviewed-button:disabled {
  background: #d1d5db;
  cursor: not-allowed;
  transform: none;
}

.wr-button-icon { font-size: 1.1em; }

/* Corrector editor */
.wr-corrector-editor {
  margin-bottom: 1rem;
}

.wr-corrector-input {
  width: 100%;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--wr-border);
  border-radius: var(--wr-radius-md);
  font-family: inherit;
  font-size: 1rem;
  transition: all var(--wr-transition);
  box-sizing: border-box;
  background: var(--wr-surface);
  color: var(--wr-text);
}

.wr-corrector-input:focus {
  outline: none;
  border-color: var(--wr-accent);
  box-shadow: 0 0 0 2px rgba(101,100,182,0.12);
}

/* Scores grid in summary */
.wr-summary-scores { margin-bottom: 1rem; }

.wr-scores-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.wr-score-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: #f9fafb;
  padding: 0.6rem;
  border-radius: var(--wr-radius-md);
  border: 1px solid var(--wr-border);
}

.wr-score-label {
  font-weight: 600;
  color: var(--wr-text-muted);
  font-size: 0.82rem;
}

.wr-score-input {
  padding: 0.35rem;
  border: 1px solid var(--wr-border);
  border-radius: var(--wr-radius-sm);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  transition: all var(--wr-transition);
  background: var(--wr-surface);
  width: 100%;
  box-sizing: border-box;
}

.wr-score-input:hover  { border-color: var(--wr-accent); }
.wr-score-input:focus  {
  outline: none;
  border-color: var(--wr-accent);
  box-shadow: 0 0 0 2px rgba(101,100,182,0.12);
}
.wr-score-input:invalid { border-color: var(--wr-error); }

/* Details accordion (read-only metadata) */
.wr-accordion-container { margin: 1rem 0; }

.wr-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.wr-detail-field {
  display: flex;
  gap: 0.4rem;
  align-items: baseline;
  background: #f9fafb;
  padding: 0.4rem 0.65rem;
  border-radius: var(--wr-radius-sm);
  border: 1px solid var(--wr-border-light);
  font-size: 0.85rem;
  word-break: break-all;
}

.wr-detail-label {
  font-weight: 600;
  color: var(--wr-text-muted);
  font-size: 0.78rem;
  flex-shrink: 0;
  white-space: nowrap;
}

.wr-detail-value {
  color: var(--wr-text);
  font-size: 0.84rem;
  flex: 1;
}

/* ── Toastify tweaks ───────────────────────────────────────────────────────── */

.toastify {
  padding: 0.5rem 1rem !important;
  font-size: 0.84rem !important;
  min-height: auto !important;
  border-radius: 7px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.14) !important;
}

.toastify-close {
  opacity: 0.6 !important;
  font-size: 1rem !important;
}

.toastify-close:hover { opacity: 1 !important; }

/* Only override `right` — Toastify writes the inline `bottom: <calculated>px`
 * on each toast to stack them vertically, and `!important` on `bottom` here
 * would force every toast to the same spot and overlap. */
.toastify-right {
  right: 1rem !important;
}

/* ── Mobile responsive ─────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .wr-advice-script-grid {
    grid-template-columns: 1fr;
  }

  .wr-example-layout {
    flex-direction: column;
  }

  .wr-example-right {
    flex: 1 1 auto;
  }

  .wr-scores-fields {
    grid-template-columns: 1fr;
  }

  .wr-details-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .wr-main { padding: 0.75rem 0.75rem 2rem; }

  .wr-filters-row {
    flex-direction: column;
    gap: 0.5rem;
  }

  .wr-filter-group-question,
  .wr-filter-group-status,
  .wr-filter-group-student {
    flex: 1 1 100%;
  }

  .wr-navigation {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
  }

  .wr-student-exam-info { display: none; }

  .wr-summary-actions { flex-direction: column; }

  .wr-tags-row { flex-direction: column; }

  .wr-handbook-iframe { height: 500px; }

  .wr-highlights-area,
  .wr-advice-area {
    padding: 0.75rem;
  }

  .wr-feedback-container { padding: 0.75rem; }
}

/* ── Accessibility — focus ring ────────────────────────────────────────────── */

.wr-section-btn:focus-visible,
.wr-nav-button:focus-visible,
.wr-btn:focus-visible,
.wr-audio-button:focus-visible,
.wr-example-nav-btn:focus-visible,
.wr-reviewed-button:focus-visible {
  outline: 2px solid var(--wr-accent);
  outline-offset: 2px;
}

/* ── Selection popup (create new tip/mistake span) ─────────────────────
   Floating popup that appears above selected text in #highlights-content,
   offering Tip 1-5 and Mistake 1-10 buttons. Click one to wrap the
   selection in a new span. Mirrors the Teachers' Panel `.selection-tip-buttons`
   styling. */
.wr-selection-popup {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  padding: 0.55rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 1000;
}

.wr-tip-buttons-row,
.wr-mistake-buttons-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.wr-tip-buttons-row {
  padding-bottom: 0.5rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.wr-sel-btn {
  border: none;
  border-radius: 4px;
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
  color: #fff;
  cursor: pointer;
  transition: background-color 120ms ease, opacity 120ms ease;
}

.wr-sel-btn--tip {
  background-color: #3366cc;
}
.wr-sel-btn--tip:hover {
  background-color: #254a99;
}
.wr-sel-btn--tip.used {
  background-color: #7799cc;
  opacity: 0.55;
}

.wr-sel-btn--mistake {
  background-color: #cc3333;
}
.wr-sel-btn--mistake:hover {
  background-color: #992525;
}
.wr-sel-btn--mistake.used {
  background-color: #cc7777;
  opacity: 0.55;
}

.wr-sel-btn--close {
  align-self: flex-end;
  background-color: #888;
  padding: 0.15rem 0.45rem;
  margin-top: 0.2rem;
  font-weight: 600;
}
.wr-sel-btn--close:hover {
  background-color: #555;
}

/* ── Empty state ───────────────────────────────────────────────────────
   Muted-italic placeholder shown when no submission is loaded.
   Cleared automatically when displaySection() writes real content. */
.wr-empty-state,
p.wr-empty-state {
  color: rgba(0, 0, 0, 0.45);
  font-style: italic;
  font-size: 0.95rem;
  margin: 0.5rem 0;
}

/* ── Desktop-only gate ─────────────────────────────────────────────────
   Writing Review is a desktop-only feature. On mobile (≤768px) we hide
   the entire review UI and show a yellow notice instead. Pattern mirrors
   the existing teacher-progress.html desktop-only block. */
.wr-desktop-only-notice {
  display: none;
  background-color: #fff3cd;
  border-left: 4px solid #ffc107;
  padding: 1rem;
  margin: 2rem 1rem;
  border-radius: 0 5px 5px 0;
  color: #856404;
}
.wr-desktop-only-notice strong {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
}
.wr-desktop-only-notice p {
  margin: 0;
  line-height: 1.45;
}

@media (max-width: 768px) {
  .wr-desktop-only-content { display: none !important; }
  .wr-desktop-only-notice { display: block; }
}

/* ── Highlight resize handles ─────────────────────────────────────────
   Orange bars that appear on either side of a tip/mistake span when
   hovered. Dragging extends or contracts the span character-by-character.
   Ported from teachers-view.css `.highlight-handle`. */
.wr-highlight-handle {
  position: fixed;
  width: 16px;
  cursor: col-resize;
  display: none;
  z-index: 1000;
  pointer-events: auto;
}

.wr-highlight-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 18px;
  border-radius: 3px;
  background: var(--theme-accent-2, #6564b6);
  box-shadow: 0 1px 2px rgba(101, 100, 182, 0.25);
  transition: width 140ms ease, height 140ms ease, box-shadow 140ms ease;
}

.wr-highlight-handle-left::after { right: 3px; }
.wr-highlight-handle-right::after { left: 3px; }

/* On hover the bar grows and gets a stronger drop shadow so the teacher
   sees clearly which side they're about to grab. Colour stays purple. */
.wr-highlight-handle:hover::after {
  width: 7px;
  height: 26px;
  box-shadow: 0 4px 10px rgba(101, 100, 182, 0.55);
}

/* The span itself gets a faint theme tint while it's being resized */
span[id^="tip"].wr-resizing,
span[id^="mistake"].wr-resizing {
  background-color: rgba(178, 154, 250, 0.45);
}

/* Hide the cursor while dragging so it doesn't fight the col-resize feel */
body.wr-dragging-handle,
body.wr-dragging-handle * {
  cursor: col-resize !important;
  user-select: none !important;
}
