/* Custom styles for XP.css integration */

/* Fix blurry text rendering - override XP.css font smoothing */
.window,
.window *,
button,
input,
select,
textarea {
  -webkit-font-smoothing: none !important;
  -moz-osx-font-smoothing: unset !important;
  font-smooth: auto !important;
  text-rendering: optimizeSpeed !important;
}

/* Use classic Windows fonts for crisp rendering */
button {
  font-family: "Tahoma", "MS Sans Serif", sans-serif;
  font-size: 11px;
  line-height: normal;
  transform: none !important;
  filter: none !important;
  backface-visibility: visible !important;
  perspective: none !important;
}

/* Ensure all form controls use same font */
input,
select,
textarea,
label {
  font-family: "Tahoma", "MS Sans Serif", sans-serif;
  font-size: 11px;
}

body {
  background: teal;
  padding: 0;
  margin: 0;
  transition: filter 0.3s ease;
}

body.dimmed {
  filter: brightness(0.5) contrast(1.25) sepia(0.6);
}

/* Mobile responsiveness */
@media screen and (max-width: 768px) {
  .window {
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    min-height: 100vh;
  }

  .field-row {
    flex-wrap: wrap;
  }

  .field-row label {
    width: 100% !important;
    margin-bottom: 4px;
  }

  .field-row input[type="text"],
  .field-row select#channel {
    flex: 1 1 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-bottom: 8px;
  }

  .field-row button,
  .field-row select {
    margin-left: 0 !important;
    margin-bottom: 8px;
  }

  .summary-row {
    flex-direction: column;
  }

  .summary-left,
  .summary-right {
    max-width: 100%;
    min-width: 100%;
  }

  .graph-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .graph-controls .field-group,
  .graph-controls input,
  .graph-controls select {
    width: 100%;
    min-width: 0;
  }
}

.toggle-row {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin-top: 8px;
}

.toggle-row > * {
  margin-left: 0 !important;
}

.toggle-item {
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.toggle-item label {
  cursor: pointer;
  width: auto !important;
}

.toggle-item--first {
  margin-left: 0;
}

.toggle-item input[type="checkbox"] {
  margin: 0;
}

.toggle-item input[type="checkbox"]:disabled + label {
  color: GrayText;
  opacity: 0.7;
}

.toggle-item input[type="checkbox"]:disabled {
  cursor: not-allowed;
}

.toggle-item input[type="checkbox"]:disabled + label {
  cursor: not-allowed;
}

.description-block {
  background: Window;
  border: 1px solid #919b9c;
  padding: 6px 8px;
  margin-top: 6px;
  font-size: 11px;
  white-space: pre-wrap;
  max-height: 6em;
  overflow-y: auto;
}

/* Layout helpers */
.summary-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.summary-left {
  flex: 0 1 280px;
  max-width: 360px;
}

.summary-right {
  flex: 1 1 0%;
  min-width: 300px;
}

.graph-window {
  width: 95%;
}

.graph-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.graph-controls .field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.graph-controls label {
  font-size: 11px;
  font-weight: bold;
}

.graph-controls .field-hint {
  font-size: 10px;
  color: #3c3c3c;
  margin: 0;
  max-width: 280px;
}

.graph-controls input,
.graph-controls select {
  min-width: 160px;
}

.graph-status {
  font-size: 11px;
  margin-bottom: 8px;
  color: #1f1f1f;
}

.graph-status.error {
  color: #b00020;
}

.graph-container {
  background: Window;
  border: 1px solid #919b9c;
  box-shadow: inset -1px -1px #0a0a0a, inset 1px 1px #fff;
  position: relative;
  width: 100%;
  min-height: 520px;
  height: auto;
  overflow: visible;
}

.graph-modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.35);
  z-index: 2000;
}

.graph-modal-overlay.active {
  display: flex;
}

.graph-modal-window {
  width: min(960px, 100%);
  max-height: calc(100vh - 48px);
}

.graph-modal-window .window-body {
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}

.graph-modal-window .graph-container {
  height: 560px;
}

body.modal-open {
  overflow: hidden;
}

.result-header {
  display: flex;
  justify-content: flex-start;
  gap: 6px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.result-header-main {
  flex: 1 1 auto;
  min-width: 220px;
}

.result-actions {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-left: auto;
}

.result-action-btn {
  white-space: nowrap;
  font-family: "Tahoma", "MS Sans Serif", sans-serif;
  font-size: 11px;
  padding: 4px 10px;
}

.result-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.result-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  line-height: 1.3;
  border: 1px solid #c4a3a3;
  background: #fff6f6;
  color: #6b1f1f;
}

.result-status::before {
  content: "⚠";
  font-size: 10px;
  line-height: 1;
}

.result-status--deleted {
  border-color: #d1a6a6;
  background: #fff8f8;
  color: #6b1f1f;
}

.graph-launch-btn {
  white-space: nowrap;
}

.graph-node-label {
  text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
}

.graph-nodes circle {
  cursor: pointer;
}

.graph-legend {
  margin: 12px 0;
  font-size: 11px;
  background: Window;
  border: 1px solid #919b9c;
  padding: 8px 10px;
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: inset -1px -1px #0a0a0a, inset 1px 1px #fff;
}

.graph-legend-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.graph-legend-title {
  font-weight: bold;
  color: #1f1f1f;
}

.graph-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.graph-legend-swatch {
  display: inline-block;
  width: 18px;
  height: 12px;
  border: 1px solid #1f1f1f;
}

.graph-legend-swatch--references {
  background: #6c83c7;
}

.graph-legend-swatch--referenced {
  background: #c76c6c;
}

.graph-legend-channel-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.graph-legend-channel {
  display: flex;
  align-items: center;
  gap: 6px;
}

.graph-legend-channel-swatch {
  width: 14px;
  height: 14px;
  background-repeat: repeat;
  background-position: 0 0;
  background-size: 6px 6px;
}

.graph-legend-channel--none .graph-legend-channel-swatch {
  background-image: none;
}

.graph-legend-channel--diag-forward .graph-legend-channel-swatch {
  background-image: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.35) 0,
    rgba(0, 0, 0, 0.35) 2px,
    transparent 2px,
    transparent 4px
  );
  background-blend-mode: multiply;
}

.graph-legend-channel--diag-back .graph-legend-channel-swatch {
  background-image: repeating-linear-gradient(
    -45deg,
    rgba(0, 0, 0, 0.35) 0,
    rgba(0, 0, 0, 0.35) 2px,
    transparent 2px,
    transparent 4px
  );
  background-blend-mode: multiply;
}

.graph-legend-channel--cross .graph-legend-channel-swatch {
  background-image:
    repeating-linear-gradient(
      45deg,
      rgba(0, 0, 0, 0.25) 0,
      rgba(0, 0, 0, 0.25) 2px,
      transparent 2px,
      transparent 4px
    ),
    repeating-linear-gradient(
      -45deg,
      rgba(0, 0, 0, 0.25) 0,
      rgba(0, 0, 0, 0.25) 2px,
      transparent 2px,
      transparent 4px
    );
  background-blend-mode: multiply;
}

.graph-legend-channel--dots .graph-legend-channel-swatch {
  background-image: radial-gradient(rgba(0, 0, 0, 0.35) 30%, transparent 31%);
  background-size: 6px 6px;
  background-blend-mode: multiply;
}

.graph-legend-note {
  font-size: 10px;
  color: #555;
  font-style: italic;
}

.title-bar-link {
  display: inline-block;
  color: inherit;
  text-decoration: none;
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid;
  border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;
  background: ButtonFace;
}

.title-bar-controls #aboutBtn {
  font-weight: bold;
  font-size: 12px;
  padding: 0 6px;
  margin-right: 6px;
}

.toggle-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toggle-help {
  font-size: 10px;
  color: #555;
}

.about-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 280px;
  background: Window;
  border: 2px solid #919b9c;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  z-index: 2100;
  font-size: 11px;
}

.about-panel__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: #0055aa;
  color: #fff;
}

.about-panel__body {
  padding: 8px;
  background: Window;
  color: #000;
}

.about-panel__header button {
  border: none;
  background: transparent;
  color: inherit;
  font-weight: bold;
  cursor: pointer;
}

/* Results styling */
#results .item {
  background: Window;
  border: 2px solid #919b9c;
  padding: 12px;
  margin-bottom: 8px;
  max-width: 100%;
  overflow: hidden;
  word-wrap: break-word;
  box-sizing: border-box;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.15);
}

#results .item:last-child {
  margin-bottom: 0;
}

#results .item strong {
  word-break: break-word;
  max-width: 100%;
  display: inline-block;
}

.window-body {
  max-width: 100%;
  overflow-x: hidden;
  margin: 0;
  padding: 1rem;
  box-sizing: border-box;
}

/* Badges */
.badge-row {
  margin-top: 6px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 100%;
  overflow: hidden;
}

.badge {
  background: #0b6efd;
  color: #fff;
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: bold;
  white-space: nowrap;
  word-break: keep-all;
}

.badge--transcript-primary {
  background: #0b6efd;
}

.badge--transcript-secondary {
  background: #8f4bff;
}

.badge--external {
  background: #f5d08a;
  color: #000;
  border: 1px solid #cfa74f;
}

.badge-clickable {
  cursor: pointer;
}

.badge-clickable:focus {
  outline: 2px solid rgba(11, 110, 253, 0.6);
  outline-offset: 1px;
}

/* Transcript and highlights */
.transcript {
  background: Window;
  border: 1px solid;
  border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
  padding: 8px;
  margin-top: 6px;
  max-height: 200px;
  overflow-y: auto;
  font-size: 11px;
}

.highlight-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: none;
  overflow: visible;
}

.highlight-row {
  padding: 4px 6px;
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 100%;
  box-sizing: border-box;
}

.highlight-row:hover {
  background: Highlight;
  color: HighlightText;
  border: 1px dotted WindowText;
}

.highlight-text {
  flex: 1 1 auto;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.highlight-source-indicator {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid transparent;
  margin-left: auto;
  flex: 0 0 auto;
}

.highlight-source-indicator--primary {
  background: #0b6efd;
  border-color: #084bb5;
}

.highlight-source-indicator--secondary {
  background: #8f4bff;
  border-color: #5d2db3;
}

.vector-chunk {
  margin-top: 8px;
  padding: 8px;
  background: #f3f7ff;
  border: 1px solid #c7d0e2;
  font-size: 11px;
  line-height: 1.5;
  word-break: break-word;
}

@media screen and (max-width: 640px) {
  .result-header {
    flex-direction: column;
    gap: 6px;
  }

  .result-header-main {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
  }

  .result-actions {
    width: auto;
    align-self: flex-start;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 4px;
    margin-left: 0;
  }

  .result-action-btn {
    width: 100%;
    text-align: left;
  }

  .highlight-row {
    flex-direction: column;
    gap: 4px;
  }

  .highlight-source-indicator {
    align-self: flex-end;
  }
}

mark {
  background: yellow;
  color: black;
  padding: 0 2px;
}

.transcript-toggle {
  margin-top: 8px;
}

.full-transcript {
  margin-top: 12px;
  padding: 8px;
  background: Window;
  border: 2px solid #919b9c;
  max-height: 400px;
  overflow-y: auto;
  font-size: 11px;
}

.transcript-segment {
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid ButtonShadow;
}

.transcript-segment--matched {
  background: #fff6cc;
}

.transcript-segment:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.transcript-segment.focused {
  background: #ffffe0;
  padding: 6px;
  border: 2px dotted #000;
  animation: pulse-highlight 1s ease-in-out;
}

@keyframes pulse-highlight {
  0%, 100% {
    background: #ffffe0;
  }
  50% {
    background: #ffffa0;
  }
}

.timestamp-link {
  display: inline-block;
  color: #0000ff;
  text-decoration: none;
  font-weight: bold;
  font-size: 10px;
  font-family: 'Courier New', monospace;
  margin-right: 8px;
  padding: 1px 3px;
  background: #e0e0e0;
  border: 1px solid #808080;
}

.timestamp-link:hover {
  background: #c0c0c0;
  text-decoration: underline;
}

.transcript-text {
  color: WindowText;
  line-height: 1.4;
}

.transcript-header,
.transcript-close {
  display: none;
}

/* Chart styling */
#frequencyChart {
  margin-top: 8px;
}

#frequencyChart svg {
  max-width: 100%;
}

#frequencyChart .axis path,
#frequencyChart .axis line {
  stroke: #808080;
}

#frequencyChart .axis text {
  fill: WindowText;
  font-size: 10px;
}

#frequencyChart .freq-layer rect {
  stroke: #fff;
  stroke-width: 0.5px;
}

.freq-legend {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 10px;
}

.freq-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.freq-legend-swatch {
  width: 12px;
  height: 12px;
  border: 1px solid #000;
  display: inline-block;
}

/* Metrics content */
#metricsContent {
  font-size: 11px;
}

/* Pager */
.pager {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

/* Loading text */
.loading-text {
  font-style: italic;
  color: GrayText;
}
