/**
 * components.css - Reusable UI components, buttons, cards, modals, and toolbars
 */

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  font-size: 0.95rem;
  transition: all 0.15s ease;
  user-select: none;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background-color: var(--primary);
  color: var(--text-inverse);
  font-weight: 600;
  padding: 0.75rem 1.4rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary-sm {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
}

.btn-primary-sm:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  font-weight: 600;
  padding: 0.75rem 1.4rem;
  border-radius: var(--radius-md);
}

.btn-secondary:hover {
  background-color: var(--bg-surface-subtle);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-secondary-sm {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-secondary-sm:hover {
  background-color: var(--bg-surface-subtle);
  border-color: var(--primary);
}

.btn-icon-tiny {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background-color: var(--bg-surface-subtle);
}

.btn-icon-tiny:hover {
  color: var(--text-primary);
  background-color: var(--border-subtle);
}

.btn-tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background-color: var(--bg-surface-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-full);
}

.btn-tool-pill:hover {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-text);
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
}

.btn-back:hover {
  color: var(--primary);
  background-color: var(--bg-surface-subtle);
}

.btn-text-danger {
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.btn-text-danger:hover {
  text-decoration: underline;
}

/* Badges & Tags */
.subject-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background-color: var(--bg-surface-subtle);
  color: var(--text-secondary);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.dp-tag {
  font-size: 0.75rem;
  font-weight: 600;
  background-color: var(--bg-surface-subtle);
  color: var(--text-secondary);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.tool-tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.tool-tag.allowed {
  background-color: var(--success-light);
  color: var(--success-text);
}

.tool-tag.forbidden {
  background-color: var(--bg-surface-subtle);
  color: var(--text-muted);
}

.q-diff-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.q-diff-badge.diff-E {
  background-color: var(--success-light);
  color: var(--success-text);
}

.q-diff-badge.diff-C {
  background-color: var(--warning-light);
  color: var(--warning-text);
}

.q-diff-badge.diff-A {
  background-color: #f3e8ff;
  color: #6b21a8;
}

/* Modals Backdrops */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* Calculator Card */
.calculator-card {
  width: 100%;
  max-width: 360px;
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  animation: fadeIn 0.2s ease-out;
}

.calculator-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background-color: var(--bg-surface-subtle);
}

.calc-header-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.9rem;
}

.calc-screen {
  background-color: #0f172a;
  color: #ffffff;
  padding: 1rem;
  text-align: right;
}

.calc-history-line {
  font-size: 0.85rem;
  color: #94a3b8;
  min-height: 1.2rem;
  font-family: var(--font-mono);
}

.calc-display-line {
  font-size: 2rem;
  font-weight: 700;
  font-family: var(--font-mono);
  overflow-x: auto;
}

.calc-keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 0.75rem;
  background-color: var(--bg-surface);
}

.calc-btn {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface-subtle);
  color: var(--text-primary);
}

.calc-btn:hover {
  background-color: var(--border-subtle);
}

.calc-btn:active {
  transform: scale(0.96);
}

.calc-btn.btn-op {
  background-color: var(--primary-light);
  color: var(--primary);
  font-size: 1.25rem;
}

.calc-btn.btn-sci {
  font-size: 0.9rem;
  background-color: var(--bg-surface-subtle);
  color: var(--text-secondary);
}

.calc-btn.btn-equals {
  background-color: var(--primary);
  color: #ffffff;
  font-size: 1.3rem;
}

/* Formula Modal */
.formula-card {
  width: 100%;
  max-width: 860px;
  max-height: 85vh;
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 0.2s ease-out;
}

.formula-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}

.formula-header-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.formula-header-title h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.formula-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.formula-toolbar {
  padding: 0.75rem 1.25rem;
  background-color: var(--bg-surface-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  pointer-events: none;
}

.search-input-wrapper input {
  width: 100%;
  padding: 0.6rem 0.75rem 0.6rem 2.2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}

.search-input-wrapper input:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.formula-nav-tabs {
  display: flex;
  overflow-x: auto;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
}

.formula-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.formula-tab:hover {
  background-color: var(--bg-surface-subtle);
  color: var(--text-primary);
}

.formula-tab.active {
  background-color: var(--primary-light);
  color: var(--primary-text);
}

.formula-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

.formula-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

.formula-card-item {
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.f-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.f-item-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.f-formula-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary-text);
  white-space: pre-wrap;
}

.f-item-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Scratchpad Drawer */
.scratchpad-drawer {
  position: fixed;
  bottom: 0;
  right: 1.5rem;
  width: 500px;
  height: 440px;
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-strong);
  border-bottom: none;
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.scratchpad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.9rem;
  background-color: var(--bg-surface-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.scratchpad-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  font-size: 0.85rem;
}

.scratchpad-tools {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  color: var(--text-secondary);
}

.tool-btn:hover, .tool-btn.active {
  background-color: var(--border-subtle);
  color: var(--text-primary);
}

.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
}

.color-dot.active {
  border-color: var(--primary);
  transform: scale(1.15);
}

.size-btn {
  font-size: 0.75rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  color: var(--text-muted);
}

.size-btn.active {
  color: var(--text-primary);
  font-weight: bold;
}

.scratchpad-canvas-wrapper {
  flex: 1;
  position: relative;
  background-color: #ffffff;
  cursor: crosshair;
  touch-action: none;
}

#scratchpad-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Audio Player Component */
.listening-audio-box {
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.9rem;
  margin-bottom: 1rem;
}

.audio-control-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn-play-audio {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
}

.btn-play-audio:hover {
  background-color: var(--primary-hover);
}

.audio-speed-selector {
  display: flex;
  gap: 2px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.speed-btn {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  color: var(--text-secondary);
}

.speed-btn.active {
  background-color: var(--primary-light);
  color: var(--primary-text);
}

.audio-wave {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 18px;
}

.wave-bar {
  width: 3px;
  height: 6px;
  background-color: var(--primary);
  border-radius: 2px;
  transition: height 0.2s ease;
}

.audio-wave.active .wave-bar:nth-child(1) { animation: wave 0.6s infinite alternate; }
.audio-wave.active .wave-bar:nth-child(2) { animation: wave 0.8s 0.2s infinite alternate; }
.audio-wave.active .wave-bar:nth-child(3) { animation: wave 0.7s 0.1s infinite alternate; }
.audio-wave.active .wave-bar:nth-child(4) { animation: wave 0.9s 0.3s infinite alternate; }

@keyframes wave {
  from { height: 4px; }
  to { height: 18px; }
}

.audio-transcript-card {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.transcript-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.transcript-text {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-primary);
}

/* Rubrics Evaluator Component */
.rubric-card {
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-top: 1rem;
}

.rubric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.rubric-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.rubric-title h3 {
  font-size: 1rem;
  font-weight: 700;
}

.rubric-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.model-answer-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1rem;
}

.model-answer-badge {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-text);
  background-color: var(--primary-light);
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.model-answer-text {
  font-size: 0.9rem;
  line-height: 1.6;
}

.rubric-table-wrapper {
  overflow-x: auto;
  margin-bottom: 0.75rem;
}

.rubric-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background-color: var(--bg-surface);
}

.rubric-table th, .rubric-table td {
  border: 1px solid var(--border-subtle);
  padding: 0.75rem;
  vertical-align: top;
}

.rubric-table th {
  background-color: var(--bg-surface-subtle);
  font-weight: 700;
  text-align: left;
}

.cell-grade-label {
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.rubric-level-cell {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.rubric-level-cell:hover {
  background-color: var(--bg-surface-subtle);
}

.rubric-level-cell.selected {
  background-color: var(--primary-light);
  border-color: var(--primary);
}

.btn-select-grade {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
}

.btn-select-grade.active {
  background-color: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.rubric-summary-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 0.85rem;
  font-weight: 600;
}

.rubric-grade-pill {
  margin-left: 1rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
}
