/* ==========================================================================
   MemConflict conversation browser
   Self-contained stylesheet — no external fonts, no CDN assets.
   ========================================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;

  --bg-page: #f4f5f7;
  --bg-pane: #ffffff;
  --bg-hover: #f1f3f6;
  --bg-active: #eaf1ff;
  --border-color: #e3e5e9;
  --border-color-strong: #d6d9de;

  --text-primary: #1b1e24;
  --text-secondary: #5b6069;
  --text-muted: #8a8f98;

  --accent: #3567e0;
  --accent-strong: #2750b8;

  --user-bubble-bg: #3567e0;
  --user-bubble-fg: #ffffff;
  --assistant-bubble-bg: #eef0f3;
  --assistant-bubble-fg: #1b1e24;

  --badge-initial-bg: #e3f6ea;
  --badge-initial-fg: #1e7a45;
  --badge-update-bg: #e5eefc;
  --badge-update-fg: #1c5fbf;
  --badge-chitchat-bg: #eceef1;
  --badge-chitchat-fg: #565b64;
  --badge-future-bg: #f2e9fb;
  --badge-future-fg: #7431b0;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(20, 22, 30, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 22, 30, 0.08);

  --site-bar-height: 44px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-page);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[x-cloak] {
  display: none !important;
}

/* ==========================================================================
   Site bar: links to the other pages, above the app shell
   ========================================================================== */

.site-bar {
  height: var(--site-bar-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--bg-pane);
  border-bottom: 1px solid var(--border-color);
  /* beats .pane-details' fixed z-index: 20 (style.css @media 900px), so the
     drawer cannot slide over the bar */
  z-index: 30;
  position: relative;
}

.site-bar-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-bar-brand {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
}

.site-bar-brand-short {
  display: none;
}

.site-bar-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
}

.site-bar-brand:hover,
.site-bar-link:hover {
  color: var(--accent-strong);
}

/* ==========================================================================
   App shell — CSS grid, up to 4 columns
   ========================================================================== */

#app {
  display: grid;
  grid-template-columns: 260px 300px 1fr;
  /* #app takes its height from the viewport, not from body, so it does not
     shrink for .site-bar above it. At a plain 100vh the document grows past
     the viewport, gains a scrollbar, and clips the grid by the bar height. */
  height: calc(100vh - var(--site-bar-height));
  width: 100vw;
  overflow: hidden;
}

#app.details-open {
  grid-template-columns: 260px 300px 1fr 340px;
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-pane);
  border-right: 1px solid var(--border-color);
  overflow: hidden;
}

.pane-chat {
  border-right: none;
  background: var(--bg-page);
}

.pane-details {
  border-right: none;
  border-left: 1px solid var(--border-color);
}

/* ==========================================================================
   Shared pane header / list scaffolding
   ========================================================================== */

.pane-header {
  flex: 0 0 auto;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.app-title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.pane-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pane-subtitle {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-page);
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
  background: var(--bg-pane);
}

.pane-list {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.empty-note {
  padding: 20px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ==========================================================================
   Persona pane
   ========================================================================== */

.persona-row {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.persona-row:hover {
  background: var(--bg-hover);
}

.persona-row.active {
  background: var(--bg-active);
  box-shadow: inset 3px 0 0 var(--accent);
}

.persona-name {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.persona-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.dot-sep {
  margin: 0 4px;
}

.persona-seed {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ==========================================================================
   Session pane
   ========================================================================== */

.session-row {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.session-row:hover {
  background: var(--bg-hover);
}

.session-row.active {
  background: var(--bg-active);
  box-shadow: inset 3px 0 0 var(--accent);
}

.session-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.session-date {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.session-row-mid {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
}

.msg-count {
  font-size: 11.5px;
  color: var(--text-muted);
}

.conflict-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e0a02b;
  flex: 0 0 auto;
}

.session-outline {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Badges (session_type pills)
   ========================================================================== */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge-initial_reveal {
  background: var(--badge-initial-bg);
  color: var(--badge-initial-fg);
}

.badge-update {
  background: var(--badge-update-bg);
  color: var(--badge-update-fg);
}

.badge-chitchat {
  background: var(--badge-chitchat-bg);
  color: var(--badge-chitchat-fg);
}

.badge-future_plan {
  background: var(--badge-future-bg);
  color: var(--badge-future-fg);
}

/* ==========================================================================
   Chat pane
   ========================================================================== */

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg-pane);
  border-bottom: 1px solid var(--border-color);
}

.chat-header-title {
  font-size: 14.5px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.details-toggle {
  flex: 0 0 auto;
  padding: 7px 14px;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-pane);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s ease;
}

.details-toggle:hover {
  background: var(--bg-hover);
}

.details-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 20px;
}

.chat-empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 14px;
}

.chat-empty-icon {
  font-size: 34px;
  opacity: 0.5;
}

.chat-transcript {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 820px;
  margin: 0 auto;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

.msg-row-user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row-assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-role-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  padding: 0 4px;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  word-wrap: break-word;
  font-size: 13.5px;
  box-shadow: var(--shadow-sm);
}

/* pre-wrap lives on the inner span, not the bubble: the span sits on its own
   indented line in the HTML, so putting pre-wrap on the bubble would preserve
   that source-formatting whitespace as a leading indent on the first line. */
.msg-bubble span {
  white-space: pre-wrap;
}

.bubble-user {
  background: var(--user-bubble-bg);
  color: var(--user-bubble-fg);
  border-bottom-right-radius: 4px;
}

.bubble-assistant {
  background: var(--assistant-bubble-bg);
  color: var(--assistant-bubble-fg);
  border-bottom-left-radius: 4px;
}

.bubble-unknown {
  background: #fff6e0;
  color: #6a5316;
  border: 1px dashed #e0c675;
}

.msg-empty {
  font-style: italic;
  opacity: 0.7;
}

/* ==========================================================================
   Details aside
   ========================================================================== */

.details-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
}

.segmented {
  display: flex;
  background: var(--bg-page);
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.segmented-btn {
  padding: 6px 14px;
  border: none;
  background: transparent;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-secondary);
  cursor: pointer;
}

.segmented-btn.active {
  background: var(--bg-pane);
  color: var(--accent-strong);
  box-shadow: var(--shadow-sm);
}

.details-close {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
}

.details-close:hover {
  color: var(--text-primary);
}

.details-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 14px;
}

.details-body details {
  margin-bottom: 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-pane);
  overflow: hidden;
}

.details-body summary {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-primary);
  background: var(--bg-hover);
  list-style: none;
}

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

.details-body summary::before {
  content: "\25B8";
  display: inline-block;
  margin-right: 6px;
  color: var(--text-muted);
  transition: transform 0.1s ease;
}

.details-body details[open] > summary::before {
  transform: rotate(90deg);
}

.tree, .personality-block {
  padding: 8px 14px 12px;
}

.tree-row {
  padding: 3px 0;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.tree-row.tree-leaf {
  color: var(--text-primary);
}

.tree-key {
  color: var(--text-secondary);
  font-weight: 500;
}

.tree-sep {
  color: var(--text-muted);
}

.tree-val {
  color: var(--text-primary);
}

.tree-group-key {
  font-weight: 700;
  color: var(--text-primary);
  display: block;
  margin-top: 6px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding: 0 14px 10px;
}

.chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-hover);
  border: 1px solid var(--border-color-strong);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.chip-event {
  background: var(--badge-update-bg);
  color: var(--badge-update-fg);
  border-color: transparent;
}

.chip-badge {
  background: var(--badge-chitchat-bg);
  color: var(--badge-chitchat-fg);
  border-color: transparent;
  text-transform: capitalize;
}

.chip-badge.diff-easy {
  background: var(--badge-initial-bg);
  color: var(--badge-initial-fg);
}

.chip-badge.diff-medium {
  background: var(--badge-update-bg);
  color: var(--badge-update-fg);
}

.chip-badge.diff-hard {
  background: #fbe4e4;
  color: #b1372f;
}

.details-session {
  display: flex;
  flex-direction: column;
}

.session-outline-full {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
  padding: 2px 2px 4px;
  white-space: pre-wrap;
}

.no-annotations {
  padding: 16px 2px;
  color: var(--text-muted);
  font-size: 13px;
}

.annotation-section {
  margin-top: 14px;
}

.section-label {
  margin: 0 0 8px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.annotation-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-pane);
  padding: 8px 12px;
  margin-bottom: 8px;
}

.question-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-pane);
  padding: 10px 12px;
  margin-bottom: 10px;
}

.question-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.question-answer {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
  white-space: pre-wrap;
}

.question-badges {
  display: flex;
  gap: 6px;
}

/* ==========================================================================
   Responsive collapse (< ~900px)
   ========================================================================== */

@media (max-width: 900px) {
  #app,
  #app.details-open {
    grid-template-columns: 160px 190px 1fr;
  }

  .pane-details {
    position: fixed;
    /* fixed positioning leaves the #app grid, so the calc() above does not
       reach the drawer. Pin it below .site-bar, not at the viewport top. */
    top: var(--site-bar-height);
    right: 0;
    bottom: 0;
    width: min(340px, 88vw);
    z-index: 20;
    box-shadow: -8px 0 24px rgba(20, 22, 30, 0.18);
  }

  .persona-seed {
    -webkit-line-clamp: 2;
  }

  .msg-row {
    max-width: 88%;
  }
}

@media (max-width: 640px) {
  #app,
  #app.details-open {
    grid-template-columns: 120px 150px 1fr;
  }

  .pane-header {
    padding: 10px 12px;
  }

  .persona-row,
  .session-row {
    padding: 10px 12px;
  }

  .site-bar {
    padding: 0 12px;
  }

  .site-bar-nav {
    gap: 10px;
  }

  /* the full project name does not fit beside Report and GitHub at 360px.
     Swap to the short form. Do not shrink --site-bar-height instead: the
     #app calc() and the drawer top offset both read it. */
  .site-bar-brand-full {
    display: none;
  }

  .site-bar-brand-short {
    display: inline;
  }
}
