/* ═══════════════════════════════════════════════
   WriteAgent — Custom UI  (Figma design match)
   ═══════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary:   #111125;
  --bg-sidebar:   #1a1a2e;
  --bg-elevated:  #28283d;
  --bg-card:      rgba(17, 17, 37, 0.85);
  --accent:       #e2b5ff;
  --accent-dark:  #2f024c;
  --text-primary: #e2e0fc;
  --text-muted:   #94a3b8;
  --text-faint:   #64748b;
  --text-mono:    #c8c5cd;
  --border:       rgba(255, 255, 255, 0.05);
  --border-light: rgba(255, 255, 255, 0.10);
  --sidebar-w:    256px;
  --appbar-h:     53px;
  --c-character:  #ff4d6d;
  --c-location:   #4cc9f0;
  --c-faction:    #7209b7;
  --c-artifact:   #00f5d4;
  --c-rule:       #94a3b8;
  --radius:       8px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

/* ════════════════════
   Layout Shell
   ════════════════════ */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ════════════════════
   Sidebar
   ════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  box-shadow: 20px 0 40px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  overflow: hidden;
}

/* Logo strip */
.sidebar-logo {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -1px;
}

/* Section header */
.sidebar-section-header {
  padding: 24px 24px 4px;
  flex-shrink: 0;
}

.sidebar-heading {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  line-height: 15px;
}

.sidebar-subheading {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 14px;
  color: rgba(226, 181, 255, 0.6);
  line-height: 20px;
}

/* New Novel button */
.sidebar-btn-wrap {
  padding: 16px 16px 24px;
  flex-shrink: 0;
}

.btn-new-novel {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius);
  border: none;
  background: linear-gradient(to right, rgba(226,181,255,0.8), #e2b5ff);
  color: #2e014b;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  position: relative;
  box-shadow: 0 10px 15px -3px rgba(226,181,255,0.1), 0 4px 6px -4px rgba(226,181,255,0.1);
  transition: opacity 0.15s, transform 0.1s;
}

.btn-new-novel:hover  { opacity: 0.92; }
.btn-new-novel:active { transform: scale(0.98); }

/* Novel list */
.novel-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.novel-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 400;
  transition: background 0.15s, color 0.15s;
  user-select: none;
  position: relative;
}

.novel-item:hover { background: rgba(40,40,61,0.5); color: var(--text-primary); }

.novel-item.active {
  background: var(--bg-elevated);
  border-left: 4px solid var(--accent);
  padding-left: 20px;
  color: var(--accent);
  font-weight: 500;
  border-radius: 0 6px 6px 0;
}

.novel-item-icon { flex-shrink: 0; opacity: 0.7; }

.novel-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.novel-rename-btn {
  flex-shrink: 0;
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1;
  transition: opacity 0.15s, color 0.15s;
}
.novel-item:hover .novel-rename-btn { opacity: 1; }
.novel-rename-btn:hover { color: var(--accent); }

.novel-delete-btn {
  flex-shrink: 0;
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1;
  transition: opacity 0.15s, color 0.15s;
}
.novel-item:hover .novel-delete-btn { opacity: 1; }
.novel-delete-btn:hover { color: #f87171; }

.novel-rename-input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 2px 6px;
  outline: none;
  min-width: 0;
}

/* ── Settings Lock State ── */
.settings-locked .combo-input,
.settings-locked .lang-btn {
  pointer-events: none;
  opacity: 0.45;
}
.settings-locked .lang-btn.active { opacity: 0.7; }
.settings-locked .btn-add-entity { display: none !important; }
.settings-locked .char-card-edit,
.settings-locked .char-card-del,
.settings-locked .btn-remove-entity { display: none !important; }

/* ════════════════════
   Main Wrapper
   ════════════════════ */
.main-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ════════════════════
   Top App Bar
   ════════════════════ */
.top-appbar {
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

/* Tab navigation */
.tab-nav {
  display: flex;
  gap: 24px;
  align-items: center;
}

.tab-link {
  font-size: 14px;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
  padding-bottom: 6px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  line-height: 20px;
  letter-spacing: 0.35px;
}

.tab-link:hover { color: var(--text-primary); }

.tab-link.active {
  color: var(--accent);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

/* Right-side actions */
.appbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.novel-id-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 6px 12px;
}

.copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.copy-btn:hover { opacity: 1; }

.appbar-divider {
  width: 1px;
  height: 32px;
  background: var(--border);
}

.hidden { display: none !important; }

.btn-refresh-graph {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: var(--radius);
  border: none;
  background: linear-gradient(168deg, #e2b5ff 0%, #2f024c 100%);
  color: #9e72bc;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-refresh-graph:hover { opacity: 0.85; }

.scene-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

/* ════════════════════
   Tab Content
   ════════════════════ */
.tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tab-content.hidden { display: none; }
.tab-content.active { display: flex; }

/* ════════════════════
   World Graph
   ════════════════════ */
.graph-workspace {
  position: relative;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at center, rgba(226,181,255,0.04) 0%, transparent 65%),
              linear-gradient(90deg, #0d1117 0%, #0d1117 100%);
  overflow: hidden;
}

#graphSvg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Entity Legend */
.entity-legend {
  position: absolute;
  top: 24px;
  right: 24px;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 17px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  z-index: 5;
}

.legend-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: #cbd5e1;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Graph Controls */
.graph-controls {
  position: absolute;
  bottom: 24px;
  left: 24px;
  display: flex;
  gap: 8px;
  z-index: 5;
}

.ctrl-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.ctrl-btn:hover { background: rgba(40,40,61,0.85); border-color: var(--border-light); }

/* Focus Card */
.focus-card {
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 320px;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 25px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  z-index: 10;
}

.focus-card.hidden { display: none; }

.focus-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

/* Entity type badge */
.entity-type-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 9999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.entity-type-badge.character { background: rgba(255,77,109,0.2); border: 1px solid rgba(255,77,109,0.3); color: #ff4d6d; }
.entity-type-badge.location  { background: rgba(76,201,240,0.2); border: 1px solid rgba(76,201,240,0.3); color: #4cc9f0; }
.entity-type-badge.faction   { background: rgba(114,9,183,0.2); border: 1px solid rgba(114,9,183,0.4); color: #c084fc; }
.entity-type-badge.artifact  { background: rgba(0,245,212,0.15); border: 1px solid rgba(0,245,212,0.3); color: #00f5d4; }
.entity-type-badge.world_rule{ background: rgba(148,163,184,0.15); border: 1px solid rgba(148,163,184,0.3); color: #94a3b8; }

.fc-name {
  font-family: 'Newsreader', serif;
  font-size: 24px;
  font-weight: 600;
  color: #e2e0fc;
  line-height: 32px;
}

.fc-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
  line-height: 0;
  transition: opacity 0.15s;
}
.fc-close:hover { opacity: 0.7; }

.fc-body { display: flex; flex-direction: column; gap: 16px; }

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

.fc-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 1px;
  text-transform: uppercase;
  line-height: 15px;
}

.fc-desc {
  font-size: 12px;
  color: #cbd5e1;
  line-height: 19.5px;
}

.fc-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.fc-stat-val {
  font-size: 18px;
  font-weight: 700;
  line-height: 28px;
}
.fc-stat-val.purple { color: var(--accent); }
.fc-stat-val.gold   { color: #ffe2ab; }

.btn-view-story {
  width: 100%;
  padding: 9px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: #e2e0fc;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s;
}
.btn-view-story:hover { background: #32324a; }

/* Graph empty state */
.graph-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}
.graph-empty p {
  max-width: 320px;
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1.6;
}
.graph-empty strong { color: var(--text-muted); font-weight: 500; }

/* ════════════════════
   Writer Tab — Two Column
   ════════════════════ */

/* Shared form helpers (used in modal + writer) */
.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
  letter-spacing: -0.2px;
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-row-equal {
  display: flex;
  gap: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.form-group.flex-2 { flex: 2; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text-muted); }

.hint { font-size: 11px; font-weight: 400; color: var(--text-faint); }

.form-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  resize: vertical;
  transition: border-color 0.15s;
  width: 100%;
}
.form-input:focus { border-color: rgba(226,181,255,0.4); }
.form-input::placeholder { color: var(--text-faint); }

/* Buttons (global) */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 24px;
  border-radius: var(--radius);
  border: none;
  background: linear-gradient(162deg, #e2b5ff 0%, #2f024c 100%);
  color: #e2e0fc;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-primary:hover   { opacity: 0.88; }
.btn-primary:active  { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 16px;
  transition: background 0.15s;
}
.btn-secondary:hover { background: #32324a; }

/* Status bar */
.status-bar {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  min-height: 18px;
  line-height: 18px;
}
.status-bar.error   { color: #ff4d6d; }
.status-bar.success { color: #00f5d4; }
.status-bar.loading { color: var(--accent); }

.section-divider {
  height: 1px;
  background: var(--border);
  margin: 28px 0;
}

/* ── Writer Layout ── */
.writer-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
  min-height: 0;
}

/* ── LEFT PANEL ── */
.writer-left {
  width: 480px;
  min-width: 280px;
  max-width: 70%;
  flex-shrink: 0;
  height: 100%;
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* ── Genre + Style row ── */
.settings-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.settings-row .form-group { flex: 1; min-width: 0; }

/* ── Resize Handle ── */
.resize-handle {
  width: 6px;
  flex-shrink: 0;
  background: transparent;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 10;
}
.resize-handle:hover,
.resize-handle.dragging { background: rgba(226,181,255,0.12); }

.resize-grip {
  width: 2px;
  height: 40px;
  border-radius: 2px;
  background: rgba(255,255,255,0.15);
}
.resize-handle:hover .resize-grip,
.resize-handle.dragging .resize-grip { background: rgba(226,181,255,0.5); }

/* ── Character Card ── */
.char-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
.char-card-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(226,181,255,0.15);
  border: 1px solid rgba(226,181,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}
.char-card-body { flex: 1; min-width: 0; }
.char-card-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.char-card-desc {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.char-card-actions { display: flex; gap: 4px; flex-shrink: 0; }
.char-card-edit, .char-card-del {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: background 0.1s, color 0.1s;
}
.char-card-edit { color: var(--text-faint); }
.char-card-edit:hover { background: rgba(226,181,255,0.1); color: var(--accent); }
.char-card-del { color: rgba(255,77,109,0.4); }
.char-card-del:hover { background: rgba(255,77,109,0.1); color: #ff4d6d; }

/* Writer panel block */
.w-panel {
  background: #161628;
  padding: 20px;
}

.w-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 18px;
  letter-spacing: 0.1px;
}

/* Field label (uppercase small) */
.field-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.field-hint {
  font-size: 9px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-faint);
  opacity: 0.7;
}

/* Combo box (input + datalist) */
.combo-box {
  position: relative;
}

.combo-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 8px 28px 8px 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
  cursor: pointer;
}
.combo-input:focus { border-color: rgba(226,181,255,0.4); cursor: text; }

.combo-arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

/* Entity rows (characters / world rules) */
.entities-section { margin-bottom: 16px; }

.entities-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.entity-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}

.entity-row-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.entity-field {
  position: relative;
}

.entity-field-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 3px;
  display: block;
}

.entity-input {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
}
.entity-input:focus { border-color: rgba(226,181,255,0.35); }
.entity-input::placeholder { color: #3a3a55; }

.entity-row-fields-inline {
  flex: 1;
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.entity-field-grow { flex: 1; }
.entity-field-fixed { flex: 0 0 90px; }

.severity-select {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.btn-remove-entity {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: none;
  border: 1px solid rgba(255,77,109,0.3);
  color: rgba(255,77,109,0.6);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 18px;
  transition: border-color 0.15s, color 0.15s;
  flex: none;
}
.btn-remove-entity:hover { border-color: #ff4d6d; color: #ff4d6d; }

.btn-add-entity {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px dashed var(--border-light);
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.btn-add-entity:hover { border-color: rgba(226,181,255,0.4); color: var(--accent); }

/* Start Novel button */
.btn-start-novel {
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  border-radius: var(--radius);
  border: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-start-novel:hover { background: #32324a; border-color: rgba(226,181,255,0.3); }
.btn-start-novel:disabled { opacity: 0.45; cursor: not-allowed; }

/* Scene brief */
.brief-wrap {
  position: relative;
  margin-bottom: 14px;
}

.brief-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 14px 28px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  outline: none;
  resize: none;
  min-height: 160px;
  transition: border-color 0.15s;
}
.brief-input:focus { border-color: rgba(226,181,255,0.4); }
.brief-input::placeholder { color: var(--text-faint); font-size: 12px; }

.brief-charcount {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 11px;
  color: var(--text-faint);
  pointer-events: none;
}

/* Distill button */
.btn-distill {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, rgba(226,181,255,0.9) 0%, #2f024c 100%);
  color: #e2e0fc;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: 0.3px;
  transition: opacity 0.15s, transform 0.1s;
  box-shadow: 0 4px 20px rgba(226,181,255,0.15);
}
.btn-distill:hover   { opacity: 0.88; }
.btn-distill:active  { transform: scale(0.98); }
.btn-distill:disabled { opacity: 0.45; cursor: not-allowed; }

/* Inject panel */
.inject-panel { overflow: visible; }
.inject-hint {
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.6;
  margin-bottom: 10px;
}

.inject-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: color 0.15s;
}
.inject-header:hover { color: var(--text-primary); }

.inject-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255,165,0,0.15);
  border: 1px solid rgba(255,165,0,0.4);
  color: orange;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.inject-chevron { transition: transform 0.2s; }
.inject-chevron.open { transform: rotate(180deg); }

.inject-body {
  padding: 0 20px 16px;
}
.inject-body.hidden { display: none; }

.btn-inject {
  width: 100%;
  margin-top: 10px;
  padding: 9px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-inject:hover { background: #32324a; color: var(--text-primary); }

/* ── RIGHT PANEL ── */
.writer-right {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #0e0e20;
  overflow: hidden;
}

/* Prose top bar */
.prose-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: #111125;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.prose-scene-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  overflow: visible;
  max-width: 280px;
  position: relative;
  user-select: none;
}
.prose-scene-pill > span {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  white-space: nowrap;
}

.prose-word-count {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
}

.prose-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.prose-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.prose-action-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }

/* Agent Pipeline */
.agent-pipeline {
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(17,17,37,0.6);
  flex-shrink: 0;
}
.agent-pipeline.hidden { display: none; }

.pipeline-track { position: relative; }

.pipeline-line {
  position: absolute;
  top: 23px;
  left: 23px;
  right: 23px;
  height: 1px;
  background: var(--border-light);
  z-index: 0;
}

.pipeline-stages {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}

/* Connector dots between pipeline stages */
.p-connector {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  justify-content: center;
}

.p-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border-light);
  transition: background 0.3s;
}

/* Loading: dots pulse in sequence */
.p-connector.loading .p-dot {
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.p-connector.loading .p-dot:nth-child(2) { animation-delay: 0.2s; }
.p-connector.loading .p-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { background: var(--border-light); transform: scale(1); }
  40%           { background: var(--accent); transform: scale(1.4); }
}

/* Done: dots lit */
.p-connector.done .p-dot {
  background: #7c3aed;
}

.p-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.p-circle {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s, border-color 0.3s;
}

/* Pending */
.p-stage.pending .p-circle {
  background: var(--bg-elevated);
  border: 1.5px solid var(--border-light);
  color: var(--text-faint);
}

/* Active */
.p-stage.active .p-circle {
  background: rgba(226,181,255,0.1);
  border: 2px solid var(--accent);
  color: var(--accent);
  animation: pipeline-pulse 1.4s ease-in-out infinite;
}

/* Done */
.p-stage.done .p-circle {
  background: rgba(124,58,237,0.3);
  border: 2px solid #7c3aed;
  color: #e2b5ff;
}

@keyframes pipeline-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226,181,255,0.3); }
  50%       { box-shadow: 0 0 0 6px rgba(226,181,255,0); }
}

.p-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-faint);
  text-transform: uppercase;
}
.p-stage.active .p-label { color: var(--accent); }
.p-stage.done .p-label   { color: #7c3aed; }

.pipeline-status {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
  font-style: italic;
}

/* Prose Display */
.prose-display {
  flex: 1;
  overflow-y: auto;
  padding: 40px 60px;
  position: relative;
}

.prose-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  pointer-events: none;
}
.prose-empty p {
  color: var(--text-faint);
  font-size: 14px;
  text-align: center;
  line-height: 1.7;
}

/* Book content */
.prose-book { max-width: 680px; margin: 0 auto; }
.prose-book.hidden { display: none; }

/* Pull quote / epigraph */
.prose-epigraph {
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-size: 15px;
  color: rgba(226,181,255,0.55);
  line-height: 1.7;
  margin-bottom: 40px;
  padding-left: 20px;
  border-left: 2px solid rgba(226,181,255,0.2);
}
.prose-epigraph:empty { display: none; }

/* Scene block */
.prose-scene { margin-bottom: 60px; }

.prose-scene-marker {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.prose-scene-marker::before,
.prose-scene-marker::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-light);
}

.prose-scene-title {
  font-family: 'Newsreader', serif;
  font-size: 32px;
  font-weight: 600;
  color: #e2e0fc;
  line-height: 1.25;
  margin-bottom: 28px;
  letter-spacing: -0.5px;
}

/* Novel paragraphs */
.prose-para {
  font-family: 'Newsreader', serif;
  font-size: 17px;
  line-height: 1.85;
  color: #c8c5e0;
  margin-bottom: 22px;
  text-align: justify;
  hyphens: auto;
}

/* Drop cap for first paragraph of each scene */
.prose-para.drop-cap::first-letter {
  font-size: 4.8em;
  font-weight: 600;
  float: left;
  line-height: 0.72;
  margin: 0.06em 0.1em -0.05em 0;
  color: var(--accent);
  font-family: 'Newsreader', serif;
}

.prose-scene-num {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* ════════════════════
   Table Views (Conflicts & Audit)
   ════════════════════ */
.table-view {
  height: 100%;
  overflow-y: auto;
  padding: 32px 40px;
}

.table-header { margin-bottom: 24px; }

.section-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.6;
}

.section-desc code {
  background: var(--bg-elevated);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--accent);
}

.audit-controls {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.num-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 4px 8px;
  color: var(--text-primary);
  font-size: 13px;
  width: 64px;
  margin-left: 6px;
  outline: none;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.btn-table-refresh {
  padding: 6px 16px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-table-refresh:hover { background: #32324a; color: var(--text-primary); }

/* Data table */
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data-table td {
  padding: 12px 16px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}

table.data-table tr:hover td { background: rgba(40,40,61,0.3); }

.resolved-yes { color: #00f5d4; font-weight: 600; }
.resolved-no  { color: #ff4d6d; font-weight: 600; }

/* Conflicts tab — row type badges */
.badge-detect {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(76,201,240,0.12);
  border: 1px solid rgba(76,201,240,0.3);
  color: #4cc9f0;
  white-space: nowrap;
}
.badge-nego {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255,77,109,0.12);
  border: 1px solid rgba(255,77,109,0.3);
  color: #ff4d6d;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 64px 32px;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1.6;
}

/* ════════════════════
   Modal
   ════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  width: 560px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 32px 64px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 24px 0;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-body {
  padding: 20px 24px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 24px;
}

.btn-cancel {
  padding: 10px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-cancel:hover { background: var(--bg-elevated); }

/* ════════════════════
   Loading States
   ════════════════════ */
.loading-row {
  text-align: center;
  padding: 32px;
  color: var(--text-faint);
  font-size: 13px;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ════════════════════
   D3 Graph Elements
   ════════════════════ */
.graph-link {
  stroke: rgba(255,255,255,0.1);
  stroke-width: 1;
  fill: none;
}

.graph-link-label {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  fill: #475569;
  pointer-events: none;
}

.graph-node circle {
  cursor: pointer;
  transition: opacity 0.2s, r 0.2s;
}

.graph-node circle:hover { opacity: 0.75; }
.graph-node.selected circle { stroke-width: 3 !important; }

.graph-node text {
  font-family: 'Inter', sans-serif;
  fill: white;
  pointer-events: none;
  dominant-baseline: central;
}

/* ════════════════════
   Scrollbars
   ════════════════════ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* ════════════════════
   Language Toggle
   ════════════════════ */
.lang-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  overflow: hidden;
  width: fit-content;
}
.lang-btn {
  padding: 6px 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.lang-btn + .lang-btn { border-left: 1px solid var(--border-light); }
.lang-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.lang-btn.active {
  background: var(--accent-dark);
  color: var(--accent);
}

/* ════════════════════
   Scene Dropdown
   ════════════════════ */
.scene-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 300;
  overflow: hidden;
}
.scene-dropdown.hidden { display: none !important; }
.scene-dropdown-item {
  display: block;
  width: 100%;
  padding: 9px 16px;
  background: none;
  border: none;
  text-align: left;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
}
.scene-dropdown-item:hover { background: rgba(226,181,255,0.1); }
.scene-dropdown-item.active { color: var(--accent); font-weight: 600; }

/* ════════════════════
   Audit Pagination
   ════════════════════ */
.audit-pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0 4px;
  justify-content: center;
}
.audit-pagination.hidden { display: none !important; }
.page-btn {
  padding: 5px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s;
}
.page-btn:hover:not(:disabled) { background: var(--accent-dark); }
.page-btn:disabled { opacity: 0.4; cursor: default; }
.page-info { font-size: 12px; color: var(--text-muted); min-width: 90px; text-align: center; }

/* ════════════════════
   Pipeline Conflict State
   ════════════════════ */
.p-stage.conflict .p-circle {
  border-color: #f59e0b;
  color: #f59e0b;
  background: rgba(245,158,11,0.12);
}
.p-stage.conflict .p-label { color: #f59e0b; }

/* ════════════════════
   Conflict Banner
   ════════════════════ */
.conflict-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 12px 28px 0;
  padding: 12px 16px;
  background: rgba(245,158,11,0.07);
  border: 1px solid rgba(245,158,11,0.28);
  border-radius: var(--radius);
  font-size: 13px;
  flex-shrink: 0;
}
.conflict-banner.hidden { display: none !important; }
.conflict-banner-icon { color: #f59e0b; font-size: 18px; line-height: 1.3; flex-shrink: 0; }
.conflict-banner-body { flex: 1; }
.conflict-banner-title { font-weight: 600; color: #f59e0b; margin-bottom: 3px; }
.conflict-banner-desc { color: var(--text-muted); line-height: 1.5; }
.conflict-banner-link {
  color: var(--accent); cursor: pointer; text-decoration: underline;
  background: none; border: none; font: inherit; font-size: 13px; padding: 0;
}
.conflict-banner-link:hover { opacity: 0.8; }
.conflict-banner-dismiss {
  background: none; border: none; color: var(--text-faint);
  cursor: pointer; font-size: 18px; padding: 0 2px; line-height: 1; flex-shrink: 0;
}
.conflict-banner-dismiss:hover { color: var(--text-primary); }

/* ════════════════════════════════
   Process Tab — Agent Reasoning
   ════════════════════════════════ */
.proc-scene-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.proc-scene-title {
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
  background: rgba(226,181,255,0.06);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.3px;
}

/* Accordion step */
.proc-step {
  border-bottom: 1px solid var(--border);
}
.proc-step:last-child { border-bottom: none; }

.proc-step-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  cursor: pointer;
  transition: background 0.12s;
  user-select: none;
}
.proc-step-header:hover { background: rgba(255,255,255,0.03); }

.proc-step-label {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  min-width: 210px;
  flex-shrink: 0;
}

.proc-step-summary {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.proc-status {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  flex-shrink: 0;
  white-space: nowrap;
}
.proc-status-done     { background: rgba(74,222,128,0.12); color: #4ade80; }
.proc-status-ok       { background: rgba(74,222,128,0.12); color: #4ade80; }
.proc-status-conflict { background: rgba(255,77,109,0.15); color: #ff4d6d; }
.proc-status-inactive  { background: rgba(148,163,184,0.1); color: var(--text-faint); }

.proc-toggle-icon {
  font-size: 18px;
  color: var(--text-faint);
  transform: rotate(0deg);
  transition: transform 0.18s;
  flex-shrink: 0;
  line-height: 1;
}
.proc-step.open .proc-toggle-icon { transform: rotate(90deg); }

/* Collapsible body */
.proc-step-body {
  display: none;
  padding: 0 16px 14px 16px;
  border-top: 1px solid var(--border);
  background: rgba(17,17,37,0.5);
}
.proc-step.open .proc-step-body { display: block; }

/* Detail sections inside body */
.proc-detail-section {
  margin-top: 12px;
}
.proc-detail-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-faint);
  margin-bottom: 6px;
}

/* Entity rows */
.proc-entity-list { display: flex; flex-direction: column; gap: 4px; }
.proc-entity-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
}
.proc-entity-type {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(74,201,240,0.12);
  color: #4cc9f0;
  flex-shrink: 0;
  text-transform: capitalize;
}
.proc-entity-name {
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
  min-width: 90px;
}
.proc-entity-desc {
  color: var(--text-muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Pre blocks */
.proc-pre {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 11px;
  color: var(--text-mono);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  max-height: 160px;
  overflow-y: auto;
}

/* Plot events list */
.proc-list {
  padding-left: 18px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Contradiction item */
.proc-contradiction {
  background: rgba(255,77,109,0.06);
  border: 1px solid rgba(255,77,109,0.15);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  margin-bottom: 6px;
}

/* Negotiation log */
.proc-neg-log { display: flex; flex-direction: column; gap: 6px; }
.proc-neg-entry {
  display: grid;
  grid-template-columns: 60px 160px 1fr;
  gap: 8px;
  align-items: start;
  font-size: 12px;
  padding: 6px 8px;
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
}
.proc-neg-round { color: var(--accent); font-weight: 600; font-size: 11px; }
.proc-neg-agent { color: #4cc9f0; font-size: 11px; }
.proc-neg-msg { color: var(--text-muted); }

/* ════════════════════════════════
   XAI Decision Chain
   ════════════════════════════════ */

/* Layout */
.xai-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}
.xai-timeline-panel { flex: 1; min-width: 0; }
.xai-negotiation-panel {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
}
.xai-neg-header {
  padding: 10px 14px;
  background: rgba(226,181,255,0.06);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.xai-neg-title { font-weight: 600; font-size: 13px; color: var(--accent); }
.xai-neg-subtitle { font-size: 11px; color: var(--text-muted); }
#xaiNegContent { padding: 12px; display: flex; flex-direction: column; gap: 8px; }

/* Scene summary header */
.xai-scene-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0 14px;
  flex-wrap: wrap;
}
.xai-scene-label {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
}
.xai-scene-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}
.xai-scene-pill--clean   { background: rgba(74,222,128,0.12); color: #4ade80; }
.xai-scene-pill--conflict { background: rgba(255,77,109,0.15); color: #ff4d6d; }
.xai-scene-pill--neg     { background: rgba(249,168,37,0.15); color: #f9a825; }

/* Timeline node */
.xai-node {
  display: flex;
  gap: 14px;
  margin-bottom: 10px;
}

/* Connector axis */
.xai-connector {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}
.xai-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 12px;
  border: 2px solid transparent;
}
.xai-dot--done     { background: rgba(74,222,128,0.12); border-color: rgba(74,222,128,0.4); color: #4ade80; }
.xai-dot--ok       { background: rgba(74,222,128,0.12); border-color: rgba(74,222,128,0.4); color: #4ade80; }
.xai-dot--conflict { background: rgba(255,77,109,0.12); border-color: rgba(255,77,109,0.4); color: #ff4d6d; }
.xai-dot--inactive  { background: rgba(148,163,184,0.08); border-color: rgba(148,163,184,0.2); color: var(--text-faint); }
.xai-dot-seq { font-size: 11px; font-weight: 700; }

.xai-line {
  flex: 1;
  width: 2px;
  background: var(--border);
  margin: 4px 0;
  min-height: 12px;
}

/* Agent card */
.xai-card {
  flex: 1;
  min-width: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 4px;
}
.xai-card-header {
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s;
}
.xai-card-header:hover { background: rgba(255,255,255,0.03); }
.xai-card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.xai-card-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  flex: 1;
}
.xai-status-pill {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  flex-shrink: 0;
}
.xai-status-pill--done     { background: rgba(74,222,128,0.12); color: #4ade80; }
.xai-status-pill--ok       { background: rgba(74,222,128,0.12); color: #4ade80; }
.xai-status-pill--conflict { background: rgba(255,77,109,0.15); color: #ff4d6d; }
.xai-status-pill--inactive  { background: rgba(148,163,184,0.1); color: var(--text-faint); }

.xai-card-chevron {
  font-size: 18px;
  color: var(--text-faint);
  transform: rotate(0deg);
  transition: transform 0.18s;
  flex-shrink: 0;
  line-height: 1;
}
.xai-card.open .xai-card-chevron { transform: rotate(90deg); }

.xai-card-summary {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.xai-card-body {
  display: none;
  padding: 0 14px 14px;
  border-top: 1px solid var(--border);
  background: rgba(17,17,37,0.5);
}
.xai-card.open .xai-card-body { display: block; }

/* WHY block */
.xai-why-block {
  background: rgba(226,181,255,0.05);
  border: 1px solid rgba(226,181,255,0.15);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0 10px;
}
.xai-why-block--empty { opacity: 0.7; }
.xai-why-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: rgba(226,181,255,0.6);
  margin-bottom: 6px;
}
.xai-rationale {
  font-style: italic;
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 8px;
  line-height: 1.6;
}
.xai-rationale--unavailable { color: var(--text-faint); font-style: normal; }

/* Tags */
.xai-tag-row { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.xai-tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.xai-tag--rule       { background: rgba(74,201,240,0.12); color: #4cc9f0; }
.xai-tag--constraint { background: rgba(249,168,37,0.12); color: #f9a825; }
.xai-tag--change     { background: rgba(74,222,128,0.10); color: #4ade80; }
.xai-tag--choice     { background: rgba(167,139,250,0.12); color: #a78bfa; }
.xai-tag--confidence { background: rgba(148,163,184,0.12); color: var(--text-muted); }
.xai-tag--check      { background: rgba(74,201,240,0.10); color: #4cc9f0; }
.xai-tag--style      { background: rgba(226,181,255,0.10); color: var(--accent); }

/* Influence badges */
.xai-influence-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.xai-influence-label { font-size: 10px; color: var(--text-faint); }
.xai-influence-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Details <details> block */
.xai-details-block {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.xai-details-block summary {
  padding: 7px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  cursor: pointer;
  user-select: none;
  background: rgba(0,0,0,0.15);
  list-style: none;
}
.xai-details-block summary::-webkit-details-marker { display: none; }
.xai-details-block summary::before { content: '› '; }
.xai-details-block[open] summary::before { content: '↓ '; }
.xai-details-block > :not(summary) { padding: 0 12px 10px; }

/* Contradiction comparison card */
.xai-contradiction-card {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid transparent;
}
.xai-contra--critical { background: rgba(255,77,109,0.07); border-color: rgba(255,77,109,0.2); }
.xai-contra--minor    { background: rgba(249,168,37,0.07); border-color: rgba(249,168,37,0.2); }

.xai-contra-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.xai-contra-severity {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.xai-contra-severity--critical { background: rgba(255,77,109,0.2); color: #ff4d6d; }
.xai-contra-severity--minor    { background: rgba(249,168,37,0.2); color: #f9a825; }
.xai-contra-field { font-size: 12px; color: var(--text-primary); flex: 1; }
.xai-contra-source { font-size: 10px; color: var(--text-faint); flex-shrink: 0; }

.xai-contra-body {
  display: grid;
  grid-template-columns: 1fr 28px 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.xai-contra-col {
  border-radius: 6px;
  padding: 6px 8px;
}
.xai-contra-col--stored { background: rgba(74,222,128,0.07); }
.xai-contra-col--draft  { background: rgba(255,77,109,0.07); }
.xai-contra-col-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-faint);
  margin-bottom: 3px;
}
.xai-contra-value {
  font-size: 12px;
  color: var(--text-primary);
  word-break: break-word;
}
.xai-contra-divider {
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: #ff4d6d;
}
.xai-contra-explanation {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 6px;
  line-height: 1.5;
}

/* Negotiation bubbles */
.xai-neg-bubble {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.xai-neg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}
.xai-neg-bubble--checker .xai-neg-avatar { background: rgba(76,201,240,0.15); color: #4cc9f0; }
.xai-neg-bubble--reviser .xai-neg-avatar { background: rgba(74,222,128,0.15); color: #4ade80; }

.xai-neg-msg-block {
  flex: 1;
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
.xai-neg-bubble--checker .xai-neg-msg-block { background: rgba(76,201,240,0.07); }
.xai-neg-bubble--reviser .xai-neg-msg-block { background: rgba(74,222,128,0.07); }
.xai-neg-bubble--other .xai-neg-msg-block   { background: rgba(255,255,255,0.04); }

.xai-neg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.xai-neg-agent-name { font-size: 11px; font-weight: 700; color: var(--text-primary); }
.xai-neg-round-label { font-size: 10px; color: var(--text-faint); }
.xai-neg-msg { font-size: 11px; color: var(--text-muted); line-height: 1.5; }
.xai-neg-changes { color: var(--text-primary); font-size: 11px; }
.xai-neg-resolved-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(74,222,128,0.15);
  color: #4ade80;
  margin-left: 4px;
}

.xai-neg-result {
  margin-top: 4px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}
.xai-neg-result--resolved   { background: rgba(74,222,128,0.10); color: #4ade80; }
.xai-neg-result--unresolved { background: rgba(255,77,109,0.10); color: #ff4d6d; }

/* ── Process Live Generation Banner ── */
.process-live-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  margin-bottom: 18px;
  background: linear-gradient(135deg, rgba(46,1,75,0.35), rgba(124,58,237,0.12));
  border: 1px solid rgba(226,181,255,0.22);
  border-radius: 10px;
  position: relative;
  overflow: hidden;
}
.process-live-banner.hidden { display: none; }
.process-live-banner::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -60%;
  width: 40%;
  background: linear-gradient(90deg, transparent, rgba(226,181,255,0.07), transparent);
  animation: plb-shimmer 2.6s ease-in-out infinite;
}
@keyframes plb-shimmer {
  0%   { left: -60%; }
  100% { left: 120%; }
}
.plb-orb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  flex-shrink: 0;
  animation: plb-orb-pulse 1.6s ease-in-out infinite;
}
@keyframes plb-orb-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226,181,255,0.55); opacity: 1; }
  50%       { box-shadow: 0 0 0 7px rgba(226,181,255,0);  opacity: 0.7; }
}
.plb-body { flex: 1; min-width: 0; }
.plb-stage-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 7px;
  letter-spacing: 0.2px;
}
.plb-stages {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.plb-arrow {
  color: var(--text-faint);
  font-size: 11px;
  opacity: 0.5;
}
.plb-s {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--text-faint);
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  transition: all 0.35s ease;
}
.plb-s.done {
  color: #9f7aea;
  background: rgba(124,58,237,0.18);
  border-color: rgba(124,58,237,0.3);
}
.plb-s.active {
  color: var(--accent);
  background: rgba(226,181,255,0.13);
  border-color: rgba(226,181,255,0.35);
  animation: plb-stage-glow 1.5s ease-in-out infinite;
}
@keyframes plb-stage-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226,181,255,0.25); }
  50%       { box-shadow: 0 0 7px rgba(226,181,255,0.45); }
}
.plb-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(226,181,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
  animation: plb-spin 0.85s linear infinite;
}
@keyframes plb-spin {
  to { transform: rotate(360deg); }
}

/* TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
   Audit Tab  Collapsible Cards
   TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT */

.audit-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  transition: border-color 0.2s;
}
.audit-card:hover { border-color: var(--border-light); }
.audit-card.open { border-color: var(--accent); }

.audit-card-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  gap: 12px;
}
.audit-card-header:hover { background: rgba(255,255,255,0.03); }

.audit-card-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.audit-agent-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--bg-primary);
  color: var(--accent);
  border: 1px solid rgba(226,181,255,0.3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 140px;
  text-align: center;
}

.audit-scene-tag {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 600;
  white-space: nowrap;
}

.audit-preview {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
}

.audit-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
}

.audit-stat { display: flex; align-items: center; gap: 4px; }

.audit-chevron {
  font-size: 18px;
  color: var(--text-faint);
  transition: transform 0.2s;
  line-height: 1;
}
.audit-card.open .audit-chevron { transform: rotate(90deg); color: var(--accent); }

.audit-card-body {
  display: none;
  padding: 16px;
  background: rgba(17,17,37,0.4);
  border-top: 1px solid var(--border);
}
.audit-card.open .audit-card-body { display: block; }

.audit-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.audit-detail-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.audit-detail-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-faint);
  letter-spacing: 1px;
}

.audit-detail-content {
  background: #090915;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-mono);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
}

.audit-detail-content.prompt { border-left: 3px solid #3b82f6; }
.audit-detail-content.output { border-left: 3px solid #10b981; }

