/* ============================================================
   Thinking Mirror — Chat Edition
   ============================================================ */

:root {
  --bg:          #0e0d0b;
  --bg-2:        #141310;
  --bg-3:        #1a1815;
  --bg-card:     #1f1d19;
  --border:      rgba(255,245,220,0.07);
  --border-2:    rgba(255,245,220,0.13);
  --ink:         #f0e8d5;
  --ink-2:       #a89878;
  --ink-3:       #5c5040;
  --gold:        #c9a84c;
  --gold-dim:    rgba(201,168,76,0.10);
  --gold-border: rgba(201,168,76,0.28);
  --red:         #a85050;
  --red-dim:     rgba(168,80,80,0.10);
  --blue:        #5878a0;
  --blue-dim:    rgba(88,120,160,0.10);
  --green:       #5a8a6a;
  --green-dim:   rgba(90,138,106,0.10);
  --bubble-a:    #1e2430;
  --bubble-b:    #1e2820;
  font-size: 15px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-family: 'Inter', ui-sans-serif, sans-serif;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
}
button, textarea, input { font: inherit; color: inherit; }
ul { list-style: none; }
.serif { font-family: 'EB Garamond', Georgia, serif; }
h1, h2, h3 { font-family: 'EB Garamond', Georgia, serif; font-weight: 500; }

/* ── App shell ── */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 28px 0 24px;
  position: sticky; top: 0; height: 100vh;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.brand-glyph { font-size: 22px; color: var(--gold); opacity: .8; }
.brand-name  { font-size: .82rem; font-weight: 500; letter-spacing: .04em; }
.brand-sub   { font-size: .68rem; color: var(--ink-3); letter-spacing: .06em; margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 0 10px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border: none; background: none; cursor: pointer;
  color: var(--ink-3);
  font-size: .78rem; letter-spacing: .06em;
  text-align: left; width: 100%;
  border-radius: 4px;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-item::before {
  content: ''; position: absolute; left: 0; top: 50%;
  transform: translateY(-50%);
  width: 2px; height: 0; background: var(--gold);
  transition: height .2s;
}
.nav-item:hover  { background: var(--bg-3); color: var(--ink-2); }
.nav-item.active { background: var(--gold-dim); color: var(--ink); }
.nav-item.active::before { height: 16px; }
.nav-icon { font-size: .9rem; opacity: .7; }
.nav-badge {
  margin-left: auto;
  font-size: .65rem; color: var(--ink-3);
  background: var(--bg-3); padding: 1px 6px;
  border: 1px solid var(--border); border-radius: 2px;
}

.sidebar-footer {
  padding: 16px 20px 0;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 7px;
  font-size: .68rem; color: var(--ink-3); letter-spacing: .04em;
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-3); flex-shrink: 0; transition: background .4s;
}
.status-dot.ready { background: var(--gold); box-shadow: 0 0 6px rgba(201,168,76,.4); }
.engine-pill {
  margin-left: auto; font-size: .62rem; letter-spacing: .06em;
  padding: 2px 7px; border: 1px solid var(--border); border-radius: 2px; color: var(--ink-3);
}
.engine-pill.llm { border-color: var(--gold-border); color: var(--gold); }

/* ── Main ── */
.main { overflow-y: auto; }
.view.hidden { display: none; }

/* ── Input zone ── */
.input-zone {
  padding: 48px 56px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.input-zone-header { margin-bottom: 24px; }
.input-zone h1    { font-size: 2rem; margin-bottom: 8px; letter-spacing: -.02em; }
.input-zone-sub   { font-size: .84rem; color: var(--ink-2); line-height: 1.7; max-width: 500px; }

.input-box {
  border: 1px solid var(--border-2);
  background: var(--bg-3);
}
textarea {
  display: block; width: 100%;
  min-height: 160px; resize: vertical;
  background: transparent; border: none; outline: none;
  padding: 18px 20px;
  color: var(--ink); line-height: 1.8;
  font-size: .88rem; letter-spacing: .01em;
}
textarea::placeholder { color: var(--ink-3); font-style: italic; }
.input-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.char-count  { font-size: .7rem; color: var(--ink-3); }
.input-bar-right { display: flex; gap: 8px; align-items: center; }

/* ── Buttons ── */
.primary-btn {
  background: var(--gold); color: #0e0d0b;
  font-size: .74rem; font-weight: 500;
  letter-spacing: .1em; text-transform: uppercase;
  padding: 8px 18px; border: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  transition: opacity .2s;
}
.primary-btn:hover    { opacity: .82; }
.primary-btn:disabled { opacity: .3; cursor: not-allowed; }

.ghost-btn {
  background: none; border: 1px solid var(--border-2);
  color: var(--ink-3); font-size: .72rem;
  letter-spacing: .06em; padding: 7px 12px; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.ghost-btn:hover { border-color: var(--gold-border); color: var(--ink-2); }

.btn-spinner { animation: spin .9s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Chat area ── */
.chat-area  { padding: 40px 56px 60px; }

.chat-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 16px;
  min-height: 300px; color: var(--ink-3);
  text-align: center;
}
.chat-empty-glyph { font-size: 3.5rem; opacity: .18; line-height: 1; }
.chat-empty-text  { font-size: .84rem; letter-spacing: .04em; max-width: 260px; line-height: 1.7; }

/* Loading bar */
.chat-loading  { padding: 40px 0; }
.loading-bar   { display: flex; flex-direction: column; gap: 18px; max-width: 360px; }
.loading-step  {
  display: flex; align-items: center; gap: 14px;
  font-size: .78rem; letter-spacing: .06em; color: var(--ink-3);
  opacity: .4; transition: opacity .4s, color .4s;
}
.loading-step.active { opacity: 1; color: var(--ink); }
.loading-step.done   { opacity: .55; color: var(--ink-2); }
.step-num {
  width: 28px; height: 28px;
  border: 1px solid var(--border-2);
  display: flex; align-items: center; justify-content: center;
  font-size: .88rem; color: var(--ink-3); flex-shrink: 0;
  transition: border-color .4s, color .4s;
}
.loading-step.active .step-num { border-color: var(--gold); color: var(--gold); animation: pulse-gold 1.4s ease-in-out infinite; }
.loading-step.done   .step-num { border-color: var(--gold); color: var(--gold); background: var(--gold-dim); }
@keyframes pulse-gold {
  0%,100% { box-shadow: 0 0 0 0 rgba(201,168,76,0); }
  50%      { box-shadow: 0 0 0 5px rgba(201,168,76,.1); }
}

/* ── Pair header ── */
.chat-thread { animation: fadeUp .5s ease-out; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pair-header {
  display: flex; align-items: center; gap: 16px;
  padding: 20px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin-bottom: 28px;
}

.pair-avatars { display: flex; }
.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 2px solid var(--bg-card);
  display: flex; align-items: center; justify-content: center;
  font-family: 'EB Garamond', serif;
  font-size: 1.1rem;
  font-style: italic;
  color: var(--ink-2);
  flex-shrink: 0;
  margin-right: -10px;
}
.avatar.advisor-a { background: #1e2430; border-color: rgba(88,120,160,.4); color: #7aa0d0; }
.avatar.advisor-b { background: #1e2820; border-color: rgba(90,138,106,.4); color: #7aaa8a; z-index: 1; }

.pair-info { flex: 1; min-width: 0; }
.pair-title  { font-size: 1.05rem; font-weight: 500; margin-bottom: 3px; }
.pair-reason { font-size: .76rem; color: var(--ink-3); line-height: 1.55; }

.run-meta-row {
  display: flex; gap: 8px; align-items: center;
  margin-top: 6px; flex-wrap: wrap;
}
.divergence-badge {
  font-size: .68rem; letter-spacing: .07em;
  padding: 2px 9px;
  border: 1px solid var(--gold-border);
  background: var(--gold-dim);
  color: var(--gold);
}
.ooc-warning {
  font-size: .68rem; letter-spacing: .05em;
  color: var(--red); background: var(--red-dim);
  padding: 2px 9px; border: 1px solid rgba(168,80,80,.25);
}
.validation-badge {
  font-size: .68rem; padding: 2px 9px; letter-spacing: .06em;
}
.validation-badge.pass    { color: var(--green); background: var(--green-dim); }
.validation-badge.blocked { color: var(--red);   background: var(--red-dim); }

/* ── Chat messages ── */
.messages { display: flex; flex-direction: column; gap: 24px; margin-bottom: 32px; }

.message {
  display: flex; gap: 14px; align-items: flex-start;
  animation: msgIn .4s ease-out both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.message:nth-child(1) { animation-delay: .05s; }
.message:nth-child(2) { animation-delay: .18s; }

.message-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'EB Garamond', serif; font-size: 1rem; font-style: italic;
  flex-shrink: 0; margin-top: 2px;
}
.message.advisor-a .message-avatar { background: #1e2430; color: #7aa0d0; }
.message.advisor-b .message-avatar { background: #1e2820; color: #7aaa8a; }

.message-body { flex: 1; min-width: 0; }

.message-meta {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px;
}
.message-name {
  font-size: .84rem; font-weight: 500;
}
.message.advisor-a .message-name { color: #7aa0d0; }
.message.advisor-b .message-name { color: #7aaa8a; }
.message-lens {
  font-size: .72rem; color: var(--ink-3); font-style: italic;
}

.bubble {
  padding: 16px 18px;
  border-radius: 2px 14px 14px 14px;
  line-height: 1.72;
  font-size: .88rem;
}
.message.advisor-a .bubble { background: var(--bubble-a); border: 1px solid rgba(88,120,160,.15); }
.message.advisor-b .bubble { background: var(--bubble-b); border: 1px solid rgba(90,138,106,.15); }

.bubble-judgment {
  font-family: 'EB Garamond', serif;
  font-size: 1rem; font-style: italic;
  line-height: 1.65; color: var(--ink);
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.bubble-analysis { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.bubble-analysis li {
  font-size: .83rem; color: var(--ink-2); line-height: 1.65;
  padding-left: 12px; border-left: 1px solid var(--border-2);
}

.bubble-blind, .bubble-conflict {
  padding: 10px 12px; margin-top: 8px;
}
.bubble-blind   { background: rgba(201,168,76,.06); border-left: 2px solid var(--gold); }
.bubble-conflict{ background: rgba(168,80,80,.06);  border-left: 2px solid var(--red); }
.bubble-tag {
  font-size: .64rem; text-transform: uppercase; letter-spacing: .12em;
  display: block; margin-bottom: 4px;
}
.bubble-blind .bubble-tag    { color: var(--gold); }
.bubble-conflict .bubble-tag { color: var(--red); }
.bubble-blind p, .bubble-conflict p {
  font-size: .8rem; color: var(--ink-2); line-height: 1.6; margin: 0;
}

/* ── Synthesis block ── */
.synthesis-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 24px 26px;
  margin-bottom: 28px;
}
.synthesis-label {
  font-size: .66rem; text-transform: uppercase;
  letter-spacing: .16em; color: var(--ink-3); margin-bottom: 18px;
}
.synthesis-conflict {
  font-family: 'EB Garamond', serif;
  font-size: 1.05rem; font-style: italic;
  color: var(--red); line-height: 1.65;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.synthesis-judgment {
  font-size: .88rem; line-height: 1.8; color: var(--ink);
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.synthesis-nextstep {
  font-size: .88rem; line-height: 1.7;
  color: var(--gold); font-style: italic;
}
.synthesis-nextstep::before {
  content: '→ '; font-style: normal; opacity: .6;
}

/* ── Proposals ── */
.proposals-block { margin-bottom: 40px; }
.proposals-header {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 20px; margin-bottom: 16px;
}
.proposals-label {
  font-size: .68rem; text-transform: uppercase;
  letter-spacing: .14em; color: var(--ink-3); margin-bottom: 4px;
}
.proposals-sub {
  font-size: .76rem; color: var(--ink-3); line-height: 1.6;
}

.proposal-list { display: flex; flex-direction: column; gap: 10px; }

.proposal-item {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 14px 16px;
  display: grid; grid-template-columns: 1fr auto;
  gap: 14px; align-items: start;
  transition: border-color .2s;
}
.proposal-item:has(input:checked) {
  border-color: var(--gold-border);
  background: rgba(201,168,76,.04);
}
.proposal-tags { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }

.tag {
  font-size: .62rem; font-weight: 500;
  letter-spacing: .07em; text-transform: uppercase;
  padding: 2px 8px; border: 1px solid;
}
.tag-thinking_pattern { border-color: var(--blue); color: var(--blue); background: var(--blue-dim); }
.tag-blind_spot       { border-color: var(--gold); color: var(--gold); background: var(--gold-dim); }
.tag-preference       { border-color: var(--green); color: var(--green); background: var(--green-dim); }
.tag-contradiction    { border-color: var(--red); color: var(--red); background: var(--red-dim); }
.tag-NEW              { border-color: var(--gold); color: var(--gold); background: var(--gold-dim); }
.tag-REINFORCEMENT    { border-color: var(--blue); color: var(--blue); background: var(--blue-dim); }
.tag-CONFLICT         { border-color: var(--red); color: var(--red); background: var(--red-dim); }

.proposal-content  { font-size: .88rem; line-height: 1.65; margin-bottom: 6px; }
.proposal-evidence { font-size: .76rem; color: var(--ink-3); line-height: 1.55; }
.proposal-conflict-note {
  font-size: .74rem; color: var(--red);
  background: var(--red-dim); padding: 7px 10px;
  margin-top: 8px; border-left: 2px solid var(--red);
}
.proposal-checkbox { width: 17px; height: 17px; accent-color: var(--gold); cursor: pointer; margin-top: 2px; }

/* ── View headers ── */
.view-header { padding: 48px 56px 0; margin-bottom: 32px; }
.view-header h1 { font-size: 2rem; letter-spacing: -.02em; margin-bottom: 10px; }
.view-sub { font-size: .84rem; color: var(--ink-2); line-height: 1.7; max-width: 480px; }
.gold-rule { width: 40px; height: 1px; background: var(--gold); opacity: .5; margin: 12px 0 16px; }

/* ── History list ── */
.memory-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 56px; margin-bottom: 20px;
}
.memory-stats { font-size: .8rem; color: var(--ink-2); }
.memory-stats strong { color: var(--gold); }

.history-list {
  padding: 0 56px;
  display: flex; flex-direction: column; gap: 10px;
}

.history-card {
  background: var(--bg-2); border: 1px solid var(--border);
  padding: 18px 20px;
  cursor: pointer; transition: border-color .2s, transform .2s;
  display: flex; align-items: center; gap: 16px;
}
.history-card:hover { border-color: var(--border-2); transform: translateX(3px); }

.history-avatars { display: flex; flex-shrink: 0; }
.history-info    { flex: 1; min-width: 0; }
.history-title   { font-family: 'EB Garamond', serif; font-size: 1rem; margin-bottom: 4px; }
.history-preview { font-size: .78rem; color: var(--ink-3); line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta    {
  font-size: .68rem; color: var(--ink-3); margin-top: 6px;
  display: flex; gap: 10px; flex-wrap: wrap;
}
.history-date  { flex-shrink: 0; }
.history-arrow { font-size: .9rem; color: var(--ink-3); }

/* ── Memory grid ── */
.memory-grid {
  padding: 0 56px 60px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.memory-card {
  background: var(--bg-2); border: 1px solid var(--border);
  padding: 16px 18px; transition: border-color .2s, transform .2s;
}
.memory-card:hover { border-color: var(--border-2); transform: translateY(-2px); }
.memory-card-tags  { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.memory-card-content { font-size: .88rem; line-height: 1.7; margin-bottom: 10px; }
.memory-card-meta  {
  font-size: .72rem; color: var(--ink-3);
  padding-top: 10px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 3px;
}

.tag-active     { border-color: var(--gold); color: var(--gold); background: var(--gold-dim); }
.tag-reinforced { border-color: var(--blue); color: var(--blue); background: var(--blue-dim); }
.tag-expired    { border-color: var(--ink-3); color: var(--ink-3); opacity: .5; }

/* ── Page empty ── */
.page-empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 14px; padding: 80px 40px;
  color: var(--ink-3); font-size: .82rem; text-align: center;
  border: 1px solid var(--border); margin: 0 56px;
}

/* ── Modal ── */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.72); backdrop-filter: blur(4px); }

.modal-panel {
  position: relative; z-index: 1;
  background: var(--bg-2); border: 1px solid var(--border-2);
  width: min(820px, calc(100vw - 40px));
  max-height: calc(100vh - 60px);
  display: flex; flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
}

.modal-head {
  display: flex; align-items: center; gap: 14px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title-wrap { flex: 1; min-width: 0; }
.modal-close { padding: 6px 10px; font-size: .9rem; }

.modal-body {
  flex: 1; overflow-y: auto;
  padding: 28px 32px 40px;
}

/* ── Toast ── */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card); border: 1px solid var(--gold-border);
  color: var(--ink); padding: 11px 22px;
  font-size: .8rem; letter-spacing: .04em;
  box-shadow: 0 8px 28px rgba(0,0,0,.5); z-index: 100;
  transition: opacity .3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* ── Utilities ── */
.hidden { display: none !important; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--border-2); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .input-zone, .chat-area, .view-header, .memory-toolbar, .history-list, .memory-grid, .page-empty { padding-left: 20px; padding-right: 20px; }
}
