.memory-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
}

.memory-button:hover {
  background: var(--panel-soft);
}

.memory-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
}

.memory-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .58);
}

.memory-panel {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(760px, calc(100dvh - 40px));
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px var(--shadow);
  overflow: hidden;
}

.memory-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.memory-header h2,
.memory-body h3 {
  margin: 0;
  letter-spacing: 0;
}

.memory-header h2 {
  font-size: 18px;
}

.memory-close,
.memory-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  min-height: 38px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
}

.memory-close:hover,
.memory-delete:hover {
  background: var(--panel-soft);
}

.memory-body {
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.memory-body h3 {
  margin-top: 18px;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--muted);
}

.memory-body h3:first-of-type {
  margin-top: 0;
}

.memory-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  margin-bottom: 10px;
}

.memory-section-header:first-of-type {
  margin-top: 0;
}

.memory-section-header h3 {
  margin: 0;
}

.memory-status {
  min-height: 20px;
  color: var(--danger);
}

.memory-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.memory-list {
  display: grid;
  gap: 10px;
}

.memory-manual,
.memory-confirm {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #171615;
}

.memory-confirm h3,
.memory-manual h3 {
  margin: 0;
  color: var(--text);
  font-size: 15px;
}

.memory-textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}

.memory-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.memory-add,
.memory-primary,
.memory-secondary {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
}

.memory-add,
.memory-secondary {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

.memory-primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #111;
  font-weight: 700;
}

.memory-add:hover,
.memory-secondary:hover {
  background: var(--panel-soft);
}

.memory-entry,
.memory-empty {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #171615;
}

.memory-entry-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.memory-key {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.memory-entry-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.memory-empty,
.memory-updated {
  color: var(--muted);
}

.memory-updated {
  font-size: 12px;
}

.memory-modal-open {
  overflow: hidden;
}

@media (max-width: 640px) {
  .memory-section-header,
  .memory-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .memory-add,
  .memory-primary,
  .memory-secondary {
    width: 100%;
  }
}
