/* ═══ AI Memory Platform - Styles ═══ */

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #232733;
  --bg-hover: #262a36;
  --border: #2d3148;
  --text: #e4e6f0;
  --text-dim: #8b8fa3;
  --text-muted: #5c6078;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --accent-bg: rgba(108,92,231,.12);
  --green: #00b894;
  --green-bg: rgba(0,184,148,.12);
  --red: #ff6b6b;
  --red-bg: rgba(255,107,107,.12);
  --orange: #fdcb6e;
  --blue: #74b9ff;
  --blue-bg: rgba(116,185,255,.12);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,.3);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --sidebar-w: 220px;
  --transition: .2s ease;
}

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

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); overflow: hidden; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ═══ SCREENS ═══ */
.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

/* ═══ AUTH ═══ */
#auth-screen {
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, rgba(108,92,231,.15) 0%, var(--bg) 70%);
}
.auth-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px;
  padding: 48px 40px; width: 400px; text-align: center; box-shadow: var(--shadow);
}
.auth-logo { font-size: 48px; margin-bottom: 16px; }
.auth-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.auth-sub { color: var(--text-dim); font-size: 14px; margin-bottom: 32px; }

.auth-tabs { display: flex; gap: 0; margin-bottom: 24px; background: var(--bg-input); border-radius: var(--radius-sm); padding: 3px; }
.auth-tabs .tab {
  flex: 1; padding: 10px; border: none; background: none; color: var(--text-dim);
  font-size: 14px; font-weight: 500; cursor: pointer; border-radius: var(--radius-sm); transition: var(--transition);
}
.auth-tabs .tab.active { background: var(--accent); color: #fff; }

.auth-form { display: none; flex-direction: column; gap: 12px; }
.auth-form.active { display: flex; }
.auth-form input {
  padding: 12px 16px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px; outline: none; transition: var(--transition);
}
.auth-form input:focus { border-color: var(--accent); }

.btn-primary {
  padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer; transition: var(--transition);
}
.btn-primary:hover { background: var(--accent-light); }
.btn-outline {
  padding: 8px 16px; background: transparent; color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; transition: var(--transition);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm {
  padding: 6px 14px; background: var(--accent-bg); color: var(--accent-light); border: none;
  border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; transition: var(--transition);
}
.btn-sm:hover { background: var(--accent); color: #fff; }
.btn-icon {
  width: 28px; height: 28px; background: none; border: none; color: var(--text-dim);
  cursor: pointer; border-radius: var(--radius-sm); font-size: 16px; transition: var(--transition);
}
.btn-icon:hover { color: var(--text); background: var(--bg-hover); }

.error-msg { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 20px; }

/* ═══ APP LAYOUT ═══ */
#app-screen { flex-direction: row; }

/* Sidebar */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w); height: 100vh;
  background: var(--bg-card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.sidebar-header { display: flex; align-items: center; gap: 10px; padding: 4px 8px; margin-bottom: 24px; }
.sidebar-header .logo { font-size: 24px; }
.sidebar-header .title { font-size: 16px; font-weight: 700; }
.nav-items { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: none;
  background: none; color: var(--text-dim); font-size: 13px; font-weight: 500;
  cursor: pointer; border-radius: var(--radius-sm); transition: var(--transition); text-align: left;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent-light); }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; }

/* Content */
#content { flex: 1; height: 100vh; overflow: hidden; position: relative; }
.view { display: none; height: 100%; flex-direction: column; }
.view.active { display: flex; }

.view-header {
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-shrink: 0;
}
.view-header h2 { font-size: 18px; font-weight: 600; white-space: nowrap; }

/* ═══ CHAT ═══ */
.chat-controls { display: flex; gap: 12px; align-items: center; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.toggle input { accent-color: var(--accent); }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px;
}
.msg {
  max-width: 80%; padding: 14px 18px; border-radius: 16px; font-size: 14px;
  line-height: 1.65; word-wrap: break-word; animation: fadeIn .3s ease;
}
.msg.user {
  align-self: flex-end; background: var(--accent); color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.assistant .msg-content { white-space: pre-wrap; }
.msg.assistant .msg-meta {
  display: flex; gap: 12px; margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border); font-size: 11px; color: var(--text-muted);
}
.msg.assistant .msg-meta button {
  background: none; border: none; color: var(--accent-light); cursor: pointer;
  font-size: 11px; padding: 0;
}
.msg.assistant .msg-meta button:hover { text-decoration: underline; }

.msg-thinking { color: var(--text-dim); font-style: italic; }
.cursor-blink::after {
  content: '▍'; color: var(--accent-light); animation: blink 1s infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.chat-input {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; gap: 12px; align-items: flex-end; flex-shrink: 0;
}
.chat-input textarea {
  flex: 1; padding: 12px 16px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px; font-family: var(--font);
  resize: none; outline: none; max-height: 150px; transition: var(--transition);
}
.chat-input textarea:focus { border-color: var(--accent); }
.btn-send {
  width: 44px; height: 44px; background: var(--accent); border: none; border-radius: var(--radius);
  color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition);
  flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-light); }
.btn-send:disabled { opacity: .5; cursor: not-allowed; }

/* Sources Panel */
.sources-panel {
  position: absolute; right: 0; top: 60px; bottom: 76px; width: 360px;
  background: var(--bg-card); border-left: 1px solid var(--border);
  overflow-y: auto; z-index: 10; box-shadow: -4px 0 24px rgba(0,0,0,.3);
}
.sources-panel.hidden { display: none; }
.sources-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--border); }
.sources-header h3 { font-size: 14px; }
.sources-list { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.source-card {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; cursor: pointer; transition: var(--transition);
}
.source-card:hover { border-color: var(--accent); }
.source-card.active { border-color: var(--accent); background: var(--accent-bg); }
.source-card .source-title { font-size: 12px; font-weight: 600; color: var(--accent-light); margin-bottom: 4px; }
.source-card .source-chunk { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.source-card .source-score {
  font-size: 11px; color: var(--green);
  display: inline-block; padding: 2px 6px; background: var(--green-bg); border-radius: 4px;
}
.source-highlight {
  background: rgba(108,92,231,.25); border-left: 3px solid var(--accent);
  padding: 2px 4px; border-radius: 2px; transition: var(--transition);
}

/* ═══ GRAPH ═══ */
.graph-controls { display: flex; gap: 8px; align-items: center; }
.input-sm {
  padding: 6px 12px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 13px; outline: none; width: 200px;
}
.input-sm:focus { border-color: var(--accent); }
.graph-container { flex: 1; position: relative; background: var(--bg); }
.graph-details {
  position: absolute; right: 16px; top: 76px; width: 320px; max-height: 60vh;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-y: auto; z-index: 10; box-shadow: var(--shadow);
}
.graph-details.hidden { display: none; }
.detail-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.detail-header h3 { font-size: 14px; }
#detail-body { padding: 14px 16px; font-size: 13px; line-height: 1.6; }
#detail-body .entity-type {
  display: inline-block; padding: 2px 8px; background: var(--accent-bg);
  color: var(--accent-light); border-radius: 4px; font-size: 11px; margin-bottom: 8px;
}
#detail-body .relation-item {
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 12px;
}
#detail-body .relation-item:last-child { border-bottom: none; }
#detail-body .rel-type { color: var(--orange); font-weight: 600; }
#detail-body .rel-entity { color: var(--blue); cursor: pointer; }
#detail-body .rel-entity:hover { text-decoration: underline; }

/* ═══ DOCUMENTS ═══ */
.dropzone {
  margin: 16px 24px; border: 2px dashed var(--border); border-radius: var(--radius);
  transition: var(--transition); position: relative; min-height: 180px;
}
.dropzone.drag-over { border-color: var(--accent); background: var(--accent-bg); }
.dropzone-inner {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px; gap: 12px; color: var(--text-dim);
}
.dropzone-inner p { font-size: 15px; font-weight: 500; }
.dropzone-sub { font-size: 12px; color: var(--text-muted); }

.upload-progress {
  position: absolute; bottom: 0; left: 0; right: 0; padding: 12px 16px;
  background: var(--bg-card); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
}
.upload-progress.hidden { display: none; }
.progress-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.progress-item .progress-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-item .progress-status { font-size: 11px; }
.progress-item .progress-status.ok { color: var(--green); }
.progress-item .progress-status.err { color: var(--red); }
.progress-bar { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--accent); transition: width .3s; }

.doc-actions { padding: 0 24px; display: flex; gap: 8px; }
.doc-list { flex: 1; overflow-y: auto; padding: 16px 24px; display: flex; flex-direction: column; gap: 8px; }
.doc-card {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: var(--transition);
}
.doc-card:hover { border-color: var(--accent); }
.doc-icon { font-size: 24px; flex-shrink: 0; }
.doc-info { flex: 1; min-width: 0; }
.doc-info .doc-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-info .doc-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.doc-status {
  font-size: 11px; padding: 3px 8px; border-radius: 4px; flex-shrink: 0;
}
.doc-status.completed { background: var(--green-bg); color: var(--green); }
.doc-status.processing { background: var(--orange); color: #000; }
.doc-status.failed { background: var(--red-bg); color: var(--red); }

/* Modals */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
  align-items: center; justify-content: center; z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; width: 500px; max-width: 90vw; display: flex; flex-direction: column; gap: 14px;
}
.modal-content h3 { font-size: 16px; }
.input-full {
  padding: 10px 14px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px; font-family: var(--font); outline: none;
}
.input-full:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ═══ PALACE ═══ */
.palace-list { flex: 1; overflow-y: auto; padding: 16px 24px; display: flex; flex-wrap: wrap; gap: 16px; }
.palace-card {
  width: 280px; padding: 20px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: var(--transition);
}
.palace-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.palace-card h4 { font-size: 15px; margin-bottom: 6px; }
.palace-card p { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.palace-card .palace-stats { display: flex; gap: 12px; font-size: 11px; color: var(--text-muted); }

.palace-walk {
  position: absolute; right: 0; top: 60px; bottom: 0; width: 420px;
  background: var(--bg-card); border-left: 1px solid var(--border);
  overflow-y: auto; z-index: 10; box-shadow: -4px 0 24px rgba(0,0,0,.3);
}
.palace-walk.hidden { display: none; }
.walk-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--border); }
.walk-body { padding: 16px; }
.walk-room { margin-bottom: 20px; }
.walk-room h4 { font-size: 14px; color: var(--accent-light); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.walk-room h4 .room-badge { font-size: 10px; padding: 2px 6px; background: var(--accent-bg); border-radius: 4px; }
.walk-locus { padding: 10px 12px; background: var(--bg-input); border-radius: var(--radius-sm); margin-bottom: 8px; }
.walk-locus .locus-name { font-size: 12px; font-weight: 600; color: var(--orange); margin-bottom: 4px; }
.walk-memory { font-size: 12px; color: var(--text-dim); padding: 4px 0; }

/* ═══ MEMORY BANK ═══ */
.bank-tabs { display: flex; gap: 4px; }
.bank-tab {
  padding: 6px 14px; background: none; border: 1px solid var(--border);
  color: var(--text-dim); font-size: 12px; cursor: pointer;
  border-radius: var(--radius-sm); transition: var(--transition);
}
.bank-tab.active { background: var(--accent-bg); color: var(--accent-light); border-color: var(--accent); }
.bank-tab:hover { border-color: var(--accent); }

.bank-panel { display: none; flex: 1; overflow-y: auto; padding: 16px 24px; }
.bank-panel.active { display: block; }

.bank-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 8px; transition: var(--transition);
}
.bank-item:hover { border-color: var(--accent); }
.bank-item-icon { font-size: 20px; flex-shrink: 0; width: 36px; text-align: center; }
.bank-item-body { flex: 1; min-width: 0; }
.bank-item-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bank-item-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.bank-item-actions { display: flex; gap: 4px; flex-shrink: 0; }
.bank-item-actions button { font-size: 11px; padding: 4px 10px; }

.bank-badge {
  display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 10px; font-weight: 600;
}
.bank-badge.episodic { background: var(--blue-bg); color: var(--blue); }
.bank-badge.semantic { background: var(--green-bg); color: var(--green); }
.bank-badge.procedural { background: var(--orange); color: #000; }
.bank-badge.emotional { background: var(--red-bg); color: var(--red); }
.bank-badge.v { background: var(--accent-bg); color: var(--accent-light); }

.modal-wide { width: 700px; max-height: 80vh; overflow-y: auto; }

.cascade-impact { margin: 12px 0; }
.cascade-impact h4 { font-size: 13px; margin-bottom: 8px; color: var(--text); }
.cascade-item {
  padding: 8px 12px; background: var(--bg-input); border-radius: var(--radius-sm);
  margin-bottom: 4px; font-size: 12px; display: flex; justify-content: space-between; align-items: center;
}
.cascade-item .cascade-label { color: var(--text-dim); }
.cascade-item .cascade-value { color: var(--text); font-weight: 500; }
.cascade-warning {
  padding: 10px 14px; background: var(--red-bg); border: 1px solid rgba(255,107,107,.3);
  border-radius: var(--radius-sm); font-size: 12px; color: var(--red); margin: 8px 0;
}
.cascade-recommendation {
  padding: 10px 14px; background: var(--green-bg); border: 1px solid rgba(0,184,148,.3);
  border-radius: var(--radius-sm); font-size: 12px; color: var(--green); margin: 8px 0;
}
.cascade-options label {
  display: flex; align-items: center; gap: 8px; padding: 6px 0;
  font-size: 13px; color: var(--text-dim); cursor: pointer;
}
.cascade-options input[type="checkbox"] { accent-color: var(--accent); }

/* Version History */
.version-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.version-entry {
  padding: 12px 14px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); display: flex; align-items: center; gap: 12px;
}
.version-entry:hover { border-color: var(--accent); }
.version-num {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-bg); color: var(--accent-light); border-radius: 50%;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.version-info { flex: 1; }
.version-info .v-type { font-size: 12px; font-weight: 600; }
.version-info .v-type.create { color: var(--green); }
.version-info .v-type.update { color: var(--blue); }
.version-info .v-type.delete { color: var(--red); }
.version-info .v-type.restore { color: var(--orange); }
.version-info .v-reason { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.version-info .v-meta { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.version-actions { display: flex; gap: 4px; }

.diff-block { margin: 12px 0; }
.diff-field { font-size: 12px; font-weight: 600; color: var(--text); margin: 8px 0 4px; }
.diff-old {
  padding: 8px 12px; background: rgba(255,107,107,.1); border-left: 3px solid var(--red);
  font-size: 12px; color: var(--text-dim); margin-bottom: 4px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  white-space: pre-wrap; word-break: break-word;
}
.diff-new {
  padding: 8px 12px; background: rgba(0,184,148,.1); border-left: 3px solid var(--green);
  font-size: 12px; color: var(--text); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  white-space: pre-wrap; word-break: break-word;
}

/* History timeline */
.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-entry {
  display: flex; gap: 12px; padding: 10px 14px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 12px;
  align-items: center;
}
.history-entry .h-icon { font-size: 16px; flex-shrink: 0; }
.history-entry .h-body { flex: 1; }
.history-entry .h-title { font-weight: 500; }
.history-entry .h-meta { color: var(--text-dim); font-size: 11px; margin-top: 2px; }

/* ═══ KEYS ═══ */
.keys-grid { display: flex; gap: 24px; padding: 16px 24px; flex: 1; overflow-y: auto; }
.keys-section { flex: 1; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-header h3 { font-size: 15px; }
.keys-list { display: flex; flex-direction: column; gap: 8px; }
.key-card {
  padding: 14px 16px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); display: flex; flex-direction: column; gap: 6px;
}
.key-card .key-name { font-size: 13px; font-weight: 600; }
.key-card .key-value { font-size: 12px; font-family: var(--mono); color: var(--text-dim); }
.key-card .key-meta { font-size: 11px; color: var(--text-muted); display: flex; gap: 12px; }
.key-card .key-actions { display: flex; gap: 6px; margin-top: 4px; }
.key-card .key-actions button { font-size: 11px; }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  #sidebar { width: 60px; min-width: 60px; padding: 12px 6px; }
  .sidebar-header .title, .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .sources-panel, .palace-walk { width: 100%; }
  .keys-grid { flex-direction: column; }
  .graph-details { width: 260px; }
}

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