:root {
  color-scheme: light dark;
  --bg: #0f1218;
  --surface: #171b24;
  --border: #2a3142;
  --text: #e8eaef;
  --muted: #9aa3b2;
  --accent: #5b8def;
  --accent-hover: #7aa3f5;
  --user-bubble: #243044;
  --coach-bubble: #1a2333;
  --danger: #e85d5d;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

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

.top-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 1.5rem;
}

.top-titles {
  flex: 1 1 12rem;
  min-width: 0;
}

.top h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 600;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.style-picker {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.style-picker label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.style-picker select {
  min-width: 12rem;
  max-width: min(100vw - 2rem, 22rem);
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.style-picker select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.top-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.usage-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  max-width: 16rem;
  text-align: right;
  line-height: 1.25;
}

.logout-btn {
  flex-shrink: 0;
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
}

.main {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

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

  .conversation-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: none;
    overflow-x: auto;
    padding-bottom: 0.15rem;
  }

  .conversation-list li {
    flex: 0 0 auto;
    min-width: 0;
    max-width: 14rem;
  }

  .conversation-item {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 720px) {
  .main {
    grid-template-columns: 1fr;
  }
}

.conversations-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 0;
  max-height: min(72vh, 680px);
  position: sticky;
  top: 1rem;
}

.btn-new-chat {
  width: 100%;
  padding: 0.45rem 0.65rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.conversation-list li {
  margin: 0;
}

.conversation-item {
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.55rem;
  font-size: 0.8rem;
  line-height: 1.35;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.2rem;
  cursor: pointer;
  font-weight: 500;
}

.conversation-item:hover:not(.active) {
  border-color: var(--muted);
}

.conversation-item.active {
  border-color: var(--accent);
  background: rgba(91, 141, 239, 0.12);
  box-shadow: 0 0 0 1px var(--accent);
}

.conversation-item.conversation-item-closed {
  border-style: dashed;
}

.conversation-item-preview {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.conversation-item-meta {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chat-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.conversation-summary {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem;
  background: rgba(91, 141, 239, 0.08);
}

.conversation-summary-title {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.conversation-summary-text {
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.85rem;
  line-height: 1.45;
}

.transcript {
  flex: 0 1 auto;
  min-height: 240px;
  max-height: min(56vh, 560px);
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.insight-candidates {
  padding: 0.25rem 0;
  background: rgba(91, 141, 239, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.insight-candidates-title {
  padding: 0.35rem 0.7rem 0.1rem;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.insight-candidate-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.45rem 0.7rem;
  border-top: 1px solid var(--border);
}

.insight-candidate-row:first-of-type {
  border-top: none;
  padding-top: 0;
}

.insight-candidate-text {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text);
}

.insight-candidate-save {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.insight-candidate-actions {
  display: flex;
  gap: 0.4rem;
}

.insight-candidate-dismiss {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.insight-candidate-edit {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.candidate-edit-modal {
  width: min(640px, calc(100vw - 2rem));
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
}

.candidate-edit-modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.candidate-edit-form {
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.candidate-edit-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.candidate-edit-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 7rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.candidate-edit-form textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.candidate-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

.session-proposals-modal {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  border: none;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--text);
}

.session-proposals-modal::backdrop {
  background: rgba(6, 8, 12, 0.85);
}

.session-proposals-shell {
  width: min(1100px, calc(100vw - 2rem));
  height: min(92vh, 920px);
  margin: 4vh auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.session-proposals-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1rem 0.8rem;
}

.session-proposals-title {
  margin: 0;
  font-size: 1.05rem;
}

.session-proposals-subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.session-proposals-content {
  padding: 0.85rem 1rem 1rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.session-proposals-category {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(91, 141, 239, 0.06);
}

.session-proposals-category-header {
  margin: 0;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.session-proposals-empty {
  padding: 0.75rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.msg {
  max-width: 92%;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border: 1px solid var(--border);
}

.msg.assistant {
  align-self: flex-start;
  background: var(--coach-bubble);
  border: 1px solid var(--border);
}

.msg.msg-highlight {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 10px;
  transition: outline 0.15s ease;
}

.msg-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.composer {
  border-top: 1px solid var(--border);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 4.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.composer textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.composer-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
}

.composer-closed-hint {
  margin: 0;
}

.saved-context-block {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
}

.saved-context-summary {
  list-style: none;
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.saved-context-summary::-webkit-details-marker {
  display: none;
}

.saved-context-summary::before {
  content: "";
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
  margin-top: -0.15em;
}

.saved-context-block[open] .saved-context-summary::before {
  transform: rotate(45deg);
  margin-top: 0.1em;
}

.saved-context-summary:hover {
  color: var(--accent-hover);
}

.saved-context-summary:hover::before {
  border-color: var(--accent-hover);
}

.saved-context-summary:focus {
  outline: none;
}

.saved-context-summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.saved-context-body {
  padding: 0 0.75rem 0.75rem;
}

.insights-block {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
}

.insights-summary {
  list-style: none;
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.insights-summary::-webkit-details-marker {
  display: none;
}

.insights-summary::before {
  content: "";
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
  margin-top: -0.15em;
}

.insights-block[open] .insights-summary::before {
  transform: rotate(45deg);
  margin-top: 0.1em;
}

.insights-summary:hover {
  color: var(--accent-hover);
}

.insights-summary:hover::before {
  border-color: var(--accent-hover);
}

.insights-summary:focus {
  outline: none;
}

.insights-summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.insights-body {
  padding: 0 0.75rem 0.75rem;
}

.insights-hint {
  margin-top: 0;
  margin-bottom: 0.55rem;
}

.subgroup-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(154, 163, 178, 0.05);
  margin-bottom: 0.6rem;
}

.subgroup-summary {
  list-style: none;
  cursor: pointer;
  padding: 0.45rem 0.65rem;
  font-size: 0.84rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.subgroup-summary::-webkit-details-marker {
  display: none;
}

.subgroup-summary::before {
  content: "";
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
  margin-top: -0.1em;
}

.subgroup-block[open] .subgroup-summary::before {
  transform: rotate(45deg);
  margin-top: 0.1em;
}

.subgroup-summary:hover {
  color: var(--accent-hover);
}

.subgroup-summary:hover::before {
  border-color: var(--accent-hover);
}

.subgroup-body {
  padding: 0 0.65rem 0.6rem;
}

.saved-context-hint {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.memory-list--context {
  max-height: min(22vh, 200px);
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: none;
  padding: 0.5rem 1.1rem;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.hint {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.memory-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 0 1 auto;
  min-height: 0;
  max-height: min(26vh, 220px);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Keep a visible minimum height for saved insights. */
#insight-list.memory-list {
  min-height: 3.25rem;
}

/* Keep a visible minimum height for committed actions. */
#committed-action-list.memory-list {
  min-height: 3.25rem;
}

/* Keep a visible minimum height for saved values. */
#value-list.memory-list {
  min-height: 3.25rem;
}

#goal-list.memory-list,
#fear-list.memory-list,
#limiting-belief-list.memory-list {
  min-height: 3.25rem;
}

.insight-list {
  max-height: min(24vh, 250px);
}

.insight-manual {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-shrink: 0;
}

.insight-manual-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.insight-manual textarea {
  width: 100%;
  resize: vertical;
  min-height: 2.75rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}

.insight-manual textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn-secondary {
  align-self: flex-start;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(91, 141, 239, 0.12);
  border-color: var(--accent);
}

.btn-secondary:disabled {
  opacity: 0.55;
}

.memory-item {
  font-size: 0.85rem;
  padding: 0.5rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  gap: 0.35rem;
  align-items: flex-start;
  justify-content: space-between;
}

.memory-text {
  flex: 1;
}

.memory-text.insight-jump {
  cursor: pointer;
  text-decoration: underline dotted;
  text-decoration-color: var(--muted);
  text-underline-offset: 0.2em;
}

.memory-text.insight-jump:hover {
  color: var(--accent-hover);
  text-decoration-color: var(--accent-hover);
}

.memory-text.insight-jump:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.memory-item button.del {
  flex-shrink: 0;
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
}

.memory-item button.del:hover {
  border-color: var(--danger);
}

.error-banner {
  background: #3d1f24;
  border: 1px solid var(--danger);
  color: #ffb4b4;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  white-space: pre-line;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
