/*!
 * Ekko 记忆管理（memory.css）
 * 用官方 CSS 变量取色，深浅主题自动跟随；全部选择器以 .em- 开头，
 * 不污染官方样式。2026-10-26 新建。
 */

#ekko-memory {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary, #fafafa);
  color: var(--text-primary, #1a1a1a);
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif);
  font-size: var(--font-size-base, 14px);
  animation: em-in 0.18s ease-out;
}

@keyframes em-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

html.em-lock,
html.em-lock body {
  overflow: hidden !important;
}

#ekko-memory *,
#ekko-memory *::before,
#ekko-memory *::after {
  box-sizing: border-box;
}

/* ───────────── 顶栏 ───────────── */
#ekko-memory .em-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-color, #e6e6e6);
  background: var(--bg-card, #fff);
}

#ekko-memory .em-back,
#ekko-memory .em-sidebtn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-color, #e6e6e6);
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

#ekko-memory .em-sidebtn { display: none; }

#ekko-memory .em-back:hover,
#ekko-memory .em-sidebtn:hover {
  background: var(--bg-secondary, #f2f2f2);
}

#ekko-memory .em-title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

#ekko-memory .em-title b {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

#ekko-memory .em-title span {
  font-size: 12px;
  color: var(--text-secondary, #8a8a8a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#ekko-memory .em-btn {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-color, #e6e6e6);
  border-radius: 9px;
  background: var(--bg-card, #fff);
  color: inherit;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

#ekko-memory .em-btn:hover:not(:disabled) {
  background: var(--bg-secondary, #f2f2f2);
}

#ekko-memory .em-btn.primary {
  border-color: transparent;
  background: var(--accent-primary, #233176);
  color: #fff;
}

#ekko-memory .em-btn.primary:hover:not(:disabled) {
  background: var(--accent-hover, var(--accent-primary, #233176));
  filter: brightness(1.08);
}

#ekko-memory .em-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ───────────── 主体 ───────────── */
#ekko-memory .em-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

/* 左栏 */
#ekko-memory .em-side {
  flex: 0 0 268px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border-color, #e6e6e6);
  background: var(--bg-card, #fff);
}

#ekko-memory .em-agents {
  flex: 0 0 auto;
  max-height: 44%;
  overflow-y: auto;
  padding: 8px 8px 6px;
  border-bottom: 1px solid var(--border-color, #e6e6e6);
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-secondary, #8a8a8a) 40%, transparent) transparent;
}

#ekko-memory .em-agents::-webkit-scrollbar,
#ekko-memory .em-tree::-webkit-scrollbar { width: 8px; }

#ekko-memory .em-agents::-webkit-scrollbar-thumb,
#ekko-memory .em-tree::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: color-mix(in srgb, var(--text-secondary, #8a8a8a) 32%, transparent);
}

#ekko-memory .em-caption {
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-secondary, #8a8a8a);
}

#ekko-memory .em-agent {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  margin-bottom: 1px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.14s;
}

#ekko-memory .em-agent:hover { background: var(--bg-secondary, #f2f2f2); }

#ekko-memory .em-agent.on {
  background: color-mix(in srgb, var(--accent-primary, #233176) 10%, transparent);
}

#ekko-memory .em-agent.on b { color: var(--accent-primary, #233176); }

#ekko-memory .em-agent i {
  position: absolute;
  left: 0;
  top: 50%;
  width: 3px;
  height: 16px;
  transform: translateY(-50%);
  border-radius: 0 3px 3px 0;
  background: var(--accent-primary, #233176);
}

#ekko-memory .em-agent b { font-weight: 600; }

#ekko-memory .em-agent span {
  font-size: 11px;
  color: var(--text-secondary, #8a8a8a);
}

/* 文件树 */
#ekko-memory .em-tree {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 8px 20px;
}

#ekko-memory .em-newfile {
  width: 100%;
  margin: 2px 0 10px;
  padding: 8px;
  border: 1px dashed var(--border-color, #d8d8d8);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary, #8a8a8a);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

#ekko-memory .em-newfile:hover {
  border-color: var(--accent-primary, #233176);
  color: var(--accent-primary, #233176);
}

#ekko-memory .em-group { margin-bottom: 12px; }

#ekko-memory .em-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: background 0.14s;
}

#ekko-memory .em-file:hover { background: var(--bg-secondary, #f2f2f2); }

#ekko-memory .em-file.on {
  background: color-mix(in srgb, var(--accent-primary, #233176) 12%, transparent);
  color: var(--accent-primary, #233176);
  font-weight: 600;
}

#ekko-memory .em-fname {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

#ekko-memory .em-fmeta {
  flex: 0 0 auto;
  font-size: 10.5px;
  color: var(--text-secondary, #9a9a9a);
  font-weight: 400;
}

#ekko-memory .em-hint,
#ekko-memory .em-empty {
  padding: 10px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary, #8a8a8a);
}

#ekko-memory .em-empty { text-align: center; padding: 28px 12px; }

/* 右栏 */
#ekko-memory .em-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

#ekko-memory .em-filehead {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 42px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color, #e6e6e6);
  background: var(--bg-card, #fff);
  font-size: 12px;
}

#ekko-memory .em-path {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
}

#ekko-memory .em-meta {
  flex: 0 0 auto;
  color: var(--text-secondary, #8a8a8a);
}

#ekko-memory .em-mini {
  flex: 0 0 auto;
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--border-color, #e6e6e6);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-size: 11.5px;
  cursor: pointer;
  transition: background 0.14s;
}

#ekko-memory .em-mini:hover { background: var(--bg-secondary, #f2f2f2); }
#ekko-memory .em-mini.danger { color: var(--error, #d64545); border-color: color-mix(in srgb, var(--error, #d64545) 35%, transparent); }
#ekko-memory .em-mini.danger:hover { background: color-mix(in srgb, var(--error, #d64545) 10%, transparent); }

#ekko-memory .em-editor {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  /* 宽屏下别让一行拉到 1400px——按阅读宽度居中，长文本才好读 */
  padding: 22px max(22px, calc((100% - 940px) / 2)) 64px;
  border: 0;
  outline: none;
  resize: none;
  background: var(--bg-primary, #fafafa);
  color: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.72;
  tab-size: 2;
}

#ekko-memory .em-editor:disabled {
  color: var(--text-secondary, #a0a0a0);
}

/* 版本抽屉 */
#ekko-memory .em-versions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 52%;
  overflow-y: auto;
  display: none;
  padding: 10px 14px 16px;
  border-top: 1px solid var(--border-color, #e6e6e6);
  background: var(--bg-card, #fff);
  box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.08);
}

#ekko-memory .em-versions.show { display: block; }

#ekko-memory .em-verbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#ekko-memory .em-ver {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: 12px;
}

#ekko-memory .em-ver:hover { background: var(--bg-secondary, #f2f2f2); }

#ekko-memory .em-ver span {
  flex: 0 0 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
}

#ekko-memory .em-ver em {
  flex: 1 1 auto;
  font-style: normal;
  font-size: 11px;
  color: var(--text-secondary, #8a8a8a);
}

/* toast */
#ekko-memory .em-toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translate(-50%, 12px);
  max-width: 80vw;
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(24, 24, 24, 0.92);
  color: #fff;
  font-size: 12.5px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100001;
}

#ekko-memory .em-toast.show { opacity: 1; transform: translate(-50%, 0); }
#ekko-memory .em-toast.bad { background: rgba(190, 48, 48, 0.94); }

/* ───────────── 移动端 ───────────── */
@media (max-width: 820px) {
  #ekko-memory .em-sidebtn { display: flex; align-items: center; justify-content: center; }
  #ekko-memory .em-title span { display: none; }

  #ekko-memory .em-side {
    position: absolute;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 84%;
    max-width: 320px;
    z-index: 20;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: 12px 0 30px rgba(0, 0, 0, 0.14);
  }

  #ekko-memory.side-open .em-side { transform: none; }

  #ekko-memory .em-body { position: relative; }
  #ekko-memory .em-editor { padding: 16px 14px 80px; font-size: 13.5px; }
  #ekko-memory .em-filehead { padding: 0 12px; gap: 8px; }
  #ekko-memory .em-filehead .em-meta { display: none; }
  #ekko-memory .em-btn { padding: 0 12px; }
}
