/* ==========================================================================
   QuartetLab Component Styles (Instrument Bar, Canvases, Tables, Modals)
   ========================================================================== */

/* Top Header & Instrument Ribbon */
.top-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-sm);
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.brand-title-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.brand-title {
  font-family: var(--font-headline);
  font-size: 1.5rem;
  line-height: 1.1;
  font-weight: 600;
}

.brand-tag {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.brand-subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* Live Moment Summary Strip (First-Screen Immediate Feedback) */
.moment-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: var(--space-2);
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3);
  box-shadow: var(--shadow-sm);
}

.moment-cell {
  padding: var(--space-1) var(--space-2);
  border-right: var(--border-thin);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.moment-cell:last-child {
  border-right: none;
}

.moment-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  font-weight: 600;
}

.moment-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
}

.moment-value.accent-primary {
  color: var(--color-primary);
}

.moment-value.accent-secondary {
  color: var(--color-secondary);
}

/* Panels & Cards */
.panel {
  position: relative;
  max-width: 100%;
  background: var(--color-surface);
  border: var(--border-thin);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-thin);
  background: var(--color-surface-subtle);
}

.panel-title-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.panel-title {
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--color-background);
  border: var(--border-thin);
  color: var(--color-text-muted);
}

.panel-body {
  padding: var(--space-4);
}

.panel-body.compact {
  padding: var(--space-3);
}

/* Controls, Buttons, Inputs & Segmented Bars */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  padding: 8px 12px;
  min-height: 34px;
  border-radius: var(--radius-md);
  border: var(--border-thin);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: var(--color-surface-subtle);
  border-color: var(--color-border-strong);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: #FFFFFF;
  border-color: var(--color-primary);
  font-weight: 600;
}

[data-theme="dark"] .btn-primary {
  color: #081C15;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-secondary-soft);
  color: var(--color-secondary);
  border-color: var(--color-secondary);
  font-weight: 600;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-secondary);
  color: #FFFFFF;
}

.btn-sm {
  padding: 5px 9px;
  min-height: 28px;
  font-size: var(--text-xs);
}

.segmented-control {
  display: inline-flex;
  background: var(--color-background);
  border: var(--border-thin);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
  flex-wrap: wrap;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 5px 10px;
  min-height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
}

.seg-btn:hover {
  color: var(--color-text);
}

.seg-btn[aria-pressed="true"],
.seg-btn.active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

/* Form Controls */
.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 110px;
  flex: 1;
}

.field-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.input-field,
.select-field {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  padding: 6px 10px;
  min-height: 34px;
  border-radius: var(--radius-md);
  border: var(--border-thin);
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
}

.input-field.mono {
  font-family: var(--font-mono);
}

.input-field:focus,
.select-field:focus {
  border-color: var(--color-accent-highlight);
}

/* Interactive Plotting Canvases */
.canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-thin);
  background: var(--color-surface);
}

.canvas-stage {
  position: relative;
  width: 100%;
  background: var(--canvas-bg);
  user-select: none;
  touch-action: none;
}

.scatter-stage {
  height: 320px;
}

.diag-stage {
  height: 185px;
}

.plot-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.canvas-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-top: var(--border-thin);
  background: var(--color-surface-subtle);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-swatch {
  width: 12px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.legend-halo {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px dashed var(--color-secondary);
  display: inline-block;
}

/* Exact-Moment Solver Grid */
.solver-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

@media (max-width: 640px) {
  .solver-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .scatter-stage {
    height: 330px;
  }
}

.solver-item {
  background: var(--color-background);
  border: var(--border-thin);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.solver-item label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.solver-item input[type="number"] {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 4px 6px;
  border: var(--border-thin);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
}

/* Minitab / AP Statistics Computer Regression Output Table */
.regression-table-wrap {
  overflow-x: auto;
}

.stat-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-xs);
}

.stat-table th,
.stat-table td {
  padding: 7px 8px;
  border-bottom: var(--border-thin);
}

.stat-table th {
  text-align: right;
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-surface-subtle);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-table th:first-child,
.stat-table td:first-child {
  text-align: left;
}

.stat-table td {
  text-align: right;
}

.stat-summary-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-background);
  border-top: var(--border-thin);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
}

/* Observation Data Table & Point Diagnostics */
.points-table-scroll {
  position: relative;
  max-height: 270px;
  overflow-y: auto;
  overflow-x: auto;
  max-width: 100%;
  border: var(--border-thin);
  border-radius: var(--radius-md);
}

.points-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.76rem;
}

.points-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--color-surface-subtle);
  border-bottom: var(--border-strong);
  padding: 6px 6px;
  text-align: right;
  color: var(--color-text-muted);
}

.points-table thead th:first-child {
  text-align: center;
}

.points-table tbody tr {
  border-bottom: var(--border-thin);
  transition: background-color 80ms linear;
}

.points-table tbody tr:hover,
.points-table tbody tr.active-row {
  background: var(--color-accent-soft);
}

.points-table td {
  padding: 4px 6px;
  text-align: right;
}

.points-table td:first-child {
  text-align: center;
  color: var(--color-text-muted);
}

.coord-input {
  width: 66px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  text-align: right;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
}

.coord-input:hover,
.coord-input:focus {
  border-color: var(--color-border-strong);
  background: var(--color-surface);
}

/* Diagnostic Flag Chips */
.diag-chip {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.diag-chip.flag-influence {
  background: var(--color-secondary-soft);
  color: var(--color-secondary);
  border: 1px solid var(--color-secondary);
}

.diag-chip.flag-leverage {
  background: var(--color-warning-soft);
  color: var(--color-warning);
  border: 1px solid var(--color-warning);
}

.diag-chip.flag-outlier {
  background: var(--color-accent-soft);
  color: var(--color-accent-highlight);
  border: 1px solid var(--color-accent-highlight);
}

.diag-chip.flag-ok {
  color: var(--color-text-muted);
}

/* Export Code & Snippet Drawer */
.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(125px, 1fr));
  gap: var(--space-2);
}

.code-preview-box {
  margin-top: var(--space-3);
  background: var(--color-background);
  border: var(--border-thin);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.45;
  overflow-x: auto;
  max-height: 210px;
  white-space: pre;
  color: var(--color-text);
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  background: var(--color-text);
  color: var(--color-surface);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: 600;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in var(--duration-normal) var(--ease-out);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Modals (CSV Import, Privacy/Storage Inspector, Printable FRQ Sheet) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 25, 0.55);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  background: var(--color-surface);
  border: var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 820px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-enter var(--duration-normal) var(--ease-out);
}

@keyframes modal-enter {
  from {
    opacity: 0;
    transform: scale(0.98) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-thin);
  background: var(--color-surface-subtle);
}

.modal-body {
  padding: var(--space-4);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: var(--border-thin);
  background: var(--color-surface-subtle);
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: var(--space-4);
  border-top: var(--border-thin);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
