@import url("https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400;600&display=swap");

:root {
  --primary-glow: #00e5ff;
  --secondary-glow: #FFD700; /* Gold for diff highlight */
  --danger-glow: #ff4757;
}

body {
  font-family: "Fira Sans", sans-serif;
  background: #1a001a;
  color: #e3d8f1;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  padding: 1em;
  background: #1a001a;
  border-bottom: 1px solid #44224d;
  flex-shrink: 0;
  gap: 1em;
}

#header h2 {
  margin: 0;
  font-size: 1.25rem;
  text-align: center;
  color: #e3d8f1;
  white-space: nowrap;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

#viewSwitcher {
  display: flex;
  background: #2b0a3d;
  border-radius: 8px;
  border: 1px solid #44224d;
  overflow: hidden;
  flex-shrink: 0;
}

#viewSwitcher button {
  background: transparent;
  border: none;
  padding: 0.5em 1em;
  color: #e3d8f1;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  font-size: 0.9rem;
}

#viewSwitcher button:disabled {
  color: #7b6a8c;
  cursor: not-allowed;
  background: #220831;
}

#viewSwitcher button.active {
  background: #8e44ad;
  color: white;
}

#viewSwitcher button:not(.active):hover:not(:disabled) {
  background: #3f1f5e;
}

#chatView {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#graphView {
  flex: 1;
  display: none;
  overflow: hidden;
  position: relative;
}

#personality-archetype {
  position: absolute;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 51;
  color: #fff;
  font-size: 1.6rem;
  font-weight: 600;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 15px var(--primary-glow);
  pointer-events: none;
  text-align: center;
  width: 100%;
}

#turn-summary {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 51;
  color: #e3d8f1;
  font-size: 0.9rem;
  font-style: italic;
  max-width: 300px;
  text-shadow: 0 0 5px #000;
  pointer-events: none;
  opacity: 0.8;
  text-align: right;
}

#cy {
  width: 100%;
  height: 100%;
  background-color: #1a001a;
}

#graph-controls {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 50;
  display: flex;
  gap: 10px;
  background: rgba(26,0,26,0.7);
  backdrop-filter: blur(5px);
  padding: 8px;
  border-radius: 10px;
  border: 1px solid #44224d;
}

#graph-controls button {
  background: #2b0a3d;
  border: 1px solid #5b3c7a;
}
#graph-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
#graph-controls button:hover:not(:disabled) {
  background: #3f1f5e;
}

#graph-controls button#cancel-edge-btn {
  background: var(--danger-glow);
  color: #111;
  font-weight: bold;
}

#filter-panel {
  position: absolute;
  top: 75px; /* Below controls */
  right: 20px;
  z-index: 49;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(43, 10, 61, 0.85);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #5b3c7a;
  backdrop-filter: blur(5px);
  box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}
#filter-panel input, #filter-panel select, #filter-panel button {
  width: 100%;
  box-sizing: border-box;
}
#filter-panel input, #filter-panel select {
  background: #1e1028;
  color: #e3d8f1;
  border: 1px solid #5b3c7a;
  padding: 0.4em 0.6em;
  border-radius: 5px;
  font-family: inherit;
  font-size: 0.9em;
}
#filter-panel button {
  font-size: 0.9em;
  padding: 0.4em 0.8em;
}


.info-panel {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 320px;
  max-height: calc(100% - 40px);
  background: rgba(26, 0, 26, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid #5b3c7a;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  z-index: 100;
  color: #e3d8f1;
  display: flex;
  flex-direction: column;
}

.info-panel__close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #aaa;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.info-panel__close:hover {
  color: white;
}

#info-panel-content {
  padding: 20px;
  overflow-y: auto;
  font-size: 0.9rem;
  flex-grow: 1;
}

#info-panel-content .attr {
  margin-bottom: 1em;
  line-height: 1.4;
  word-wrap: break-word;
}

#info-panel-content .attr-key {
  font-weight: 600;
  color: #c084fc;
  display: block;
  margin-bottom: 0.3em;
  text-transform: capitalize;
}

#info-panel-content .attr-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.3em 0.5em;
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

#info-panel-actions {
  padding: 10px 20px;
  border-top: 1px solid #44224d;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

#info-panel-actions button {
  flex-grow: 1;
  font-size: 0.8rem;
  padding: 0.5em;
}

#info-panel-actions .delete-btn {
  background-color: #7c1a27;
}

#info-panel-actions .delete-btn:hover {
  background-color: #a12b39;
}

#graph-legend {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 50;
  background: rgba(26,0,26,0.7);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #44224d;
  font-size: 0.8rem;
  pointer-events: none;
}
.legend-item {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
}
.legend-item:last-child {
  margin-bottom: 0;
}
.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 8px;
  display: inline-block;
  border: 1px solid rgba(255,255,255,0.3);
}
.legend-color.gold {
  background-color: var(--secondary-glow);
}
.legend-color.blue {
  background-color: var(--primary-glow);
}


#settingsPanel {
  position: absolute;
  top: 70px;
  right: 20px;
  background: #2a0033;
  border: 1px solid #5b3c7a;
  padding: 1.5em;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  display: none;
  z-index: 101;
  width: 300px;
  max-width: 90%;
}

.settings-group {
  margin-bottom: 1.5em;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-group h4 {
  margin: 0 0 1em;
  border-bottom: 1px solid #44224d;
  padding-bottom: 0.5em;
}

.settings-group label {
  display: block;
  margin-bottom: 0.5em;
  font-weight: bold;
}

.inputRow {
  display: flex;
  gap: 0.5em;
  align-items: center;
}

#settingsPanel input[type="password"] {
  flex: 1;
  background: #1e1028;
  color: #e3d8f1;
  border: 1px solid #5b3c7a;
  padding: 0.6em 0.75em;
  border-radius: 5px;
  font-family: inherit;
  font-size: 1em;
  box-sizing: border-box;
}

#settingsPanel button {
  background: #8e44ad;
  color: white;
  border: none;
  padding: 0.6em 1em;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.2s ease;
  white-space: nowrap;
}

#settingsPanel button:hover {
  background: #a76fc9;
}

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  margin-top: 0.5em;
}

input[type="range"]::-webkit-slider-runnable-track {
  background: #1e1028;
  height: 0.5rem;
  border-radius: 1rem;
  border: 1px solid #5b3c7a;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -6px;
  background-color: #c084fc;
  height: 1.25rem;
  width: 1.25rem;
  border-radius: 50%;
  border: 2px solid #2a0033;
}

#temperature-value,
#max-tokens-value {
  font-weight: normal;
  color: #c084fc;
}

#input-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 200;
  display: flex;
  justify-content: center;
  align-items: center;
}

#input-modal {
  background: #2a0033;
  border: 1px solid #5b3c7a;
  padding: 1.5em;
  border-radius: 12px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 10px 40px #000;
}

#modal-title {
  margin: 0 0 1em;
  color: #e3d8f1;
}

#modal-body .form-group {
  margin-bottom: 1em;
}

#modal-body label {
  display: block;
  margin-bottom: 0.5em;
  font-weight: bold;
  font-size: 0.9em;
}

#modal-body input,
#modal-body select {
  width: 100%;
  background: #1e1028;
  color: #e3d8f1;
  border: 1px solid #5b3c7a;
  padding: 0.6em 0.75em;
  border-radius: 5px;
  font-family: inherit;
  font-size: 1em;
  box-sizing: border-box;
}

#modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1em;
  margin-top: 1.5em;
}

#modal-cancel-btn {
  background-color: #444;
}

#modal-cancel-btn:hover {
  background-color: #666;
}

@media (max-width: 768px) {
  #header {
    flex-wrap: wrap;
    justify-content: center;
  }
  #header h2 {
    font-size: 1rem;
    order: -1;
    width: 100%;
    text-align: center;
    margin-bottom: 0.5em;
  }
  .info-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 50vh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
  }
  #personality-archetype { font-size: 1.2rem; top: 10px; }
  #turn-summary { display: none; }
  #graph-controls { top: 15px; right: 15px; }
  #filter-panel { top: 65px; right: 15px; }
  #graph-legend { font-size: 0.7rem; bottom: 10px; left: 10px; }

}

#chatContainer {
  flex: 1;
  overflow-y: auto;
  padding: 2em 1em;
  display: flex;
  flex-direction: column;
  gap: 1.5em;
}

.message {
  max-width: 75%;
  padding: 1em 1.25em;
  border-radius: 1.2em;
  white-space: pre-wrap;
  word-wrap: break-word;
  transition: all 0.3s ease;
  opacity: 0;
  transform: translateY(10px);
  animation: fadeIn 0.3s forwards;
}

.user {
  align-self: flex-end;
  background: #3f1f5e;
  color: #e0f7ff;
}

.bot {
  align-self: flex-start;
  background: #2b0a3d;
  color: #e3d8f1;
}

#inputArea {
  padding: 1em;
  background: #2a0033;
  border-top: 1px solid #44224d;
}

.api-cost-notice {
  display: block;
  text-align: center;
  font-size: 0.75rem;
  color: #e3d8f1;
  opacity: 0.5;
  padding-bottom: 0.5em;
}

.inputWrapper {
  position: relative;
  width: 100%;
}

#userInput {
  width: 100%;
  font-size: 1em;
  padding: 0.75em 3em 0.75em 1em;
  border-radius: 20px;
  border: 1px solid #5b3c7a;
  background: #220028;
  color: #fff;
  line-height: 1.4em;
  min-height: 2.5em;
  overflow: hidden;
  resize: none;
  transition: border-color 0.2s ease;
  box-sizing: border-box;
}

#userInput:focus {
  outline: none;
  border-color: #8e44ad;
}

#runButton {
  position: absolute;
  top: 50%;
  right: 0.75em;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #c084fc;
  font-size: 1.5em;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: transform 0.2s ease, color 0.2s ease;
}

#runButton:disabled {
  color: #666;
  cursor: not-allowed;
}

#runButton:hover:not(:disabled) {
  transform: translateY(-50%) scale(1.2);
}

#gearButton {
  background: none;
  border: none;
  color: white;
  font-size: 1.5em;
  cursor: pointer;
  transition: transform 0.2s ease;
}

#gearButton:hover {
  transform: rotate(30deg);
  color: #bbb;
}

button {
  background: #8e44ad;
  color: white;
  border: none;
  padding: 0.6em 1.2em;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s ease;
}

button:hover {
  background: #a76fc9;
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-thumb {
  background: #5b3c7a;
  border-radius: 3px;
}

@keyframes fadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message h1,
.message h2,
.message h3 {
  margin: 0.2em 0 0.2em;
  font-weight: 600;
  font-size: 1.1em;
  line-height: 1.3;
}

.message ul {
  margin: 0.2em 0;
  padding-left: 1.2em;
  list-style-position: inside;
  line-height: 1.4;
}

.message ol {
  list-style-position: outside;
  margin: 0.4em 0;
  padding-left: 1.5em;
}

.message ol li {
  padding: 0;
  line-height: 1.4;
  white-space: normal;
}

.message ol li::marker {
  font-size: 0.95em;
  color: #aaa;
}

.message li {
  margin: 0.1em 0;
  padding: 0;
  line-height: 1.4;
}

.message li::marker {
  font-size: 0.9em;
  line-height: 1;
}

.message p {
  margin: 0.2em 0;
  line-height: 1.4;
}

.message.expandable .expander-header {
  user-select: none;
  cursor: pointer;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.message.expandable .expander-header .caret {
  font-family: monospace;
}

.message.expandable.expanded .expander-header {
  opacity: 1;
}

.message.expandable .expander-body {
  display: none;
}

.message.expandable.expanded .expander-body {
  display: block;
}

.section {
  margin-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 0.6rem;
}

.section h4 {
  margin: 0 0 0.4rem;
  font-weight: 600;
  font-size: 0.95rem;
  opacity: 0.9;
}

.md {
  white-space: normal;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.85em;
}

.dim {
  opacity: 0.7;
}

.live-dot {
  display: inline-block;
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
  animation: pulse 1.2s infinite;
  vertical-align: middle;
  margin-left: 0.35rem;
}

@keyframes pulse {
  0% {
    opacity: 0.2;
  }
  50% {
    opacity: 0.9;
  }
  100% {
    opacity: 0.2;
  }
}

@keyframes pulse-glow-add {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 229, 255, 0.7);
  }
  70% {
    box-shadow: 0 0 10px 15px rgba(0, 229, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(0, 229, 255, 0);
  }
}

@keyframes pulse-glow-update {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 171, 0, 0.7);
  }
  70% {
    box-shadow: 0 0 10px 15px rgba(255, 171, 0, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 171, 0, 0);
  }
}